Merge remote-tracking branch 'origin/passingEvents' into passingEvents

This commit is contained in:
Michał Czekański 2020-04-05 23:45:48 +02:00
commit df83f13bef
3 changed files with 28 additions and 26 deletions

View File

@ -16,29 +16,29 @@ class Statistics:
self.hp = 100
def set_hunger(self, hunger_diff):
if 0 <= self.hp + hunger_diff <= 100:
self.hp = self.hp + hunger_diff
if 0 <= self.hunger + hunger_diff <= 100:
self.hunger = self.hunger + hunger_diff
else:
if self.hp + hunger_diff <= 0:
self.hp = 0
if self.hunger + hunger_diff <= 0:
self.hunger = 0
else:
self.hp = 100
self.hunger = 100
def set_thirst(self, thirst_diff):
if 0 <= self.hp + thirst_diff <= 100:
self.hp = self.hp + thirst_diff
if 0 <= self.thirst + thirst_diff <= 100:
self.thirst = self.thirst + thirst_diff
else:
if self.hp + thirst_diff <= 0:
self.hp = 0
if self.thirst + thirst_diff <= 0:
self.thirst = 0
else:
self.hp = 100
self.thirst = 100
def set_stamina(self, stamina_diff):
if 0 <= self.hp + stamina_diff <= 100:
self.hp = self.hp + stamina_diff
if 0 <= self.stamina + stamina_diff <= 100:
self.stamina = self.stamina + stamina_diff
else:
if self.hp + stamina_diff <= 0:
self.hp = 0
if self.stamina + stamina_diff <= 0:
self.stamina = 0
else:
self.hp = 100
self.stamina = 100

View File

@ -6,8 +6,10 @@ from os import path
from game.EventManager import EventManager
from game.Screen import Screen
from game.Map import Map
from src.entities.Pickupable import Pickupable
from src.entities.Player import Player
from src.game.Timer import Timer
from src.entities.Statistics import Statistics
class Game:
@ -38,11 +40,6 @@ class Game:
print("The screen cannot be in a vertical orientation. Exiting...")
exit(1)
# Initialize timers
self.pgTimer = pygame.time.Clock()
self.ingameTimer = Timer()
self.ingameTimer.startClock()
self.screen = Screen(self, self.config["window"])
print("OK")
@ -52,13 +49,11 @@ class Game:
self.map.addEntity(self.player)
self.eventManager = EventManager(self, self.player)
self.mainLoop()
def mainLoop(self):
while self.running:
# Update ingame clock
self.ingameTimer.updateTime(self.pgTimer.tick())
self.eventManager.handleEvents()
self.spritesList.draw(self.screen.pygameScreen)
pygame.display.flip()

View File

@ -1,8 +1,8 @@
import json
import pygame
from game.TerrainTile import TerrainTile
from game.Screen import Locations
from src.game.TerrainTile import TerrainTile
from src.game.Screen import Locations
from src.entities.Entity import Entity
from src.entities.Pickupable import Pickupable
@ -75,6 +75,13 @@ class Map:
self.screen.draw(object, Locations.MAP, 0, 0)
self.collidables.add(object)
def getEntityOnCoord(self, coord):
result = None
for entity in self.collidables:
if entity.rect.x == coord[0] and entity.rect.y == coord[1]:
result = entity
return result
def addEntity(self, entity):
self.screen.draw(entity, Locations.MAP, 0, 0)
self.collidables.add(entity)