我正在用 pygame 制作一个有趣的小游戏,但到目前为止我只能创建播放器,我想添加另一个类,该类应该跟随玩家,如果它接触玩家一定数量的玩家死亡的时间。我想学习如何为我的其他项目做这件事,所以我更喜欢 pygame 初学者的更一般的答案。
我已经尝试基于此类创建类。:
class Char(pygame.sprite.Sprite):
def __init__(self, color, pos, radius, width):
super().__init__()
self.image = pygame.Surface([radius*2, radius*2])
self.image.fill(WHITE)
self.image.set_colorkey(WHITE)
pygame.draw.circle(self.image, color, [radius, radius], radius, width)
self.rect = self.image.get_rect()
这显然不起作用,然后我放弃了,因为我能想到的一切都超出了我对 pygame 的了解。
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*2, radius*2])
self.image.fill(WHITE)
self.image.set_colorkey(WHITE)
pygame.draw.circle(self.image, color, [radius, radius], radius, width)
self.rect = self.image.get_rect()
def moveRight(self, pixels):
self.rect.x += pixels
pass
def moveLeft(self, pixels):
self.rect.x -= pixels
pass
def moveUp(self, pixels):
self.rect.y -= pixels
pass
def moveDown(self, pixels):
self.rect.y += pixels
pass
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()
慕的地8271018
MMMHUHU
相关分类