From 9b7011a010b6037f3abec2391ca55556c030c21e Mon Sep 17 00:00:00 2001 From: jonspacz Date: Sat, 4 Apr 2020 20:21:37 +0200 Subject: [PATCH 1/2] Fixed Collidable and made pickupable TODO - make object disappear after pickup --- src/entities/Collidable.py | 23 +---------------------- src/entities/Pickupable.py | 13 ++++++++++++- src/entities/Statistics.py | 10 +++++----- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/entities/Collidable.py b/src/entities/Collidable.py index 72a7c36..2a2d556 100644 --- a/src/entities/Collidable.py +++ b/src/entities/Collidable.py @@ -5,27 +5,6 @@ class Collidable(Entity): def __init__(self, texture, pos, id): super().__init__(texture, pos, id) - - def check_for_collision(self, x_pos, y_pos): - if self.pos[0] == x_pos: - if self.pos[1] == y_pos: - return True - - return False + self.is_collidable = True -col = Collidable(1, 1, 1) - - -""" - def interact_with_hp(self, hp, Statistics): - Statistics.set_hp(hp) - - def interact_with_hunger(self, hunger, Statistics): - Statistics.set_hunger(hunger) - - def interact_with_thirst(self, thirst, Statistics): - Statistics.set_thirst(thirst) - - def interact_with_stamina(self, stamina, Statistics): - Statistics.set_stamina(stamina)""" \ No newline at end of file diff --git a/src/entities/Pickupable.py b/src/entities/Pickupable.py index b59b728..cb7e7d6 100644 --- a/src/entities/Pickupable.py +++ b/src/entities/Pickupable.py @@ -1,5 +1,16 @@ import src.entities.Interactable as Interactable +from src.entities import Statistics, Player class Pickupable(Interactable): - pass + def __init__(self, texture, pos, id): + super().__init__(texture, pos, id) + self.is_pickupable = True + + def on_pickup(self, Player, Statistics): + Player.statistics.set_hp(Statistics.hp) + Player.statistics.set_stamina(Statistics.stamina) + Player.statistics.set_thirst(Statistics.thirst) + Player.statistics.set_hunger(Statistics.hunger) + + # TODO delete pickupable object from map diff --git a/src/entities/Statistics.py b/src/entities/Statistics.py index 1b28c2b..1ebe1f4 100644 --- a/src/entities/Statistics.py +++ b/src/entities/Statistics.py @@ -1,9 +1,9 @@ class Statistics: - def __init__(self): - self.hp = 100 - self.hunger = 100 - self.thirst = 100 - self.stamina = 100 + def __init__(self, hp, hunger, thirst, stamina): + self.hp = hp + self.hunger = hunger + self.thirst = thirst + self.stamina = stamina # methods that don't let the values pass below 0 and over 100 during change def set_hp(self, hp_diff): From 057f711317736ebc28fc1dd6b0962d470c575c3d Mon Sep 17 00:00:00 2001 From: jonspacz Date: Sun, 5 Apr 2020 20:34:45 +0200 Subject: [PATCH 2/2] Removed Collidable because was not useful finished todo in pickupable and added Statistics to contstructor --- src/entities/Collidable.py | 31 ------------------------------- src/entities/Npc.py | 4 +--- src/entities/Pickupable.py | 17 +++++++++-------- 3 files changed, 10 insertions(+), 42 deletions(-) delete mode 100644 src/entities/Collidable.py diff --git a/src/entities/Collidable.py b/src/entities/Collidable.py deleted file mode 100644 index 9ecf2eb..0000000 --- a/src/entities/Collidable.py +++ /dev/null @@ -1,31 +0,0 @@ -from src.entities.Entity import Entity - - -class Collidable(Entity): - - def __init__(self, texture, pos, id): - super().__init__(texture, pos, id) - - def check_for_collision(self, x_pos, y_pos): - if self.pos[0] == x_pos: - if self.pos[1] == y_pos: - return True - - return False - - -#col = Collidable(1, 1, 1) - - -""" - def interact_with_hp(self, hp, Statistics): - Statistics.set_hp(hp) - - def interact_with_hunger(self, hunger, Statistics): - Statistics.set_hunger(hunger) - - def interact_with_thirst(self, thirst, Statistics): - Statistics.set_thirst(thirst) - - def interact_with_stamina(self, stamina, Statistics): - Statistics.set_stamina(stamina)""" \ No newline at end of file diff --git a/src/entities/Npc.py b/src/entities/Npc.py index 5867cac..ac81f0b 100644 --- a/src/entities/Npc.py +++ b/src/entities/Npc.py @@ -1,10 +1,8 @@ -from src.entities.Collidable import Collidable from src.entities.Interactable import Interactable -class Npc(Collidable, Interactable): +class Npc(Interactable): def __init__(self, texture, pos, id, path, speed): - Collidable.__init__(self, texture, pos, id) Interactable.__init__(self, texture, pos, id) self.path = path self.speed = speed diff --git a/src/entities/Pickupable.py b/src/entities/Pickupable.py index cb7e7d6..319daa1 100644 --- a/src/entities/Pickupable.py +++ b/src/entities/Pickupable.py @@ -1,16 +1,17 @@ import src.entities.Interactable as Interactable from src.entities import Statistics, Player - +from game.MapNew import Map class Pickupable(Interactable): - def __init__(self, texture, pos, id): + def __init__(self, texture, pos, id, Statistics): super().__init__(texture, pos, id) self.is_pickupable = True + self.Statistics = Statistics - def on_pickup(self, Player, Statistics): - Player.statistics.set_hp(Statistics.hp) - Player.statistics.set_stamina(Statistics.stamina) - Player.statistics.set_thirst(Statistics.thirst) - Player.statistics.set_hunger(Statistics.hunger) + def on_pickup(self, Player): + Player.statistics.set_hp(self.Statistics.hp) + Player.statistics.set_stamina(self.Statistics.stamina) + Player.statistics.set_thirst(self.Statistics.thirst) + Player.statistics.set_hunger(self.Statistics.hunger) - # TODO delete pickupable object from map + Map.removeSpriteFromMap(self)