From 65b5c8074b6685972609617c1bc256818ac9fa84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Pierzy=C5=84ski?= Date: Mon, 1 Apr 2019 12:48:11 +0200 Subject: [PATCH] Dodano generowanie obiektow na siatce z plikow map --- DataModels/Cell.py | 26 +++++++++ DataModels/Container.py | 10 ++++ DataModels/Dump.py | 7 +++ DataModels/Grass.py | 8 +++ DataModels/House.py | 6 ++ DataModels/Road.py | 8 +++ DataModels/__pycache__/Cell.cpython-36.pyc | Bin 0 -> 1429 bytes .../__pycache__/Container.cpython-36.pyc | Bin 0 -> 807 bytes DataModels/__pycache__/Dump.cpython-36.pyc | Bin 0 -> 599 bytes DataModels/__pycache__/Grass.cpython-36.pyc | Bin 0 -> 657 bytes DataModels/__pycache__/House.cpython-36.pyc | Bin 0 -> 571 bytes Resources/Maps/map_000.txt | 3 + __pycache__/config.cpython-36.pyc | Bin 0 -> 548 bytes c | Bin 0 -> 8296 bytes c.c | 11 ++++ config.py | 12 ++-- main.py | 55 ++++++++++++++++-- 17 files changed, 136 insertions(+), 10 deletions(-) create mode 100644 DataModels/Cell.py create mode 100644 DataModels/Container.py create mode 100644 DataModels/Dump.py create mode 100644 DataModels/Grass.py create mode 100644 DataModels/House.py create mode 100644 DataModels/Road.py create mode 100644 DataModels/__pycache__/Cell.cpython-36.pyc create mode 100644 DataModels/__pycache__/Container.cpython-36.pyc create mode 100644 DataModels/__pycache__/Dump.cpython-36.pyc create mode 100644 DataModels/__pycache__/Grass.cpython-36.pyc create mode 100644 DataModels/__pycache__/House.cpython-36.pyc create mode 100644 Resources/Maps/map_000.txt create mode 100644 __pycache__/config.cpython-36.pyc create mode 100755 c create mode 100644 c.c diff --git a/DataModels/Cell.py b/DataModels/Cell.py new file mode 100644 index 0000000..3884a11 --- /dev/null +++ b/DataModels/Cell.py @@ -0,0 +1,26 @@ +import pygame, random + +from DataModels.Container import Container + +from PIL import Image,ImageDraw +from config import CELL_SIZE + +class Cell( pygame.sprite.Sprite ): + def __init__( self, x, y, max_rubbish, yellow = 0, green = 0, blue = 0, image_name = None): + pygame.sprite.Sprite.__init__( self ) + self.image_name = image_name or type(self).__name__ + self.update_rect( x,y ) + self.container = Container( max_rubbish, yellow, green, blue ) + self.update_image() + + def update_rect( self, x, y ): + self.x, self.y = x,y + self.rect = pygame.Rect( x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE ) + + def update_image( self ): + image = Image.open("Resources/Images/Image_" + self.image_name + ".png" ) + draw = ImageDraw.Draw(image) + draw.text( (5,5), str( self.container.status() ) ) + mode, size, data = image.mode, image.size, image.tobytes() + + self.image = pygame.image.frombuffer( data, size, mode ) diff --git a/DataModels/Container.py b/DataModels/Container.py new file mode 100644 index 0000000..4918a31 --- /dev/null +++ b/DataModels/Container.py @@ -0,0 +1,10 @@ + +class Container(): + def __init__( self, max, y = 0, g = 0, b = 0 ): + self.y, self.g, self.b = y, g, b + + def empty( self ): + self.y, self.g, self.b = 0,0,0 + + def status( self ): + return [self.y, self.g, self.b] \ No newline at end of file diff --git a/DataModels/Dump.py b/DataModels/Dump.py new file mode 100644 index 0000000..712aed9 --- /dev/null +++ b/DataModels/Dump.py @@ -0,0 +1,7 @@ +import pygame +from DataModels.Cell import Cell + +class Dump( Cell ): + def __init__( self, x, y, max_rubbish, dump_type, yellow = 0, green = 0, blue = 0 ): + Cell.__init__( self, x, y, max_rubbish, yellow, green, blue, dump_type ) + diff --git a/DataModels/Grass.py b/DataModels/Grass.py new file mode 100644 index 0000000..9cf974a --- /dev/null +++ b/DataModels/Grass.py @@ -0,0 +1,8 @@ +import pygame +from config import CELL_SIZE + +class Grass( pygame.sprite.Sprite ): + def __init__( self, x, y ): + pygame.sprite.Sprite.__init__( self ) + self.rect = pygame.Rect( x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE ) + self.image = pygame.image.load("Resources/Images/Image_Grass.png") \ No newline at end of file diff --git a/DataModels/House.py b/DataModels/House.py new file mode 100644 index 0000000..3e29543 --- /dev/null +++ b/DataModels/House.py @@ -0,0 +1,6 @@ +from DataModels.Cell import Cell + +class House( Cell ): + def __init__( self, x, y, max_rubbish, yellow = 0, green = 0, blue = 0 ): + Cell.__init__( self, x, y, max_rubbish, yellow, green, blue ) + diff --git a/DataModels/Road.py b/DataModels/Road.py new file mode 100644 index 0000000..16805b8 --- /dev/null +++ b/DataModels/Road.py @@ -0,0 +1,8 @@ +import pygame +from config import CELL_SIZE + +class Road( pygame.sprite.Sprite ): + def __init__( self, x, y ): + pygame.sprite.Sprite.__init__( self ) + self.rect = pygame.Rect( x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE ) + self.image = pygame.image.load("Resources/Images/Image_Road.png") \ No newline at end of file diff --git a/DataModels/__pycache__/Cell.cpython-36.pyc b/DataModels/__pycache__/Cell.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1cf07f17e27934ec5926a0ac100a643685a07f9c GIT binary patch literal 1429 zcmZuxPmkj?6t^8GP1AOE7Dmj1xPTB+B{YTYUXT!C)EQ94Y_*z#5Yb9eTD#qZq$#$m zomQDs=ZkRUEBV5K(~57viT9lOcfiv76~mwxP*K^(X_FIr_7hm`z4gfD^{A_7VBb{_4$xFhJ4 z^jq&BE1C4EZI7yzNwbwyeP;b}nJ%SmJ9DPew=UrP;v$)jTj)eoc~~CV8u-HQO^vOjvt0ul+jMLqyVswP;Te12~ON`W+jrx68DYHqdL88L-pF zhDnmGGLs~ho9$X!n6DrX=23}BQF3k+gVJn!eg~KB-Y&ZMerUOt#lq4n zOSiUDrdNsD%x0N>V}mVRx_WEwszrPONRHYnfvk`J-^gzFO z@q9QO4$h?h%~b2bH2&%5Q9Lwx+yuzYmjvWU4lUK%i+9>q|qXKPGv(c89@RC5PY$t8YRI{y-x`EVp zjI+@~Rpo56SU~Fr4XB^FV+5pCpMa}AZRS9W24DxZLm3f10=ebI5sl~v^cmYdeT;R( zZ0`E?K~3PaE+&qW1ZvzA*frfG`F)cXO%FNNxrbDE&ZDy*3c#ns&ezVNQ7hyM-F~;Z zWT4WOsLJ^0fz&7Wzbe;@vG;0x;gEH3+5lQ}ku4q96sA^4e3$h9DzM=21X KWL*aR!Ttln97w|e literal 0 HcmV?d00001 diff --git a/DataModels/__pycache__/Container.cpython-36.pyc b/DataModels/__pycache__/Container.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..391e59b9afa1d1030ded2a7b4fb95e771545ddb1 GIT binary patch literal 807 zcma)3O>fgc5ZwP0Fwk%=rrPvt{pvd^i$+J*`$BXQ{#-=ptXcYWK zbO7e+WBjEmRBY@@s?wU+93CEwMx*#hnXk55#|AsBdQ0G*bLj!5T4Fg#nP@ZvhC?X-%}I2(-3MVn7jv6lXC*@3Z{T^Vd)TX(Oo+Xmqe_Vct;4seZSRwyA{C`3`o)dKH3LVR0gi#DP| wP}TR5c98J*-Xg52ak;oRgOdj|#;b7oio}J+Q4%BP1)kb|I~^N$o@slpDMV zN8W`e@Rbwdz`duAgZLTg`#iSC-;8Jaz255GkBccC*(PSEeWkadd!tGwnLuU_R){!KML6DdVUr^y)1HNbY zzGK;_$_fn_vIvlzxwVTJBFqL-Nq$2^8fa+aHGb1+RvLB{0G5XmFb%1u7-a*_(`8z6 z9tM^fseW0wuu$6%S#rU3HJ_*E%ytFl<7Hh)+o`eS{M`DdTFRwmb5+S(qI;G%85NSZ%oUPQC_`;TEf9q`#?ygwWdjt&QSHs1NX{biP=a*-zb z@;FPQQBo$8Tu5ai_tCAQ)~?e&!nmRdT=v?Fm)fVH*LLHLLgs$9Oft#2UFAH>MWvj- z#`)hWQO`H6Y+L&~`iKd%n}f^Q<_n08+?7v N|ILleINbo&=znb@i=_Yn literal 0 HcmV?d00001 diff --git a/DataModels/__pycache__/Grass.cpython-36.pyc b/DataModels/__pycache__/Grass.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e0e9c6735ce47ecacfdbf9fab91f13385630581c GIT binary patch literal 657 zcmYjP&1%~~5T21%vJ;ZDhn#Zi)ljN7&ZVWKF^&nMi4RswK@=9D-MCUE%iUc=ZG3ZH zB*#8RUt_O@LSLb$&dN1-VE%SS-+VjT{_*kQ&)<)q-yy&+*b_$a6{&tsMu5NyQs=!2 zYcKT>Zb0~gJ%C^mO21?qKMe#X&Tu$GKsqGVZ^#%ZvGhuR4I4z4u{E0D6xN=zCNRN6Bf88>FlwfWW=+>e)o~XpG>iw6_X9eM&tJZJoz#WQi%hLP)kSojne46+veMCi z&P&yy0d7Y+Bm;PYXSh1qR(F)gv{~Xmqk9qmL(c0)EGictasF+QRohAn)e_z_PYG1H z|KMJRcDL?goA*NHj%=7Wv-@J&E<`yZ$`NT>_F&u^l*6*!x7+EL^z=YGh%O#^{{a7e Bn*aa+ literal 0 HcmV?d00001 diff --git a/DataModels/__pycache__/House.cpython-36.pyc b/DataModels/__pycache__/House.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c33f3005448e0a6ec78dcfb53ad1ed673a283a35 GIT binary patch literal 571 zcmYjOJx{|h5cTDwt)PXC0Wq*rL}=T(iA%p6lE)agpvQl z03fG?SMa3K?*3W!Y-V`ElSfepgA-EJDn|^*V|Cc9@0Tl<`>l=5jmZiO^Hk zklHGN*R@$@Zn@{#W&{iJ9DSitm~cwf3Z+TP@>s`JN}uvDo@I=#alb@0>>%{?HB7?_ jm_2q0))($}^ply{ne38+9*58}s&Y7Me54=9XjQF0>EwY( literal 0 HcmV?d00001 diff --git a/Resources/Maps/map_000.txt b/Resources/Maps/map_000.txt new file mode 100644 index 0000000..0cf75ee --- /dev/null +++ b/Resources/Maps/map_000.txt @@ -0,0 +1,3 @@ +2 2 +E H +H B diff --git a/__pycache__/config.cpython-36.pyc b/__pycache__/config.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b9af045a53a3b4bcce3eebb88d498a4352f0a32d GIT binary patch literal 548 zcmYjN%Wl&^6umQ^IF9q6i*Dc#BB8o8-5^C(E!#8}C5`G-5u+l@WQNqiFFY=ysI1Hn z@ChvWrP(4D`Gu|+Czaqz=bU>-cXW@=sNXlA|M_{{LIA(vztU8HsvzDgV!%)Wbf<_S zhACzm)i~j>ZZYx{SgXcVXF6+t2d=N%HLQ&qT&U4CrX6Z>ljD7$UEbMhkE3;;5oV}g z1BL<^b~fq`OgE>BH{*tsBaoX XyG{5>le8Ep+QS49yoa7)0~z=)0Evet literal 0 HcmV?d00001 diff --git a/c b/c new file mode 100755 index 0000000000000000000000000000000000000000..2723b4529f6856b89b54d977974a6aea2b573722 GIT binary patch literal 8296 zcmeHMYiv}<6`u8Cynwx493T#)Ws^VzX}y@2F--`&esPV=qr{|*61Z7=*Y-C1aCh&f zHmX`wlc+07LZ$wokMvLfq-k0u{ZUzcC{Pdys#GOEsvxzMNCmBfis~u}B2Do2oVn*) z-+R3-QPuuqr1hEe%{gbzoS8dwX8iT;zMdMNPoenL!-~0Rt&K#bVclI)Are*XY7zbY zl)76jBz}R$?DnWlsMRhv#58C?a6eJjYp<~ZFTGpjK;a=%aZM!LWWRI(s#I7Dupaw5 z*`QgXVO;_JqWJNoQ0OtsdT)r{8=?m~EslX=d^|S(^@}|(?V>g=pe)N}{}n62_4+!^ z&Y=(4umXkN=Sh$K{G=r$f(N9(`Ql=T|DZBlwIQ7vXxp+OooGp?vc<8MvG%r>wk?rD zF0x6Fo9(mguDu6!PdwiUE&IHTevEN@Hu{?j`B#53G+eXd!{49!@(ZuG{Cb9U@uTV| zE;~swTt#{bVNF%=d*;C(Cp=t5{!8=VZ2R6S@`~a#$YE(yqxn?U8d9b?I2JdDQrUPq zbtFkFOPB>Kp0~_QJe5_u`g%J$%}tR_k*&(??cZZ2lKJFts$eDa{d+poxoomOK9FY3 z;Y=mRuOI7lZD3TsW^ z;4e1XIIDAiD3=^KuLG1R2adJPZPO0i`TgH;;Li2`rr`V;Va#mDnD~3ZI9_{gaabA8 zoVIGpZyFQl0%y5Nm-5z^sHwd6W%}E=I!ZO>N4V|XOJyo+e@pz(Nn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11 @@ +#include + +int main( void ) { + + char c = NULL; + int b = c || 5; + + printf("%d\r\n", b); + + return 0; +} diff --git a/config.py b/config.py index d398027..d34b059 100644 --- a/config.py +++ b/config.py @@ -1,12 +1,12 @@ +import sys, random CELL_SIZE = 64 - FPS = 60 -HOME_AMOUNT = 7 - -GRID_HEIGHT = HOME_AMOUNT -GRID_WIDTH = GRID_HEIGHT +map = open( sys.argv[1], 'r' ) +GRID_WIDTH, GRID_HEIGHT = [int(x) for x in map.readline().split()] WINDOW_HEIGHT = GRID_HEIGHT * CELL_SIZE -WINDOW_WIDTH = GRID_WIDTH * CELL_SIZE \ No newline at end of file +WINDOW_WIDTH = GRID_WIDTH * CELL_SIZE + +HOUSE_CAPACITY = random.randint(1, 11) \ No newline at end of file diff --git a/main.py b/main.py index 68fafb0..b279024 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,57 @@ -import pygame +import pygame, sys -from config import WINDOW_HEIGHT, WINDOW_WIDTH +from random import randint +from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS + +from DataModels.Grass import Grass +from DataModels.House import House +from DataModels.Dump import Dump pygame_sprites = pygame.sprite.Group() FPS_CLOCK = pygame.time.Clock() -GAME_WINDOW = display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32) +GAME_WINDOW = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32) -grid = [ [] for x in range(0)] +map = open(sys.argv[1], 'r') +map.readline() + +map_objects = [ [ None for y in range(0,GRID_WIDTH)] for x in range(0, GRID_HEIGHT)] + +def generate( letter ): + letter_mapping = { + 'E': lambda x, y: Grass(x,y), + 'H': lambda x, y, max_rubbish, yellow, green, blue: House( x, y, max_rubbish, yellow, green, blue ), + 'B': lambda x, y, max_rubbish, dump_type: Dump( x, y, max_rubbish, dump_type ) + } + return letter_mapping[letter] + +i = 0 +for y in map.readlines(): + for x in y.split(): + x_coord = i%GRID_WIDTH + y_coord = i //GRID_HEIGHT + yellow, green, blue = [randint(0, HOUSE_CAPACITY //2),randint(0, HOUSE_CAPACITY //2),randint(0, HOUSE_CAPACITY //2)] + if x is 'E': + map_objects[x_coord][y_coord] = generate(x)(x_coord, y_coord) + elif x is 'H': + map_objects[x_coord][y_coord] = generate(x)(x_coord, y_coord, HOUSE_CAPACITY, yellow, green, blue) + elif x is 'B': + map_objects[x_coord][y_coord] = generate(x)(x_coord, y_coord, 100, "Dump_Blue") + i += 1 + +for line in map_objects: + for item in line: + pygame_sprites.add(item) + +while True: + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + sys.exit() + + pygame_sprites.update() + pygame_sprites.draw(GAME_WINDOW) + + pygame.display.flip() + FPS_CLOCK.tick(FPS) \ No newline at end of file