John Fraser Computer Contest Club

Forums

Post Reply
Forum Home > Turing > Jumping character (on 2d ss)

Stanley
Moderator
Posts: 5

Here is a sample code to get a character to jump upward.

Its simple and just modifies velocity.





const Gravity := 2

var x := 100

var y := 100

var y_velocity := 0

var keys : array char of boolean

setscreen ("offscreenonly")

loop

Input.KeyDown (keys)

if keys (KEY_UP_ARROW) and y <= 0 then

y_velocity := 30 %If the jump button is pressed, velocity shoots up.

end if

if keys (KEY_LEFT_ARROW) and x > 0 then

x -= 5 %basic X movement.

end if

if keys (KEY_RIGHT_ARROW) and x < maxx then

x += 5

end if

 

 

y_velocity -= Gravity

y += y_velocity

 

if y < 0 then %this makes sure the character stays above the ground (if he goes undr, it brings him back up)

y := 0

y_velocity := 0

end if

 

Draw.FillOval (x, y, 10, 10, 79)

View.Update

delay (20)

cls

end loop

 


--

- Stanley

October 11, 2010 at 9:29 PM Flag Quote & Reply

DOM
Member
Posts: 11

im just saying, we shouldn't bother making these with this idk what language. flash actionscript is soooo mush better for these small games...

October 17, 2010 at 4:34 PM Flag Quote & Reply

Rui Lin
Moderator
Posts: 8

Mmm, yeah flash can be useful sometimes, like for these simpler examples, but if you want to make more complicated programs with turing or any other language, you'll have to start simpler first, and build your skills up


- Rui

October 18, 2010 at 7:29 PM Flag Quote & Reply

You must login to post.