From 11ece2ee54c6096dc161fdee13f0d5956ca13a1b Mon Sep 17 00:00:00 2001 From: Berger Lena Date: Fri, 8 May 2026 15:03:41 +0200 Subject: [PATCH] feat: item - Create item.py - Add update to remove expired items - Add item settings for spawn interval, despawn timer, and size --- src/item.py | 19 +++++++++++++++++++ src/settings.py | 20 +++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 src/item.py diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000..1b24f20 --- /dev/null +++ b/src/item.py @@ -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 diff --git a/src/settings.py b/src/settings.py index e19f541..d3c221b 100644 --- a/src/settings.py +++ b/src/settings.py @@ -4,6 +4,7 @@ from typing import Mapping, Literal, Tuple DESK_WIDTH = 70 DESK_HEIGHT = 40 + # --- DOOR --- DOOR_WIDTH = 20 DOOR_HEIGHT = 100 @@ -11,13 +12,13 @@ DOOR_BORDER_WIDTH = 3 COLOR_DOOR_BEIGE = (245, 245, 220) COLOR_DOOR_BORDER = (100, 90, 80) -COLOR_HP_BAR_GREEN = (0, 255, 0) -COLOR_HP_BAR_BG = (50, 50, 50) + # Players Constants / Settings # Valid movement/animation directions. Direction = Literal["down", "left", "right", "up"] + # Sprite files are grouped by direction. # Example: "down" uses sprite_01.png, sprite_02.png, sprite_03.png. DIRECTION_FRAMES: Mapping[Direction, Tuple[int, int, int]] = { @@ -27,14 +28,15 @@ DIRECTION_FRAMES: Mapping[Direction, Tuple[int, int, int]] = { "up": (10, 11, 12), } + # Default drawing size and animation speed. DEFAULT_SPRITE_HEIGHT: int = 138 DEFAULT_FRAME_TIME: float = 0.16 -======= + # --- ECTS --- 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_COST = 50 @@ -60,12 +62,12 @@ PROJECTILE_SPEED = 7 COLOR_PROJECTILE = (200, 200, 0) 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 --- -ITEM_SHOPPING_TIMER = 10000 # for items like coffee, beer, tower - how long u have time to buy it - - -# -- ZOMBIE --- +# --- ZOMBIE --- ZOMBIE_EASY_HP = 30 ZOMBIE_EASY_DMG = 3