From e02e2ad1945a04eb921cab320cbdeb476585cac1 Mon Sep 17 00:00:00 2001 From: Anton Laktionov Date: Mon, 25 May 2026 17:08:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=B6?= =?UTF-8?q?=D0=B8=D0=B7=D0=BD=D0=B8=20=D0=B8=D0=B3=D1=80=D0=BE=D0=BA=D1=83?= =?UTF-8?q?=20=D0=B8=20=D0=B2=D1=80=D0=B0=D0=B3=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bullet.py | 7 ++++++- tank.py | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/bullet.py b/bullet.py index 5556348..2b4336c 100644 --- a/bullet.py +++ b/bullet.py @@ -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: diff --git a/tank.py b/tank.py index c165569..812f645 100644 --- a/tank.py +++ b/tank.py @@ -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))