接上篇文章继续解绍arcade游戏编程的基本知识。今天主要在上节实现敌人如何寻找角色方向及角色开炮,开炮的同时向玩家移动,类的实现及调用。为以后的通过游戏做准备。
self.center_x = x
self.center_y = y
self.word = 'book'
self.hz = '书'
self.life = 1 # 生命条数,即挨几颗子弹消失
self.speed_to_player = speed_to_player # 面向角色移动的速度
def draw_word(self, x, y, fcolor=arcade.csscolor.GREEN, fsize=18, text=None):
if text:
arcade.draw_text(text, x, y, fcolor, fsize)
else:
arcade.draw_text(self.word, x, y, fcolor, fsize)
def update(self):
super().update()
if self.speed_to_player:
# 敌人向角色移动变量
self.change_x = math.cos(self.angle) * 0.3
self.change_y = math.sin(self.angle) * 0.3
class enemy_tank(arcade.Sprite):
def __init__(self, filename, scale, x, y, speed_to_player=0.2):
super().__init__(filename, scale)
self.center_x = x
self.center_y = y
self.word = 'book'
self.hz = '书'
self.life = 1
self.speed_to_player = speed_to_player
def draw_word(self, x, y, fcolor=arcade.csscolor.GREEN, fsize=18, text=None):
if text:
arcade.draw_text(text, x, y, fcolor, fsize)
else:
arcade.draw_text(self.word, x, y, fcolor, fsize)
def update(self):