Skip to content

Commit

Permalink
Merge branch 'Grimmys:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
JimZhouZZY committed Jun 17, 2024
2 parents 65dff56 + 8ae050e commit f08ac1d
Show file tree
Hide file tree
Showing 18 changed files with 278 additions and 265 deletions.
7 changes: 5 additions & 2 deletions data/en/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def f_LEVEL_NUMBER_AND_NAME(number: int, name: str):
STR_END_TURN = "End turn"
STR_DEFAULT_DIARY_BODY_CONTENT = "No event has been recorded yet"


# Reward menu
STR_REWARD_CONGRATULATIONS = "Congratulations! Objective has been completed!"

Expand Down Expand Up @@ -90,6 +89,10 @@ def f_UR_GOLD(gold):
return f"Your gold: {gold}"


def f_SHOP_GOLD(shop_balance):
return f"Shopkeeper gold: {shop_balance}"


# Trade menu
STR_50G_TO_RIGHT = "50G ->"
STR_200G_TO_RIGHT = "200G ->"
Expand Down Expand Up @@ -256,7 +259,7 @@ def f_YOU_RECEIVED_ITEM(item):
)
STR_NOT_ENOUGH_GOLD_TO_BY_THIS_ITEM = "Not enough gold to buy this item."
STR_THE_ITEM_HAS_BEEN_SOLD = "The item has been sold."
STR_THIS_ITEM_CANT_BE_SOLD = "This item can't be sold !"
STR_THIS_ITEM_CANT_BE_SOLD = "The vendor lacks the funds to buy from you!"
STR_THIS_HOUSE_SEEMS_CLOSED = "This house seems closed..."


Expand Down
2 changes: 1 addition & 1 deletion src/game_entities/movable.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def get_formatted_alterations(self) -> str:

def get_abbreviated_alterations(self) -> str:
"""
Return the list of alterations in a abbreviated
Return the list of alterations in an abbreviated
way
"""
formatted_string: str = ""
Expand Down
13 changes: 8 additions & 5 deletions src/game_entities/shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Shop(Building):
stock -- the data structure containing all the available items to be bought with their associated quantity
menu -- the shop menu displaying all the items that could be bought
gold_sfx -- the sound that should be started when an item is sold or bought
shop_balance -- the amount of gold the shop has
"""

interaction_callback = None
Expand All @@ -50,16 +51,18 @@ def __init__(
name: str,
position: Position,
sprite_link: str,
shop_balance: int,
stock: list[dict[str, any]],
interaction: Optional[dict[str, any]] = None,
sprite: Optional[pygame.Surface] = None,
) -> None:
super().__init__(name, position, sprite_link, interaction, sprite)
self.shop_balance = shop_balance
self.current_visitor: Optional[Character] = None
self.stock: list[dict[str, any]] = stock
self.interaction: dict[str, any] = interaction
self.menu: InfoBox = menu_creator_manager.create_shop_menu(
Shop.interaction_callback, self.stock, 0
Shop.interaction_callback, self.stock, 0, self.shop_balance
)
self.gold_sfx: pygame.mixer.Sound = pygame.mixer.Sound(
os.path.join("sound_fx", "trade.ogg")
Expand All @@ -85,7 +88,7 @@ def update_shop_menu(self, gold: int) -> None:
gold -- the new gold amount for the player that should be displayed
"""
self.menu = menu_creator_manager.create_shop_menu(
Shop.interaction_callback, self.stock, gold
Shop.interaction_callback, self.stock, gold, self.shop_balance
)

def interact(self, actor: Character) -> list[list[BoxElement]]:
Expand Down Expand Up @@ -127,10 +130,9 @@ def buy(self, item: Item) -> str:
if self.current_visitor.gold >= item.price:
if len(self.current_visitor.items) < self.current_visitor.nb_items_max:
pygame.mixer.Sound.play(self.gold_sfx)

self.current_visitor.gold -= item.price
self.current_visitor.set_item(copy(item))

self.shop_balance += item.price
entry: Optional[dict[str, any]] = self.get_item_entry(item)
entry["quantity"] -= 1
if entry["quantity"] <= 0:
Expand All @@ -153,9 +155,10 @@ def sell(self, item: Item) -> tuple[bool, str]:
actor -- the actor selling the item
item -- the item that is being sold
"""
if item.resell_price > 0:
if 0 < item.resell_price < self.shop_balance:
self.current_visitor.remove_item(item)
self.current_visitor.gold += item.resell_price
self.shop_balance -= item.resell_price

# Update shop screen content (gold total amount has been augmented)
self.update_shop_menu(self.current_visitor.gold)
Expand Down
13 changes: 10 additions & 3 deletions src/gui/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
"""
from __future__ import annotations

from typing import Union

import pygame

Position = Union[pygame.Vector2, tuple[int, int]]

class Position(pygame.Vector2):
def __init__(self, x, y):
super().__init__(x, y)

def __hash__(self):
return hash((self.x, self.y))

def __str__(self):
return f'({self.x}, {self.y})'
4 changes: 2 additions & 2 deletions src/gui/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def show_fps(
def blit_alpha(
target: pygame.Surface,
source: pygame.Surface,
location: tuple[int, int],
location: Position,
opacity: int,
):
"""
Expand All @@ -44,7 +44,7 @@ def blit_alpha(
opacity -- the opacity of the blitted surface
"""
source.set_alpha(opacity)
target.blit(source, location)
target.blit(source, (location.x, location.y))


def distance(position: Position, other_position: Position) -> int:
Expand Down
3 changes: 2 additions & 1 deletion src/scenes/level_loading_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from src.gui.animation import Frame
from src.gui.fade_in_out_animation import FadeInOutAnimation
from src.gui.fonts import fonts
from src.gui.position import Position
from src.scenes.level_scene import LevelScene
from src.scenes.scene import Scene
from src.services.language import *
Expand Down Expand Up @@ -61,7 +62,7 @@ def _load_level_introduction_animation_frame(self) -> Frame:
),
)

return Frame(level_title_screen, pygame.Vector2(0, 0), DELAY_BETWEEN_FRAMES)
return Frame(level_title_screen, Position(0, 0), DELAY_BETWEEN_FRAMES)

def _generate_level_title_rendering(self) -> pygame.Surface:
"""
Expand Down
Loading

0 comments on commit f08ac1d

Please sign in to comment.