From ff29e52a8dd195c8c7f28368537830869a53f83c Mon Sep 17 00:00:00 2001 From: jonspacz Date: Wed, 1 Apr 2020 14:46:49 +0200 Subject: [PATCH 01/20] added 4 methods to Statistics class --- src/entities/Statistics.py | 48 ++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/entities/Statistics.py b/src/entities/Statistics.py index 18b4cc9..1b28c2b 100644 --- a/src/entities/Statistics.py +++ b/src/entities/Statistics.py @@ -1,6 +1,46 @@ class Statistics: def __init__(self): - self.hp - self.hunger - self.thirst - self.stamina + self.hp = 100 + self.hunger = 100 + self.thirst = 100 + self.stamina = 100 + + # methods that don't let the values pass below 0 and over 100 during change + def set_hp(self, hp_diff): + if 0 <= self.hp + hp_diff <= 100: + self.hp = self.hp + hp_diff + else: + if self.hp + hp_diff <= 0: + self.hp = 0 + else: + self.hp = 100 + + def set_hunger(self, hunger_diff): + if 0 <= self.hp + hunger_diff <= 100: + self.hp = self.hp + hunger_diff + else: + if self.hp + hunger_diff <= 0: + self.hp = 0 + else: + self.hp = 100 + + def set_thirst(self, thirst_diff): + if 0 <= self.hp + thirst_diff <= 100: + self.hp = self.hp + thirst_diff + else: + if self.hp + thirst_diff <= 0: + self.hp = 0 + else: + self.hp = 100 + + def set_stamina(self, stamina_diff): + if 0 <= self.hp + stamina_diff <= 100: + self.hp = self.hp + stamina_diff + else: + if self.hp + stamina_diff <= 0: + self.hp = 0 + else: + self.hp = 100 + + + From ef798b02e7a80c2cec1422c4ea7fcc37e1c68950 Mon Sep 17 00:00:00 2001 From: jonspacz Date: Thu, 2 Apr 2020 13:38:14 +0200 Subject: [PATCH 02/20] Added method to collidable to check if a collision occurred. Added = None to each attribute in Entity to stop errors from showing --- src/entities/Collidable.py | 10 ++++++++-- src/entities/Entity.py | 7 ++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/entities/Collidable.py b/src/entities/Collidable.py index ebe0f2f..6f391df 100644 --- a/src/entities/Collidable.py +++ b/src/entities/Collidable.py @@ -1,5 +1,11 @@ -import src.entities.Entity as Entity +from src.entities.Entity import Entity class Collidable(Entity): - pass + + def check_for_collision(self, x_pos, y_pos): + if self.pos[0] == x_pos: + if self.pos[1] == y_pos: + return True + + return False diff --git a/src/entities/Entity.py b/src/entities/Entity.py index b9d4d43..cc2ee36 100644 --- a/src/entities/Entity.py +++ b/src/entities/Entity.py @@ -1,5 +1,6 @@ class Entity: + def __init__(self): - self.texture - self.pos - self.id + self.texture = None + self.pos = None + self.id = None From 9efad498f7ee580b16041f954fbc03e1aa9765fd Mon Sep 17 00:00:00 2001 From: jonspacz Date: Thu, 2 Apr 2020 16:22:17 +0200 Subject: [PATCH 03/20] changed Interactable, Collidable, Npc, Entity --- src/entities/Collidable.py | 20 ++++++++++++++++++++ src/entities/Entity.py | 8 ++++---- src/entities/Interactable.py | 23 +++++++++++++++++++++-- src/entities/Npc.py | 13 ++++++++----- 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/entities/Collidable.py b/src/entities/Collidable.py index 6f391df..72a7c36 100644 --- a/src/entities/Collidable.py +++ b/src/entities/Collidable.py @@ -3,9 +3,29 @@ from src.entities.Entity import Entity class Collidable(Entity): + def __init__(self, texture, pos, id): + super().__init__(texture, pos, id) + def check_for_collision(self, x_pos, y_pos): if self.pos[0] == x_pos: if self.pos[1] == y_pos: return True return False + + +col = Collidable(1, 1, 1) + + +""" + def interact_with_hp(self, hp, Statistics): + Statistics.set_hp(hp) + + def interact_with_hunger(self, hunger, Statistics): + Statistics.set_hunger(hunger) + + def interact_with_thirst(self, thirst, Statistics): + Statistics.set_thirst(thirst) + + def interact_with_stamina(self, stamina, Statistics): + Statistics.set_stamina(stamina)""" \ No newline at end of file diff --git a/src/entities/Entity.py b/src/entities/Entity.py index cc2ee36..e9be7f1 100644 --- a/src/entities/Entity.py +++ b/src/entities/Entity.py @@ -1,6 +1,6 @@ class Entity: - def __init__(self): - self.texture = None - self.pos = None - self.id = None + def __init__(self, texture, pos, id): + self.texture = texture + self.pos = pos + self.id = id diff --git a/src/entities/Interactable.py b/src/entities/Interactable.py index 7720fdf..a3f3fb9 100644 --- a/src/entities/Interactable.py +++ b/src/entities/Interactable.py @@ -1,5 +1,24 @@ -import src.entities.Entity as Entity +from src.entities.Entity import Entity class Interactable(Entity): - pass + + def __init__(self, texture, pos, id): + super().__init__(texture, pos, id) + + @staticmethod + def interact_with_hp(hp, Statistics): + Statistics.set_hp(hp) + + @staticmethod + def interact_with_hunger(hunger, Statistics): + Statistics.set_hunger(hunger) + + @staticmethod + def interact_with_thirst(thirst, Statistics): + Statistics.set_thirst(thirst) + + @staticmethod + def interact_with_stamina(stamina, Statistics): + Statistics.set_stamina(stamina) + diff --git a/src/entities/Npc.py b/src/entities/Npc.py index 45f460e..5867cac 100644 --- a/src/entities/Npc.py +++ b/src/entities/Npc.py @@ -1,7 +1,10 @@ -import src.entities.Collidable as Collidable +from src.entities.Collidable import Collidable +from src.entities.Interactable import Interactable -class Npc(Collidable): - def __init__(self): - self.path - self.speed +class Npc(Collidable, Interactable): + def __init__(self, texture, pos, id, path, speed): + Collidable.__init__(self, texture, pos, id) + Interactable.__init__(self, texture, pos, id) + self.path = path + self.speed = speed From 1e179598f630bfcfdb8914327185581b31535ffc Mon Sep 17 00:00:00 2001 From: Mateusz Tylka Date: Fri, 3 Apr 2020 19:36:13 +0200 Subject: [PATCH 04/20] drawTerrain in Map class, examle map draw --- src/Run.py | 2 +- src/game/Game.py | 9 +++++++-- src/game/Map.py | 36 +++++++++++++++++++++++++++++++++--- src/game/TerrainTile.py | 22 ++++++++++++++++++++-- 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/Run.py b/src/Run.py index 07e0abb..a3e220a 100644 --- a/src/Run.py +++ b/src/Run.py @@ -1,3 +1,3 @@ -from src.game.Game import Game +from game.Game import Game game = Game() diff --git a/src/game/Game.py b/src/game/Game.py index e1c1fea..1df88e4 100644 --- a/src/game/Game.py +++ b/src/game/Game.py @@ -1,9 +1,11 @@ import pygame import json from pathlib import Path +from os import path from game.EventManager import EventManager from game.Screen import Screen +from game.Map import Map class Game: @@ -24,8 +26,8 @@ class Game: print("Initializing pygame...", end=" ") pygame.init() + self.spritesList = pygame.sprite.Group() print("OK") - print("Initializing screen, params: " + str(self.config["window"]) + "...", end=" ") # Vertical rotation is unsupported due to UI layout @@ -38,7 +40,10 @@ class Game: self.eventManager = EventManager(self) - self.spritesList = pygame.sprite.Group() + # Start Map implement + self.mapDataFolder = path.dirname("../data/mapdata/") + self.map = Map(path.join(self.mapDataFolder, 'map.txt'), self, self.screen) + # End Map implement self.mainLoop() diff --git a/src/game/Map.py b/src/game/Map.py index 8a4b1c9..7ed7db2 100644 --- a/src/game/Map.py +++ b/src/game/Map.py @@ -1,4 +1,34 @@ +import pygame +from game.TerrainTile import TerrainTile +from game.Screen import Locations + class Map: - def __init__(self): - self.terrain - self.entites = [] + def __init__(self, filename, game, screen): + self.game = game + self.screen = screen + self.terrain = [] + self.entities = [] + with open(filename, 'rt') as f: + for line in f: + self.terrain.append(line) + + self.tileSize = self.screen.mapSize/20 + + self.tileWidth = len(self.terrain[0]) + self.tileHeight = len(self.terrain) + self.width = self.tileWidth * self.tileSize + self.height = self.tileHeight * self.tileSize + + self.terrainDraw() + + def terrainDraw(self): + for row, tiles in enumerate(self.terrain): + for col, tile in enumerate(tiles): + if tile == 'w': + self.screen.draw(TerrainTile(self.game, col, row, 'wall.png', self.screen.mapSize), Locations.MAP, col, row) + if tile == ',': + self.screen.draw(TerrainTile(self.game, col, row, 'floor.png', self.screen.mapSize), Locations.MAP, col, row) + if tile == '.': + self.screen.draw(TerrainTile(self.game, col, row, 'grass.png', self.screen.mapSize), Locations.MAP, col, row) + + diff --git a/src/game/TerrainTile.py b/src/game/TerrainTile.py index ec906e5..dcebdc8 100644 --- a/src/game/TerrainTile.py +++ b/src/game/TerrainTile.py @@ -1,3 +1,21 @@ -class TerrainTile: - def __init__(self): +import pygame +import os +from os import path + + +class TerrainTile(pygame.sprite.Sprite): + def __init__(self, game, x, y, texture, mapSize): self.tiles = [] + self.groups = game.spritesList + pygame.sprite.Sprite.__init__(self, self.groups) + self.game = game + 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.set_colorkey((0,100,0)) + self.rect = self.image.get_rect() + self.x = x + self.y = y + self.tileSize = mapSize/20 + self.rect.x = self.x * self.tileSize + self.rect.y = self.y * self.tileSize From 5b60ddb8da1d42eb8f9a6b58fce47fb789f24547 Mon Sep 17 00:00:00 2001 From: Mateusz Tylka Date: Fri, 3 Apr 2020 19:49:53 +0200 Subject: [PATCH 05/20] add all folders --- data/images/terrain/floor.png | Bin 0 -> 506 bytes data/images/terrain/grass.png | Bin 0 -> 350 bytes data/images/terrain/wall.png | Bin 0 -> 297 bytes data/mapdata/map.txt | 20 ++++++++++++++++++ .../__pycache__/EventManager.cpython-36.pyc | Bin 0 -> 669 bytes src/game/__pycache__/Game.cpython-36.pyc | Bin 0 -> 1712 bytes src/game/__pycache__/Map.cpython-36.pyc | Bin 0 -> 1256 bytes src/game/__pycache__/Screen.cpython-36.pyc | Bin 0 -> 1570 bytes .../__pycache__/TerrainTile.cpython-36.pyc | Bin 0 -> 955 bytes 9 files changed, 20 insertions(+) create mode 100644 data/images/terrain/floor.png create mode 100644 data/images/terrain/grass.png create mode 100644 data/images/terrain/wall.png create mode 100644 data/mapdata/map.txt create mode 100644 src/game/__pycache__/EventManager.cpython-36.pyc create mode 100644 src/game/__pycache__/Game.cpython-36.pyc create mode 100644 src/game/__pycache__/Map.cpython-36.pyc create mode 100644 src/game/__pycache__/Screen.cpython-36.pyc create mode 100644 src/game/__pycache__/TerrainTile.cpython-36.pyc diff --git a/data/images/terrain/floor.png b/data/images/terrain/floor.png new file mode 100644 index 0000000000000000000000000000000000000000..bab8d021fa7d9f4173cb43d6d994724d220b3289 GIT binary patch literal 506 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sDEfH31!Z9ZwBhJH^M$B>G+w=?6j4jb?syKHYD@n&K9>(70c zxZf!4KIAvG{m_C97Zv^Gj$Vlfda`TvKKTy*OD3F`(jzm&<@47+KY5_$kI$~^O21hv zW#heG@4EJTUF6{=mJMyJoC&<#LI`q-*Ub1o%|-u^b;3uL9U?EEOncw%d12<& z---D}4!pUnODe1t=JT^hR6BH*@_J3Qa^QZ(aIL+0juPjWhKsfbc9lhY%xC74uw%bq z&A74pSLm~_z9!};AFs{i9U^Ow6vS_%<8&y5aBYS_u|LrV%P#1jQ zoZ#OSKYNMkv$y4!UR6%@v#%0sU|zDH{f}kiw>;Lh?1n=V0gRRL4V6s?M%zHY%&R@4%xom+KFppIAs!2 zd}mHRvbaf3;Vt9LH*D|a9;XYhQ0&m9tl0ra*sp o!*u2)-_It9L!J46bH+0H6>Gg`IGO+X0E{mNPgg&ebxsLQ0C*110{{R3 literal 0 HcmV?d00001 diff --git a/data/images/terrain/grass.png b/data/images/terrain/grass.png new file mode 100644 index 0000000000000000000000000000000000000000..6df59c81169d54621e029b096e89361f4f019432 GIT binary patch literal 350 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBufiR<}hF1en@Uy3jV@O5Z+u4C!O%4)lYt8wu814=&|FqE| zO;yZgyU6BzwiG#`sSo1~51#&8SY387rcj6Nz(xs%<4FuM-HZhwPK`{0L|ftP#eeo~ ziT8c|&-DHCm|_`qkcvA#_rE{hW}4llS~liu%9Vf)S*k^O|YM z`m3AfvVv{;Q#_?Q@U`tqQ7~_hwY#mn&fM#q2R0sI|FGK;=28iU_DiMuGe2d<%JW_+ Q1$v*s)78&qol`;+05~dxvH$=8 literal 0 HcmV?d00001 diff --git a/data/images/terrain/wall.png b/data/images/terrain/wall.png new file mode 100644 index 0000000000000000000000000000000000000000..9db4a3a65cc67eaa106708cb00617edd0b7ba6af GIT binary patch literal 297 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBufiR<}hF1enaG$4(V@O5Z+nEP>4;cs?2zvH{hvxvtngcPh zot`(C?drZ>RT34w`OhNXyR&3^=Fa}_0>uZTxEi+l^uMm($GCmw;jZW1huwBDMR+rA zn8uW#%X%Q{3*#)djZiktYEjOdhCPgdzJPdxmn$);ZtGe}o68^ebEo zVpy}30cOfC2H$2Fd$ze#`v2$ur>$c^Rr84##B@8Gn90s`C*#gAo_4`! z@dbRCzIyT%JXw`taTYA7udA!Ss{X1T92`u3F28?71o#DeCMiB5_qPcQ7;GSi7hr^u z7hvSM$kE^%NY!t8hiS=pX@Y_ya({=w0x=;M293CYTpDQR0QR1^EsdJ?bWB+mfa6<5%K>#%uY_{Hv3w+ z-e<|bH!#7?tt*4< zGpA|9v$v!{>oC!Jero!L<3#IaUo^WHH>O_hI>Wzzhlqc1ya`t38Dfm(kRiD&WQhM) Q7UD;{-yZWuho#5zFFy8_YybcN literal 0 HcmV?d00001 diff --git a/src/game/__pycache__/Game.cpython-36.pyc b/src/game/__pycache__/Game.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..24e8dca6492340b38b809afe25befd58190a7267 GIT binary patch literal 1712 zcmZt`$!^<5bcVYm%9icKjUIi>B0%aIL2ai%0wf)vA;uco8ipd7;m8Z2 zoD`s^9{L&mp&oecDZh|Y-y2$i3xveHdGq#d=DU8s`rrw*gfD{kLm#1?vqS;idp=P~k^^QR@p6J{tIq=DF|6u7 zfP`R>%o0>s?+LSoEgaY#;etD_aSr$_nNSeK4^!>KdIGE31FE145)%!&sQ0Hu$<>~= zguA5g=zMqF=r9F`Lmz0v1B>&PO+JDnkCzRk1oB%mG5FOlqBf0eo zsoj-z-ATJklYeg4pyP(y|i1l6a#!>%( z=HRAZy}tM)v$Vj+;FFJyMVrN@-b!zY4U^Gry$z=wuzFi;qC8-Or44#_0NcfQ1%YaA z9lxmW92Q*2{4AOj`KdgcE3Rdck4B@9G{Rmbxv1Aiqp{$ck6W2>y*}eIe_|9yX;tLR zdiG1bx35&8B9(l`UUVw6WEAaRN)5ii`UmV_z5O%?0?%ZP5tLVF&|6^E5B^85%;4-r zC0Be_J&KrjA#+h&)HcX6Z<@%nsczg0DfF~{^kSMstwuEAd0yz~B#C4m@#s8JT26Qt z6-vTrwu#<|sUEEIobl4+Tl;{G^rar&ZG1J)a|p9>OC@uyaA+F`vv1rCYFM!jrXK6$ zQa4^(sm6c$%v7au5=g!A+7y{1A#dhYU`Z#;Jy6BGY`E);q6@E0Mmcy0 zlN*;x;q*7YkSd3|u|CB56Ljh4A`^*H@G4+@h0GfpI8A^(J1mNFXg5xkWTz}_gKXtl z_xc2l`kSZ+p#AZi@wAvF;|rj zxy5k^2CAg9YhZl+wgEco- z{d+(zM=;DpA*88=Lk$>SZIZgFXReQ*25AR5Z>^W@$kXFtS7B^w2LKDFJQrDFo~laS zLXsmCzfjwT+qSEHxYQPspxRZL@hj$>X0jYog-@2LRtp~D@g9J0VO0SD0{M06fL`ad z>ca8R#bROS;<)L?@vIQ@4Dm3I-_Ci~a?}@K!5F;Z1e>FbCm*mLtO}w^EHD)4wizko;B&Dw!4GW;KVqjU O^bG+)lS61W{Purgf~)EP literal 0 HcmV?d00001 diff --git a/src/game/__pycache__/Map.cpython-36.pyc b/src/game/__pycache__/Map.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e9f8b09d45b8129c2c3f916e811fe89ea9528fd1 GIT binary patch literal 1256 zcmZuxO>fgc5Zzg?9Xm}!sS1>W5GSM{)F8MbR752>Kn1i?kOf#))=3;3JKc4fHcBp} z5=SJC95}-t;KVQ4E2o~h^~8+bic0N9Gk!BWvmf(j^KfyoI#ZuN{1uG-VP}SgcmqX0 zKqZ-kg!%O42@JT;fv}ZW1K|r`&zKa_K4j9KbKjP*%^J=T=CQ2?n1!84sW47=;v_=T zdy%!nJkCiM82D2ISCmniBjJq zvlYv{=T`|nkK%4GH};rZ#_5&j!pZWRDjZ`Sg^rSraXT2F;we;x&gG&q&@m#3)95Et zSI|Db-|S_Bs5y?+NH=A)*OYn^2YRIT;=M3II+|Lwn{<^X8tcOY;|4*T#(5ABKY9%n z1Lx#dgDR}?I$wes)S=ENHA*^7Xj5fq*eD)K!R&7Y`@iynl{p}HKi=^f%=rFy^zp*; z6+PBWOofDxTQ}j|ws%nJjq2h~p@~UC0%LP{1*te+(w6WS*Vg%uW$5LITv?WxlD4GC+6<7ur z?wrWv5)pEyS+*KBF-lz$1g07UgG`PR!nGjS9fe6bqpsmv#nNZCqXtsNp7dmiR87DI zcUcj@Ms$V;)I0tX>Ghre{};t&%|hYcE}lqn-y-j#EsXo9JlSJvB2B&LVw2VQKQ5^) AQ2+n{ literal 0 HcmV?d00001 diff --git a/src/game/__pycache__/Screen.cpython-36.pyc b/src/game/__pycache__/Screen.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7f4da67290f06a8576bacf363c8501eefbf1739c GIT binary patch literal 1570 zcmZuxOK%%D5awfFmSx9HTSrb>psz!=2&#h%^imW~-PAE)t3{jw$sW4cENOc;t4GL{ z9SibFLHb+z2l``p?MZ*3m-d^L>=;ET%(uhga5$X##O<}U)?csw`2B6b*x&5N@SyKN z?2iD&6t7r9Us3VCNCaQlWFnPJygjBo<-cLdpNYiBEKnh4p%ycl1d1QAIGQ64>&4u8 zj|Ss@@qjaylj&**C_51Q6+p9uE0zewm3YJG5ar>ELsWpTuR;pxf}`AMJ;)`t(4cP! z*@f7*fGMA{luZ$5i$UYiM5BpXmR{*&F1Of>bJom*DJ!v~6vtvlJ45KvjCQWnt#Wm_ zy3)aQ?_n40ZR}es*Rc{R@@^}Nu|jg<%_NnHGVMA4yioP23r=-$a#}lYkoEPP?mYh& zU{DPfOB0cP4e>44I)UFWFG`(b&v`L;*5Gp&j4o)!g{rWlD!Xv2R@Z5sjp|}Ja1l-V zL#17N;kT%h+sv~nA6Hqe53|uvMPCmr+^q}y+32X4Xy^4aBu%1(;Zj?Gzd zmQ^^pYfavz^t+3^z8PJ(C{2q&QK#uDLf8!e;{k8sx4}1MOLpYs*3$dRGpC}_ptciV zo3?)oMe$2&BfAtpG`+)W@sgPbQ&C@AI;_Jk`M{eB_!2`!@2U%wf@uLTL?YOFwwthWAEwrMdHJ4t%UE25o;2y-b0gQV*kn8*-;fcwo%L}}}3%O7J81%iq z&IFSwFJZt%&B+{kTL=|3>8NN=aRt&YL>64+zH%=q|nx>1yDWZVI!^k2Y zZA5E^Y&qn55CL}}me}#`&BA*n@K#B@Qyz%ro6oU4Cuc*i)12ZURYO-YF~QdaUjUNu z;L*=bHNPZNlg~S7GNWMIkY#2b7}gvRhvq|=ou~1>8hTm`G0=QMKu0!S?+fXo?-zyo RfpWBT?TEKUBt5wv{|DuySUms$ literal 0 HcmV?d00001 diff --git a/src/game/__pycache__/TerrainTile.cpython-36.pyc b/src/game/__pycache__/TerrainTile.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1e1f00f988f3be38a5395e04ea8329916f4be285 GIT binary patch literal 955 zcmYjPy>HYo6u0xuUDB5JT0lVeTP_0(3)U2NizDPet!Pz5b}rY9S`_hxcVgkBaD_L8(x}Gke!mQ zoXnx*17R-nZVB@^k*@SQH}e^tlc|3Pk>p}ZtydT3YJt-If!~Jg6Cj*m#>`=qIkzNp znG4aL9ba;#3bDQvC0_))NPMxhcX0J@fF)^3PFgA{ypDkaq%VUOw9@IIycYGLiR1%D zJLDtaW3Y}G*g=jVCXol`P!9UI^*X1c@~Fei33w**AqzSRxsV_C`jZx8C#?&3+WO3Y zir#17F@bwFLEjUw6M4EPpE3fig%{hy*(_y+DN?a2mRzScG()qBLQi)L0Y@`+dxi3W z_iXye`UVD~?O4}J7_L7GZEUbqRa0vl)Hlmw#cePcZ7}bhY?S9>Eli$U5A6!)Z$l>3 z8l)^9s(4?Oj4SKOO02VFSI|!B_b%2etAbgl(l%UF>kU`N#+sXaQI(bY#&2x21WECQ zv0jh#+EUPB$#b#g)4+O~mtWNZHuML)PPJO3*i*W659$Io5T=InfvJu1d{wcgL>}k)_ogTZOaDz@>K>fKhsp)OZPhsIi1zX{P$RUR hAfR525n=@N-^+pBD@ Date: Fri, 3 Apr 2020 19:56:03 +0200 Subject: [PATCH 06/20] gitignore --- .gitignore | 1 + src/.gitignore | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 src/.gitignore diff --git a/.gitignore b/.gitignore index 85e7c1d..78b759b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.idea/ +__pycache__ diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..78b759b --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,2 @@ +/.idea/ +__pycache__ From 9f95091ff67ddcb3a0cf96822defa153612ce97e Mon Sep 17 00:00:00 2001 From: Mateusz Tylka Date: Fri, 3 Apr 2020 19:57:44 +0200 Subject: [PATCH 07/20] gitignore --- src/.gitignore | 2 -- src/game/__pycache__/EventManager.cpython-36.pyc | Bin 669 -> 0 bytes src/game/__pycache__/Game.cpython-36.pyc | Bin 1712 -> 0 bytes src/game/__pycache__/Map.cpython-36.pyc | Bin 1256 -> 0 bytes src/game/__pycache__/Screen.cpython-36.pyc | Bin 1570 -> 0 bytes src/game/__pycache__/TerrainTile.cpython-36.pyc | Bin 955 -> 0 bytes 6 files changed, 2 deletions(-) delete mode 100644 src/.gitignore delete mode 100644 src/game/__pycache__/EventManager.cpython-36.pyc delete mode 100644 src/game/__pycache__/Game.cpython-36.pyc delete mode 100644 src/game/__pycache__/Map.cpython-36.pyc delete mode 100644 src/game/__pycache__/Screen.cpython-36.pyc delete mode 100644 src/game/__pycache__/TerrainTile.cpython-36.pyc diff --git a/src/.gitignore b/src/.gitignore deleted file mode 100644 index 78b759b..0000000 --- a/src/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/.idea/ -__pycache__ diff --git a/src/game/__pycache__/EventManager.cpython-36.pyc b/src/game/__pycache__/EventManager.cpython-36.pyc deleted file mode 100644 index 0311caa42beca3eeed7e6390cdb6e675d702e286..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 669 zcmZut&5G1O5U%R(%)}upUW8RV3jr|)PlCvTe|XptQ4s>##B@8Gn90s`C*#gAo_4`! z@dbRCzIyT%JXw`taTYA7udA!Ss{X1T92`u3F28?71o#DeCMiB5_qPcQ7;GSi7hr^u z7hvSM$kE^%NY!t8hiS=pX@Y_ya({=w0x=;M293CYTpDQR0QR1^EsdJ?bWB+mfa6<5%K>#%uY_{Hv3w+ z-e<|bH!#7?tt*4< zGpA|9v$v!{>oC!Jero!L<3#IaUo^WHH>O_hI>Wzzhlqc1ya`t38Dfm(kRiD&WQhM) Q7UD;{-yZWuho#5zFFy8_YybcN diff --git a/src/game/__pycache__/Game.cpython-36.pyc b/src/game/__pycache__/Game.cpython-36.pyc deleted file mode 100644 index 24e8dca6492340b38b809afe25befd58190a7267..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1712 zcmZt`$!^<5bcVYm%9icKjUIi>B0%aIL2ai%0wf)vA;uco8ipd7;m8Z2 zoD`s^9{L&mp&oecDZh|Y-y2$i3xveHdGq#d=DU8s`rrw*gfD{kLm#1?vqS;idp=P~k^^QR@p6J{tIq=DF|6u7 zfP`R>%o0>s?+LSoEgaY#;etD_aSr$_nNSeK4^!>KdIGE31FE145)%!&sQ0Hu$<>~= zguA5g=zMqF=r9F`Lmz0v1B>&PO+JDnkCzRk1oB%mG5FOlqBf0eo zsoj-z-ATJklYeg4pyP(y|i1l6a#!>%( z=HRAZy}tM)v$Vj+;FFJyMVrN@-b!zY4U^Gry$z=wuzFi;qC8-Or44#_0NcfQ1%YaA z9lxmW92Q*2{4AOj`KdgcE3Rdck4B@9G{Rmbxv1Aiqp{$ck6W2>y*}eIe_|9yX;tLR zdiG1bx35&8B9(l`UUVw6WEAaRN)5ii`UmV_z5O%?0?%ZP5tLVF&|6^E5B^85%;4-r zC0Be_J&KrjA#+h&)HcX6Z<@%nsczg0DfF~{^kSMstwuEAd0yz~B#C4m@#s8JT26Qt z6-vTrwu#<|sUEEIobl4+Tl;{G^rar&ZG1J)a|p9>OC@uyaA+F`vv1rCYFM!jrXK6$ zQa4^(sm6c$%v7au5=g!A+7y{1A#dhYU`Z#;Jy6BGY`E);q6@E0Mmcy0 zlN*;x;q*7YkSd3|u|CB56Ljh4A`^*H@G4+@h0GfpI8A^(J1mNFXg5xkWTz}_gKXtl z_xc2l`kSZ+p#AZi@wAvF;|rj zxy5k^2CAg9YhZl+wgEco- z{d+(zM=;DpA*88=Lk$>SZIZgFXReQ*25AR5Z>^W@$kXFtS7B^w2LKDFJQrDFo~laS zLXsmCzfjwT+qSEHxYQPspxRZL@hj$>X0jYog-@2LRtp~D@g9J0VO0SD0{M06fL`ad z>ca8R#bROS;<)L?@vIQ@4Dm3I-_Ci~a?}@K!5F;Z1e>FbCm*mLtO}w^EHD)4wizko;B&Dw!4GW;KVqjU O^bG+)lS61W{Purgf~)EP diff --git a/src/game/__pycache__/Map.cpython-36.pyc b/src/game/__pycache__/Map.cpython-36.pyc deleted file mode 100644 index e9f8b09d45b8129c2c3f916e811fe89ea9528fd1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1256 zcmZuxO>fgc5Zzg?9Xm}!sS1>W5GSM{)F8MbR752>Kn1i?kOf#))=3;3JKc4fHcBp} z5=SJC95}-t;KVQ4E2o~h^~8+bic0N9Gk!BWvmf(j^KfyoI#ZuN{1uG-VP}SgcmqX0 zKqZ-kg!%O42@JT;fv}ZW1K|r`&zKa_K4j9KbKjP*%^J=T=CQ2?n1!84sW47=;v_=T zdy%!nJkCiM82D2ISCmniBjJq zvlYv{=T`|nkK%4GH};rZ#_5&j!pZWRDjZ`Sg^rSraXT2F;we;x&gG&q&@m#3)95Et zSI|Db-|S_Bs5y?+NH=A)*OYn^2YRIT;=M3II+|Lwn{<^X8tcOY;|4*T#(5ABKY9%n z1Lx#dgDR}?I$wes)S=ENHA*^7Xj5fq*eD)K!R&7Y`@iynl{p}HKi=^f%=rFy^zp*; z6+PBWOofDxTQ}j|ws%nJjq2h~p@~UC0%LP{1*te+(w6WS*Vg%uW$5LITv?WxlD4GC+6<7ur z?wrWv5)pEyS+*KBF-lz$1g07UgG`PR!nGjS9fe6bqpsmv#nNZCqXtsNp7dmiR87DI zcUcj@Ms$V;)I0tX>Ghre{};t&%|hYcE}lqn-y-j#EsXo9JlSJvB2B&LVw2VQKQ5^) AQ2+n{ diff --git a/src/game/__pycache__/Screen.cpython-36.pyc b/src/game/__pycache__/Screen.cpython-36.pyc deleted file mode 100644 index 7f4da67290f06a8576bacf363c8501eefbf1739c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1570 zcmZuxOK%%D5awfFmSx9HTSrb>psz!=2&#h%^imW~-PAE)t3{jw$sW4cENOc;t4GL{ z9SibFLHb+z2l``p?MZ*3m-d^L>=;ET%(uhga5$X##O<}U)?csw`2B6b*x&5N@SyKN z?2iD&6t7r9Us3VCNCaQlWFnPJygjBo<-cLdpNYiBEKnh4p%ycl1d1QAIGQ64>&4u8 zj|Ss@@qjaylj&**C_51Q6+p9uE0zewm3YJG5ar>ELsWpTuR;pxf}`AMJ;)`t(4cP! z*@f7*fGMA{luZ$5i$UYiM5BpXmR{*&F1Of>bJom*DJ!v~6vtvlJ45KvjCQWnt#Wm_ zy3)aQ?_n40ZR}es*Rc{R@@^}Nu|jg<%_NnHGVMA4yioP23r=-$a#}lYkoEPP?mYh& zU{DPfOB0cP4e>44I)UFWFG`(b&v`L;*5Gp&j4o)!g{rWlD!Xv2R@Z5sjp|}Ja1l-V zL#17N;kT%h+sv~nA6Hqe53|uvMPCmr+^q}y+32X4Xy^4aBu%1(;Zj?Gzd zmQ^^pYfavz^t+3^z8PJ(C{2q&QK#uDLf8!e;{k8sx4}1MOLpYs*3$dRGpC}_ptciV zo3?)oMe$2&BfAtpG`+)W@sgPbQ&C@AI;_Jk`M{eB_!2`!@2U%wf@uLTL?YOFwwthWAEwrMdHJ4t%UE25o;2y-b0gQV*kn8*-;fcwo%L}}}3%O7J81%iq z&IFSwFJZt%&B+{kTL=|3>8NN=aRt&YL>64+zH%=q|nx>1yDWZVI!^k2Y zZA5E^Y&qn55CL}}me}#`&BA*n@K#B@Qyz%ro6oU4Cuc*i)12ZURYO-YF~QdaUjUNu z;L*=bHNPZNlg~S7GNWMIkY#2b7}gvRhvq|=ou~1>8hTm`G0=QMKu0!S?+fXo?-zyo RfpWBT?TEKUBt5wv{|DuySUms$ diff --git a/src/game/__pycache__/TerrainTile.cpython-36.pyc b/src/game/__pycache__/TerrainTile.cpython-36.pyc deleted file mode 100644 index 1e1f00f988f3be38a5395e04ea8329916f4be285..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 955 zcmYjPy>HYo6u0xuUDB5JT0lVeTP_0(3)U2NizDPet!Pz5b}rY9S`_hxcVgkBaD_L8(x}Gke!mQ zoXnx*17R-nZVB@^k*@SQH}e^tlc|3Pk>p}ZtydT3YJt-If!~Jg6Cj*m#>`=qIkzNp znG4aL9ba;#3bDQvC0_))NPMxhcX0J@fF)^3PFgA{ypDkaq%VUOw9@IIycYGLiR1%D zJLDtaW3Y}G*g=jVCXol`P!9UI^*X1c@~Fei33w**AqzSRxsV_C`jZx8C#?&3+WO3Y zir#17F@bwFLEjUw6M4EPpE3fig%{hy*(_y+DN?a2mRzScG()qBLQi)L0Y@`+dxi3W z_iXye`UVD~?O4}J7_L7GZEUbqRa0vl)Hlmw#cePcZ7}bhY?S9>Eli$U5A6!)Z$l>3 z8l)^9s(4?Oj4SKOO02VFSI|!B_b%2etAbgl(l%UF>kU`N#+sXaQI(bY#&2x21WECQ zv0jh#+EUPB$#b#g)4+O~mtWNZHuML)PPJO3*i*W659$Io5T=InfvJu1d{wcgL>}k)_ogTZOaDz@>K>fKhsp)OZPhsIi1zX{P$RUR hAfR525n=@N-^+pBD@ Date: Fri, 3 Apr 2020 20:23:36 +0200 Subject: [PATCH 08/20] refactor TerrainTile --- src/game/Game.py | 2 +- src/game/Map.py | 9 ++++----- src/game/TerrainTile.py | 7 ++----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/game/Game.py b/src/game/Game.py index 1df88e4..6e6e8e4 100644 --- a/src/game/Game.py +++ b/src/game/Game.py @@ -42,7 +42,7 @@ class Game: # Start Map implement self.mapDataFolder = path.dirname("../data/mapdata/") - self.map = Map(path.join(self.mapDataFolder, 'map.txt'), self, self.screen) + self.map = Map(path.join(self.mapDataFolder, 'map.txt'), self.screen) # End Map implement self.mainLoop() diff --git a/src/game/Map.py b/src/game/Map.py index 7ed7db2..7ea843a 100644 --- a/src/game/Map.py +++ b/src/game/Map.py @@ -3,8 +3,7 @@ from game.TerrainTile import TerrainTile from game.Screen import Locations class Map: - def __init__(self, filename, game, screen): - self.game = game + def __init__(self, filename, screen): self.screen = screen self.terrain = [] self.entities = [] @@ -25,10 +24,10 @@ class Map: for row, tiles in enumerate(self.terrain): for col, tile in enumerate(tiles): if tile == 'w': - self.screen.draw(TerrainTile(self.game, col, row, 'wall.png', self.screen.mapSize), Locations.MAP, col, row) + self.screen.draw(TerrainTile(col, row, 'wall.png', self.screen.mapSize), Locations.MAP, col, row) if tile == ',': - self.screen.draw(TerrainTile(self.game, col, row, 'floor.png', self.screen.mapSize), Locations.MAP, col, row) + self.screen.draw(TerrainTile(col, row, 'floor.png', self.screen.mapSize), Locations.MAP, col, row) if tile == '.': - self.screen.draw(TerrainTile(self.game, col, row, 'grass.png', self.screen.mapSize), Locations.MAP, col, row) + self.screen.draw(TerrainTile(col, row, 'grass.png', self.screen.mapSize), Locations.MAP, col, row) diff --git a/src/game/TerrainTile.py b/src/game/TerrainTile.py index dcebdc8..c541760 100644 --- a/src/game/TerrainTile.py +++ b/src/game/TerrainTile.py @@ -4,11 +4,8 @@ from os import path class TerrainTile(pygame.sprite.Sprite): - def __init__(self, game, x, y, texture, mapSize): - self.tiles = [] - self.groups = game.spritesList - pygame.sprite.Sprite.__init__(self, self.groups) - self.game = game + def __init__(self, x, y, texture, mapSize): + 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() From 9ef8d99c61a09129df3ea9c6dfcd632d3bf98513 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Fri, 3 Apr 2020 23:07:12 +0200 Subject: [PATCH 09/20] Fixed map rendering --- src/game/Map.py | 12 ++++++------ src/game/TerrainTile.py | 14 +++----------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/game/Map.py b/src/game/Map.py index 7ed7db2..0b60871 100644 --- a/src/game/Map.py +++ b/src/game/Map.py @@ -12,7 +12,7 @@ class Map: for line in f: self.terrain.append(line) - self.tileSize = self.screen.mapSize/20 + self.tileSize = int(self.screen.mapSize/20) self.tileWidth = len(self.terrain[0]) self.tileHeight = len(self.terrain) @@ -25,10 +25,10 @@ class Map: for row, tiles in enumerate(self.terrain): for col, tile in enumerate(tiles): if tile == 'w': - self.screen.draw(TerrainTile(self.game, col, row, 'wall.png', self.screen.mapSize), Locations.MAP, col, row) - if tile == ',': - self.screen.draw(TerrainTile(self.game, col, row, 'floor.png', self.screen.mapSize), Locations.MAP, col, row) - if tile == '.': - self.screen.draw(TerrainTile(self.game, col, row, 'grass.png', self.screen.mapSize), Locations.MAP, col, row) + self.screen.draw(TerrainTile('wall.png', self.tileSize), Locations.MAP, col*self.tileSize, row*self.tileSize) + elif tile == ',': + 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) diff --git a/src/game/TerrainTile.py b/src/game/TerrainTile.py index dcebdc8..636838b 100644 --- a/src/game/TerrainTile.py +++ b/src/game/TerrainTile.py @@ -4,18 +4,10 @@ from os import path class TerrainTile(pygame.sprite.Sprite): - def __init__(self, game, x, y, texture, mapSize): - self.tiles = [] - self.groups = game.spritesList - pygame.sprite.Sprite.__init__(self, self.groups) - self.game = game + def __init__(self, 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.set_colorkey((0,100,0)) + self.image = pygame.transform.scale(self.image, (tileSize, tileSize)) self.rect = self.image.get_rect() - self.x = x - self.y = y - self.tileSize = mapSize/20 - self.rect.x = self.x * self.tileSize - self.rect.y = self.y * self.tileSize From 46441b94c93d0240ab175e7ab19ef180e7fc2e75 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Fri, 3 Apr 2020 23:09:00 +0200 Subject: [PATCH 10/20] Removed redundant argument --- 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 0b60871..7daa356 100644 --- a/src/game/Map.py +++ b/src/game/Map.py @@ -3,8 +3,7 @@ from game.TerrainTile import TerrainTile from game.Screen import Locations class Map: - def __init__(self, filename, game, screen): - self.game = game + def __init__(self, filename, screen): self.screen = screen self.terrain = [] self.entities = [] From c454d8d328ca44336dcd017ac19bf053c307224f Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sat, 4 Apr 2020 20:53:13 +0200 Subject: [PATCH 11/20] Updated entity class --- src/entities/Entity.py | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/entities/Entity.py b/src/entities/Entity.py index e9be7f1..cda0aed 100644 --- a/src/entities/Entity.py +++ b/src/entities/Entity.py @@ -1,6 +1,37 @@ -class Entity: +from pathlib import Path +import pygame + + +class Entity: + nextId = 1 + + def __init__(self, texture, pos): + self.image = texture + self.rect = self.image.get_rect() + self.rect.x = pos[0] + self.rect.y = pos[1] + self.id = self.getId() + + # A method to return auto-incremented ID + def getId(self): + id = Entity.nextId + Entity.nextId += 1 + return id + + # A method that returns image and rect from a file + @staticmethod + def getTexture(textureName, tileSize): + texturesFolder = "" + textureFile = "" + try: + texturesFolder = Path("../data/images/entities") + textureFile = texturesFolder / textureName + except IOError: + print("Cannot load texture from " + texturesFolder + ". Exiting...") + exit(1) + image = pygame.image.load(str(textureFile)).convert_alpha() + image = pygame.transform.scale(image, (tileSize, tileSize)) + rect = image.get_rect() + return image, rect + - def __init__(self, texture, pos, id): - self.texture = texture - self.pos = pos - self.id = id From 5e021ca087e08d4c5fc6e3663df8e419b59a514a Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sat, 4 Apr 2020 20:53:33 +0200 Subject: [PATCH 12/20] Added constructor params --- src/entities/Statistics.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/entities/Statistics.py b/src/entities/Statistics.py index 1b28c2b..c506eee 100644 --- a/src/entities/Statistics.py +++ b/src/entities/Statistics.py @@ -1,9 +1,9 @@ class Statistics: - def __init__(self): - self.hp = 100 - self.hunger = 100 - self.thirst = 100 - self.stamina = 100 + def __init__(self, hp, hunger, thirst, stamina): + self.hp = hp + self.hunger = hunger + self.thirst = thirst + self.stamina = stamina # methods that don't let the values pass below 0 and over 100 during change def set_hp(self, hp_diff): @@ -42,5 +42,3 @@ class Statistics: else: self.hp = 100 - - From cad65b8ed77971697bb5960cff1547bd6e44751a Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sat, 4 Apr 2020 20:53:54 +0200 Subject: [PATCH 13/20] Added temporary player texture --- data/images/entities/player.jpg | Bin 0 -> 17438 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 data/images/entities/player.jpg diff --git a/data/images/entities/player.jpg b/data/images/entities/player.jpg new file mode 100644 index 0000000000000000000000000000000000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py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/entities/Player.py b/src/entities/Player.py index 0cc7578..84f9775 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -1,6 +1,24 @@ -import src.entities.Entity as Entity +from enum import Enum + +from src.entities.Entity import Entity +from src.entities.Statistics import Statistics +import pygame -class Player(Entity): - def __init__(self): - self.statistics +class Player(Entity, pygame.sprite.Sprite): + def __init__(self, spawnpoint, size): + pygame.sprite.Sprite.__init__(self) + + self.statistics = Statistics(100, 0, 0, 100) + + self.image, self.rect = Entity.getTexture("player.jpg", size) + super(Player, self).__init__(self.image, spawnpoint) + # Where the player is facing, 0 - north, 1 + self.rotation = Rotations.NORTH + + +class Rotations(Enum): + NORTH = 0 + EAST = 1 + SOUTH = 2 + WEST = 3 \ No newline at end of file From 8c1dad010139f516b7c506ab4ceb4e27408bfe52 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sat, 4 Apr 2020 21:33:24 +0200 Subject: [PATCH 15/20] Added move and rotate function --- src/entities/Player.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/entities/Player.py b/src/entities/Player.py index 84f9775..c51f272 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -16,6 +16,19 @@ class Player(Entity, pygame.sprite.Sprite): # Where the player is facing, 0 - north, 1 self.rotation = Rotations.NORTH + # Move in a desired direction + def move(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.rotate(rotation) + # Otherwise, move one tile to a given direction + else: + return 1 + + def rotate(self, rotation): + self.image = pygame.transform.rotate(self.image, (abs(self.rotation.value - rotation.value) * 90)) + self.rotation = rotation + class Rotations(Enum): NORTH = 0 From 277a84b72e74e942c6f54c7dc4913de2acc1cac3 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sat, 4 Apr 2020 21:33:39 +0200 Subject: [PATCH 16/20] Added player movement --- src/game/EventManager.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 3cc4e99..5d51510 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -1,11 +1,38 @@ import pygame +from src.entities.Player import Rotations + class EventManager: - def __init__(self, gameObject): + def __init__(self, gameObject, player): self.game = gameObject + self.player = player + + # Player controls + + # TODO + def loadKeyboardSettings(self): + pass def handleEvents(self): + pygame.event.pump() + + keys = pygame.key.get_pressed() for event in pygame.event.get(): if event.type == pygame.QUIT: self.game.running = False + + self.handlePlayerControls(keys) + + def handlePlayerControls(self, keys): + # Key names are temporary + # TODO: Load key bindings from JSON + if keys[pygame.K_w]: + self.player.move(Rotations.NORTH) + if keys[pygame.K_s]: + self.player.move(Rotations.SOUTH) + if keys[pygame.K_d]: + self.player.move(Rotations.EAST) + if keys[pygame.K_a]: + self.player.move(Rotations.WEST) + From e184e6417be536120283aca7f1e93868fa4b4b9a Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sun, 5 Apr 2020 14:06:56 +0200 Subject: [PATCH 17/20] Entity now inherits from pygame.sprite.Sprite --- src/entities/Entity.py | 3 ++- src/entities/Player.py | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/entities/Entity.py b/src/entities/Entity.py index cda0aed..98dff66 100644 --- a/src/entities/Entity.py +++ b/src/entities/Entity.py @@ -2,10 +2,11 @@ from pathlib import Path import pygame -class Entity: +class Entity(pygame.sprite.Sprite): nextId = 1 def __init__(self, texture, pos): + super().__init__() self.image = texture self.rect = self.image.get_rect() self.rect.x = pos[0] diff --git a/src/entities/Player.py b/src/entities/Player.py index c51f272..667372b 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -5,14 +5,12 @@ from src.entities.Statistics import Statistics import pygame -class Player(Entity, pygame.sprite.Sprite): +class Player(Entity): def __init__(self, spawnpoint, size): - pygame.sprite.Sprite.__init__(self) - self.statistics = Statistics(100, 0, 0, 100) self.image, self.rect = Entity.getTexture("player.jpg", size) - super(Player, self).__init__(self.image, spawnpoint) + super().__init__(self.image, spawnpoint) # Where the player is facing, 0 - north, 1 self.rotation = Rotations.NORTH From 6efd5652dd4314be6c79f3345e52821c556684e8 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sun, 5 Apr 2020 14:49:37 +0200 Subject: [PATCH 18/20] Implemented proper player movement --- src/entities/Player.py | 12 ++++++++++-- src/game/EventManager.py | 14 ++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/entities/Player.py b/src/entities/Player.py index 667372b..6fda5bf 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -21,10 +21,18 @@ class Player(Entity): self.rotate(rotation) # Otherwise, move one tile to a given direction else: - return 1 + # TODO: Collision checks + if rotation.value == Rotations.NORTH.value: + self.rect.y -= self.rect.w + elif rotation.value == Rotations.EAST.value: + self.rect.x += self.rect.w + elif rotation.value == Rotations.SOUTH.value: + self.rect.y += self.rect.w + elif rotation.value == Rotations.WEST.value: + self.rect.x -= self.rect.w def rotate(self, rotation): - self.image = pygame.transform.rotate(self.image, (abs(self.rotation.value - rotation.value) * 90)) + self.image = pygame.transform.rotate(self.image, ((self.rotation.value - rotation.value) * 90)) self.rotation = rotation diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 5d51510..d2a9a13 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -2,12 +2,15 @@ import pygame from src.entities.Player import Rotations - +# Player can move every given milliseconds +TIMEOUT = 100 class EventManager: + keyTimeout = 0 + def __init__(self, gameObject, player): self.game = gameObject self.player = player - + self.keyTimer = pygame.time.Clock() # Player controls # TODO @@ -21,12 +24,15 @@ class EventManager: for event in pygame.event.get(): if event.type == pygame.QUIT: self.game.running = False - - self.handlePlayerControls(keys) + self.keyTimeout += self.keyTimer.tick() + if self.keyTimeout >= TIMEOUT: + self.handlePlayerControls(keys) + self.keyTimeout = 0 def handlePlayerControls(self, keys): # Key names are temporary # TODO: Load key bindings from JSON + if keys[pygame.K_w]: self.player.move(Rotations.NORTH) if keys[pygame.K_s]: From d88670f456342bf8ad89d75e4879c879581854b3 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sun, 5 Apr 2020 14:52:19 +0200 Subject: [PATCH 19/20] Fixed retarded Entity implementation --- src/entities/Entity.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/entities/Entity.py b/src/entities/Entity.py index 98dff66..857f664 100644 --- a/src/entities/Entity.py +++ b/src/entities/Entity.py @@ -5,10 +5,9 @@ import pygame class Entity(pygame.sprite.Sprite): nextId = 1 - def __init__(self, texture, pos): + def __init__(self, texture, size, pos): super().__init__() - self.image = texture - self.rect = self.image.get_rect() + self.image, self.rect = self.getTexture(texture, size) self.rect.x = pos[0] self.rect.y = pos[1] self.id = self.getId() @@ -20,8 +19,7 @@ class Entity(pygame.sprite.Sprite): return id # A method that returns image and rect from a file - @staticmethod - def getTexture(textureName, tileSize): + def getTexture(self, textureName, tileSize): texturesFolder = "" textureFile = "" try: From a264ac7cb19edfeda4b57a98e603ed0a484706be Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sun, 5 Apr 2020 14:52:30 +0200 Subject: [PATCH 20/20] Refactor to fixed Entity class --- src/entities/Player.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/entities/Player.py b/src/entities/Player.py index 6fda5bf..ed6f38a 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -7,10 +7,7 @@ import pygame class Player(Entity): def __init__(self, spawnpoint, size): - self.statistics = Statistics(100, 0, 0, 100) - - self.image, self.rect = Entity.getTexture("player.jpg", size) - super().__init__(self.image, spawnpoint) + super().__init__("player.jpg", size, spawnpoint) # Where the player is facing, 0 - north, 1 self.rotation = Rotations.NORTH