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.

Dark GDK / offsetting a sprite by only 25 pix at a time

Author
Message
Slim Pimpin
16
Years of Service
User Offline
Joined: 30th Dec 2007
Location: lost in the web
Posted: 30th Dec 2007 18:02
i am writing a turn based dungeon crawler type game. the problem i am having is getting my sprite to move 25 pix in any given direction then stopping. My current code he just keeps moving. any help will be appreciated. i know that i probably should be using different classes for my hero and monster but i am just starting this programming thing and will get to that after i have the basics down.

here is my code


Pimpin aint eazy
James Bondo
17
Years of Service
User Offline
Joined: 12th Nov 2006
Location: Denmark
Posted: 30th Dec 2007 18:37
Heres what i think you need. Im no good at C++ so you get it as pseudo code:

Should give you the idea. This will set a variable to true when you push a button, then when you release the button the player moves and the variable is set back to false.

Using Dark GDK.NET
Slim Pimpin
16
Years of Service
User Offline
Joined: 30th Dec 2007
Location: lost in the web
Posted: 30th Dec 2007 18:53
thx, the pseudo code did help. it put me in the right mind set to figure it out on my own. i added a null "while loop" inside the if statement so it wont move you until you let go of the button. thank you again



Pimpin aint eazy
Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 30th Dec 2007 19:01
I suspect the code is updating too fast and you are getting multiple moves on one keypress.
Try adding a timer after issuing the DbSprite command such as
MyTimer = dbTimer() +250
then check that MyTimer is greater than dbTimer() before updating the sprite

Hpe this helps

Codger

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
James Bondo
17
Years of Service
User Offline
Joined: 12th Nov 2006
Location: Denmark
Posted: 30th Dec 2007 22:29
Using a while loop within your main game loop is unwise. Just remember that while you are keeping the button pressed, no other code will run and your game would look like it has locked up. It may not be problematic at its current state, but if you plan to expand on it, it could potentially leave the game unplayable.

Imagine a first person shooter game that completely froze while you kept your mousebutton down to prevent you from shooting until you press again.

A timer like Codger sugested is one solution that could work. Pseudo:
if RightKey and TimeSinceLastMove greater than 250ms
PlayerX += 25

Using Dark GDK.NET

Login to post a reply

Server time is: 2024-09-29 07:25:51
Your offset time is: 2024-09-29 07:25:51