You're missing a bit still.

You need a floor (a way to stop falling), vertical velocity with
acceleration of gravity (a way to smoothly rise then fall), and then a way
to know if you are on the floor or in the air (still need for double jump).

floor = 0

# No jumping in air (modify with a counter if you want double/triple jumps)
if ninja.y == floor and ninja.v_y == 0:
  if keymap[key.SPACE] or keymap[key.UP]:
    ninja.v_y = 30 # initial jump velocity
    # if not ninja: play the jumping sound :)

if ninja.y > floor or ninja.v_y > 0:
  ninja.v_y -= dt * 20 # Gravity
  ninja.y += ninja.v_y

  if ninja.y < floor:
      ninja.y = floor
      ninja.v_y = 0
      # if not ninja: play the landing sound :)

You can then use velocity with x similar to the above (only limit x
velocity). Also, if the ninja is in the air only allow a small change in
velocity for x.

On Thu, Aug 25, 2011 at 1:37 PM, Paul <[email protected]> wrote:

> hello, I have been having a really hard time on trying to make my
> character jump in this platformer, here is the code, do not mind the
> "from pif import *" that is for my animation, and dont mind the "two"
> function haha.
>
> thank you very muchimport pyglet
> from pyglet.window import key
> from pif import *
>
> ninja = two('ninja.move.2.png', 'ninja.move.1.png', 0.2)
> ninja.still = pyglet.image.load('ninja.still.png')
> ninja.y = 122
> window = pyglet.window.Window(500, 500)
> map = pyglet.image.load('map.png')
> keymap = key.KeyStateHandler()
> window.push_handlers(keymap)
> ninja.still = pyglet.sprite.Sprite(ninja.still)
>
> @window.event
> def on_draw():
>        window.clear()
>        map.blit(0, 0, 0)
>
>        if not keymap[key.LEFT] and not keymap[key.RIGHT] and not
> keymap[key.SPACE]:
>                ninja.still.set_position(ninja.x, ninja.y)
>                ninja.still.draw()
>        else:
>                ninja.draw()
>                ninja.set_position(ninja.x, ninja.y)
> def update(dt):
>        if keymap[key.LEFT]:
>                ninja.x -= dt * 60
>                if keymap[key.SPACE] or keymap[key.UP]:
>                        ninja.y += dt * 120
>        elif keymap[key.RIGHT]:
>                ninja.x += dt * 60
>                if keymap[key.SPACE] or keymap[key.UP]:
>                        ninja.y += dt * 120
>        elif keymap[key.SPACE] or keymap[key.UP]:
>                ninja.y += dt * 120
>
> pyglet.clock.schedule_interval(update, 1/60.)
> pyglet.app.run()
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.

Reply via email to