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.

2D All the way! / enemy shooting

Author
Message
AluminumPork
20
Years of Service
User Offline
Joined: 28th Oct 2003
Location: Duluth, MN, USA
Posted: 5th Nov 2003 03:31
wow, i'm asking alot of questions on here. oh well. anywayz, my game is coming along nicely. i now designate the formation of guys in each wave using a "data" statement and reading it all into an array.
by assigning different numbers in the array i can assign different fire rates of the enemies. how can i have each any have their own firing rate? there are going to be 8-10 enemies on the screen at once. they each have their own x,y variables, shootspeed variables, and ship type variables. and each one has it's very own sprite. any code examples that might help me out?
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 5th Nov 2003 06:29
you need a variable for a shot_timer and a shot_timer_set for each enemy. I don't know if your using arrays or types for the enemy but I'll assume types

after enemy shoots set the shot_timer to the timer()
assuming you have a function for shooting insert

function shoot(enemy_number)
enemy(enemy_number).shot_timer = timer()
endfunction

then check the time lapsed since the last shot to the shot_timer_set to see if it's time to shoot again, you need a loop to loop though how every many enemies there are.

for enemy = 0 to 9
if timer() - enemy(enemy).shot_timer then shoot(enemy)
next enemy

something like that will work well for you.

CTP
AluminumPork
20
Years of Service
User Offline
Joined: 28th Oct 2003
Location: Duluth, MN, USA
Posted: 5th Nov 2003 07:59
alright... i have used that method in qb, but can't seem to get it to work here... here is what my example code looked like, but it just keeps print "shoot" with no time in between, really don't understand why
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 8th Nov 2003 16:19
your logic is fine, the problem is --
you dim 9 slots --- dim enemyshot_timer(9)
which are defined in DB as 0 - 8
you then try to assign something to slot 9 which doesn't exist --- for maketime = 1 to 9
you the try to access 10 slots after you only assigned 9 slots --- for enemy = 0 to 9

heres the code with the timer randomly set 0 to 4999

db should crash when you try to acess memory slots that don't exist but it doesn't, just gives eractic results which make debuging very tough.

CTP
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 8th Nov 2003 17:49
Not sure about DB producing bad results from using slot (9). I always use 1-9 rather than 0-8 or even 0-9. I have other languages that allow the use of slot (9) as well. I just tested it, and everything seems to work fine with slot (9).

Pincho.
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 9th Nov 2003 04:51
DBP produces bad results for me, don't know about dbc.

Login to post a reply

Server time is: 2024-04-27 23:38:45
Your offset time is: 2024-04-27 23:38:45