- Move hardcoded door size and colors to settings.py - Update Door class to use constants for drawing
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
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
|
|
# as we will have multiple rooms to go in
|
|
class Door:
|
|
def __init__(self, x, y, hp_value):
|
|
# for each door we can set our own x/y position
|
|
self.x = x
|
|
self.y = y
|
|
|
|
self.max_hp = hp_value
|
|
self.current_hp = hp_value
|
|
self.is_closed = False
|
|
|
|
self.door_color = COLOR_DOOR_BEIGE
|
|
self.door_border_color = COLOR_DOOR_BORDER
|
|
|
|
def draw(self, screen):
|
|
# door
|
|
pygame.draw.rect(screen, self.door_color, (self.x, self.y, DOOR_WIDTH, DOOR_HEIGHT))
|
|
|
|
# doorframe
|
|
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
|
|
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 |