Skip to content
Permalink
Browse files

separated being as entity with HP

  • Loading branch information
flipcoder committed Mar 26, 2020
1 parent 2a2b91d commit bb829c78c47f21df73357acb7d3f39abf92e0d98
Showing with 29 additions and 22 deletions.
  1. +22 −0 game/base/being.py
  2. +3 −20 game/base/enemy.py
  3. +2 −1 game/entities/butterfly.py
  4. +2 −1 game/entities/player.py
@@ -0,0 +1,22 @@
#!/usr/bin/env python

from game.base.entity import Entity

class Being(Entity):
"""
An entity with HP
"""
def __init__(self, app, scene, filename=None):
super().__init__(app, scene, filename)
self.solid = True
self.hp = 1

def hurt(self, dmg, bullet, player):
if not self.hp:
return 0
self.hp -= dmg
if self.hp <= 0:
player.score += dmg
self.kill(dmg, bullet, player)
return dmg
return dmg
@@ -1,24 +1,7 @@
#!/usr/bin/env python

from game.base.entity import Entity
from game.constants import Y, SOUNDS_DIR, SPRITES_DIR, ORANGE, FULL_FOG_DISTANCE
from game.base.being import Being


class Enemy(Entity):
DEFAULT_SCALE = 5

def __init__(self, app, scene, pos, color=ORANGE, scale=DEFAULT_SCALE, num=0, hp=1):
class Enemy(Being):
def __init__(self, app, scene):
super().__init__(app, scene)
self.num = num
self.solid = True
self.hp = hp

def hurt(self, dmg, bullet, player):
if not self.hp:
return 0
self.hp -= dmg
if self.hp <= 0:
player.score += dmg
self.kill(dmg, bullet, player)
return dmg
return dmg
@@ -23,8 +23,9 @@ def __init__(self, app, scene, pos, color=ORANGE, scale=DEFAULT_SCALE, num=0):
:param scale:
"""

super().__init__(app, scene, pos, color, scale, num, hp=1)
super().__init__(app, scene)

self.num = num
self.frames = self.get_animation(color)

size = self.frames[0].get_size()
@@ -6,6 +6,7 @@
import weakref

from game.base.entity import Entity
from game.base.being import Being
from game.constants import *
from game.entities.bullet import Bullet
from game.entities.butterfly import Butterfly
@@ -23,7 +24,7 @@ def __init__(self, letter, filename, color, ammo, speed, damage):
self.damage = damage
self.img = None

class Player(Entity):
class Player(Being):

Weapons = [
Weapon("P", "bullet.png", "yellow", -1, 10, 1),

0 comments on commit bb829c7

Please sign in to comment.
You can’t perform that action at this time.