我认为这个错误是不言自明的,所以我只发布代码和发生的事情的屏幕截图
'''
Created on Oct 29, 2012
@author: pipsqueaker
'''
import pygame, sys, random
from pygame.locals import *
frapsClock = pygame.time.Clock()
class Alien:
def __init__(self, arg1, arg2):
self.x = arg1
self.y = arg2
def move(self, craftx, crafty):
if self.x < craftx:
self.x += 1
elif self.x > craftx:
self.x -= 1
if self.y < crafty:
self.y += 1
elif self.y > crafty:
self.y -= 1
class PlayShip():
def __init__(self, ag1, ag2):
self.x = ag1
self.y = ag2
class mainLopp():
Board = pygame.display.set_mode((650, 500))
pygame.display.set_caption("This")
pygame.init()
player = PlayShip(random.randrange(1, 650), random.randrange(1, 500))
alienList = [Alien(random.randrange(1, 650), random.randrange(1, 500))]
while True:
pygame.draw.rect(Board, (0, 0, 255), (player.x, player.y, 12, 12))
for currAlien in alienList:
currAlien.move(player.x, player.y)
pygame.draw.rect(Board, (255, 0, 0), (currAlien.x, currAlien.y, 16, 16))
for event in pygame.event.get():
if event.type == QUIT:
print(alienList)
pygame.quit()
sys.exit()
pygame.display.update()
frapsClock.tick(100)
move() 方法应该(随着时间的推移)将外星人(红色)移动到玩家(蓝色)。但是当该代码运行时,就会发生这种情况
它不应该像那样连续。这引出了一个问题,我该如何解决?