2017-12-26 3 views
0

파이썬 게임에 문제가 있습니다. 내 첫 번째 프로젝트입니다. 오류가 발생합니다 (TypeError : integer argument expected, float). 사용자 정의 기능 촬영을 삽입하면 시작됩니다. 이 문제를 해결하거나 SuperMario 이미지를 클래스와 함께 원형 객체로 만드는 방법. 감사합니다 :)TypeError : 정수 인수가 필요합니다. float, python이 있습니다. 파이 게임이있는 3.6.3입니다.

import pygame 
import time 

pygame.init() 

display_height = 600 
display_width = 800 

white = (255,255,255) 

gameDisplay = pygame.display.set_mode((display_width, display_height)) 
pygame.display.set_caption('Igra1') 
clock = pygame.time.Clock() 

bg = pygame.image.load('background.jpg') 
bg = pygame.transform.scale(bg,(800, 600)) 

Img_SuperMario = pygame.image.load('SuperMario.png') 
SuperMario_width = 611 
SuperMario_height = 611 
Img_SuperMario = pygame.transform.scale(Img_SuperMario, (100, 100)) 

def shoot(xshoot): 
    while xshoot < display_width: 
     pygame.draw.circle(gameDisplay, white, (xshoot,50), 20 ,0) 
     xshoot += 10 

def SuperMario(x,y): 
    gameDisplay.blit(Img_SuperMario,(x,y)) 

def gameloop(): 

x = (display_width * 0.1) 
y = (display_height * 0.1) 

x_change = 0 
y_change = 0 

game_exit = False 

while not game_exit: 

    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      pygame.quit() 
      quit() 

     if event.type == pygame.KEYDOWN: 
      if event.key == pygame.K_LEFT: 
       x_change = -5 
      elif event.key == pygame.K_RIGHT: 
       x_change = 5 
      elif event.key == pygame.K_UP: 
       y_change = -5 
      elif event.key == pygame.K_DOWN: 
       y_change = 5 

     if event.type == pygame.KEYUP: 
      if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT or event.key == pygame.K_DOWN or event.key == pygame.K_UP: 
       x_change = 0 
       y_change = 0 


    if x == display_width - 100 or x == 0: 
     x_change = 0 

    if y == (display_height - 100) or y == 0: 
     y_change = 0 


    x += x_change 
    y += y_change 
    xshoot = x 

    gameDisplay.fill(white) 
    gameDisplay.blit(bg,(0,0)) 

    if event.type == pygame.KEYDOWN: 
      if event.key == pygame.K_SPACE: 
       while xshoot < display_width: 
        shoot(x) 
    SuperMario(x,y) 

    pygame.display.update() 
    clock.tick(60) 

gameloop() 
pygame.quit() 
quit() 
+2

다음 번에 오류가 발생한 행을 통합하십시오. 오류를 쉽게 추적 할 수 있습니다. – Tai

+1

은 항상 전체 오류 메시지 (Traceback)를 문제로 둡니다 (스크린 샷이 아닌 텍스트). 다른 유용한 정보가 있습니다. – furas

+0

오류 메시지는 어디에 문제가 있는지 보여 주어야합니다. 그런 다음'print()'와'print (type (...))'를 사용하여 변수의 값과 유형을 검사하여'float' 값을 가진 변수를 찾은 다음 'int()'를 사용해야합니다. – furas

답변

0

x = int((display_width * 0.1)) y = int((display_height * 0.1)) 시도 구문 분석 아마 작동합니다, int로.

1

함수는 정수 만 허용하지만 x 변수는 부동 소수점입니다. 당신은 또한 메인 루프와 shoot 함수에서 while xshoot < display_width: 루프를 변경해야처럼

pygame.draw.circle(gameDisplay, white, (int(xshoot), 50), 20 ,0) 

것 같습니다,하지만 난 당신이 원하는 것을 확실하지 않다 다음 shoot 기능, 예를 들면의 정수로 xshoot 변수 변환 달성하기.

관련 문제