2012-02-25 4 views
0

저는 파이 게임에서 게임을 만들려고합니다. 그러나 어떤 이유로 액터와 inp는 같은 값을가집니다. 클래스 대신 배열로 가져 오려고했지만 문제가 해결되지 않았습니다.변수는 같은 값을 가지고 있습니다, 파이 게임

import pygame, sys 
from pygame.locals import * 

pygame.init() 
screen=pygame.display.set_mode((640,360),0,32) 

a=pygame.image.load('a.png') 

class xy: 
    x=0 
    y=0 
    jump=0 

actor=xy 
inp=xy 

def events(): 
    for event in pygame.event.get(): 
     if event.type == QUIT: 
      pygame.quit() 
      sys.exit() 
      return 
     elif event.type == KEYDOWN: 
      if event.key==K_LEFT: 
       inp.x=-1 
      elif event.key==K_RIGHT: 
       inp.x=1 
      elif event.key==K_UP: 
       inp.y=-1 
      elif event.key==K_DOWN: 
       inp.y=1 
      elif event.key==K_SPACE: 
       inp.jump=True 
     elif event.type==KEYUP: 
      if event.key==K_LEFT: 
       inp.x=0 
      elif event.key==K_RIGHT: 
       inp.x=0 
      elif event.key==K_UP: 
       inp.y=0 
      elif event.key==K_DOWN: 
       inp.y=0 
      elif event.key==K_SPACE: 
       inp.jump=False 
    return 

def controller(): 
    if inp.x<0: 
     actor.x-=1 
    elif inp.x>0: 
     actor.x+=1 
    if inp.y<0: 
     actor.y-=1 
    elif inp.y>0: 
     actor.y+=1 

## actor.x+=inp.x 
## actor.y+=inp.y 
    return 

def screen_update(): 
    pygame.draw.rect(screen, 0x006633, ((0,0),(640,360)),0) 
    screen.blit(a, (actor.x,actor.y)) 
    pygame.display.update() 

if __name__ == '__main__': 
    while True: 
     events() 
     print 'inp='+str(inp.x)+','+str(inp.y) 
     print 'actor='+str(actor.x)+','+str(inp.y) 
     controller() 
     screen_update() 

왜 내가 만든 것들이 제대로 작동하지 않을 수 있습니까? :(

답변

3

은 완전히 잘못을 클래스 하고있어, 간단히 말해.

class xy: 
    def __init__(self): 
    self.x = 0 
    self.y = 0 
    self.jump = 0 

actor = xy() 
inp = xy()