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 / Moving in Bursts?

Author
Message
Blazer
17
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: United States
Posted: 24th Oct 2002 07:01
how do you make a code so when you push an arrow key, an object moves exatly 80 pixles over then stops untill you press the arrow key again?
Shock
AGK Developer
17
Years of Service
User Offline
Joined: 24th Oct 2002
Location: United Kingdom
Posted: 24th Oct 2002 23:17
best thing to do is make a 'timer'

e.g.

do
time = time + 1
if time > 500
then (..move fast..)
(..else move slow..)
if time > 1000
then time = 0
loop

i think thats right, i cant think my brain has gone blank from the 6 month db break

...:::ShockForge:::...
www.shockforge.com www.havochost.com www.s8i.com
And i aint a n00b although it says i am...
The Darthster
17
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 25th Oct 2002 01:50
I assume the object moves 80 pixels at a rate of one a frame, and it moves all the way with just one keypress.



That should do it, the code needs adjusting to suit your program. Basically:
If the upkey is pressed and the object is not currently moving, then set the distance to 80.
If the distance is greater than 0, then move the object and decrease the distance.
If the distance is zero and the upkey is not pressed then reset the object_moving variable so you can start again.
DBGuy
17
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Finland
Posted: 26th Oct 2002 22:58
man you guys are clever...

--- code ---
if upkey() = 1 and upressed = 0
upressed = 1
move object 1, 80
endif

if upkey() = 0 and upressed = 1
upressed = 0
endif
--- code ---

OR (with variables)

--- code ---
if upkey() = 1 and upressed = 0
upressed = 1
X = X + newxvalue(X, object angle y(1), 80)
Z = Z + newzvalue(Z, object angle y(1), 80)
endif

if upkey() = 0 and upressed = 1
upressed = 0
endif
--- code ---

DBGuy

: AMD Athlon 1.4GHz : 256MB : GeForce 2 Pro :
That toyfrog in my avatar is model, not real

Login to post a reply

Server time is: 2020-08-13 18:38:10
Your offset time is: 2020-08-13 18:38:10