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.

Newcomers DBPro Corner / when I shoot everything stops

Author
Message
soapyfish
20
Years of Service
User Offline
Joined: 24th Oct 2003
Location: Yorkshire, England
Posted: 17th Nov 2003 21:57 Edited at: 17th Nov 2003 21:58
Hi all ,I'm making a game and everythings fine (apart from the code being a little messy). My prolem is that when I press the spacebar to shoot the program goes to a sub-routine and stops the rest of the program until the sub-routine has finished.Heres the code so far. Any help will be really appreciated.Thanks.


"fireball"
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 17th Nov 2003 22:49
this will give the same effect as the logic of your code seems to be trying to provide, as long as the spacekey is pressed then the bullet will go up the screen, when you release the key it will disapear, if thats what you intended then thats what this code will do, put the sync at the end of the loop is the best bet, then you can be sure you have drawn everything before the sync.
I just changed the code so that if the fire key is pressed then the bullet move routine will be called and the position updated on every pass, so it only alters the bullet by one position per loop and the rest of the main loop can run at the same time.

do
`player movement
if spacekey()=1 then fired=1
if leftkey()=1 then plx=plx-5
if rightkey()=1 then plx=plx+5
if plx<=0 then plx=0
if plx>=640 then plx=640
sprite 1,plx,400,1
sprite 3,plx,buly,3
`enemy movement
eny=eny+4
if eny>=500
eny=0
enx=(rnd(640))
endif
sprite 2,enx,eny,2
if fired=1 then gosub bullpos
sync
loop

bulpos:
sprite 3,plx,buly,3
if spacekey()=1 then show sprite 3
buly=buly-10
if buly=0 then buly=390
if spacekey()=0
hide sprite 3
fired=0
endif
return

If this isn`t what you where trying to do then a better description of the effect you wanted would be a help, note that when the key is released then the fired value gets set to zero to prevent the routine from being called every loop, cheers.

Mentor.
soapyfish
20
Years of Service
User Offline
Joined: 24th Oct 2003
Location: Yorkshire, England
Posted: 18th Nov 2003 19:52
Thanks, what I meant was that when the program goes to the sub routine it ignores the rest of the program. (Player movement , enemy movement etc) until the sub routine is over. Is there anybody who knows a way round this problem.

"fireball"
Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 18th Nov 2003 20:19
Subroutines should be treated as parts of code that are excecuted and then the program returns to the loop. There should never be syncs in your game other than you main loop.

Xander - Bolt Software

Why do the antagonists always have to look so cool?
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 18th Nov 2003 20:24
in your main loop see if the bullet object exists, if it does then increment it's movement, along with player and enemies, if it doesn't exist don't execute it's movements

-RUST-
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th Nov 2003 22:25
In simple terms...

if your bullet takes 10 steps to get from the gun to the target, you are effectively stopping your program for 10 cycles.

Your bullet subroutine should be called once every cycle. If there is a bullet in the air, it should move it one more step, and only one step.

Here's an example...

Do forever
Walk a bit
move alien a bit
move bullets a bit
loop


What you are effectively doing is:


Do forever
Walk a bit
move alien a bit
move bullets a bit
move bullets a bit
move bullets a bit
move bullets a bit
move bullets a bit
move bullets a bit
move bullets a bit
move bullets a bit
move bullets a bit
move bullets a bit
loop

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
Magpie
21
Years of Service
User Offline
Joined: 16th Jul 2003
Location: Otherland! Cos it rocks!
Posted: 18th Nov 2003 22:46
Or, better yet, use flags.


Click image to see screenshots...
soapyfish
20
Years of Service
User Offline
Joined: 24th Oct 2003
Location: Yorkshire, England
Posted: 18th Nov 2003 23:02
I sort of understand what BatVink mes but if omeone could put an example in code so I knew al the syntax that would be a massive help,thanks.

"fireball"
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 18th Nov 2003 23:05
DUH! that WAS an example? didn`t it work?

Mentor.
soapyfish
20
Years of Service
User Offline
Joined: 24th Oct 2003
Location: Yorkshire, England
Posted: 18th Nov 2003 23:16 Edited at: 18th Nov 2003 23:17
I don't know if it works or not because I don't know how to put it into my code so all the syntax is right.

"fireball"
soapyfish
20
Years of Service
User Offline
Joined: 24th Oct 2003
Location: Yorkshire, England
Posted: 19th Nov 2003 23:28
Its okay now I looked at all the posts a bit more closely and have sorted my problems.Thanks to everyone wh posted.

"fireball"
soapyfish
20
Years of Service
User Offline
Joined: 24th Oct 2003
Location: Yorkshire, England
Posted: 19th Nov 2003 23:29 Edited at: 19th Nov 2003 23:30
I just used the inc command I think thats right.

"fireball"
Jaze
20
Years of Service
User Offline
Joined: 20th Nov 2003
Location: Connecticut, USA
Posted: 20th Nov 2003 10:33
OK..Newbie...Just got the Gamer Bundle (DBP, Carto, Texture, DarkMatter, and 3d canvas) Whoa..(Got wait for shipping I guess 3 weeks) But I got some demos going...dbp seems like the place to start) I'm not new to programming...and I haven't made games since 386/486 era (2d Adventure...zelda sorta stuff...map editors, textures..etc)

My questions are as follows: (Forum says put them together)
(Thanx in advance)

#1
Does Darkbasic support user created multi threading? (And possibly multi CPU support) I haven't seen anything yet in this regard. (It seems you need to make your own round robin task schedular... (Star Wraith Game Demo makes me think you can somehow)...perhaps they used dll to do it?


#2
Does anyone know if this dialect of basic is (or can be made to be) object oriected? How about if there are plans to do this.

#3
Does DarkBasic allow shelling...or more to my desire...allow creating multiple applications that work together.... Main Screen EXE, Game EXE, and stuff to allow only utilizing the memory resources required for each specific "part" of the game or demo?

Thats a good start. I will being doing nothing but self teaching in the meantime...checking those tutorials and such you guys/gals have so kindly made available.

Thank You

-=/Jaze/=-
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 20th Nov 2003 12:32
1. No, you could make your own task schedular useing the timer() or loop counter.

2. No and I don't think it will ever be oo.

3. Dbpro has the ability to delete media that it has previously loaded. If you don't want main menu images consuming resources just delete them before starting the main game loop and re-load them if you need to show the main menu again.

dbpro : p166mmx @ 233 : 256mb : sb 128pci : sis onboard

Login to post a reply

Server time is: 2024-09-21 09:38:54
Your offset time is: 2024-09-21 09:38:54