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! / need 2D help

Author
Message
sadsack
22
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 10th Mar 2006 01:27
I had this in the DBP, but no help. I may do better here thank you



Hello,
Well this is what I have, I have a moon type lander that goes up when you fire the rocket. I have never made a 2D game befor( played around with 2d when i first got DBP) I have gravity pushing down on the lander and the engine pushing up when fired. the upward velocity
rate goes up longer you use the engine. But it stay at that rate when the engine stop. then when you start the engine again the velocity is at the rate that you left off at.
I need to drop the velocity back to 0 when the engine is not running.
I tryed to use this: if keystate"a" = 0 and dec velocity#,.01

I could not get it to compile

I all so finding ouy that when I stop the engine gravity take over
that sec. that you stop pressing "a" there no slowwing down than falling back to the ground. I need help with the two things

I have DBP 5.9 and the down load, is the code and sprite
Thank you
renny
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Mar 2006 03:38
"keystate" uses a number instead of a string. The number associated with the key you want can be found out using the "scancode" command.

Or you can use a graphic I made (using another graphic as a reference) that shows the keystate of all the keys (it's attached to this message).

if keystate(30)=0 then dec velocity#,.01


With regards to the gravity you need to slowly decrease the velocity when no keys are pressed. Because in low gravity when you hit the truster you keep going for a bit even after you stop the thruster. The best way to do this is to add a "timer()" so it's not too fast (regardless of what computer it's on). You really only need one variable because "velocity" can be positive or negative.

Also you don't need to set the current directory if everything the code needs is in the same directory as the code (or .exe).

In the code snip I also added "upper$" to change "ch$" to uppercase... we use this so no matter what case the keyboard is in it will always be uppercase to check the keys pressed (a and A are two different characters). I took out "z" and "c" to just focus on the main problems you're having. I also made "velocity" an integer... it doesn't need to be a float because its made to increase/decrease by pixels. The screen coordinates are always whole numbers.




sadsack
22
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 10th Mar 2006 05:24
Thank you Grog Grueslayer, I would never have came up with that. i just got the book "Hands on Dark basic Pro vol. 1" and been trying out some of the 2D code. Your code is very neat.
renny hampton
Thanks
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Mar 2006 05:41
Thanks and np.


Chris Franklin
20
Years of Service
User Offline
Joined: 2nd Aug 2005
Location: UK
Posted: 10th Mar 2006 20:50
wow grog nice keystate image *saves*

sadsack
22
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 11th Mar 2006 19:22 Edited at: 15th Mar 2006 04:33
hello Grog Grueslayer,

Well I just don't under stand what I am doing wrong. I been knoking my head on the wall, floor, computer and any thing else I can find. What I been trying to do is rotate the sprite right and left so I can move around the screen with my lander.
I tryed this among many other ways:
code:
` Increase velocity if the A is held down every 500 milliseconds
if ch$="S" and timer()>burntime+500
rotate sprite 1,-25
inc velocity

if ch$="d" and timer()>burntime+500
rotate sprite 1,25
inc velocity

That will not work. that even stop A key from working
I try to just make a function to rotate the sprite, no good.

I found out that I could rotate the sprite (but it stay rotate)
If I just put that comm. in the do loop.
What do you think is the best way to rotatr right and left and still be able to go up?


SOLVED

Login to post a reply

Server time is: 2026-07-02 03:29:56
Your offset time is: 2026-07-02 03:29:56