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