feature: door basic mechanic
- Move hardcoded door size and colors to settings.py - Update Door class to use constants for drawing
This commit is contained in:
+14
-6
@@ -1,5 +1,13 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
from src.settings import (
|
||||||
|
DOOR_WIDTH,
|
||||||
|
DOOR_HEIGHT,
|
||||||
|
DOOR_BORDER_WIDTH,
|
||||||
|
COLOR_DOOR_BEIGE,
|
||||||
|
COLOR_DOOR_BORDER
|
||||||
|
)
|
||||||
|
|
||||||
# using class to be able to reuse it
|
# using class to be able to reuse it
|
||||||
# as we will have multiple rooms to go in
|
# as we will have multiple rooms to go in
|
||||||
class Door:
|
class Door:
|
||||||
@@ -12,15 +20,15 @@ class Door:
|
|||||||
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_color = COLOR_DOOR_BEIGE
|
||||||
self.door_border_color = (100, 90, 80)
|
self.door_border_color = COLOR_DOOR_BORDER
|
||||||
|
|
||||||
def draw(self, screen):
|
def draw(self, screen):
|
||||||
# main space of the door with 20x100 px
|
# door
|
||||||
pygame.draw.rect(screen, self.door_color, (self.x, self.y, 20, 100))
|
pygame.draw.rect(screen, self.door_color, (self.x, self.y, DOOR_WIDTH, DOOR_HEIGHT))
|
||||||
|
|
||||||
# doorframe 3px
|
# doorframe
|
||||||
pygame.draw.rect(screen, self.door_border_color, (self.x, self.y, 20, 100), 3)
|
pygame.draw.rect(screen, self.door_border_color, (self.x, self.y, DOOR_WIDTH, DOOR_HEIGHT), DOOR_BORDER_WIDTH)
|
||||||
|
|
||||||
# when attacked and gets dmg reduces the health (if closed), door "breaks" when health = 0
|
# when attacked and gets dmg reduces the health (if closed), door "breaks" when health = 0
|
||||||
def take_damage(self, amount):
|
def take_damage(self, amount):
|
||||||
|
|||||||
@@ -2,3 +2,13 @@
|
|||||||
DESK_WIDTH = 70
|
DESK_WIDTH = 70
|
||||||
DESK_HEIGHT = 40
|
DESK_HEIGHT = 40
|
||||||
|
|
||||||
|
|
||||||
|
# --- DOOR ---
|
||||||
|
DOOR_WIDTH = 20
|
||||||
|
DOOR_HEIGHT = 100
|
||||||
|
DOOR_BORDER_WIDTH = 3
|
||||||
|
|
||||||
|
COLOR_DOOR_BEIGE = (245, 245, 220)
|
||||||
|
COLOR_DOOR_BORDER = (100, 90, 80)
|
||||||
|
COLOR_HP_BAR_GREEN = (0, 255, 0)
|
||||||
|
COLOR_HP_BAR_BG = (50, 50, 50)
|
||||||
Reference in New Issue
Block a user