Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need help with my character jumping... he won't come down!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
balofagus




PostPosted: Sat Nov 05, 2005 1:49 pm   Post subject: Need help with my character jumping... he won't come down!

Hey, my name is Sean. I'm taking TIK 20 (Grade 10 Computer Programming) and we've reached the end of the curriculum so it's Culminating Activity Time (OH YEAH!). Anywho... we have to make something that includes what we've done thus far... ifs, loops, drawing/animation, GUI, yadaa, yadaa you get the point. For my last little assignment we did a quick Mario animation. My teacher told me that he'd like to see me make a mario game (or at least a level) so thats what I'm up to. Now to the question:

- I've got mario moving (thanks to the movment Tutorial I found here) and he can jump (all with the arrow keys (up is jump)) but he wont come down. I've tried putting in the go up thing...then a delay...then go down all when you press the up arrow but nothing happens. I'm at a loss on how to get him to fall down. Anyone have any ideas?

- I would also like to know how to get him to fall down after he jumps up onto something (like a ledge) and then gets to the end.

Here's what I have so far:
Quote:

var key : string (1) := ""
var chars : array char of boolean
var mariox : int := 0
var marioy : int := 15
var mario, backImage, ground : int

backImage := Pic.FileNew ("background.jpg")
ground := Pic.FileNew ("ground.bmp")
mario := Pic.FileNew ("mario_still.bmp")

Pic.SetTransparentColor (mario, 10)

setscreen ("graphics:512;224")
setscreen ("offscreenonly")

procedure drawBackGround ()
Pic.Draw (backImage, 0, 0, picCopy)
Pic.Draw (ground, 0, -30, picCopy)
end drawBackGround

loop
setscreen ("offscreenonly")
View.Update
drawBackGround
Pic.Draw (mario, mariox, marioy, picMerge)
key := ""
if hasch then
getch (key)
end if
if key = (KEY_RIGHT_ARROW) then
mariox := mariox + 2
elsif key = (KEY_LEFT_ARROW) then
mariox := mariox - 2
elsif key = (KEY_UP_ARROW) then
marioy := marioy + 30
end if

end loop
Sponsor
Sponsor
Sponsor
sponsor
Carino




PostPosted: Sat Nov 05, 2005 2:16 pm   Post subject: (No subject)

You have to incorporate gravity to have him jump and at least make it look real, and this luckily is pretty simple. All you have to do is declare another variable that be added to the chars y variable, and have it decrease over time, something like this.

code:

var marioy, marioNewY : int
marioNewY := 6
var jumping : boolean := false

Input.KeyDown (chars)

if chars (KEY_UP_ARROW) then
jumping := true
end if

if jumping == true then
marioy += marioNewY
marioNewY -= 1

if marioy <= 10 then
jumping := false
marioy := 10
marioNewY := 6
end if
end if

Pic.Draw (mario, mariox, marioy, picMerge)

etc....


Basically like that, i just showed you the main part, im sure you can figure out how to use it. Make sure to setscreen to offscreenonly, and use delay() and View.Update along with cls.
RedRogueXIII




PostPosted: Sat Nov 05, 2005 2:31 pm   Post subject: (No subject)

declare the ground or ledge's height as a variable, and for ledge you need the end , x so basially
if mario = over the end "x" then he falls to the ground's height or offscreen.

to be more efficent in the jumping process
when he jumps he saves the ground "y" as a variable and then goes however high "say 6+y" before going down.
GlobeTrotter




PostPosted: Sat Nov 05, 2005 2:50 pm   Post subject: (No subject)

RedRogueXIII wrote:
declare the ground or ledge's height as a variable, and for ledge you need the end , x so basially
if mario = over the end "x" then he falls to the ground's height or offscreen.

to be more efficent in the jumping process
when he jumps he saves the ground "y" as a variable and then goes however high "say 6+y" before going down.


That won't necessarily work. What if the character jumps from the ground to a block floating in the air? How will the game know to stop the character ontop of the block. There are really only two ways to do this: One way to check where the ground is is to use whatdotcolor. This may seem easier at first, but limits your game, and limits the graphics of your game to simple colours. The second method is to save each level as a data file, with each character in the data file representing a tile. This method is harder to implement, but the game can be made to look much nicer.
balofagus




PostPosted: Sat Nov 05, 2005 3:32 pm   Post subject: (No subject)

Thanks Carino, I got him jumping now.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: