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 / Running IF branch commands only once untill..?

Author
Message
Pyromaniac
21
Years of Service
User Offline
Joined: 8th Jan 2003
Location: United Kingdom
Posted: 8th Jan 2003 23:34
Im pretty new to darkbasic and, following the advice on other posts on this forum, ive decided to start small and create a simple "pong" game.

I have all the basics in place (sprites, movement, etc) but ive hit a problem.

when the ball goes out of the screen, i want the program to add one to the score, but even though the ball says outside the screen for a split second, the IF commands repeat several times

I cant figure a way around this so i though you guys could help me

Below is the offending IF statement(s)

IF SPRITE X(1)
Pyromaniac
21
Years of Service
User Offline
Joined: 8th Jan 2003
Location: United Kingdom
Posted: 8th Jan 2003 23:46
Sorry here's the code



Pyromaniac
21
Years of Service
User Offline
Joined: 8th Jan 2003
Location: United Kingdom
Posted: 8th Jan 2003 23:47
Im having a bad day

Here's the REAL code



Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 8th Jan 2003 23:49
Your problem is that the sprite changes direction, but is still outside of the screen. It would help if you placed the sprite in the middle of the playing area each time someone scores a point.

Whatever I did I didn't do it!
Pyromaniac
21
Years of Service
User Offline
Joined: 8th Jan 2003
Location: United Kingdom
Posted: 9th Jan 2003 18:02
That works in theory but when i try it, it still adds more than one to the score. What i really need is something to tell darkbasic "only do these commands once when this IF is activated untill the ball returns to the center" if you understand what i mean




Arrow
21
Years of Service
User Offline
Joined: 1st Jan 2003
Location: United States
Posted: 9th Jan 2003 18:50
Is the code where you score located inside the loop?

This is Truth!
This is my Belief!
...at least for now.
Moggie100
22
Years of Service
User Offline
Joined: 15th Oct 2002
Location: Behind You...
Posted: 11th Jan 2003 20:45
its possibly to do with speeds, math can be dont much quicker than positioning spites, so try positioning the sprite then adding score after its moved, something like this:

in the main loop:


then after the main loop in the 'Socre' routine:


assuming that the score for the player is 'playerscore' and that your screen resolution in the game is 640x480, that should work.

Life is like a hot bath, the longer you're in it, the more wrinkles you get.

Login to post a reply

Server time is: 2024-11-23 21:21:03
Your offset time is: 2024-11-23 21:21:03