def tick(self): self.beer_manager.update() pygame.event.get() for i, player in enumerate(self.players): keys = input_map.get_player_keys(i) direction = 0 if keys[input_map.ACTION]: player.jump() if keys[input_map.RIGHT]: direction = 1 elif keys[input_map.LEFT]: direction = -1 player.move(direction, self.game_rect, [p for p in self.players if p != player][0]) self.beer_manager.detect_collision(player) self.screen.blit(self.background, [0, 0]) for player in self.players: player.blit(self.screen) self.beer_manager.blit(self.screen) self.score = [self.players[0].score, self.players[1].score]
def update(self): pygame.event.get() #Ladder Collision for i in range(2): ladderHits = 0 for ladder in self.ladders: if self.eyeballs[i].colliderect(ladder): self.inLadder[i] = True ladderHits += 1 if ladderHits == 0: self.inLadder[i] = False #Shitty gravity for i, eye in enumerate(self.eyeballs): onPlatform = False for platform in self.platforms: if eye.colliderect(platform) and not self.inLadder[i]: eye.bottom = platform.top + 1 onPlatform = True if eye.bottom < 480 and not self.inLadder[i] and not onPlatform: eye.y += 15 elif eye.bottom > 480: eye.bottom = 480 #Player movement and shooting for i in range(2): keys = input_map.get_player_keys(i) if len(keys) > 0: if keys[input_map.RIGHT]: if self.eyeballs[i].right < 725: self.eyeballs[i].x += 10 self.lookingLeft[i] = False if keys[input_map.LEFT]: if self.eyeballs[i].left > 25: self.eyeballs[i].x -= 10 self.lookingLeft[i] = True if keys[input_map.ACTION]: if self.lastShot[i] > 80: self.addProjectile(i, self.lookingLeft[i]) self.lastShot[i] = 0.0 if keys[input_map.UP] and self.inLadder[i]: self.eyeballs[i].y -= 10 if keys[input_map.DOWN] and self.inLadder[i]: self.eyeballs[i].y += 10 #TODO: Projectile movement. for i, list in enumerate(self.projectiles): for proj in list[:]: if proj[0]['leftFacing'] == True: proj[0]['rect'].x -= 20 else: proj[0]['rect'].x += 20 if i == 0 and proj[0]['rect'].colliderect(self.eyeballs[1]): self.hits[0] += 1 self.projectiles[i].remove(proj) elif i == 1 and proj[0]['rect'].colliderect(self.eyeballs[0]): self.hits[1] += 1 self.projectiles[i].remove(proj)
def events(self): pygame.event.get() for i in range(2): keys = input_map.get_player_keys(i) if keys[input_map.UP]: self.players[i].move("up") if keys[input_map.RIGHT]: self.players[i].move("right") if keys[input_map.DOWN]: self.players[i].move("down") if keys[input_map.LEFT]: self.players[i].move("left") if keys[input_map.ACTION]: self.hit(i)
def tick(self): pygame.event.get() for i, bar in enumerate(self.bars): keys = input_map.get_player_keys(i) if keys[input_map.UP]: bar.move(-self.BAR_SPEED) elif keys[input_map.DOWN]: bar.move(self.BAR_SPEED) for i, ball in enumerate(self.balls): ball.move() # Check collisions for ball in self.balls: ball.check_ball_collision(self.balls) for ball in self.balls: ball.check_bar_collision(self.bars) # Check goals. balls_to_delete = [] for ball in self.balls: if ball.rect.centerx < 0 or ball.rect.centerx > self.width: if ball.rect.centerx < 0: self.score[1] += 1 elif ball.rect.centerx > self.width: self.score[0] += 1 balls_to_delete.append(ball) # Create new balls and delete the old ones. for i in range(len(balls_to_delete)): self.create_ball() for ball in balls_to_delete: self.balls.remove(ball) # Draw game. self.screen.fill((0, 0, 0)) for bar in self.bars: bar.draw(self.screen) for ball in self.balls: ball.draw(self.screen)
def playerUpdate(self): #Player movement and shooting for i in range(2): keys = input_map.get_player_keys(i) if len(keys) > 0: if keys[input_map.RIGHT]: if self.eyeballs[i].right < 725: self.eyeballs[i].x += 10 self.lookingLeft[i] = False if keys[input_map.LEFT]: if self.eyeballs[i].left > 25: self.eyeballs[i].x -= 10 self.lookingLeft[i] = True if keys[input_map.ACTION]: if self.lastShot[i] > 0.25: self.addProjectile(i, self.lookingLeft[i]) self.lastShot[i] = 0.0 if keys[input_map.UP] and self.inLadder[i]: self.eyeballs[i].y -= 10 if keys[input_map.DOWN] and self.inLadder[i]: self.eyeballs[i].y += 10
def get_player_keys(self): print input_map.get_player_keys(self.game.active_player) return input_map.get_player_keys(self.game.active_player)
def update(self): pygame.event.get() #Player movement and shooting for i in range(2): keys = input_map.get_player_keys(i) if len(keys) > 0: if keys[input_map.RIGHT]: self.players[i].x += self.moveSpeed self.looking[i] = 1 if keys[input_map.LEFT]: self.players[i].x -= self.moveSpeed self.looking[i] = 3 if keys[input_map.ACTION]: if self.lastShot[i] > 0.2: self.addProjectile(i, self.looking[i]) self.lastShot[i] = 0.0 if keys[input_map.UP]: self.players[i].y -= self.moveSpeed self.looking[i] = 0 if keys[input_map.DOWN]: self.players[i].y += self.moveSpeed self.looking[i] = 2 for i, list in enumerate(self.projectiles): for proj in list[:]: if proj[0]['direction'] == 0: proj[0]['rect'].y -= self.projectileSpeed elif proj[0]['direction'] == 1: proj[0]['rect'].x += self.projectileSpeed elif proj[0]['direction'] == 2: proj[0]['rect'].y += self.projectileSpeed else: proj[0]['rect'].x -= self.projectileSpeed if i == 0 and proj[0]['rect'].colliderect(self.players[1]): if proj[0]['direction'] == 0: self.players[1].y -= self.pushBack elif proj[0]['direction'] == 1: self.players[1].x += self.pushBack elif proj[0]['direction'] == 2: self.players[1].y += self.pushBack else: self.players[1].x -= self.pushBack self.projectiles[i].remove(proj) elif i == 1 and proj[0]['rect'].colliderect(self.players[0]): if proj[0]['direction'] == 0: self.players[0].y -= self.pushBack elif proj[0]['direction'] == 1: self.players[0].x += self.pushBack elif proj[0]['direction'] == 2: self.players[0].y += self.pushBack else: self.players[0].x -= self.pushBack self.projectiles[i].remove(proj) for i, water in enumerate(self.waters): if water.colliderect(self.players[0]): self.playerDead = 0 self.game.state.game_done() elif water.colliderect(self.players[1]): self.playerDead = 1 self.game.state.game_done() if random.randint(0, 1) == 0: self.waters[0].height += self.waterSpeed else: self.waters[1].width += self.waterSpeed if random.randint(0, 1) == 0: self.waters[2].height += self.waterSpeed self.waters[2].y -= self.waterSpeed else: self.waters[3].width += self.waterSpeed self.waters[3].x -= self.waterSpeed