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 Professional Discussion / A small challenge

Author
Message
DivW
22
Years of Service
User Offline
Joined: 31st Jul 2003
Location: Scotland
Posted: 30th Aug 2003 22:58
Here's a wee challenge. Can anyone hel me debug this code? It's supposed to shoot bullets from the front of the ship but it doesn't work. The bullet's locked in the Upper Left Corner of the Screen, and Space bar does nothing. It's supposed to have varous fire modes, but i'm working on a test baddie just now. Gotta go please post if ya can figure this blighter out.

Your soul...it tastes like chicken
Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 30th Aug 2003 23:49
you might like to alter that bulletposx# to bulletposx#(i) for a start


Mentor.
DivW
22
Years of Service
User Offline
Joined: 31st Jul 2003
Location: Scotland
Posted: 2nd Sep 2003 14:36
Ok i fixed those variable names. But i'm still having trouble with it. I can see the bullet at the top left side of the screen and it just sits there, not moving. Everthing else works. The Spacebar doesn't seem to do anything. I havn't got my code or my screen shots here or i'd post them, so i'll just edit the code from my previous post to the way i have it at home. I do't know if it's important but it's a side scroller i'm trying to develop, the bullets are supossed to move from the left side of the screen to the right. Well anyway if you can help me debug this little get then i'll be a happy man.

-DivW

PS: Thanks mentor for ur help so far!

Your soul...it tastes like chicken
the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 2nd Sep 2003 23:17 Edited at: 2nd Sep 2003 23:19
Dbpros usless error checking strikes again.

You are diming the array with dim bulletnumber(20)
and in the main loop you where using
for i = 500 to 520
if bulletnumber(i)=1 then
next i
You should be useing
for i = 500 to 520
if bulletnumber(i-500)=1 then
next i

Dbpro should really give an error if you try and access an array outside of its dimensions but doesn't.

I fixed the code but you need to re-think it as all 20 bullets get fired at the same time.

Edit: I accidently left some code in which makes some images so I didn't need any media and some code that uses text to show the contents of an array. Just remove it, it's not needed.
DivW
22
Years of Service
User Offline
Joined: 31st Jul 2003
Location: Scotland
Posted: 3rd Sep 2003 02:21
Thanks...i havn't tested the code yet but what you'v said does make a lot of sense. I'm gonna go and Try it now and say what happens in a minute. If it doesn't work then i'llpost, and if it does then i'll post anyway. Would a simple wait command stop all the bullets from firing at once? I'll test it all out, see what happens, Try some algorithms, and repost either when i get stuck or fix it. Thanks Peeps!

-DivW

Your soul...it tastes like chicken
DivW
22
Years of Service
User Offline
Joined: 31st Jul 2003
Location: Scotland
Posted: 3rd Sep 2003 03:05
Ok, i can't figure out a way of getting them to shoot seperately. So i need some ideas. I thought it might be possible that, instead if having it going "for i=500 to 520" you could have a sort of:

If i=20 then i=1
REM Shooting Function
if spacekey()=1
i=i+1
if bulletnumber(i-500)=0
bulletnumber(i-500)=20
bulletposx#(i-500)=x#
bulletposy#(i-500)=y#
endif
endif

But i can't get this to work properly...well ok i havn't tested it that's because i'm still not sure how it works. If i could get it to work fully, to shoot a stream of bullets, i could figure it all out. Here's my code so far in case anyone needs it. Ok thanks very much see u later -DivW

Your soul...it tastes like chicken
the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 3rd Sep 2003 06:35 Edited at: 3rd Sep 2003 06:37
No doubt there are a few ways you could do it, the method that comes to my mind would be to use the timer().
Store the timer the game runs.
check the difference between the current timer() result and the stored on and shoot another bullet if the difference is great enough. Then store the results of timer() again and repeat.

You also need to check if the bullets are off screen or have hit anything then either delete the sprites or hide them off screen for re-use.
DivW
22
Years of Service
User Offline
Joined: 31st Jul 2003
Location: Scotland
Posted: 3rd Sep 2003 16:30
A timer eh? Thanks, i'll give that a try. I've used them in visual basic so i have a small idea of what they are, but i'll figure it out when i get home. I'm guessing you's put the If statement around the "Next i" part? It'll be a while before i get home to my code, so i thought i'd post just now. Ta all -DivW

Your soul...it tastes like chicken
DivW
22
Years of Service
User Offline
Joined: 31st Jul 2003
Location: Scotland
Posted: 4th Sep 2003 03:19
Righto. I've been messing around with this all night long, and i've ran into a few problems. I can't seem to get it to work. I managed to get the delete off screen bullets command to work, but i'm having a lot of trouble with Timers. What i think i know:
Timers are set to a specific time. They will always incriment at the same time, so can be used to record times and find time difference instead of having to use the wait command, which pauses the program. I tried putting the "Next i" Part of the code into the Loop Marked with REMSTART/END in the code, but that didn't work, it gave an error saying the code was in the wrong place. The way the code is now gives an error message around line 163, saying that the command's out of place. But i can't seem to see anything wrong and it worked before, so i'm going to assume that this is just another useless DBP error message. Well anyway please post and give me a hand cos if you don't i'll use the crying smiley. Here's a demo- do you think you could take more than 5 of those? lol Please post -DivW

PS Thanks for your help so far peeps.

Your soul...it tastes like chicken
the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 4th Sep 2003 03:54
The timer() command returns a number that increases a thousand times a second. So if you do

it will do stuff after a seccond has passed since it last did stuff.

I changed the code a little and it now fires once every 250ms.
DivW
22
Years of Service
User Offline
Joined: 31st Jul 2003
Location: Scotland
Posted: 8th Sep 2003 18:02
Thanks. I'll try this out.

Your soul...it tastes like chicken

Login to post a reply

Server time is: 2026-07-25 08:13:27
Your offset time is: 2026-07-25 08:13:27