所以我无法将玩家角色的形状从矩形更改为圆形。之前它说缺少一个参数,所以我们添加了它,然后它说有一个太多了。现在它说了一些不同的东西,我不再记得了,任何人都可以查看提供的代码。
谢谢你的帮助!
import pygame
import turtle
import time
import math
import random
import sys
import os
pygame.init()
WHITE = (255,255,255)
GREEN = (0,255,0)
BGColor = (117,168,55)
RED = (255,0,0)
BLUE = (0,0,255)
BLACK = (0,0,0)
MOVE = 2.5
size = (1200, 620)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Zombie Game")
class Char(pygame.sprite.Sprite):
def __init__(self, color, pos, radius, width):
super().__init__()
self.image = pygame.Surface([radius, width])
self.image.fill(WHITE)
self.image.set_colorkey(WHITE)
pygame.draw.circle(self.image, color, [0, 0], radius, width)
self.circle = self.image.get_circle()
def moveRight(self, pixels):
self.rect.x += pixels
def moveLeft(self, pixels):
self.rect.x -= pixels
def moveUp(self, pixels):
self.rect.y -= pixels
def moveDown(self, pixels):
self.rect.y += pixels
all_sprites_list = pygame.sprite.Group()
playerChar = Char(BLUE, [0, 0], 30, 0)
playerChar.rect.x = 0
playerChar.rect.y = 0
all_sprites_list.add(playerChar)
carryOn = True
clock = pygame.time.Clock()
while carryOn:
for event in pygame.event.get():
if event.type==pygame.QUIT:
carryOn=False
elif event.type==pygame.KEYDOWN:
if event.key==pygame.K_x:
carryOn=False
keys = pygame.key.get_pressed()
if keys[pygame.K_a]:
playerChar.moveLeft(MOVE)
if keys[pygame.K_d]:
playerChar.moveRight(MOVE)
if keys[pygame.K_w]:
playerChar.moveUp(MOVE)
if keys[pygame.K_s]:
playerChar.moveDown(MOVE)
screen.fill(BGColor)
pygame.display.flip()
clock.tick(60)
pygame.quit()
蝴蝶刀刀
相关分类