import random
WIDTH = 800
HEIGHT = 500
background = Actor('background')
player = Actor('player')
enemy = Actor('enemy')
money = Actor('money', pos=(300, 300))
player2 = Actor('alien')
score = 0
score2 = 0
player.x = 200
player.y = 200
def draw():
screen.clear()
background.draw()
player.draw()
enemy.draw()
money.draw()
player2.draw()
def update():
global score
if keyboard.right:
player.x = player.x + 4
if keyboard.left:
player.x = player.x - 4
if keyboard.down:
player.y = player.y + 4
if keyboard.up:
player.y = player.y - 4
if player.x > WIDTH:
player.x = WIDTH
if player.x < 0:
player.x = 0
if player.y < 0:
player.y = 0
if player.y > HEIGHT:
player.y = HEIGHT
if enemy.x < player.x:
enemy.x = enemy.x + 1
if enemy.x > player.x:
enemy.x = enemy.x - 1
if enemy.y < player.y:
enemy.y = enemy.y + 1
if enemy.y > player.y:
enemy.y = enemy.y - 1
if player.colliderect(enemy):
exit()
if money.colliderect(player):
money.x = random.randint(0, WIDTH)
money.y = random.randint(0, HEIGHT)
score = score + 1
print ('Score:', score)
if keyboard.d:
player2.x = player2.x + 4
if keyboard.a:
player2.x = player2.x - 4
if keyboard.s:
player2.y = player2.y + 4
if keyboard.w:
player2.y = player2.y - 4
if player.colliderect(player2):
exit()
if player2.x > WIDTH:
player2.x = WIDTH
if player2.x < 0:
player2.x = 0
if player2.y < 0:
player2.y = 0
if player2.y > HEIGHT:
player2.y = HEIGHT
我只是尝试将一个 player2 引入我在 MU-editor 中制作的 python 游戏中,我可以看到 player2 并移动他,但存在一些问题。敌人没有追玩家2,玩家2不能捡到钱。我还想为 player2 添加一个 score2 变量,并在他与钱碰撞时存储分数。