Сделал жизни игроку и врагам
This commit is contained in:
@@ -12,7 +12,12 @@ class Bullet(arcade.Sprite):
|
||||
self.center_y = y + math.cos(self.angle * math.pi / 180) * shift
|
||||
self.speed = 10
|
||||
Bullet.ls.append(self)
|
||||
|
||||
def destroy(self):
|
||||
Bullet.ls.remove(self)
|
||||
|
||||
@classmethod
|
||||
def get_colls(cls,sprite):
|
||||
return arcade.check_for_collision_with_list(sprite, cls.ls)
|
||||
@classmethod
|
||||
def update_list(cls):
|
||||
for bullet in cls.ls:
|
||||
|
||||
@@ -9,8 +9,12 @@ class Tank():
|
||||
self.sp_body = arcade.SpriteList()
|
||||
self.sp_gun = arcade.SpriteList()
|
||||
self.type = type
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.gun_angle = 0
|
||||
self.speed = 5
|
||||
self.health = 100
|
||||
self.max_health = 100
|
||||
if type == 'player':
|
||||
body = arcade.Sprite(
|
||||
'./assets/tankBody_blue.png',
|
||||
@@ -57,18 +61,22 @@ class Tank():
|
||||
gun.center_x,
|
||||
gun.center_y,
|
||||
gun.angle,
|
||||
shift = 25
|
||||
shift = 50
|
||||
)
|
||||
def destroy(self):
|
||||
Tank.ls.remove(self)
|
||||
@classmethod
|
||||
def update(cls):
|
||||
for tank in cls.ls:
|
||||
tank.sp_body.update()
|
||||
tank.x = tank.sp_body[0].center_x
|
||||
tank.y = tank.sp_body[0].center_y
|
||||
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)
|
||||
@@ -76,10 +84,30 @@ class Tank():
|
||||
gun.cur += 1
|
||||
gun.set_texture(gun.cur)
|
||||
bonus.destroy()
|
||||
#Столкновения с пулями
|
||||
colls = Bullet.get_colls(tank.sp_body[0])
|
||||
for bullet in colls:
|
||||
tank.health -= 10
|
||||
bullet.destroy()
|
||||
if tank.health <= 0:
|
||||
tank.destroy()
|
||||
|
||||
@classmethod
|
||||
def draw(cls):
|
||||
for tank in cls.ls:
|
||||
tank.sp_body.draw()
|
||||
tank.sp_gun.draw()
|
||||
|
||||
heal_max_width = 40
|
||||
heal_width = tank.health/tank.max_health * heal_max_width
|
||||
arcade.draw_polygon_filled([
|
||||
(tank.x-heal_max_width//2,tank.y+25),
|
||||
(tank.x-heal_max_width//2+heal_width,tank.y+25),
|
||||
(tank.x-heal_max_width//2+heal_width,tank.y+20),
|
||||
(tank.x-heal_max_width//2,tank.y+20),
|
||||
],(255,0,0))
|
||||
arcade.draw_polygon_outline([
|
||||
(tank.x-20,tank.y+25),
|
||||
(tank.x+20,tank.y+25),
|
||||
(tank.x+20,tank.y+20),
|
||||
(tank.x-20,tank.y+20),
|
||||
],(0,0,0))
|
||||
|
||||
Reference in New Issue
Block a user