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 / Need some help with my code

Author
Message
Seraf
20
Years of Service
User Offline
Joined: 22nd Feb 2004
Location:
Posted: 23rd Apr 2005 07:54
I can't seem to get my image to move when I press the Rightkey, it would be greatly appreciated if somebody could please help me. ^^


sync on
sync rate 40
hide mouse

`Begin player setup
load image "ship.png",1
sprite 1,shipX,shipY,1

`player coordinates
shipX = 30
shipY = 50

if rightkey() = 1 then shipX = shipX - 10
if leftkey() = 1 then shipY = shipY + 10
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 23rd Apr 2005 08:06 Edited at: 23rd Apr 2005 08:13
The code will work if you have it in a loop. You need to have a main outer game loop.

Your code (as is) positions the sprite once and then has one chance to see if the right key or left key is being pressed; if so it then changes the variables and then ends. And all of this would happen pretty fast so the right key would need to be held pretty much as the program is run.

You need to think of a game as program that only ends if the game is finished or the user exits. This is done by a main game loop. With the game loop set your program will now check for right key and left key input and update the sprites position accordingly, at a rate of 40 frames per second.




Seraf
20
Years of Service
User Offline
Joined: 22nd Feb 2004
Location:
Posted: 23rd Apr 2005 09:09
Thank you a lot! ^_^ I figured out how to make it so I can move up and down, left and right also. I have a few more questions(This is my first time ever actually making my own code without looking at tutorials, lol so I have some questions about how to do things But is there anyway I can contact you through Instant Messenger or something?

sync on
sync rate 40
hide mouse
`set initial coordinates
`player coordinates
shipX = 30
shipY = 50

`display player
`Begin player setup
load image "ship.png",1
sprite 1,shipX,shipY,1


`Main game loop
do

`check for input
if rightkey() = 1 then shipX = shipX + 5
if leftkey() = 1 then shipX = shipX - 5
if upkey() = 1 then shipY = shipY - 5
if downkey() = 1 then shipY = shipY + 5

`display ship each frame
sprite 1,shipX,shipY,1
sync
loop
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 23rd Apr 2005 09:21
Aim username zenassem


Login to post a reply

Server time is: 2024-09-23 17:27:10
Your offset time is: 2024-09-23 17:27:10