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 / Character not moving?

Author
Message
Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 8th Jul 2008 18:42
I am setting up something to where when you press spacebar he moves up, it is the highly remarked code, I made it easier for you (and me) to find.

Code:


What am I doing wrong?


Thanks,
~Zeus~
Ed222
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: Calgary
Posted: 8th Jul 2008 18:50 Edited at: 8th Jul 2008 19:00
I can't seem to find the problem could you tell us whats wrong?
BTW why are you using 2 sprites for 1 character?

Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 8th Jul 2008 19:02 Edited at: 8th Jul 2008 19:03
The command:
if spacekey()=1 then y=y-10
is what you're doing wrong - the instant the user hits the space bar, the characters y-coord is decreased by 10 every time the program loops. The result is that the character will almost immediately vanish off screen.

What you need is some kind of "gravity" that slows the player going up, and then pulls him down again. For example:



Of course, if you want the player to "stick" to the staircase sprite mentioned in your code, you can always check for "Sprite Hit" (or is it sprite collision? I'm afraid I've never been able to figure out the difference). If there is a collision, just set the variable jumping to 0 to freeze the y-coord where it already is.

By the way, I just noticed - you're using two different sprites for the normal and crouch positions. You only need to use the one sprite for a character, and just change which image the sprite uses.

Hope this helps!

Edit: Blimey, took so long typing that someone beat me to it!

It is said there are 10 types of people in this world - those who understand binary, and those who have friends!
Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 8th Jul 2008 19:04
One is crouch and one is stand.

Here is the code I was talking about,

Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 8th Jul 2008 19:07
@Tha_Rami: It still doesn't move....
Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 8th Jul 2008 19:13 Edited at: 8th Jul 2008 19:31
Quote: "@Tha_Rami: It still doesn't move.... "

Do you mean me, or did you mean to post on another topic?

Actually, just realised I made a mistake - Y numbers are 0 at the top of the screen, and increase going down. My code snippet should read like this:


Oops!

Edit
Oh, <slaps head>. I've just realised why nothing's moving.
You need to put the commands:

inside your Do-Loop block. Otherwise, your sprites never get updated!

It is said there are 10 types of people in this world - those who understand binary, and those who have friends!
Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 8th Jul 2008 19:29
Still doesn't work.
Ed222
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: Calgary
Posted: 8th Jul 2008 19:46 Edited at: 8th Jul 2008 19:53
oh man how could I have missed it! i use 2d all the time. anyways Robert The Robot is right you have to make your guy come down but you also need a sync and a cls at the end of the loop also don't forget sync on so it should look like this

BTW you should make your 2 sprites into 1

Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 8th Jul 2008 19:49
@tha_rami's edit: Now it is disappearing.
Ed222
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: Calgary
Posted: 8th Jul 2008 19:54
Quote: "@tha_rami's edit: Now it is disappearing"

tha_rami? he didn't post here did he?

Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 8th Jul 2008 22:05
OMG Robert the Robot sorry.
Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 9th Jul 2008 12:58 Edited at: 9th Jul 2008 16:59
Don't worry Zeus, I don't mind.

I've just been running your code (I went and forgot to save the page last night ) and I think I've got it working. When you said "Now it is disappearing" it was because I'd messed up the SpaceKey() command:

means that if you press and hold the space key, Gravity will always be 10, so the sprite will just go up and up and up. Anyway, I've corected that, and made a minor adjustment to my Gravity-Jump code so the sprite comes down at exactly the pixel it left from. I've also added in the "Sync" command as Ed222 pointed out, but CLS doesn't seem to make any difference so I left it out. Oh, and I've combined both player sprites so you only need the one.

Hope this works for you!

It is said there are 10 types of people in this world - those who understand binary, and those who have friends!

Login to post a reply

Server time is: 2025-06-07 06:33:47
Your offset time is: 2025-06-07 06:33:47