Or maybe build yourself a class
class Ninja(object):
def __init__(self, sprite, x, y):
self.sprite = sprite
self.initial_speed = 20
self.gravity = 1
self.friction = 0.0
self.velocity_up = 0
self.x = x
self.y = y
self.actual_y = y
self.jumping = False
def draw(self):
self.sprite.blit(self.x, self.actual_y)
def update(self, dt):
self.actual_y = self.y + self.velocity_up
if not self.jumping and self.velocity_up > 0:
self.velocity_up -= self.gravity * self.friction
self.friction += FRICTION_PER_TICK
elif self.jumping and self.velocity_up < MAX_JUMP:
self.velocity_up += self.gravity*self.friction
self.friction += FRICTION_PER_TICK
if self.velocity_up > MAX_JUMP:
self.velocity_up = MAX_JUMP
self.friction = 0.0
def jump(self):
self.jumping = True
self.friction = 0.0
pyglet.clock.schedule(ninja_instance.update)
2011/8/26 Michael LaRue <[email protected]>
> My code example already did link it:
>
>
> ninja.y += ninja.v_y
>
> though it really should be (my mistake):
>
> ninja.y += ninja.v_y * dt
>
> It should be updating ninja.y every update, as long as this is true
> (regardless of the key state):
>
>
> if ninja.y > floor or ninja.v_y > 0:
>
> And just in case you though ninja.v_y = 30 should be the initial value...
> It's not. 0 should be. 30 is the velocity that's set when a player pressed
> the jump button (if they are still on the ground). The velocity is reduced
> every update by gravity (ninja.v_y -= dt * 20) and the position is adjusted
> every update by velocity (ninja.y += ninja.v_y * dt).
>
> On Fri, Aug 26, 2011 at 2:05 PM, Paul <[email protected]> wrote:
>
>> ok, but when i use 'ninja.v_y = 30' for the velocity, how is that
>> supposed to correspond to the ninja.y value??? how do i link the
>> velocity to the y value? thnx
>>
>> On Aug 26, 4:26 pm, Michael LaRue <[email protected]> wrote:
>> > Just need to initialize it at the beginning. ninja.v_y = 0
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Fri, Aug 26, 2011 at 1:24 PM, Paul <[email protected]> wrote:
>> > > okay, haha now im stuck.
>> >
>> > > i dont have any variable 'ninja.v_y', is there supossed to be that
>> > > variable or am i supposed to declare ninja.v_y as something ???
>> > > plz help , 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.
>>
>>
> --
> 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.