Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Enemy Movement

Author
Message
Darth Gazak
16
Years of Service
User Offline
Joined: 13th Jan 2009
Location:
Posted: 29th Jan 2009 11:26
Hello again,

I managed to overcome my main program loop problem, and spawn ten enemies along the right edge of the screen at random y coordinates (Thanks to BN2 Productions and Ashingda for their assistance)

However, i am now having trouble making the enemy sprites move. I use a loop to spawn the sprites (numbered from 2 - 11, as sprite number 1 is the player ship) yet when i try and make them move using another loop (to correspond with the numbering) i get an error, stating 'BOB DOES NOT EXIST AT LINE 115'. I know this is something to do with the numbering being inaccurate, and DB trying to move a sprite which doesn't exist. The code will show it better:



I hope you can understand what i am trying to achieve here. Thanks in advance for any help you can offer.

Darth Gazak
Ashingda 27
17
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 29th Jan 2009 15:05 Edited at: 29th Jan 2009 15:09
The value of current_enemy is too large. First it's asigned = 2 then it's inc in a loop of 10. When looping to move enemies, it is 12 and that is 2 more than there are sprites.

Remember to reset your increasing values. Inside the Spawn_Enemies subroutine:



You seem to have an ENDIF out of place?


It might be that you may have had a check there befor it was removed. Anyhow a IF SPRITE EXIST() would be good there as well to check if the sprite exist befor attempting to move it and not being sure if it still exist, it might have been shot and died.

Another thing, the 2 should be 1, it's best to loop through the same amount of times while moving as it took to spawn it. current_enemy can also simply be 10 or a variable that holds the max for both loops such as Max_Enemy for example.

Darth Gazak
16
Years of Service
User Offline
Joined: 13th Jan 2009
Location:
Posted: 30th Jan 2009 12:29
Hello,
Thanks for your help, i took what you said into account and implemented it into my program, yet I still have a problem; none of the enemy sprites appear on the screen, never mind moving! I realise this may be because i haven't used the sync command, but i'm still unsure about how to use it correctly.

Here's the code, it is error free but doesn't display the enemy sprites:


Could someone try and solve the problem, or help me implement the sync command correctly.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 31st Jan 2009 03:48
in your original thing the reason you were getting that error was you had it inc the current_Enemy variable after it makes the sprite every time witch means that all you have to do to make the old one work is instead of inc before you call the sprite command

so the starting value of current_Enemy would need to be one instead of 2 or make it zero for your second variation of the code.

then you wouldn't get that error.

the reason it's doing that is because when it makes the last sprite it inc again so that number is 2 extra then how many are out there because that equals 12 when moving you encounter problems because your using 12 as the number of sprites. though sprite exist command does solve thta and other problems when you add other sprites that are past the sprite number of the enemies

and when you moved sprites you start with sprite one which you said was the player so I'm not sure how that works
Ashingda 27
17
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 31st Jan 2009 05:31 Edited at: 31st Jan 2009 05:41
In your Spawn routine you can use the variable in the FOR..Next statement instead of current_enemy.

At the end of that loop, the variable i will be 10 thus going from 1 to 10. You can then simply current_enemy = i.

While setting a random value for the Y, it will assign Y a random value only one time. So if you create 10 enemies after Y=RND(x) then all the enemies will have the same Y. You must put Y inside the For..Next loop to assign a new random Y for each enemy.


The default display mode will be set to 640x480 16bit if you dont manually set it yourself. Your previous value of Y=RND(600) X=700 was too high.

While moving the sprites you can use the same For..Next as when you spawn them.


You do not need to reset a variable befor using it in a For..Next. That statement will set and change the variable.


To have your Grand2 have the same x,y position as the mouse it's easier to do it this way.

Note that you can also use the mouse functions directly:



To sync properly make sure you have this at or near the top of the page:

Then in your main loop have it right befor you loop. You may also want a cls at the very end or very beginning.


Lastly you might want to go here. Could save you alot of time and headaches.
http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10
Darth Gazak
16
Years of Service
User Offline
Joined: 13th Jan 2009
Location:
Posted: 5th Feb 2009 11:06
I cannot thank you enough for your help Ashingda, you have truly helped me out of a hole here.

After a bit of fiddling, i managed to implement the sync command. I couldn't get my background to appear, but that isn't a problem, i just removed it and it worked perfectly. Now 10 enemy sprites spawn at random Y coordinates (albeit they overlap, but i will look at your previous suggestions on ways to counter this) and move across the screen. I also used your mouse control advice, which solved the problem of sluggish movement. Genius!

These are the things that remain to be implemented:

1. Non overlapping enemy sprites
2. Sprites spawning in waves
3. Collision detection
4. Timer to derive a score from

Thanks again for your assistance, i won't hesitate to post again if i encounter problems in any of these remaining tasks.

Thank you!
Darth Gazak
PackRat
18
Years of Service
User Offline
Joined: 12th Apr 2007
Location: U.S.
Posted: 14th Feb 2009 11:55
@Darth Gazak

You can use make object plain object number,width,height and texture it with your background image then adjust it to the camera. Doing this gives you some pretty cool options for level changes, etc. (e.g. rolling the completed level out of view then texturing it with your next level background and rolling it back into view).

Login to post a reply

Server time is: 2025-05-18 03:06:35
Your offset time is: 2025-05-18 03:06:35