Делаю физический движок
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user