2017-01-29 1 views
0

이봐 난 화살표 키 또는 WASD 중 하나와 파이썬에서 이미지를 이동하기 위해 노력하고있어하지만 난파이썬, 파이 게임 이미지의 움직임

File "1stgame.py", line 43 elif event.key == pygame.K_RIGHT: ^ IndentationError: unindent does not match any outer indentation level

import pygame 

#Start pygame 

pygame.init() 

#Window/Screen/Display 

display_x = 1280 
display_y = 720 
display = pygame.display.set_mode((display_x,display_y)) 
pygame.display.set_caption('Platforms') 

clock = pygame.time.Clock() 

#Colors 

black = (0,0,0) 
green = (1,166,17) 

#Images 
character = pygame.image.load('character.gif') 
def chrctr(x,y): 
    display.blit(character,(x,y)) 
x_c = (display_x/2) 
y_c = (display_y/2) 

floor_1 = pygame.image.load('wood.jpg') 
def floor(x,y): 
    display.blit(floor_1,(x,y)) 
x = (display_x * 0) 
y = (display_y * 0.9) 

not_dead=True 
while not_dead: 
    for event in pygame.event.get(): 
     if (event.type==pygame.QUIT): 
      not_dead=False 

     if event.type == pygame.KEYDOWN: 
      if event.key == pygame.K_LEFT: 
       x_c = -5 
      elif event.key == pygame.K_RIGHT: 
       x_c = 5 
     if event.type == pygame.KEYUP: 
      if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: 
       x_c = 0 

    display.fill(green) 
    pygame.draw.rect(display, black, [0, 550, 200, 50]) 
    pygame.draw.rect(display, black, [0, 450, 200, 50]) 
    pygame.draw.rect(display, black, [0, 350, 200, 50]) 
    pygame.draw.rect(display, black, [0, 250, 200, 50]) 
    pygame.draw.rect(display, black, [0, 150, 200, 50]) 
    pygame.draw.rect(display, black, [0, 50, 200, 50]) 
    pygame.draw.rect(display, black, [1080, 550, 200, 50]) 
    pygame.draw.rect(display, black, [1080, 450, 200, 50]) 
    pygame.draw.rect(display, black, [1080, 350, 200, 50]) 
    pygame.draw.rect(display, black, [1080, 250, 200, 50]) 
    pygame.draw.rect(display, black, [1080, 150, 200, 50]) 
    pygame.draw.rect(display, black, [1080, 50, 200, 50]) 

    floor(0,display_y * 0.9) 
    floor(236, display_y * 0.9) 
    floor(472, display_y * 0.9) 
    floor(708, display_y * 0.9) 
    floor(944, display_y * 0.9) 
    floor(1180, display_y * 0.9) 
    chrctr(x_c, y_c) 


    pygame.display.update() 
    clock.tick(60) 
print "Hello" 

pygame.quit() 
+0

읽기 : http://stackoverflow.com/a/10238788/4927751 –

답변

0

귀하의 코드가 정확한지, 그것은에서 실행 들여 쓰기 오류가 계속 내 컴퓨터에 오류가 없습니다. 아마도 실수로 소스 코드에서 잘못 들여 쓰기가되었을 수 있습니다. 그러나 당신이 위에 올린 사람은 훌륭하게 일했습니다. 그러나 예상대로 작동하지 않습니다.

부수적으로, "hello"주위에 대괄호를 추가하여 버전 호환 가능으로 만들 것을 권장합니다. print("hello").

+0

감사합니다. 코드가 메모장 ++에서 여기까지 어떻게 바뀌 었는지는 모르지만 지금은 저에게 잘 돌아갑니다 2. 감사합니다. 여보세요) – jmonster555games