From 2b50846297a62b5fca24e5a4b00615a29a8517b7 Mon Sep 17 00:00:00 2001 From: Anton Laktionov Date: Mon, 25 May 2026 18:00:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=B5=D0=BB=D0=B0=D1=8E=20=D1=84=D0=B8?= =?UTF-8?q?=D0=B7=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B9=20=D0=B4=D0=B2?= =?UTF-8?q?=D0=B8=D0=B6=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bullet.py | 6 ++++-- main.py | 4 ++++ map.py | 8 +++++--- tank.py | 29 +++++++++++++++++------------ 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/bullet.py b/bullet.py index 2b4336c..77ed135 100644 --- a/bullet.py +++ b/bullet.py @@ -3,14 +3,16 @@ import math class Bullet(arcade.Sprite): ls = arcade.SpriteList() - def __init__(self,x,y,a,shift=0): + def __init__(self,x,y,a,shift=0,power=0,owner=None): super().__init__( './assets/laserBlue01.png', - scale=0.7) + scale=power/30) self.angle = a self.center_x = x + math.sin(self.angle * math.pi / 180) * shift self.center_y = y + math.cos(self.angle * math.pi / 180) * shift self.speed = 10 + self.power = power + self.owner = owner Bullet.ls.append(self) def destroy(self): Bullet.ls.remove(self) diff --git a/main.py b/main.py index fe16715..5817ef5 100644 --- a/main.py +++ b/main.py @@ -12,8 +12,11 @@ class MainView(arcade.View): def __init__(self): super().__init__() self.background_color = (100,100,200) + self.block_list = arcade.SpriteList() + self.map = Map(SCREEN_WIDTH,SCREEN_HEIGHT,64,64) self.player = list(filter(lambda tank: tank.type=='player', Tank.ls))[0] + self.physics_engine = arcade.PhysicsEngineSimple(self.player.get_sprite(),Map.block_list) def on_draw(self): self.clear() @@ -23,6 +26,7 @@ class MainView(arcade.View): Bullet.draw() def on_update(self,time_delta): + self.physics_engine.update() Tank.update() Bonus.update_list(time_delta) Bullet.update_list() diff --git a/map.py b/map.py index dca897a..394be02 100644 --- a/map.py +++ b/map.py @@ -6,6 +6,7 @@ from random import randint class Map(): ground_tiles = arcade.SpriteList() object_tiles = arcade.SpriteList() + block_list = arcade.SpriteList() def __init__(self,width,height,tw,th): self.height = height self.width = width @@ -27,9 +28,9 @@ class Map(): ' e e ', ' s ', ' ', - ' p ', + ' s p ', ' ', - ' e ', + ' e s ', ' ', ' s e ', ] @@ -59,10 +60,11 @@ class Map(): self.height - (self.tileh//2 + i * self.tileh), 'player') elif self.objects[i][j] == 'e': - Tank( + tank = Tank( self.tilew//2 + j * self.tilew, self.height - (self.tileh//2 + i * self.tileh) ) + Map.block_list.append(tank.get_sprite()) elif self.objects[i][j] == 's': Bonus( self.tilew//2 + j * self.tilew, diff --git a/tank.py b/tank.py index 812f645..da9b3e1 100644 --- a/tank.py +++ b/tank.py @@ -5,16 +5,17 @@ from bonus import Bonus class Tank(): ls = list() - def __init__(self,x,y,type='enemy'): + def __init__(self,x,y,type='enemy',max_health=100,speed = 5): 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 + self.speed = speed + self.max_health = max_health + self.health = self.max_health + self.power = 10 if type == 'player': body = arcade.Sprite( './assets/tankBody_blue.png', @@ -43,6 +44,8 @@ class Tank(): self.sp_gun.append(gun) Tank.ls.append(self) + def get_sprite(self): + return self.sp_body[0] 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 @@ -53,15 +56,17 @@ class Tank(): 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 + gun.change_x = self.sp_body[0].change_x + gun.change_y = self.sp_body[0].change_y def shoot(self): for gun in self.sp_gun: Bullet( gun.center_x, gun.center_y, gun.angle, - shift = 50 + shift = 20+self.power*0.6, + power = self.power, + owner=self ) def destroy(self): Tank.ls.remove(self) @@ -77,17 +82,17 @@ class Tank(): for bonus in colls: if bonus.type == 'star': for gun in tank.sp_gun: - if gun.cur > len(gun.textures): - gun.cur = 0 - gun.set_texture(gun.cur) - else: + if gun.cur < len(gun.textures)-1: gun.cur += 1 gun.set_texture(gun.cur) + tank.power *= 2 bonus.destroy() #Столкновения с пулями colls = Bullet.get_colls(tank.sp_body[0]) for bullet in colls: - tank.health -= 10 + if tank == bullet.owner: + continue + tank.health -= bullet.power bullet.destroy() if tank.health <= 0: tank.destroy()