Merge branch 'feat/desk' into 'main'
feature: desk basic mechanic See merge request swd25-bootcamp/silent-fh!7
This commit is contained in:
+30
@@ -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)
|
||||
@@ -0,0 +1,4 @@
|
||||
# --- DESK ---
|
||||
DESK_WIDTH = 70
|
||||
DESK_HEIGHT = 40
|
||||
|
||||
Reference in New Issue
Block a user