From 9d9cd159a04aa7c563e289d78f5df5fdd4d41efc Mon Sep 17 00:00:00 2001 From: Wirus Date: Sun, 5 Apr 2020 14:53:54 +0200 Subject: [PATCH 1/7] addEntity method in Map --- src/game/Game.py | 3 +++ src/game/Map.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/game/Game.py b/src/game/Game.py index 6e6e8e4..8e5b7b5 100644 --- a/src/game/Game.py +++ b/src/game/Game.py @@ -6,6 +6,7 @@ from os import path from game.EventManager import EventManager from game.Screen import Screen from game.Map import Map +from src.entities.Player import Player class Game: @@ -43,6 +44,8 @@ class Game: # Start Map implement self.mapDataFolder = path.dirname("../data/mapdata/") self.map = Map(path.join(self.mapDataFolder, 'map.txt'), self.screen) + self.player = Player((0, 0), self.map.tileSize) + self.map.addEntity(self.player) # End Map implement self.mainLoop() diff --git a/src/game/Map.py b/src/game/Map.py index 7daa356..17f19d3 100644 --- a/src/game/Map.py +++ b/src/game/Map.py @@ -1,6 +1,7 @@ import pygame from game.TerrainTile import TerrainTile from game.Screen import Locations +from src.entities.Player import Player class Map: def __init__(self, filename, screen): @@ -19,7 +20,7 @@ class Map: self.height = self.tileHeight * self.tileSize self.terrainDraw() - + def terrainDraw(self): for row, tiles in enumerate(self.terrain): for col, tile in enumerate(tiles): @@ -29,5 +30,8 @@ class Map: self.screen.draw(TerrainTile('floor.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize) elif tile == '.': self.screen.draw(TerrainTile('grass.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize) - + + def addEntity(self, entity): + self.entities.append(entity) + self.screen.draw(entity, Locations.MAP, 0, 0) From 6a1fe72cabdbc3b85d9210c17298856cbd392eac Mon Sep 17 00:00:00 2001 From: Wirus Date: Sun, 5 Apr 2020 15:41:42 +0200 Subject: [PATCH 2/7] Game: correct declarative order Map: collidableTerrain list --- src/game/Game.py | 7 ++++--- src/game/Map.py | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/game/Game.py b/src/game/Game.py index 8e5b7b5..d586e17 100644 --- a/src/game/Game.py +++ b/src/game/Game.py @@ -39,14 +39,15 @@ class Game: self.screen = Screen(self, self.config["window"]) print("OK") - self.eventManager = EventManager(self) - # Start Map implement + self.mapDataFolder = path.dirname("../data/mapdata/") self.map = Map(path.join(self.mapDataFolder, 'map.txt'), self.screen) self.player = Player((0, 0), self.map.tileSize) self.map.addEntity(self.player) - # End Map implement + self.eventManager = EventManager(self, self.player) + + self.mainLoop() diff --git a/src/game/Map.py b/src/game/Map.py index 17f19d3..fecffd0 100644 --- a/src/game/Map.py +++ b/src/game/Map.py @@ -8,6 +8,8 @@ class Map: self.screen = screen self.terrain = [] self.entities = [] + self.collidableTerrain = [] + with open(filename, 'rt') as f: for line in f: self.terrain.append(line) @@ -26,6 +28,7 @@ class Map: for col, tile in enumerate(tiles): if tile == 'w': self.screen.draw(TerrainTile('wall.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize) + self.collidableTerrain.append(self.terrain) elif tile == ',': self.screen.draw(TerrainTile('floor.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize) elif tile == '.': From c98d8870a8e0f1c143960176d258b9a41547ed62 Mon Sep 17 00:00:00 2001 From: Wirus Date: Sun, 5 Apr 2020 15:44:03 +0200 Subject: [PATCH 3/7] add some images and venv to gitignore --- .gitignore | 1 + data/images/entities/bush.png | Bin 0 -> 3446 bytes data/images/entities/treasure.png | Bin 0 -> 7840 bytes 3 files changed, 1 insertion(+) create mode 100644 data/images/entities/bush.png create mode 100644 data/images/entities/treasure.png diff --git a/.gitignore b/.gitignore index 78b759b..215a7f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.idea/ __pycache__ +/venv/ diff --git a/data/images/entities/bush.png b/data/images/entities/bush.png new file mode 100644 index 0000000000000000000000000000000000000000..a59627dd4b4326f04b095ce40cff836a37cc8da7 GIT binary patch literal 3446 zcmV-+4TN2bZe?^J zG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ppBsYy!uc$BW0Vb)upn~< zp)=DTi*56fZ`UK!6o;&csrcs8CZ${3DcrwbKL%e?w*>5`eWUOnZ>A{%-fVRHR=Xs8 zzuq#MzgtPT8U*ZqZU^d8+^};w3zha{JYP0idB9t%#^7~=@1S=$LVt}9){Vj+2cNduXrDf9g4O21iX;I%M+AsDb=BiWAcwxC7F8UI+Br*9*d;F$*4_oQ@VvO8gXac zNM^3FO1r+?G#XzViNrhG{IR`c9R6+lkaqoXCq4C+73a5p_wPCP5g@jb1c+PrWskt# zk`Z{Z;@3FeJPud8-Ep&j3U2pLz?=2I!fUnv#4s3%9@Yu%<`GPToXq#GRcO&6Pv?nh zIpt*uL4|o9$}C}O%c|5IhB9*~O438I*cyszTPW(CQE1MMMtgo7x{LJaF4m)Kp$-js zIxKZ1B0oC~xtRtmu2`h*wUYM~-4ahc+3Jb^dXM$V*S+}Wwo7RjZknkNR%%xc{_@FE z9A3_Pf}$~XJO8a~)%Z^2@GX{0J@n|ZDM>DNHUyn*x zGKyR#IGt9cCdKhGL)Q}0MYq=4+}NnOvELYpSC)^&g(f$=TI+@@ts`-B%}AWC9f@-d zkFp$hQ^MWA-wa>lzRBHd)h_nw6vGoWBk=}*e5qx$(gCqI2>#TvQP|HLHdOun|NK0# zbu+99p(xMPp)yN{DrY>F=IF7+m4J$zMC7?F>Ku?G Date: Sun, 5 Apr 2020 15:51:16 +0200 Subject: [PATCH 4/7] Map: delete import Player --- src/game/Map.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/game/Map.py b/src/game/Map.py index fecffd0..487db0f 100644 --- a/src/game/Map.py +++ b/src/game/Map.py @@ -1,7 +1,6 @@ import pygame from game.TerrainTile import TerrainTile from game.Screen import Locations -from src.entities.Player import Player class Map: def __init__(self, filename, screen): From 853a3b16013b669eeb3446a444bf9220fa464362 Mon Sep 17 00:00:00 2001 From: Wirus Date: Sun, 5 Apr 2020 19:08:08 +0200 Subject: [PATCH 5/7] Map: collidable group of sprites TerrainTile: position attributes EventManager: collision method --- src/entities/Collidable.py | 2 +- src/entities/Player.py | 3 +-- src/game/EventManager.py | 16 ++++++++++++---- src/game/Game.py | 5 +---- src/game/Map.py | 10 ++++++---- src/game/TerrainTile.py | 6 +++++- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/entities/Collidable.py b/src/entities/Collidable.py index 72a7c36..9ecf2eb 100644 --- a/src/entities/Collidable.py +++ b/src/entities/Collidable.py @@ -14,7 +14,7 @@ class Collidable(Entity): return False -col = Collidable(1, 1, 1) +#col = Collidable(1, 1, 1) """ diff --git a/src/entities/Player.py b/src/entities/Player.py index ed6f38a..6472d46 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -18,7 +18,7 @@ class Player(Entity): self.rotate(rotation) # Otherwise, move one tile to a given direction else: - # TODO: Collision checks + # TODO: Collision checks "and not to events" if rotation.value == Rotations.NORTH.value: self.rect.y -= self.rect.w elif rotation.value == Rotations.EAST.value: @@ -32,7 +32,6 @@ class Player(Entity): self.image = pygame.transform.rotate(self.image, ((self.rotation.value - rotation.value) * 90)) self.rotation = rotation - class Rotations(Enum): NORTH = 0 EAST = 1 diff --git a/src/game/EventManager.py b/src/game/EventManager.py index d2a9a13..5143fee 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -7,6 +7,7 @@ TIMEOUT = 100 class EventManager: keyTimeout = 0 + #self.game.map def __init__(self, gameObject, player): self.game = gameObject self.player = player @@ -33,12 +34,19 @@ class EventManager: # Key names are temporary # TODO: Load key bindings from JSON - if keys[pygame.K_w]: + if keys[pygame.K_w] and not self.collision(self.player.rect.x, self.player.rect.y - self.player.rect.w): self.player.move(Rotations.NORTH) - if keys[pygame.K_s]: + if keys[pygame.K_s] and not self.collision(self.player.rect.x, self.player.rect.y + self.player.rect.w): self.player.move(Rotations.SOUTH) - if keys[pygame.K_d]: + if keys[pygame.K_d] and not self.collision(self.player.rect.x + self.player.rect.w, self.player.rect.y): self.player.move(Rotations.EAST) - if keys[pygame.K_a]: + if keys[pygame.K_a] and not self.collision(self.player.rect.x - self.player.rect.w, self.player.rect.y): self.player.move(Rotations.WEST) + # add object to map.collidables list to be collidable + def collision(self, x, y): + for b in self.game.map.collidables: + if b.rect.x == x and b.rect.y == y: + return True + return False + diff --git a/src/game/Game.py b/src/game/Game.py index d586e17..88f4647 100644 --- a/src/game/Game.py +++ b/src/game/Game.py @@ -28,6 +28,7 @@ class Game: print("Initializing pygame...", end=" ") pygame.init() self.spritesList = pygame.sprite.Group() + print("OK") print("Initializing screen, params: " + str(self.config["window"]) + "...", end=" ") @@ -39,16 +40,12 @@ class Game: self.screen = Screen(self, self.config["window"]) print("OK") - - self.mapDataFolder = path.dirname("../data/mapdata/") self.map = Map(path.join(self.mapDataFolder, 'map.txt'), self.screen) self.player = Player((0, 0), self.map.tileSize) self.map.addEntity(self.player) self.eventManager = EventManager(self, self.player) - - self.mainLoop() def mainLoop(self): diff --git a/src/game/Map.py b/src/game/Map.py index 487db0f..c072880 100644 --- a/src/game/Map.py +++ b/src/game/Map.py @@ -8,6 +8,7 @@ class Map: self.terrain = [] self.entities = [] self.collidableTerrain = [] + self.collidables = pygame.sprite.Group() with open(filename, 'rt') as f: for line in f: @@ -26,12 +27,13 @@ class Map: for row, tiles in enumerate(self.terrain): for col, tile in enumerate(tiles): if tile == 'w': - self.screen.draw(TerrainTile('wall.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize) - self.collidableTerrain.append(self.terrain) + object = TerrainTile(col, row, 'wall.png', self.tileSize) + self.screen.draw(object, Locations.MAP, 0, 0) + self.collidables.add(object) elif tile == ',': - self.screen.draw(TerrainTile('floor.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize) + self.screen.draw(TerrainTile(col, row, 'floor.png', self.tileSize), Locations.MAP, 0, 0) elif tile == '.': - self.screen.draw(TerrainTile('grass.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize) + self.screen.draw(TerrainTile(col, row, 'grass.png', self.tileSize), Locations.MAP, 0, 0) def addEntity(self, entity): self.entities.append(entity) diff --git a/src/game/TerrainTile.py b/src/game/TerrainTile.py index 636838b..064c303 100644 --- a/src/game/TerrainTile.py +++ b/src/game/TerrainTile.py @@ -4,10 +4,14 @@ from os import path class TerrainTile(pygame.sprite.Sprite): - def __init__(self, texture, tileSize): + def __init__(self, x, y, texture, tileSize): super().__init__() self.imagesFolder = path.dirname("../data/images/") self.terrainFolder = path.join(self.imagesFolder, 'terrain') self.image = pygame.image.load(os.path.join(self.terrainFolder, texture)).convert() self.image = pygame.transform.scale(self.image, (tileSize, tileSize)) self.rect = self.image.get_rect() + self.x = x + self.y = y + self.rect.x = x * tileSize + self.rect.y = y * tileSize From c1215196055b1b7366697db9d50ea3ae532d1766 Mon Sep 17 00:00:00 2001 From: Wirus Date: Sun, 5 Apr 2020 20:20:37 +0200 Subject: [PATCH 6/7] move collision to Map class --- src/game/EventManager.py | 15 +++++---------- src/game/Map.py | 6 ++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 5143fee..f093015 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -34,19 +34,14 @@ class EventManager: # Key names are temporary # TODO: Load key bindings from JSON - if keys[pygame.K_w] and not self.collision(self.player.rect.x, self.player.rect.y - self.player.rect.w): + if keys[pygame.K_w] and 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] and not self.collision(self.player.rect.x, self.player.rect.y + self.player.rect.w): + if keys[pygame.K_s] and 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] and not self.collision(self.player.rect.x + self.player.rect.w, self.player.rect.y): + if keys[pygame.K_d] and 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] and not self.collision(self.player.rect.x - self.player.rect.w, self.player.rect.y): + if keys[pygame.K_a] and not self.game.map.collision(self.player.rect.x - self.player.rect.w, self.player.rect.y): self.player.move(Rotations.WEST) - # add object to map.collidables list to be collidable - def collision(self, x, y): - for b in self.game.map.collidables: - if b.rect.x == x and b.rect.y == y: - return True - return False + diff --git a/src/game/Map.py b/src/game/Map.py index c072880..e5a1d27 100644 --- a/src/game/Map.py +++ b/src/game/Map.py @@ -39,3 +39,9 @@ class Map: self.entities.append(entity) self.screen.draw(entity, Locations.MAP, 0, 0) + # add object to map.collidables list to be collidable + def collision(self, x, y): + for b in self.collidables: + if b.rect.x == x and b.rect.y == y: + return True + return False From f399ba0d53afae6221aa0b5b111cae0cc2863ac4 Mon Sep 17 00:00:00 2001 From: Wirus Date: Sun, 5 Apr 2020 20:24:28 +0200 Subject: [PATCH 7/7] add entity to collidables in Map method --- src/game/Map.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/game/Map.py b/src/game/Map.py index e5a1d27..82a498f 100644 --- a/src/game/Map.py +++ b/src/game/Map.py @@ -6,7 +6,6 @@ class Map: def __init__(self, filename, screen): self.screen = screen self.terrain = [] - self.entities = [] self.collidableTerrain = [] self.collidables = pygame.sprite.Group() @@ -36,8 +35,8 @@ class Map: self.screen.draw(TerrainTile(col, row, 'grass.png', self.tileSize), Locations.MAP, 0, 0) def addEntity(self, entity): - self.entities.append(entity) self.screen.draw(entity, Locations.MAP, 0, 0) + self.collidables.add(entity) # add object to map.collidables list to be collidable def collision(self, x, y):