Re: [pygame] move problems

2009-04-10 Thread Yanom Mobis

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 unlucky...@gmail.com wrote:

From: Brian Song unlucky...@gmail.com
Subject: Re: [pygame] move problems
To: pygame-users@seul.org
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 ninmonk...@gmail.com 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





  

Re: [pygame] move problems

2009-04-10 Thread Yanom Mobis
oops... that was why my spaceship wasn't moving... lol.

--- On Thu, 4/9/09, Ian Mallett geometr...@gmail.com wrote:

From: Ian Mallett geometr...@gmail.com
Subject: Re: [pygame] move problems
To: pygame-users@seul.org
Date: Thursday, April 9, 2009, 8:53 PM

On Thu, Apr 9, 2009 at 2:48 PM, Yanom Mobis ya...@rocketmail.com wrote:


if key[K_RIGHT]:
    spaceship.speed=(spaceship.speed[0]+10, spaceship.speed[1])
    print(K_RIGHT) #debug
    if key[K_RIGHT]:
    spaceship.speed=(spaceship.speed[0]-10, spaceship.speed[1])

    print(K_LEFT) #debugif key[K_RIGHT]:
    move right
if key[K_RIGHT]:
    move left 

Two K_RIGHT ?
That should cancel any speed changes out...





  

Re: [pygame] move problems

2009-04-09 Thread Ian Mallett
On Thu, Apr 9, 2009 at 2:48 PM, Yanom Mobis ya...@rocketmail.com wrote:

 if key[K_RIGHT]:
 spaceship.speed=(spaceship.speed[0]+10, spaceship.speed[1])
 print(K_RIGHT) #debug
 if key[K_RIGHT]:
 spaceship.speed=(spaceship.speed[0]-10, spaceship.speed[1])
 print(K_LEFT) #debug

if key[K_RIGHT]:
move right
if key[K_RIGHT]:
move left

Two K_RIGHT ?
That should cancel any speed changes out...


Re: [pygame] move problems

2009-04-09 Thread Brian Song
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 ninmonk...@gmail.com 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



Re: [pygame] move problems

2009-02-18 Thread Michael George

pymike wrote:

if keys[LEFT]:
   print True

This works, because you're checking to see if the 3rd numeral in the 
list is positive/true.


Just a minor point - it's actually checking if the 3rd numeral is 
non-zero/true.


--Mike


Re: [pygame] move problems

2009-02-11 Thread Johan Ceuppens
Have a look at my game's game.py file for your key problem.

Love,tullaris.

http://www.mediafire.com/?l4md0edjnmm

2009/2/11 Yanom Mobis ya...@rocketmail.com


 this code is in my main game loop

 key = pygame.key.get_pressed() #create a key index

if K_UP in key: #check if the up arrow is pressed
redcar.speed = (0, -2)
else:
redcar.speed = (0, 0)

redcar.rect = redcar.rect.move(redcar.speed) #move redcar by speed

 but pressing the up arrow doesn't move the sprite.







Re: [pygame] move problems

2009-02-11 Thread Yanom Mobis
Hmm. now i remember how it's done. the part about pygame.key.get_pressed 
returning 1's and 0's makes sense, but I just don't get why

if key[K_UP]:

works if 

if K_UP in key:

doesn't.

--- On Tue, 2/10/09, mani...@gmx.de mani...@gmx.de wrote:

From: mani...@gmx.de mani...@gmx.de
Subject: Re: [pygame] move problems
To: pygame-users@seul.org
Date: Tuesday, February 10, 2009, 7:22 PM


-Inline Attachment Follows-

hi,

K_UP has the value 273 and pygame.key.get_pressed() returns a tuple where the 
n'th value is 1 if the n'th key was pressed.
This should work:

if key[K_UP]:
    .

 this code is in my main game loop

 key = pygame.key.get_pressed() #create a key index

     if K_UP in key: #check if the up arrow is pressed
         redcar.speed = (0, -2)
     else:
         redcar.speed = (0, 0)

     redcar.rect = redcar.rect.move(redcar.speed) #move redcar by speed

 but pressing the up arrow doesn't move the sprite.



  

Re: [pygame] move problems

2009-02-11 Thread James Paige
On Wed, Feb 11, 2009 at 03:46:21PM -0800, Yanom Mobis wrote:
if key[K_UP]:  

This uses K_UP as the index and returns the value at that index.

if K_UP in key:

The in operator searches the values of the key list but it will 
never find a match because K_UP is not a 0 or a 1.

---
James Paige


Re: [pygame] move problems

2009-02-11 Thread pymike
Here's an example:

UP= 0
DOWN  = 1
LEFT  = 2
RIGHT = 3

keys = [0, 0, 1, 0] #up, down, left, and right keys, respectively. 0 stands
for 'not pressed', 1 stands for 'is pressed'.

if LEFT in keys:
  print True

Now, it won't work, because 2 is not in the keys list.

if keys[LEFT]:
   print True

This works, because you're checking to see if the 3rd numeral in the list is
positive/true.

HTH

On Wed, Feb 11, 2009 at 5:46 PM, Yanom Mobis ya...@rocketmail.com wrote:

 Hmm. now i remember how it's done. the part about pygame.key.get_pressed
 returning 1's and 0's makes sense, but I just don't get why

 if key[K_UP]:

 works if

 if K_UP in key:

 doesn't.

 --- On *Tue, 2/10/09, mani...@gmx.de mani...@gmx.de* wrote:


 From: mani...@gmx.de mani...@gmx.de
 Subject: Re: [pygame] move problems
 To: pygame-users@seul.org
 Date: Tuesday, February 10, 2009, 7:22 PM


 -Inline Attachment Follows-

 hi,

 K_UP has the value 273 and pygame.key.get_pressed() returns a tuple where
 the
 n'th value is 1 if the n'th key was pressed.
 This should work:

 if key[K_UP]:
 .

  this code is in my main game loop
 
  key = pygame.key.get_pressed() #create a key index
 
  if K_UP in key: #check if the up arrow is pressed
  redcar.speed = (0, -2)
  else:
  redcar.speed = (0, 0)
 
  redcar.rect = redcar.rect.move(redcar.speed) #move redcar by speed
 
  but pressing the up arrow doesn't move the sprite.





-- 
- pymike
Python eggs me on.


Re: [pygame] move problems

2009-02-11 Thread Yanom Mobis
ohhh. I get it now.
thanks!


--- On Wed, 2/11/09, pymike pymik...@gmail.com wrote:

From: pymike pymik...@gmail.com
Subject: Re: [pygame] move problems
To: pygame-users@seul.org
Date: Wednesday, February 11, 2009, 6:08 PM

Here's an example:

UP    = 0
DOWN  = 1

LEFT  = 2
RIGHT = 3


keys = [0, 0, 1, 0] #up, down, left, and right keys, respectively. 0 stands for 
'not pressed', 1 stands for 'is pressed'.


if LEFT in keys:
  print True


Now, it won't work, because 2 is not in the keys list.

if keys[LEFT]:

   print True

This works, because you're checking to see if the 3rd numeral in the list is 
positive/true.

HTH

On Wed, Feb 11, 2009 at 5:46 PM, Yanom Mobis ya...@rocketmail.com wrote:


Hmm. now i remember how it's done. the part about pygame.key.get_pressed 
returning 1's and 0's makes sense, but I just don't get why

if key[K_UP]:

works if 

if K_UP in key:


doesn't.

--- On Tue, 2/10/09, mani...@gmx.de mani...@gmx.de wrote:


From: mani...@gmx.de mani...@gmx.de
Subject: Re: [pygame] move problems
To: pygame-users@seul.org

Date: Tuesday, February 10, 2009, 7:22 PM


-Inline Attachment Follows-

hi,

K_UP has the value 273 and pygame.key.get_pressed() returns a tuple where the 
n'th value is 1 if the n'th key was pressed.

This should work:

if key[K_UP]:
    .

 this code is in my
 main game loop

 key = pygame.key.get_pressed() #create a key index

     if K_UP in key: #check if the up arrow is pressed
         redcar.speed = (0, -2)
     else:
         redcar.speed = (0, 0)


     redcar.rect = redcar.rect.move(redcar.speed) #move redcar by speed

 but pressing the up arrow doesn't move the sprite.





  


-- 
- pymike
Python eggs me on.




  

Re: [pygame] move problems

2009-02-11 Thread Yanom Mobis
ok.
thanks

--- On Wed, 2/11/09, James Paige b...@hamsterrepublic.com wrote:

From: James Paige b...@hamsterrepublic.com
Subject: Re: [pygame] move problems
To: pygame-users@seul.org
Date: Wednesday, February 11, 2009, 6:04 PM


-Inline Attachment Follows-

On Wed, Feb 11, 2009 at 03:46:21PM -0800, Yanom Mobis wrote:
    if key[K_UP]:                                                              

This uses K_UP as the index and returns the value at that index.

    if K_UP in key:                                                            

The in operator searches the values of the key list but it will 
never find a match because K_UP is not a 0 or a 1.

---
James Paige



  

[pygame] move problems

2009-02-10 Thread Yanom Mobis

this code is in my main game loop

key = pygame.key.get_pressed() #create a key index

if K_UP in key: #check if the up arrow is pressed
redcar.speed = (0, -2)
else:
redcar.speed = (0, 0)

redcar.rect = redcar.rect.move(redcar.speed) #move redcar by speed

but pressing the up arrow doesn't move the sprite.


  



Re: [pygame] move problems

2009-02-10 Thread RB[0]
if key[K_UP] should work better :)

On Tue, Feb 10, 2009 at 6:47 PM, Yanom Mobis ya...@rocketmail.com wrote:


 this code is in my main game loop

 key = pygame.key.get_pressed() #create a key index

if K_UP in key: #check if the up arrow is pressed
redcar.speed = (0, -2)
else:
redcar.speed = (0, 0)

redcar.rect = redcar.rect.move(redcar.speed) #move redcar by speed

 but pressing the up arrow doesn't move the sprite.







Re: [pygame] move problems

2009-02-10 Thread maniaxx
hi,

K_UP has the value 273 and pygame.key.get_pressed() returns a tuple where the 
n'th value is 1 if the n'th key was pressed.
This should work:

if key[K_UP]:
.

 this code is in my main game loop

 key = pygame.key.get_pressed() #create a key index

 if K_UP in key: #check if the up arrow is pressed
 redcar.speed = (0, -2)
 else:
 redcar.speed = (0, 0)

 redcar.rect = redcar.rect.move(redcar.speed) #move redcar by speed

 but pressing the up arrow doesn't move the sprite.