feature: desk basic mechanic

This commit is contained in:
Haiden Niklas
2026-05-07 18:37:12 +00:00
parent 9cb8bd2d24
commit 9fc7a2cbda
2 changed files with 34 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
import pygame
from src.settings import DESK_WIDTH, DESK_HEIGHT
class Desk:
def __init__(self, x, y):
# each desk must be positioned with its own x/y coordinates
self.x = x
self.y = y
# size for collision rect and table
self.rect = pygame.Rect(self.x, self.y, DESK_WIDTH, DESK_HEIGHT)
try:
self.image = pygame.image.load("assets/furniture/desk.png").convert_alpha()
# scale the sprite to match collision rect
self.image = pygame.transform.scale(self.image, (DESK_WIDTH, DESK_HEIGHT))
except Exception as e:
print(f"Error loading desk sprite: {e}")
self.image = None
# check if player touches table
def check_collision(self, player_rect):
return self.rect.colliderect(player_rect)
# draw table - use sprite and as fallback a brown rect
def draw(self, screen):
if self.image:
screen.blit(self.image, self.rect)
else:
pygame.draw.rect(screen, (193, 69, 19), self.rect)
+4
View File
@@ -0,0 +1,4 @@
# --- DESK ---
DESK_WIDTH = 70
DESK_HEIGHT = 40