feat: item

- Create item.py
- Add update to remove expired items
- Add item settings for spawn interval, despawn timer, and size
This commit is contained in:
Berger Lena
2026-05-08 15:03:41 +02:00
parent 872786c8e3
commit 11ece2ee54
2 changed files with 30 additions and 9 deletions
+19
View File
@@ -0,0 +1,19 @@
import pygame
import random
from src.settings import (
ITEM_SPAWN_INTERVAL, ITEM_SHOPPING_TIMER, ITEM_SIZE,
COLOR_HP_BAR_YELLOW, COLOR_HP_BAR_BG
)
# remove expired items
def update(self, room_rect, blocked_rects):
now = pygame.time.get_ticks()
remaining_items = []
for item in self.items:
if item.is_expired() == False:
remaining_items.append(item)
# replace the old list with the new temp_list
self.items = remaining_items
+11 -9
View File
@@ -4,6 +4,7 @@ from typing import Mapping, Literal, Tuple
DESK_WIDTH = 70 DESK_WIDTH = 70
DESK_HEIGHT = 40 DESK_HEIGHT = 40
# --- DOOR --- # --- DOOR ---
DOOR_WIDTH = 20 DOOR_WIDTH = 20
DOOR_HEIGHT = 100 DOOR_HEIGHT = 100
@@ -11,13 +12,13 @@ DOOR_BORDER_WIDTH = 3
COLOR_DOOR_BEIGE = (245, 245, 220) COLOR_DOOR_BEIGE = (245, 245, 220)
COLOR_DOOR_BORDER = (100, 90, 80) COLOR_DOOR_BORDER = (100, 90, 80)
COLOR_HP_BAR_GREEN = (0, 255, 0)
COLOR_HP_BAR_BG = (50, 50, 50)
# Players Constants / Settings # Players Constants / Settings
# Valid movement/animation directions. # Valid movement/animation directions.
Direction = Literal["down", "left", "right", "up"] Direction = Literal["down", "left", "right", "up"]
# Sprite files are grouped by direction. # Sprite files are grouped by direction.
# Example: "down" uses sprite_01.png, sprite_02.png, sprite_03.png. # Example: "down" uses sprite_01.png, sprite_02.png, sprite_03.png.
DIRECTION_FRAMES: Mapping[Direction, Tuple[int, int, int]] = { DIRECTION_FRAMES: Mapping[Direction, Tuple[int, int, int]] = {
@@ -27,14 +28,15 @@ DIRECTION_FRAMES: Mapping[Direction, Tuple[int, int, int]] = {
"up": (10, 11, 12), "up": (10, 11, 12),
} }
# Default drawing size and animation speed. # Default drawing size and animation speed.
DEFAULT_SPRITE_HEIGHT: int = 138 DEFAULT_SPRITE_HEIGHT: int = 138
DEFAULT_FRAME_TIME: float = 0.16 DEFAULT_FRAME_TIME: float = 0.16
=======
# --- ECTS --- # --- ECTS ---
START_ECTS_VALUE = 1 # how many ECTS are generated at the beginning START_ECTS_VALUE = 1 # how many ECTS are generated at the beginning
ECTS_UPDATE_INTERVAL = 1000 # time in ms = 1 sec ECTS_UPDATE_INTERVAL = 1000 # time in ms (1000 = 1 sec)
BEER_BOTTLE_ECTS_VALUE = 2 BEER_BOTTLE_ECTS_VALUE = 2
BEER_COST = 50 BEER_COST = 50
@@ -60,12 +62,12 @@ PROJECTILE_SPEED = 7
COLOR_PROJECTILE = (200, 200, 0) COLOR_PROJECTILE = (200, 200, 0)
TOWER_TIMER = 30000 # how long the tower stays and attack before it disappears TOWER_TIMER = 30000 # how long the tower stays and attack before it disappears
# --- ITEM SPAWN TIMER ---
ITEM_SPAWN_INTERVAL = 5000 # ms until a new item spawns
ITEM_SHOPPING_TIMER = 10000 # how long you have time to buy items before they despawn
ITEM_SIZE = 30
# --- SHOPPING TIMER --- # --- ZOMBIE ---
ITEM_SHOPPING_TIMER = 10000 # for items like coffee, beer, tower - how long u have time to buy it
# -- ZOMBIE ---
ZOMBIE_EASY_HP = 30 ZOMBIE_EASY_HP = 30
ZOMBIE_EASY_DMG = 3 ZOMBIE_EASY_DMG = 3