我想制作一个游戏,其中有来自屏幕两侧的敌人。现在我有它,以便敌人一次在屏幕上滚动一个。我希望一次多来一个,慢慢增加他们遇到的频率。这是我的代码
import pygame, sys, time, random
from pygame.locals import *
pygame.init()
winW = 1000
winH = 600
surface = pygame.display.set_mode ((winW, winH),0,32)
pygame.display.set_caption ('Moving Orc')
class Enemy:
def __init__(self, char, startY, startX):
self.char=char
self.startY=startY
self.startX=startX
self.drawChar()
def drawChar (self):
self.space = pygame.image.load (self.char)
self.spaceRect = self.space.get_rect ()
self.spaceRect.topleft = (self.startX,self.startY)
self.moveChar()
def moveChar (self):
if self.startX == 0:
self.xMoveAmt = 5
elif self.startX == 800:
self.xMoveAmt = -5
while True:
surface.fill ((255,255,255))
self.spaceRect.left += self.xMoveAmt
surface.blit (self.space, self.spaceRect)
pygame.display.update()
time.sleep (0.02)
if self.spaceRect.right >= winW:
surface.fill ((255,255,255))
break
elif self.spaceRect.left <= 0:
surface.fill ((255,255,255))
break
#MAINLINE
while True:
enemyList=[]
leftOrRight = random.randint(0,1)
if leftOrRight == 0:
leftOrRight = 0
elif leftOrRight == 1:
leftOrRight = 800
enemyList.append(Enemy(("orc.png"), random.randint(50, 500), leftOrRight))
for i in range (0,len(enemyList)):
enemyList[i].drawChar()
break
我有它,这样每次你进入循环时,它都会重置它在我创建的类中运行的列表。一个人会从左边或右边穿过屏幕。
我什至会从哪里开始?