[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] move problems




ok, thanks! by the way, python2.6 won't let me change just one part of a tuple...
--- On Thu, 4/9/09, Brian Song <unlucky777@xxxxxxxxx> wrote:

From: Brian Song <unlucky777@xxxxxxxxx>
Subject: Re: [pygame] move problems
To: pygame-users@xxxxxxxx
Date: Thursday, April 9, 2009, 10:26 PM

Yea... Jakes method would do.. or you can just simplify it
 
spaceship_speed = 10  
 
if keys[K_LEFT]:
   x_move += -spaceship_speed
if keys[K_RIGHT]:
   x_move += spaceship_self.speed
   
rect = rect.move(x_move, 0)
 
BTW... spaceship.speed=(spaceship.speed[0]-10, spaceship.speed[1]) is unnecessary. No point in rewriting the whole list when your only changing one part
 
On Thu, Apr 9, 2009 at 9:56 PM, Jake b <ninmonkeys@xxxxxxxxx> wrote:
Print out .speed to see what the values are.

example: in IDLE

>>> from euclid import Vector2

>>> class Ship():
def __init__(self):
self.speed = Vector2(0,0)
self.loc = Vector2(0,0)
def accel(self, xvel, yvel):
self.speed += Vector2(xvel, yvel)
def update(self):
self.loc += self.speed
def __repr__(self): return "s=%s, l=%s" % (self.speed, self.loc )
>>> s = Ship()
>>> s
s=Vector2(0.00, 0.00), l=Vector2(0.00, 0.00)

>>> s.accel( 10, 0 )
>>> s
s=Vector2(10.00, 0.00), l=Vector2(0.00, 0.00)

>>> s.update()
>>> s
s=Vector2(10.00, 0.00), l=Vector2(10.00, 0.00)

>>> s.update()
>>> s
s=Vector2(10.00, 0.00), l=Vector2(20.00, 0.00)

--
Jake