feature: door basic mechanic
- add door color and border color - add draw method to render the door - add take_damage method to handle health reduction and door breaking
This commit is contained in:
+19
-1
@@ -10,4 +10,22 @@ class Door:
|
|||||||
|
|
||||||
self.max_hp = hp_value
|
self.max_hp = hp_value
|
||||||
self.current_hp = hp_value
|
self.current_hp = hp_value
|
||||||
self.is_closed = False
|
self.is_closed = False
|
||||||
|
|
||||||
|
self.door_color = (245, 245, 220)
|
||||||
|
self.door_border_color = (100, 90, 80)
|
||||||
|
|
||||||
|
def draw(self, screen):
|
||||||
|
# main space of the door with 20x100 px
|
||||||
|
pygame.draw.rect(screen, self.door_color, (self.x, self.y, 20, 100))
|
||||||
|
|
||||||
|
# doorframe 3px
|
||||||
|
pygame.draw.rect(screen, self.door_border_color, (self.x, self.y, 20, 100), 3)
|
||||||
|
|
||||||
|
# when attacked and gets dmg reduces the health (if closed), door "breaks" when health = 0
|
||||||
|
def take_damage(self, amount):
|
||||||
|
if self.is_closed:
|
||||||
|
self.current_hp -= amount
|
||||||
|
if self.current_hp <= 0:
|
||||||
|
self.current_hp = 0
|
||||||
|
self.is_closed = False
|
||||||
Reference in New Issue
Block a user