diff --git a/Run.py b/Run.py index 2b53e92..cb169de 100644 --- a/Run.py +++ b/Run.py @@ -2,5 +2,6 @@ from pathlib import Path from src.game.Game import Game +# TODO: Paths are still retarded programPath = Path(".").resolve() game = Game(programPath) diff --git a/src/entities/Entity.py b/src/entities/Entity.py index 73c7071..4f45318 100644 --- a/src/entities/Entity.py +++ b/src/entities/Entity.py @@ -1,7 +1,7 @@ from pathlib import Path import pygame - +# TODO: Add getters to retrieve relative coords class Entity(pygame.sprite.Sprite): nextId = 1 diff --git a/src/entities/Player.py b/src/entities/Player.py index 662617c..a950359 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -24,13 +24,6 @@ class Player(Entity): # If a player dies, the death reason is stored here self.deathReason = None - # Update player's rotation - def updateRotation(self, movement): - if movement == Movement.ROTATE_L: - self.rotate(Rotations((self.rotation.value - 1) % 4)) - elif movement == Movement.ROTATE_R: - self.rotate(Rotations((self.rotation.value + 1) % 4)) - # Move; movement - Enum def move(self, movement): # Rotation @@ -40,6 +33,7 @@ class Player(Entity): else: self.moveForward() + # Deprecated - use move() instead def moveForward(self): self.movePoints += 1 # You can only move if you have enough stamina @@ -54,6 +48,18 @@ class Player(Entity): elif self.rotation.value == Rotations.WEST.value: self.rect.x -= self.rect.w + def updateRotation(self, movement): + if movement == Movement.ROTATE_L: + self.rotate(Rotations((self.rotation.value - 1) % 4)) + elif movement == Movement.ROTATE_R: + self.rotate(Rotations((self.rotation.value + 1) % 4)) + + def rotate(self, rotation): + # If the player is not facing given direction, it will not move the first time, it will only get rotated + if self.rotation.value != rotation.value: + self.image = pygame.transform.rotate(self.image, ((self.rotation.value - rotation.value) * 90)) + self.rotation = rotation + def applyWalkingFatigue(self): # looses hunger every 10 steps taken if self.movePoints % 10 == 0: @@ -74,7 +80,7 @@ class Player(Entity): self.statistics.set_stamina(2) self.fatigueTimeout = 0 - + # TODO: Remove def getFacingCoord(self): if self.rotation == Rotations.NORTH: return self.rect.x, self.rect.y - (self.rect.h) @@ -97,14 +103,10 @@ class Player(Entity): return self.statistics.stamina return None + # TODO: Useless? def getStatistics(self): return self.statistics - - def rotate(self, rotation): - # If the player is not facing given direction, it will not move the first time, it will only get rotated - if self.rotation.value != rotation.value: - self.image = pygame.transform.rotate(self.image, ((self.rotation.value - rotation.value) * 90)) - self.rotation = rotation + # Update player's rotation # Updates self.alive if any of the statistic reaches critical value def determineLife(self): diff --git a/src/game/EventManager.py b/src/game/EventManager.py index c745a71..5902cee 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -14,10 +14,13 @@ class EventManager: #self.game.map def __init__(self, gameObject, player): + # TODO: Is this really neccessary? self.game = gameObject + self.player = player self.keyTimer = pygame.time.Clock() + # TODO: Make this not retarded self.turnOff = False # Player controls @@ -32,6 +35,7 @@ class EventManager: sleep(5) exit(0) + # TODO: Move to ui.update() self.game.screen.ui.updateTime() keys = pygame.key.get_pressed() @@ -43,11 +47,12 @@ class EventManager: pos = pygame.mouse.get_pos() self.handleClickingOnCollidablesAndTerrains(pos) - + # TODO: Move to ui.update() self.game.screen.ui.updateBasedOnPygameEvent(event) self.keyTimeout += self.keyTimer.tick() if self.keyTimeout >= TIMEOUT: if self.player.alive: + # TODO: Add A* here? self.handlePlayerControls(keys) self.keyTimeout = 0 else: @@ -88,26 +93,9 @@ class EventManager: object.on_interaction(self.player) self.game.screen.ui.updateOnPlayerInteraction(self.player.statistics, object) - # Movement - # if keys[pygame.K_w]: - # self.player.rotate(Rotations.NORTH) - # if not self.game.map.collision(self.player.rect.x, self.player.rect.y - self.player.rect.w): - # self.player.move(Rotations.NORTH) - # if keys[pygame.K_s]: - # self.player.rotate(Rotations.SOUTH) - # if not self.game.map.collision(self.player.rect.x, self.player.rect.y + self.player.rect.w): - # self.player.move(Rotations.SOUTH) - # if keys[pygame.K_d]: - # self.player.rotate(Rotations.EAST) - # if not self.game.map.collision(self.player.rect.x + self.player.rect.w, self.player.rect.y): - # self.player.move(Rotations.EAST) - # if keys[pygame.K_a]: - # self.player.rotate(Rotations.WEST) - # if not self.game.map.collision(self.player.rect.x - self.player.rect.w, self.player.rect.y): - # self.player.move(Rotations.WEST) if keys[pygame.K_w]: - # TODO: Collision ckecks - self.player.move(Movement.FORWARD) + if not self.game.map.collision(self.player.getFacingCoord()[0], self.player.getFacingCoord()[1]): + self.player.move(Movement.FORWARD) if keys[pygame.K_a]: self.player.move(Movement.ROTATE_L) if keys[pygame.K_d]: diff --git a/src/game/Game.py b/src/game/Game.py index b0efc04..abd6503 100644 --- a/src/game/Game.py +++ b/src/game/Game.py @@ -42,9 +42,6 @@ class Game: print("The screen cannot be in a vertical orientation. Exiting...") exit(1) - # Initialize screen - self.screen = Screen(self, self.config["window"]) - print("OK") # Initialize timers # PyGame timer - precise timer, counts milliseconds every frame @@ -53,6 +50,10 @@ class Game: self.ingameTimer = Timer() self.ingameTimer.startClock() + # Initialize screen + self.screen = Screen(self, self.config["window"]) + print("OK") + self.deltaTime = 0 self.lastTimePassed = self.ingameTimer.timePassed @@ -60,6 +61,7 @@ class Game: self.moveTime = 100 # Load map data from file + mapFile = None try: mapFile = Path(str(filesPath) + "/data/mapdata/") except IOError: @@ -100,6 +102,7 @@ class Game: # Call update() method for each entity self.spritesList.update() + # TODO: Move this to player.update() if self.moveTimer > 0: self.moveTimer -= self.deltaTime else: diff --git a/src/game/Map.py b/src/game/Map.py index 6a56cd9..137a1f0 100644 --- a/src/game/Map.py +++ b/src/game/Map.py @@ -10,9 +10,10 @@ from src.entities.Entity import Entity from src.entities.Pickupable import Pickupable from src.entities.Statistics import Statistics - +# TODO: Map should determine entities' position class Map: def __init__(self, filename, screen): + # TODO: Should map be self-aware of its own loacation? self.screen = screen # tekstowa macierz terenów self.terrain = [] @@ -130,6 +131,7 @@ class Map: # TODO: REMOVE DONT ADD def addEntity(self, entity, DONTADD=False): + # TODO: This method should set entities coords self.screen.draw(entity, Locations.MAP, 0, 0) # dodajemy bo wszystkie entity są kolizyjne self.collidables.add(entity) @@ -144,6 +146,7 @@ class Map: self.entities.remove(sprite) if sprite in self.terrainTilesList: self.terrainTilesList.remove(sprite) + # TODO: Suspicious? self.screen.removeSprite(sprite) # add object to map.collidables list to be collidable diff --git a/src/game/Screen.py b/src/game/Screen.py index 112c4e6..35cc6de 100644 --- a/src/game/Screen.py +++ b/src/game/Screen.py @@ -32,6 +32,7 @@ class Screen: # draw a white rect to resemble map pygame.draw.rect(self.pygameScreen, (255, 255, 255), [self.mapCoord, 0, self.mapSize, self.mapSize]) + # TODO: Move to game / envents self.__initUi__() def calculateMapDimensions(self): @@ -47,7 +48,9 @@ class Screen: return result # method to draw a sprite. Location param specifies where to draw the item (Locations enum) + # TODO: Retarded def draw(self, sprite, location, posX, posY): + # TODO: Screen cannot alter sprites position!! sprite.rect.x += posX sprite.rect.y += posY if location.value is Locations.RIGHT_UI.value: @@ -56,6 +59,7 @@ class Screen: sprite.rect.x += self.mapCoord self.gameObject.spritesList.add(sprite) + # TODO: Remove def removeSprite(self, sprite): self.gameObject.spritesList.remove(sprite) @@ -67,6 +71,7 @@ class Screen: elif location is Locations.MAP: return self.mapSize + # TODO: Move to game / events def __initUi__(self): self.ui = Ui(self.getUiWidth(Locations.RIGHT_UI), self.getUiWidth(Locations.LEFT_UI), self.winY, self.gameObject.ingameTimer) diff --git a/src/game/TerrainTile.py b/src/game/TerrainTile.py index 9af1c78..04edcc1 100644 --- a/src/game/TerrainTile.py +++ b/src/game/TerrainTile.py @@ -2,7 +2,7 @@ from pathlib import Path import pygame - +# TODO: Relative coords class TerrainTile(pygame.sprite.Sprite): def __init__(self, x, y, texture, tileSize, cost): super().__init__()