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
|
||||
|
||||
# TODO: Paths are still retarded
|
||||
programPath = Path(".").resolve()
|
||||
game = Game(programPath)
|
||||
|
@ -1,7 +1,7 @@
|
||||
from pathlib import Path
|
||||
import pygame
|
||||
|
||||
|
||||
# TODO: Add getters to retrieve relative coords
|
||||
class Entity(pygame.sprite.Sprite):
|
||||
nextId = 1
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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]:
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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__()
|
||||
|
Loading…
Reference in New Issue
Block a user