86 lines
2.2 KiB
Python
86 lines
2.2 KiB
Python
import arcade
|
|
import math
|
|
from bullet import Bullet
|
|
from bonus import Bonus
|
|
|
|
class Tank():
|
|
ls = list()
|
|
def __init__(self,x,y,type='enemy'):
|
|
self.sp_body = arcade.SpriteList()
|
|
self.sp_gun = arcade.SpriteList()
|
|
self.type = type
|
|
self.gun_angle = 0
|
|
self.speed = 5
|
|
if type == 'player':
|
|
body = arcade.Sprite(
|
|
'./assets/tankBody_blue.png',
|
|
scale=1
|
|
)
|
|
gun = arcade.Sprite()
|
|
gun.append_texture(arcade.load_texture('./assets/tankBlue_barrel2.png'))
|
|
gun.append_texture(arcade.load_texture('./assets/tankBlue_barrel3.png'))
|
|
gun.append_texture(arcade.load_texture('./assets/tankBlue_barrel1.png'))
|
|
gun.cur = 0
|
|
gun.set_texture(gun.cur)
|
|
else:
|
|
body = arcade.Sprite(
|
|
'./assets/tankBody_dark.png',
|
|
scale=1
|
|
)
|
|
gun = arcade.Sprite(
|
|
'./assets/tankBlue_barrel2.png',
|
|
scale=1
|
|
)
|
|
body.center_x = x
|
|
body.center_y = y
|
|
self.sp_body.append(body)
|
|
gun.center_x = x
|
|
gun.center_y = y
|
|
self.sp_gun.append(gun)
|
|
|
|
Tank.ls.append(self)
|
|
def gun_to_xy(self,x,y):
|
|
for gun in self.sp_gun:
|
|
gun.angle = math.atan2(x-gun.center_x,y-gun.center_y) * 180 / math.pi
|
|
def move(self,dx,dy):
|
|
for body in self.sp_body:
|
|
body.change_x = dx*self.speed
|
|
body.change_y = dy*self.speed
|
|
if dx != 0 or dy != 0:
|
|
body.angle = math.atan2(dx,dy) * 180 / math.pi
|
|
for gun in self.sp_gun:
|
|
gun.change_x = dx*self.speed
|
|
gun.change_y = dy*self.speed
|
|
def shoot(self):
|
|
for gun in self.sp_gun:
|
|
Bullet(
|
|
gun.center_x,
|
|
gun.center_y,
|
|
gun.angle,
|
|
shift = 25
|
|
)
|
|
@classmethod
|
|
def update(cls):
|
|
for tank in cls.ls:
|
|
tank.sp_body.update()
|
|
tank.sp_gun.update()
|
|
colls = Bonus.get_colls(tank.sp_body[0])
|
|
for bonus in colls:
|
|
if bonus.type == 'star':
|
|
for gun in tank.sp_gun:
|
|
print(gun.cur)
|
|
if gun.cur > len(gun.textures):
|
|
gun.cur = 0
|
|
gun.set_texture(gun.cur)
|
|
else:
|
|
gun.cur += 1
|
|
gun.set_texture(gun.cur)
|
|
bonus.destroy()
|
|
|
|
@classmethod
|
|
def draw(cls):
|
|
for tank in cls.ls:
|
|
tank.sp_body.draw()
|
|
tank.sp_gun.draw()
|
|
|