Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random, pygame, sys
- from pygame.locals import *
- import time
- size = [600, 600]
- clock = pygame.time.Clock()
- pygame.init()
- screen = pygame.display.set_mode(size)
- FLOORNUMBER=6
- FloorHeight = size[1]/FLOORNUMBER
- BLACK = ( 0, 0, 0)
- RED = (255, 0, 0)
- GREEN = ( 0, 255, 0)
- BLUE = ( 0, 0, 255)
- WHITE = (255, 255, 255)
- class Passenger():
- def __init__(self, StartFloor, DestinationFloor):
- self.StartFloor=StartFloor
- self.DestinationFloor=DestinationFloor
- def getStartFloor(self): return self.StartFloor
- def getDestinationFloor(self): return self.DestinationFloor
- class Elevator(pygame.sprite.Sprite ):
- def __init__(self, FloorNumber):
- self.FloorNumber=FloorNumber
- self.Passenger=[]
- self.CurrentFloor=0
- self.StopList=[]
- self.image=pygame.image.load("lift.jpg").convert_alpha()
- self.rect=self.image.get_rect()
- self.rect.x=100
- self.rect.y=size[0]-self.getRect()[3]
- def addPassenger(self, utas):
- self.Passenger.append(utas)
- #self.StopList.append(utas.getStartFloor())
- def addStop(self, floor):
- if floor not in self.StopList:
- self.StopList.append(floor)
- def appendlist(self, num):
- self.StopList.append(num)
- def move(self, num):
- self.CurrentFloor+=num
- tempy=self.rect.y
- if num == 1:
- print("fel: " + str(self.CurrentFloor))
- else:
- print("le: " + str(self.CurrentFloor))
- def printCurrentFloor(self):
- print(self.CurrentFloor)
- def getCurrentFloor(self):
- return self.CurrentFloor
- def getPassenger(self):
- return self.Passenger
- def getStopList(self):
- return self.StopList
- def getImage(self):
- return self.image
- def getRect(self):
- return self.rect
- def draw(self,surface):
- surface.blit(lift.getImage(),lift.getRect())
- def moveUp(self, pixels):
- if self.rect.y>0:
- self.rect.y-=pixels
- def moveDown(self, pixels):
- self.rect.y+=pixels
- utas1=Passenger(0,2)
- utas2=Passenger(2,1)
- utas3=Passenger(5,0)
- utas4=Passenger(4,6)
- lift=Elevator(FLOORNUMBER)
- lift.addPassenger(utas1)
- lift.addPassenger(utas2)
- lift.addPassenger(utas3)
- lift.printCurrentFloor()
- for i in lift.getPassenger():
- lift.appendlist(i.getStartFloor())
- lift.appendlist(i.getDestinationFloor())
- print(lift.getStopList())
- lines=[]
- for i in range(FLOORNUMBER):
- lines.append([(0, i*FloorHeight), (size[0], i*FloorHeight)])
- def drawlines():
- for i in lines:
- pygame.draw.line(screen, BLUE, i[0], i[1], 1)
- """while True:
- if lift.rect.y==lift.rect.y-int(FloorHeight):
- break
- lift.moveUp(1)
- print(lift.rect.y)
- print(lift.rect.y-int(FloorHeight))"""
- while True:
- clock.tick(30)
- screen.fill(WHITE)
- lift.draw(screen)
- drawlines()
- pygame.display.update()
- if len(lift.getStopList())==0:
- break
- elif lift.getCurrentFloor() == lift.getStopList()[0]:
- lift.getStopList().pop(0)
- #print("valami történik")
- elif lift.getCurrentFloor() < lift.getStopList()[0]:
- tempy=lift.rect.y
- while True:
- if lift.rect.y==tempy-FloorHeight:
- break
- lift.moveUp(1)
- print("update")
- time.sleep(0.01)
- screen.blit(lift.getImage(),lift.getRect())
- pygame.display.update()
- lift.move(1)
- else:
- tempy=lift.rect.y
- while True:
- if lift.rect.y==tempy+FloorHeight:
- break
- lift.moveDown(1)
- time.sleep(0.01)
- screen.blit(lift.getImage(),lift.getRect())
- pygame.display.update()
- lift.move(-1)
- #lift.printCurrentFloor()
- # print(lift.getStopList())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement