From 7ef526f25317bd889a1e6b209928e5cdd31ccccb Mon Sep 17 00:00:00 2001 From: Michal Kijowski Date: Sun, 5 Apr 2020 17:20:32 +0000 Subject: [PATCH] =?UTF-8?q?Prze=C5=9Blij=20pliki=20do=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- program.py | 53 +++++++++++++++++++++++++ wheel.py | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 program.py create mode 100644 wheel.py diff --git a/program.py b/program.py new file mode 100644 index 0000000..f671a3d --- /dev/null +++ b/program.py @@ -0,0 +1,53 @@ +import pygame +from os import sys +from generate import Generate +from floor import Floor +from wall import Wall +from shelf import Shelf +from wheel import Wheel +from boxOnTheFloor import BoxOnTheFloor +from box import Box +from unboxOnTheFloor import UnboxOnTheFloor + +class MainWindow: + def __init__(self, szerokosc, wysokosc, kruche, latwopalne, radioaktywne, niebezpieczne): + #config + self.cell = 50 + #init + pygame.init() + pygame.display.set_caption('Inteligentny wózek widłowy') + self.map = Generate.generate(szerokosc+2, wysokosc+2, kruche, latwopalne, radioaktywne, niebezpieczne) + self.screen = pygame.display.set_mode((((szerokosc+2)*self.cell), ((wysokosc+2)*self.cell))) + #create + self.wheel = Wheel(self.screen, self.cell); + for i in range(len(self.map)): + for j in range(len(self.map[i])): + if (self.map[i][j]==1): + self.map[i][j] = Wall(self.screen, self.cell, i, j) + elif (self.map[i][j]==2): + self.map[i][j] = Floor(self.screen, self.cell, i, j) + elif (self.map[i][j]==23): + self.map[i][j] = UnboxOnTheFloor(self.screen, self.cell, i, j) + else: + self.map[i][j] = Shelf(self.screen, self.cell, i, j, (self.map[i][j]-3)%4, (self.map[i][j]-3)//4) + #loop + while True: + self.events() + self.draw() + + def events(self): + for event in pygame.event.get(): + if(event.type==pygame.QUIT): + sys.exit() + elif(event.type==pygame.KEYDOWN): + self.wheel.move(event, self.map) + elif(event.type==pygame.MOUSEBUTTONDOWN): + if (type(self.map[0][2]) == Floor): + self.map[0][2] = BoxOnTheFloor(self.screen, self.cell, 0, 2, Box()) + def draw(self): + self.screen.fill((33,69,108)) + for i in range(len(self.map)): + for j in range(len(self.map[i])): + self.map[i][j].draw() + self.wheel.draw() + pygame.display.flip() diff --git a/wheel.py b/wheel.py new file mode 100644 index 0000000..32fe8b1 --- /dev/null +++ b/wheel.py @@ -0,0 +1,114 @@ +import pygame +from floor import Floor +from boxOnTheFloor import BoxOnTheFloor +from unboxOnTheFloor import UnboxOnTheFloor +from shelf import Shelf + +class Wheel: + def __init__(self, screen, cell): + self.cell = cell + self.ns = 1 + self.we = 2 + self.direction = 3 + self.m_ns = 0 + self.m_we = 0 + self.occupied = False + self.box = False + # 1 - w gore + # 2 - w prawo + # 3 - w dol + # 4 - w lewo + self.screen = screen + self.imageorg = pygame.image.load(r'images/wo.png') + self.imageorg = pygame.transform.scale(self.imageorg, (cell, cell)) + self.image = pygame.transform.scale(self.imageorg, (cell, cell)) + def draw(self): + self.screen.blit(self.image, ((self.cell*self.we)+self.m_we, (self.cell*self.ns)+self.m_ns)) + self.m_ns = self.m_ns*(0.9) + self.m_we = self.m_we*(0.9) + def isOccupied(self): + return self.occupied + def putBox(self, boxik): + self.box = boxik + self.occupied = True + self.imageorg = pygame.image.load(r'images/wop.png') + self.imageorg = pygame.transform.scale(self.imageorg, (self.cell, self.cell)) + self.image = pygame.transform.scale(self.imageorg, (self.cell, self.cell)) + def getBox(self): + self.occupied = False + self.imageorg = pygame.image.load(r'images/wo.png') + self.imageorg = pygame.transform.scale(self.imageorg, (self.cell, self.cell)) + self.image = pygame.transform.scale(self.imageorg, (self.cell, self.cell)) + return self.box + def move(self, move, krata): + if(move.key==pygame.K_DOWN): + if(type(krata[self.ns][self.we])==UnboxOnTheFloor): + pass + elif(type(krata[self.ns+1][self.we])==Floor): + self.ns+=1 + self.m_ns=self.cell*(-1) + self.direction = 3 + elif(type(krata[self.ns+1][self.we])==Shelf): + if(self.occupied==True and krata[self.ns+1][self.we].isOccupied()==False and krata[self.ns+1][self.we].kierunek==1): + krata[self.ns+1][self.we].put(self.getBox()) + self.direction = 3 + elif(self.occupied==False and krata[self.ns+1][self.we].isOccupied()==True and krata[self.ns+1][self.we].kierunek==1): + self.putBox(krata[self.ns+1][self.we].get()) + self.direction = 3 + elif(type(krata[self.ns+1][self.we])==UnboxOnTheFloor): + if(self.ns+1==len(krata)-1): + self.ns+=1 + self.m_ns=self.cell*(-1) + self.direction = 1 + self.getBox() + elif(move.key==pygame.K_UP): + if(type(krata[self.ns-1][self.we])==Floor): + self.ns-=1 + self.m_ns=self.cell + self.direction = 1 + elif(type(krata[self.ns-1][self.we])==BoxOnTheFloor): + if(self.occupied==False): + self.putBox(krata[self.ns - 1][self.we].get()) + krata[self.ns - 1][self.we] = Floor(self.screen, self.cell, self.ns - 1, self.we) + self.ns -= 1 + self.m_ns = self.cell + self.direction = 1 + elif(type(krata[self.ns-1][self.we])==Shelf): + if(self.occupied==True and krata[self.ns-1][self.we].isOccupied()==False and krata[self.ns-1][self.we].kierunek==0): + krata[self.ns-1][self.we].put(self.getBox()) + self.direction = 1 + elif(self.occupied==False and krata[self.ns-1][self.we].isOccupied()==True and krata[self.ns-1][self.we].kierunek==0): + self.putBox(krata[self.ns-1][self.we].get()) + self.direction = 1 + elif(move.key==pygame.K_LEFT): + if(type(krata[self.ns][self.we-1])==Floor): + self.we-=1 + self.m_we=self.cell + self.direction = 4 + elif(type(krata[self.ns][self.we-1])==Shelf): + if(self.occupied==True and krata[self.ns][self.we-1].isOccupied()==False and krata[self.ns][self.we-1].kierunek==3): + krata[self.ns][self.we-1].put(self.getBox()) + self.direction = 4 + elif(self.occupied==False and krata[self.ns][self.we-1].isOccupied()==True and krata[self.ns][self.we-1].kierunek==3): + self.putBox(krata[self.ns][self.we-1].get()) + self.direction = 4 + elif(move.key==pygame.K_RIGHT): + if(type(krata[self.ns][self.we+1])==Floor): + self.we+=1 + self.m_we=self.cell*(-1) + self.direction = 2 + elif(type(krata[self.ns][self.we+1])==Shelf): + if(self.occupied==True and krata[self.ns][self.we+1].isOccupied()==False and krata[self.ns][self.we+1].kierunek==2): + krata[self.ns][self.we+1].put(self.getBox()) + self.direction = 2 + elif(self.occupied==False and krata[self.ns][self.we+1].isOccupied()==True and krata[self.ns][self.we+1].kierunek==2): + self.putBox(krata[self.ns][self.we+1].get()) + self.direction = 2 + if (self.direction==1): + self.image = pygame.transform.rotate(self.imageorg, 180) + elif (self.direction==2): + self.image = pygame.transform.rotate(self.imageorg, 90) + elif (self.direction==3): + self.image = pygame.transform.rotate(self.imageorg, 0) + elif (self.direction==4): + self.image = pygame.transform.rotate(self.imageorg, 270)