30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
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) |