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