简体   繁体   English

需要解密 integer 时出错

[英]There is an error Decrypting an integer is required

I have been following this tutorial to build a simple 2D game using pygame.我一直在按照本教程使用 pygame 构建一个简单的 2D 游戏。 I have checked multiple times my code but I still can't figure out what this error means我已经检查了多次我的代码,但我仍然无法弄清楚这个错误意味着什么

import pygame as pygame  

pygame.init() 
window = pygame.display.set_mode((500, 500))
pygame.display.set_caption('First Game')
pygame.display.update()

Here I set up all commands in response to the user's imput这里我设置了所有命令以响应用户的输入

walkRight = [pygame.image.load('R1.png'), pygame.image.load('R2.png'), pygame.image.load('R3.png'),
             pygame.image.load('R4.png'), pygame.image.load('R5.png'), pygame.image.load('R6.png'),
             pygame.image.load('R7.png'), pygame.image.load('R8.png'), pygame.image.load('R9.png')]
walkLeft = [pygame.image.load('L1.png'), pygame.image.load('L2.png'), pygame.image.load('L3.png'),
            pygame.image.load('L4.png'), pygame.image.load('L5.png'), pygame.image.load('L6.png'),
            pygame.image.load('L7.png'), pygame.image.load('L8.png'), pygame.image.load('L9.png')]
bg = pygame.image.load('bg.jpg')
char = pygame.image.load('standing.png')

clock = pygame.time.Clock()
x = 50
y = 50
width = 64
height = 64
vel = 5

isJump = False
jumpCount = 10

left = False
right = False
walkCount = 0

run = True

Here I defined the frames and the corresponding pictures with each movement.在这里,我定义了每个动作的帧和相应的图片。 The problem is coming from here but I don't understand why问题来自这里,但我不明白为什么

def redrawgamewindow():
    global walkCount

window.blit(bg, (0, 0))
pygame.draw.rect(window, (255, 255, 255), (x, y, width, height))


if walkCount + 1 >= 27:
    walkCount = 0
if left:
    window.blit(walkLeft[walkCount // 3], (x, y))
    walkCount += 1
elif right:
    window.blit(walkRight[walkCount // 3], (x, y))
    walkCount += 1
else:
    window.blit(char, (x, y))
    walkCount = 0
pygame.display.update() 


while run:
    clock.tick(27)

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

        keys = pygame.key.get_pressed()
        if keys[pygame.K_LEFT] and x > vel:
            x -= vel
            right = False
            left = True
        elif keys[pygame.K_RIGHT] and x < 500 - (width + vel):
            x += vel
            right = True
            left = False
        else:
            right = False
            left = False
            walkCount = 0
        if not isJump:
            if keys[pygame.K_UP] and y > vel:
                y -= vel
            if keys[pygame.K_DOWN] and y < 500 - (height + vel):
                y += vel
            if keys[pygame.K_SPACE]:
                isJump = True
                right = False
                left = False
        else:
            if jumpCount >= -10:
                neg = 1
                if jumpCount < 0:
                    neg = -1
                y -= (jumpCount * abs( jumpCount))*0.5
                jumpCount -= 1
            else:
                isJump = False
                jumpCount = 10

        redrawgamewindow()
pygame.quit()

The error displayed is显示的错误是

/Users/Thomas.V/Documents/Documents/Perso/Coding /Python /Pycharm Projects/Pygame.py:40: DeprecationWarning: an integer is required (got type float).  Implicit conversion to integers using __int__ is deprecated and may be removed in a future version of Python.
  pygame.draw.rect(window, (255, 255, 255), (x, y, width, height))

The warning is caused because y is not an integral value, because of警告是因为y不是整数值,因为

y -= (jumpCount * abs( jumpCount))*0.5

Get rid of the warning by rounding y (see round ):通过舍入y来消除警告(参见round ):

pygame.draw.rect(window, (255, 255, 255), (x, round(y), width, height))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM