def main(): # initialize the pygame module pygame.init() # load and set the logo pygame.display.set_caption("Mercury Simulation") # initialize the screen screen = pygame.display.set_mode(list(SCREEN_SIZE)) obstacleList = [] robot = Robot(Vector2(360, 450)) # Let's make a background so we can see if we're moving background = Drawable(Vector2(0, 0), "background.png", offset=None) # Initialize the gameClock for more realistic velocity gameClock = pygame.time.Clock() # define a variable to control the main loop RUNNING = True # main loop while RUNNING: # Draw everything, adjust by offset background.draw(screen) robot.draw(screen) for obstacle in obstacleList: obstacle.draw(screen) # Flip the display to the monitor pygame.display.flip() # event handling, gets all event from the eventqueue for event in pygame.event.get(): # only do something if the event is of type QUIT or ESCAPE is pressed if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): # change the value to False, to exit the main loop RUNNING = False robot.handleEvent(event) if event.type == pygame.MOUSEBUTTONDOWN: adjustedPos = list([int(x) for x in event.pos]) obstacleList.append( Obstacle(Vector2(*background.adjustMousePos(adjustedPos)), "sidewall.png", SCREEN_SIZE)) # if event.key == pygame.K_S: # obstacleList.append(Obstacle(Vector2(*background.adjustMousePos(adjustedPos)), "sidewall.png", SCREEN_SIZE)) # elif event.key == pygame.K_T: # obstacleList.append(Obstacle(Vector2(*background.adjustMousePos(adjustedPos)), "topwall.png", SCREEN_SIZE)) gameClock.tick(60) ticks = gameClock.get_time() / 1000 # Update everything robot.update(WORLD_SIZE, ticks) for obstacle in obstacleList: if robot.getCollideRect().colliderect(obstacle.getCollideRect()): print("You hit the wall") # Update the camera background.updateOffset(robot, SCREEN_SIZE, WORLD_SIZE) pygame.quit()
def update(self, WORLD_SIZE, SCREEN_SIZE, ticks): """updates all of the objects in the current level in the world""" #determine if cheat is being used: take blob to end of level if self._keydown[1] == True and self._keydown[ 2] == True and self._keydown[3] == True: if self._filename != "level3.txt" and self._filename != "level6.txt": self._blob.update(WORLD_SIZE, ticks, cheat=True, horizontal=True) else: self._blob.update(WORLD_SIZE, ticks, cheat=True, horizontal=False) else: #otherwise update blob normally self._blob.update(WORLD_SIZE, ticks) #update pan animation for pan in self._traps["pan"]: pan.update(ticks) #update blob zaps movement for zap2 in self._blob._zaps: zap2.update(WORLD_SIZE, ticks) #update devil animation and movement for devil in self._enemies["devil"]: devil.update(WORLD_SIZE, ticks) #update gaston animation and movement of his arrows for gaston in self._enemies["gaston"]: gaston.update(WORLD_SIZE, ticks) #update ring zap movement for ring in self._traps["ring"]: ring.update(WORLD_SIZE, ticks) #update boss animation and spawn movements for boss in self._enemies["boss"]: boss.update(WORLD_SIZE, ticks) #update ceiling falling once ceiling is smashed in final level if self._filename == "level6.txt" and self._ceiling.readyForNextLevel( ): SoundManager.getInstance().playSound("big_smash.ogg") self._ceiling.update(ticks) #if blob is dead, reset the level if self._blob.isDead(): if self._deathCycle > 30: self.reset() self.loadLevel() # initialize the blob on top of the ground self._blob = Blob( Vector2(0, WORLD_SIZE[1] - 100 - CHAR_SPRITE_SIZE.y), self._blob._color) self._deathCycle = 0 else: self._deathCycle += 1 # getting the offset of the of the current blob (our tracking object) Drawable.updateOffset(self._blob, SCREEN_SIZE, WORLD_SIZE) #update the position of the downbar on the final level if self._downbar != None: self._downbar._position = Vector2( Drawable.WINDOW_OFFSET.x, Drawable.WINDOW_OFFSET.y + SCREEN_SIZE[1] - 28) for i in range(4): self._downbarSelections[i]._position = Vector2( i * 28 + Drawable.WINDOW_OFFSET.x, Drawable.WINDOW_OFFSET.y + SCREEN_SIZE[1] - 28)