From ff29e52a8dd195c8c7f28368537830869a53f83c Mon Sep 17 00:00:00 2001 From: jonspacz Date: Wed, 1 Apr 2020 14:46:49 +0200 Subject: [PATCH 1/3] added 4 methods to Statistics class --- src/entities/Statistics.py | 48 ++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/entities/Statistics.py b/src/entities/Statistics.py index 18b4cc9..1b28c2b 100644 --- a/src/entities/Statistics.py +++ b/src/entities/Statistics.py @@ -1,6 +1,46 @@ class Statistics: def __init__(self): - self.hp - self.hunger - self.thirst - self.stamina + self.hp = 100 + self.hunger = 100 + self.thirst = 100 + self.stamina = 100 + + # methods that don't let the values pass below 0 and over 100 during change + def set_hp(self, hp_diff): + if 0 <= self.hp + hp_diff <= 100: + self.hp = self.hp + hp_diff + else: + if self.hp + hp_diff <= 0: + self.hp = 0 + else: + self.hp = 100 + + def set_hunger(self, hunger_diff): + if 0 <= self.hp + hunger_diff <= 100: + self.hp = self.hp + hunger_diff + else: + if self.hp + hunger_diff <= 0: + self.hp = 0 + else: + self.hp = 100 + + def set_thirst(self, thirst_diff): + if 0 <= self.hp + thirst_diff <= 100: + self.hp = self.hp + thirst_diff + else: + if self.hp + thirst_diff <= 0: + self.hp = 0 + else: + self.hp = 100 + + def set_stamina(self, stamina_diff): + if 0 <= self.hp + stamina_diff <= 100: + self.hp = self.hp + stamina_diff + else: + if self.hp + stamina_diff <= 0: + self.hp = 0 + else: + self.hp = 100 + + + From ef798b02e7a80c2cec1422c4ea7fcc37e1c68950 Mon Sep 17 00:00:00 2001 From: jonspacz Date: Thu, 2 Apr 2020 13:38:14 +0200 Subject: [PATCH 2/3] Added method to collidable to check if a collision occurred. Added = None to each attribute in Entity to stop errors from showing --- src/entities/Collidable.py | 10 ++++++++-- src/entities/Entity.py | 7 ++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/entities/Collidable.py b/src/entities/Collidable.py index ebe0f2f..6f391df 100644 --- a/src/entities/Collidable.py +++ b/src/entities/Collidable.py @@ -1,5 +1,11 @@ -import src.entities.Entity as Entity +from src.entities.Entity import Entity class Collidable(Entity): - pass + + 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 diff --git a/src/entities/Entity.py b/src/entities/Entity.py index b9d4d43..cc2ee36 100644 --- a/src/entities/Entity.py +++ b/src/entities/Entity.py @@ -1,5 +1,6 @@ class Entity: + def __init__(self): - self.texture - self.pos - self.id + self.texture = None + self.pos = None + self.id = None From 9efad498f7ee580b16041f954fbc03e1aa9765fd Mon Sep 17 00:00:00 2001 From: jonspacz Date: Thu, 2 Apr 2020 16:22:17 +0200 Subject: [PATCH 3/3] changed Interactable, Collidable, Npc, Entity --- src/entities/Collidable.py | 20 ++++++++++++++++++++ src/entities/Entity.py | 8 ++++---- src/entities/Interactable.py | 23 +++++++++++++++++++++-- src/entities/Npc.py | 13 ++++++++----- 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/entities/Collidable.py b/src/entities/Collidable.py index 6f391df..72a7c36 100644 --- a/src/entities/Collidable.py +++ b/src/entities/Collidable.py @@ -3,9 +3,29 @@ 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/Entity.py b/src/entities/Entity.py index cc2ee36..e9be7f1 100644 --- a/src/entities/Entity.py +++ b/src/entities/Entity.py @@ -1,6 +1,6 @@ class Entity: - def __init__(self): - self.texture = None - self.pos = None - self.id = None + def __init__(self, texture, pos, id): + self.texture = texture + self.pos = pos + self.id = id diff --git a/src/entities/Interactable.py b/src/entities/Interactable.py index 7720fdf..a3f3fb9 100644 --- a/src/entities/Interactable.py +++ b/src/entities/Interactable.py @@ -1,5 +1,24 @@ -import src.entities.Entity as Entity +from src.entities.Entity import Entity class Interactable(Entity): - pass + + def __init__(self, texture, pos, id): + super().__init__(texture, pos, id) + + @staticmethod + def interact_with_hp(hp, Statistics): + Statistics.set_hp(hp) + + @staticmethod + def interact_with_hunger(hunger, Statistics): + Statistics.set_hunger(hunger) + + @staticmethod + def interact_with_thirst(thirst, Statistics): + Statistics.set_thirst(thirst) + + @staticmethod + def interact_with_stamina(stamina, Statistics): + Statistics.set_stamina(stamina) + diff --git a/src/entities/Npc.py b/src/entities/Npc.py index 45f460e..5867cac 100644 --- a/src/entities/Npc.py +++ b/src/entities/Npc.py @@ -1,7 +1,10 @@ -import src.entities.Collidable as Collidable +from src.entities.Collidable import Collidable +from src.entities.Interactable import Interactable -class Npc(Collidable): - def __init__(self): - self.path - self.speed +class Npc(Collidable, 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