def update(dt): global level_text_brightness, hs if len(flowers) == 0: next_level() for flower in flowers: flower.update(dt, screen_size) for bee in bees: bee.update(screen_size) player1.update(dt, screen_size) #game_end) if player1.score > hs: hs = player1.score if len(clouds) != 0: for cloud in clouds: cloud.update(screen_size) if player1.alive: # player1.collide_bullets(asteroids, particle_system, dt) player1.collide_bees_bullet(bees, particle_system, dt) player1.collide_flowers(flowers, baske, particle_system) player1.collide_bees(bees, particle_system) emitter_rocket.set_position(player1.position) ## particle_system.set_particle_occluders([asteroid.occluder for asteroid in asteroids]) particle_system.update(dt) if level_text_brightness > 0.0: level_text_brightness -= dt return True
def run(self): done = False while not done: self.screen.blit(Menu.sky, self.screen.get_rect()) self.water.update() self.water_sprite.draw(self.screen) for i in xrange(len(self.menu)): self.render(i) cloud.update() cloud.draw(self.screen) rect = Menu.logo.get_rect() rect.centerx = self.screen.get_rect().centerx rect.top = 0 self.screen.blit(Menu.logo, rect) image = util.smallfont.render("http://funnyboat.sourceforge.net/", True, (0, 0, 0)) rect = image.get_rect() rect.midbottom = self.screen.get_rect().midbottom self.screen.blit(image, rect) pygame.display.flip() self.t += 1 nextframe = False while not nextframe: pygame.event.post(pygame.event.wait()) for event in pygame.event.get(): if event.type == QUIT or \ event.type == KEYDOWN and event.key == K_ESCAPE: self.selection = -1 done = True nextframe = True elif event.type == NEXTFRAME: nextframe = True elif event.type == JOYAXISMOTION: if event.axis == 1: if event.value < -0.5: self.move_up() if event.value > 0.5: self.move_down() elif event.type == JOYBUTTONDOWN: if event.button == 0: done = True elif event.type == KEYDOWN: if event.key == K_UP: self.move_up() elif event.key == K_DOWN: self.move_down() elif event.key == K_SPACE or event.key == K_RETURN: done = True return self.selection
def run(self): done = False while not done: self.screen.blit(Menu.sky, self.screen.get_rect()) self.water.update() self.water_sprite.draw(self.screen) for i in xrange(len(self.menu)): self.render(i) cloud.update() cloud.draw(self.screen) rect = Menu.logo.get_rect() rect.centerx = self.screen.get_rect().centerx rect.top = 0 self.screen.blit(Menu.logo, rect) image = util.smallfont.render("http://funnyboat.sourceforge.net/", True, (0,0,0)) rect = image.get_rect() rect.midbottom = self.screen.get_rect().midbottom self.screen.blit(image, rect) pygame.display.flip() self.t += 1 nextframe = False while not nextframe: pygame.event.post(pygame.event.wait()) for event in pygame.event.get(): if event.type == QUIT or \ event.type == KEYDOWN and event.key == K_ESCAPE: self.selection = -1 done = True nextframe = True elif event.type == NEXTFRAME: nextframe = True elif event.type == JOYAXISMOTION: if event.axis == 1: if event.value < -0.5: self.move_up() if event.value > 0.5: self.move_down() elif event.type == JOYBUTTONDOWN: if event.button == 0: done = True elif event.type == KEYDOWN: if event.key == K_UP: self.move_up() elif event.key == K_DOWN: self.move_down() elif event.key == K_SPACE or event.key == K_RETURN: done = True return self.selection
def run(self): water = Water.global_water water_sprite = pygame.sprite.Group() water_sprite.add(water) while not self.done: self.screen.blit(self.sky, self.screen.get_rect()) water.update() cloud.update() cloud.draw(self.screen) water_sprite.draw(self.screen) rect = self.title.get_rect() rect.centerx = self.screen.get_rect().centerx rect.top = 10 self.screen.blit(self.title, rect) for i in range(10): color = (0, 0, 0) if self.inputting and self.input_score == i: color = (220, 120, 20) score = self.scores[i] image = self.font.render( str(i + 1) + ". " + score[0], True, color) rect = image.get_rect() rect.top = 50 + i * 1.5 * rect.height rect.left = 10 self.screen.blit(image, rect) image = self.font.render(str(score[1]), True, color) rect = image.get_rect() rect.top = 50 + i * 1.5 * rect.height rect.right = self.screen.get_rect().right - 10 self.screen.blit(image, rect) pygame.display.flip() nextframe = False while not nextframe: pygame.event.post(pygame.event.wait()) for event in pygame.event.get(): if event.type == NEXTFRAME: nextframe = True continue if self.inputting: if event.type == QUIT: self.inputting = False self.write_scores() if event.type == KEYDOWN: if event.key == K_RETURN or event.key == K_ESCAPE: self.inputting = False self.write_scores() elif event.key == K_BACKSPACE: if len(self.scores[self.input_score][0]) != 0: self.scores[ self.input_score][0] = self.scores[ self.input_score][0][:-1] elif event.key == K_SPACE or event.unicode != " ": if len(self.scores[self.input_score][0]) < 32: self.scores[ self.input_score][0] += event.unicode else: if event.type == KEYDOWN or event.type == QUIT or event.type == JOYBUTTONDOWN: self.done = True nextframe = True
def run(self): while not self.done: if not self.pause: if not self.gameover: self.spawn_enemies() self.update_enemies() self.player.update() self.health.update() cloud.update() for cb in self.cannonballs: if not cb.underwater: #~ particle_point=cb.rect.left, cb.rect.top particle_point = cb.tail_point() self.particles.add_trace_particle(particle_point) particle_point = [particle_point[i] + cb.vect[i]/2 for i in (0,1)] self.particles.add_trace_particle(particle_point) if cb.special and (not cb.underwater or rr()>0.6) : particle_point = cb.tail_point() self.particles.add_explosion_particle(particle_point) und_old=cb.underwater cb.update() if cb.underwater and not und_old: for i in range(5): particle_point=cb.rect.right-4.0+rr()*8.0, cb.rect.top+rr()*2.0 self.particles.add_water_particle(particle_point) if (cb.rect.right < 0 and cb.vect[0] < 0) or (cb.rect.left > SCREEN_WIDTH and cb.vect[0] > 0) or (cb.rect.top > SCREEN_HEIGHT): self.cannonballs.remove(cb) self.cannonball_sprites.remove(cb) self.score.update() # Add steam particles if Variables.particles: particle_point = self.player.get_point((5.0 + rr() * 9.0, 0)) particle_point[0] += self.player.rect.centerx particle_point[1] += self.player.rect.centery if self.spacepressed and self.t > self.spacepressed + FPS * 3: pass #~ self.particles.add_fire_steam_particle(particle_point) else: self.particles.add_steam_particle(particle_point) particle_point = self.player.get_point((19.0 + rr() * 7.0, 5.0)) particle_point[0] += self.player.rect.centerx particle_point[1] += self.player.rect.centery if self.spacepressed and self.t > self.spacepressed + FPS * 3: pass #~ self.particles.add_fire_steam_particle(particle_point) else: self.particles.add_steam_particle(particle_point) if self.titanic: for j in range(4): particle_point = self.titanic.get_point((49 + rr() * 9.0 + 28 * j, 25)) particle_point[0] += self.titanic.rect.centerx particle_point[1] += self.titanic.rect.centery self.particles.add_steam_particle(particle_point) self.particles.update() self.water.update() if self.player.splash: if Variables.particles: for i in range(10): r = rr() x = int(r * self.player.rect.left + (1.0-r) * self.player.rect.right) point = (x, self.water.get_water_level(x)) self.particles.add_water_particle(point) for powerup in self.powerups: powerup.update() if powerup.picked: self.powerups.remove(powerup) self.powerup_sprites.remove(powerup) if not self.gameover: self.check_collisions() if self.health.hearts_left == 0 and not self.player.dying: self.player.die() if self.player.dying and not self.player.dead: if Variables.particles: self.particles.add_explosion_particle((self.player.rect.centerx, self.player.rect.centery)) self.particles.add_debris_particle((self.player.rect.centerx, self.player.rect.centery)) if self.player.dead: #self.done = True self.set_gameover() if self.damage_count > 0: self.damage_count -= 1 self.lastshot += 1 self.t += 1 self.draw() self.handle_events() return self.score.get_score()
def run(self): done = False while not done: self.screen.blit(Options.sky, self.screen.get_rect()) self.water.update() self.water_sprite.draw(self.screen) for i in xrange(len(self.menu)): self.render(i) cloud.update() cloud.draw(self.screen) rect = Options.logo.get_rect() rect.centerx = self.screen.get_rect().centerx rect.top = 0 self.screen.blit(Options.logo, rect) image = util.smallfont.render("http://funnyboat.sourceforge.net/", True, (0, 0, 0)) rect = image.get_rect() rect.midbottom = self.screen.get_rect().midbottom self.screen.blit(image, rect) pygame.display.flip() self.t += 1 nextframe = False while not nextframe: pygame.event.post(pygame.event.wait()) for event in pygame.event.get(): if event.type == QUIT or \ event.type == KEYDOWN and event.key == K_ESCAPE: self.selection = -1 done = True nextframe = True elif event.type == NEXTFRAME: nextframe = True elif event.type == JOYAXISMOTION: if event.axis == 1: if event.value < -0.5: self.move_up() if event.value > 0.5: self.move_down() elif event.axis == 0: if event.value < -0.5: self.change_left() if event.value > 0.5: self.change_right() elif event.type == JOYBUTTONDOWN: if self.gamepad: if self.gamepad.is_pressed('a', event): self.change_right() elif self.gamepad.is_pressed('b', event): done = True elif event.button == 0: #done = True self.change_right() elif event.button == 1: done = True elif event.type == KEYDOWN: if event.key == K_UP: self.move_up() elif event.key == K_DOWN: self.move_down() elif event.key == K_LEFT: self.change_left() elif event.key == K_RIGHT: self.change_right() elif self.selection == Options.NAME: if event.key == K_BACKSPACE: if len(Variables.name) != 0: Variables.name = Variables.name[:-1] elif event.key == K_SPACE or event.unicode != " " and event.unicode >= u' ': if len(Variables.name) < 32: Variables.name += event.unicode self.refresh() elif event.key == K_SPACE or event.key == K_RETURN: #done = True self.change_right() util.save_config() return self.selection
def run(self): done = False while not done: self.screen.blit(self.sky, self.screen.get_rect()) self.water.update() self.water_sprite.draw(self.screen) if not self.gametype_select: self.render("New Game", Menu.NEWGAME) self.render("High Scores", Menu.HIGHSCORES) #self.render("Options", Menu.OPTIONS) self.render("Quit", Menu.QUIT) else: self.render("Story mode", Menu.STORY) self.render("Endless mode", Menu.ENDLESS) cloud.update() cloud.draw(self.screen) rect = self.logo.get_rect() rect.centerx = self.screen.get_rect().centerx rect.top = 0 self.screen.blit(self.logo, rect) image = self.url_font.render("http://funnyboat.sourceforge.net/", True, (0,0,0)) bottom = rect.bottom rect = image.get_rect() rect.midbottom = self.screen.get_rect().midbottom #rect.bottomright = self.screen.get_rect().bottomright #rect.bottom = bottom self.screen.blit(image, rect) pygame.display.flip() self.t += 1 nextframe = False while not nextframe: pygame.event.post(pygame.event.wait()) for event in pygame.event.get(): if event.type == QUIT or \ event.type == KEYDOWN and event.key == K_ESCAPE: self.selection = -1 done = True nextframe = True elif event.type == NEXTFRAME: nextframe = True elif event.type == JOYAXISMOTION: if event.axis == 1: if event.value < -0.5: self.selection -= 1 if not self.gametype_select: if self.selection == Menu.OPTIONS: self.selection = Menu.HIGHSCORES if self.selection < 0: self.selection = 0 if event.value > 0.5: self.selection += 1 if not self.gametype_select: if self.selection == Menu.OPTIONS: self.selection = Menu.QUIT if self.selection > Menu.QUIT: self.selection = Menu.QUIT else: if self.selection > Menu.ENDLESS: self.selection = Menu.ENDLESS elif event.type == JOYBUTTONDOWN: if event.button == 0: done = True elif event.type == KEYDOWN: if event.key == K_UP: self.selection -= 1 if not self.gametype_select: if self.selection == Menu.OPTIONS: self.selection = Menu.HIGHSCORES if self.selection < 0: self.selection = 0 elif event.key == K_DOWN: self.selection += 1 if not self.gametype_select: if self.selection == Menu.OPTIONS: self.selection = Menu.QUIT if self.selection > Menu.QUIT: self.selection = Menu.QUIT else: if self.selection > Menu.ENDLESS: self.selection = Menu.ENDLESS elif event.key == K_SPACE or event.key == K_RETURN: done = True return self.selection
def run(self): water = Water.global_water water.set_amplitude(SCREEN_HEIGHT / 8.0) water_sprite = pygame.sprite.Group() water_sprite.add(water) while not self.done: self.screen.blit(Highscores.sky, self.screen.get_rect()) water.update() cloud.update() cloud.draw(self.screen) water_sprite.draw(self.screen) rect = self.title.get_rect() rect.centerx = self.screen.get_rect().centerx rect.top = 10 self.screen.blit(self.title, rect) for i in xrange(10): color = (0,0,0) #if self.inputting and self.input_score == i: if self.input_score == i: color = (220, 120, 20) score = self.scores[i] image = 0 try: image = util.smallfont.render(str(i + 1) + ". " + score[0], True, color) except: image = util.smallfont.render(str(i + 1) + ". Error", True, color) rect = image.get_rect() rect.top = 50 + i * 1.5 * rect.height rect.left = 10 self.screen.blit(image, rect) image = util.smallfont.render(str(score[1]), True, color) rect = image.get_rect() rect.top = 50 + i * 1.5 * rect.height rect.right = self.screen.get_rect().right - 10 self.screen.blit(image, rect) pygame.display.flip() nextframe = False while not nextframe: pygame.event.post(pygame.event.wait()) for event in pygame.event.get(): if event.type == NEXTFRAME: nextframe = True continue if self.inputting: if event.type == QUIT: self.inputting = False self.write_scores() if event.type == KEYDOWN: if event.key == K_RETURN or event.key == K_ESCAPE: self.inputting = False if self.endless: self.submit_score() self.write_scores() elif event.key == K_BACKSPACE: if len(self.scores[self.input_score][0]) != 0: self.scores[self.input_score][0] = self.scores[self.input_score][0][:-1] elif event.key == K_SPACE or event.unicode != " ": if len(self.scores[self.input_score][0]) < 32: self.scores[self.input_score][0] += event.unicode else: if event.type == KEYDOWN or event.type == QUIT or event.type == JOYBUTTONDOWN: self.done = True nextframe = True
def run(self): done = False while not done: self.screen.blit(Options.sky, self.screen.get_rect()) self.water.update() self.water_sprite.draw(self.screen) for i in xrange(len(self.menu)): self.render(i) cloud.update() cloud.draw(self.screen) rect = Options.logo.get_rect() rect.centerx = self.screen.get_rect().centerx rect.top = 0 self.screen.blit(Options.logo, rect) image = util.smallfont.render("http://funnyboat.sourceforge.net/", True, (0,0,0)) rect = image.get_rect() rect.midbottom = self.screen.get_rect().midbottom self.screen.blit(image, rect) pygame.display.flip() self.t += 1 nextframe = False while not nextframe: pygame.event.post(pygame.event.wait()) for event in pygame.event.get(): if event.type == QUIT or \ event.type == KEYDOWN and event.key == K_ESCAPE: self.selection = -1 done = True nextframe = True elif event.type == NEXTFRAME: nextframe = True elif event.type == JOYAXISMOTION: if event.axis == 1: if event.value < -0.5: self.move_up() if event.value > 0.5: self.move_down() elif event.axis == 0: if event.value < -0.5: self.change_left() if event.value > 0.5: self.change_right() elif event.type == JOYBUTTONDOWN: if event.button == 0: #done = True self.change_right() elif event.button == 1: done = True elif event.type == KEYDOWN: if event.key == K_UP: self.move_up() elif event.key == K_DOWN: self.move_down() elif event.key == K_LEFT: self.change_left() elif event.key == K_RIGHT: self.change_right() elif self.selection == Options.NAME: if event.key == K_BACKSPACE: if len(Variables.name) != 0: Variables.name = Variables.name[:-1] elif event.key == K_SPACE or event.unicode != " " and event.unicode>=u' ': if len(Variables.name) < 32: Variables.name += event.unicode self.refresh() elif event.key == K_SPACE or event.key == K_RETURN: #done = True self.change_right() util.save_config() return self.selection
def run(self): while not self.done: if not self.pause: if not self.gameover: self.spawn_enemies() self.update_enemies() self.player.update() self.health.update() cloud.update() for cb in self.cannonballs: if not cb.underwater: #~ particle_point=cb.rect.left, cb.rect.top particle_point = cb.tail_point() self.particles.add_trace_particle(particle_point) particle_point = [particle_point[i] + cb.vect[i]/2 for i in (0,1)] self.particles.add_trace_particle(particle_point) if cb.special and (not cb.underwater or rr()>0.6) : particle_point = cb.tail_point() self.particles.add_explosion_particle(particle_point) und_old=cb.underwater cb.update() if cb.underwater and not und_old: for i in xrange(5): particle_point=cb.rect.right-4.0+rr()*8.0, cb.rect.top+rr()*2.0 self.particles.add_water_particle(particle_point) if (cb.rect.right < 0 and cb.vect[0] < 0) or (cb.rect.left > SCREEN_WIDTH and cb.vect[0] > 0) or (cb.rect.top > SCREEN_HEIGHT): self.cannonballs.remove(cb) self.cannonball_sprites.remove(cb) self.score.update() # Add steam particles if Variables.particles: particle_point = self.player.get_point((5.0 + rr() * 9.0, 0)) particle_point[0] += self.player.rect.centerx particle_point[1] += self.player.rect.centery if self.spacepressed and self.t > self.spacepressed + FPS * 3: pass #~ self.particles.add_fire_steam_particle(particle_point) else: self.particles.add_steam_particle(particle_point) particle_point = self.player.get_point((19.0 + rr() * 7.0, 5.0)) particle_point[0] += self.player.rect.centerx particle_point[1] += self.player.rect.centery if self.spacepressed and self.t > self.spacepressed + FPS * 3: pass #~ self.particles.add_fire_steam_particle(particle_point) else: self.particles.add_steam_particle(particle_point) if self.titanic: for j in xrange(4): particle_point = self.titanic.get_point((49 + rr() * 9.0 + 28 * j, 25)) particle_point[0] += self.titanic.rect.centerx particle_point[1] += self.titanic.rect.centery self.particles.add_steam_particle(particle_point) self.particles.update() self.water.update() if self.player.splash: if Variables.particles: for i in xrange(10): r = rr() x = int(r * self.player.rect.left + (1.0-r) * self.player.rect.right) point = (x, self.water.get_water_level(x)) self.particles.add_water_particle(point) for powerup in self.powerups: powerup.update() if powerup.picked: self.powerups.remove(powerup) self.powerup_sprites.remove(powerup) if not self.gameover: self.check_collisions() if self.health.hearts_left == 0 and not self.player.dying: self.player.die() if self.player.dying and not self.player.dead: if Variables.particles: self.particles.add_explosion_particle((self.player.rect.centerx, self.player.rect.centery)) self.particles.add_debris_particle((self.player.rect.centerx, self.player.rect.centery)) if self.player.dead: #self.done = True self.set_gameover() if self.damage_count > 0: self.damage_count -= 1 self.lastshot += 1 self.t += 1 self.draw() self.handle_events() return self.score.get_score()
def run(self): while not self.done: util.android_check_pause() if not self.pause: if not self.gameover: self.spawn_enemies() self.update_enemies() self.player.update() self.health.update() cloud.update() for cb in self.cannonballs: cb.update() if (cb.rect.right < 0 and cb.vect[0] < 0) or (cb.rect.left > SCREEN_WIDTH and cb.vect[0] > 0): self.cannonballs.remove(cb) self.cannonball_sprites.remove(cb) self.score.update() # Add steam particles if not self.noparticles: for i in range(STEAM_3): particle_point = self.player.get_point((5.0 + random.random() * 9.0, 0)) particle_point[0] += self.player.rect.centerx particle_point[1] += self.player.rect.centery self.particles.add_steam_particle(particle_point) for i in range(STEAM_3): particle_point = self.player.get_point((19.0 + random.random() * 7.0, 5.0)) particle_point[0] += self.player.rect.centerx particle_point[1] += self.player.rect.centery self.particles.add_steam_particle(particle_point) if self.titanic: for j in range(4): for i in range(STEAM_3): particle_point = self.titanic.get_point((49 + random.random() * 9.0 + 28 * j, 25)) particle_point[0] += self.titanic.rect.centerx particle_point[1] += self.titanic.rect.centery self.particles.add_steam_particle(particle_point) self.particles.update() self.water.update() if self.player.splash: if not self.noparticles: for i in range(SPLASH_30): r = random.random() x = int(r * self.player.rect.left + (1.0-r) * self.player.rect.right) point = (x, self.water.get_water_level(x)) self.particles.add_water_particle(point) for powerup in self.powerups: powerup.update() if powerup.picked: self.powerups.remove(powerup) self.powerup_sprites.remove(powerup) if not self.gameover: self.check_collisions() if self.health.hearts_left == 0 and not self.player.dying: self.player.die() if self.player.dying and not self.player.dead: if not self.noparticles: for i in range(BLOOD_3): self.particles.add_explosion_particle((self.player.rect.centerx, self.player.rect.centery)) self.particles.add_debris_particle((self.player.rect.centerx, self.player.rect.centery)) if self.player.dead: #self.done = True self.set_gameover() if self.damage_count > 0: self.damage_count -= 1 self.lastshot += 1 self.t += 1 self.draw() self.handle_events() return self.score.get_score()
def run(self): done = False while not done: util.android_check_pause() self.screen.blit(self.sky, self.screen.get_rect()) self.water.update() self.water_sprite.draw(self.screen) if not self.gametype_select: self.render("New Game", Menu.NEWGAME) self.render("High Scores", Menu.HIGHSCORES) #self.render("Options", Menu.OPTIONS) self.render("Quit", Menu.QUIT) else: self.render("Story mode", Menu.STORY) self.render("Endless mode", Menu.ENDLESS) cloud.update() cloud.draw(self.screen) rect = self.logo.get_rect() rect.centerx = self.screen.get_rect().centerx rect.top = 0 self.screen.blit(self.logo, rect) image = self.url_font.render("https://github.com/zielmicha/funnyboat-android", True, (0,0,0)) bottom = rect.bottom rect = image.get_rect() rect.midbottom = self.screen.get_rect().midbottom #rect.bottomright = self.screen.get_rect().bottomright #rect.bottom = bottom self.screen.blit(image, rect) pygame.display.flip() self.t += 1 nextframe = False while not nextframe: pygame.event.post(pygame.event.wait()) for event in pygame.event.get(): if event.type == QUIT or \ event.type == KEYDOWN and event.key == K_ESCAPE: self.selection = -1 done = True nextframe = True elif event.type == MOUSEBUTTONUP or event.type == MOUSEBUTTONDOWN: pos = event.pos for id, rect in self.option_rects.items(): if rect.collidepoint(pos): self.selection = id if event.type == MOUSEBUTTONUP: done = True elif event.type == NEXTFRAME: nextframe = True elif event.type == JOYAXISMOTION: if event.axis == 1: if event.value < -0.5: self.selection -= 1 if not self.gametype_select: if self.selection == Menu.OPTIONS: self.selection = Menu.HIGHSCORES if self.selection < 0: self.selection = 0 if event.value > 0.5: self.selection += 1 if not self.gametype_select: if self.selection == Menu.OPTIONS: self.selection = Menu.QUIT if self.selection > Menu.QUIT: self.selection = Menu.QUIT else: if self.selection > Menu.ENDLESS: self.selection = Menu.ENDLESS elif event.type == JOYBUTTONDOWN: if event.button == 0: done = True elif event.type == KEYDOWN: if event.key == K_UP: self.selection -= 1 if not self.gametype_select: if self.selection == Menu.OPTIONS: self.selection = Menu.HIGHSCORES if self.selection < 0: self.selection = 0 elif event.key == K_DOWN: self.selection += 1 if not self.gametype_select: if self.selection == Menu.OPTIONS: self.selection = Menu.QUIT if self.selection > Menu.QUIT: self.selection = Menu.QUIT else: if self.selection > Menu.ENDLESS: self.selection = Menu.ENDLESS elif event.key == K_SPACE or event.key == K_RETURN: done = True return self.selection
def run(self): while not self.done: if not self.pause: if not self.gameover: self.spawn_enemies() self.update_enemies() self.player.update() self.health.update() cloud.update() for cb in self.cannonballs: cb.update() if (cb.rect.right < 0 and cb.vect[0] < 0) or (cb.rect.left > SCREEN_WIDTH and cb.vect[0] > 0): self.cannonballs.remove(cb) self.cannonball_sprites.remove(cb) self.score.update() # Add steam particles if not self.noparticles: for i in range(3): particle_point = self.player.get_point( (5.0 + random.random() * 9.0, 0)) particle_point[0] += self.player.rect.centerx particle_point[1] += self.player.rect.centery self.particles.add_steam_particle(particle_point) for i in range(3): particle_point = self.player.get_point( (19.0 + random.random() * 7.0, 5.0)) particle_point[0] += self.player.rect.centerx particle_point[1] += self.player.rect.centery self.particles.add_steam_particle(particle_point) if self.titanic: for j in range(4): for i in range(3): particle_point = self.titanic.get_point( (49 + random.random() * 9.0 + 28 * j, 25)) particle_point[0] += self.titanic.rect.centerx particle_point[1] += self.titanic.rect.centery self.particles.add_steam_particle( particle_point) self.particles.update() self.water.update() if self.player.splash: if not self.noparticles: for i in range(30): r = random.random() x = int(r * self.player.rect.left + (1.0 - r) * self.player.rect.right) point = (x, self.water.get_water_level(x)) self.particles.add_water_particle(point) for powerup in self.powerups: powerup.update() if powerup.picked: self.powerups.remove(powerup) self.powerup_sprites.remove(powerup) if not self.gameover: self.check_collisions() if self.health.hearts_left == 0 and not self.player.dying: self.player.die() if self.player.dying and not self.player.dead: if not self.noparticles: for i in range(3): self.particles.add_explosion_particle( (self.player.rect.centerx, self.player.rect.centery)) self.particles.add_debris_particle( (self.player.rect.centerx, self.player.rect.centery)) if self.player.dead: #self.done = True self.set_gameover() if self.damage_count > 0: self.damage_count -= 1 self.lastshot += 1 self.t += 1 self.draw() self.handle_events() return self.score.get_score()
def run(self): water = Water.global_water water_sprite = pygame.sprite.Group() water_sprite.add(water) if util.android: util.android.show_keyboard() while not self.done: self.screen.blit(self.sky, self.screen.get_rect()) water.update() cloud.update() cloud.draw(self.screen) water_sprite.draw(self.screen) rect = self.title.get_rect() rect.centerx = self.screen.get_rect().centerx rect.top = 10 self.screen.blit(self.title, rect) for i in range(10): color = (0, 0, 0) if self.inputting and self.input_score == i: color = (220, 120, 20) score = self.scores[i] image = self.font.render(str(i + 1) + ". " + score[0], True, color) rect = image.get_rect() rect.top = 50 + i * 1.5 * rect.height rect.left = 10 self.screen.blit(image, rect) image = self.font.render(str(score[1]), True, color) rect = image.get_rect() rect.top = 50 + i * 1.5 * rect.height rect.right = self.screen.get_rect().right - 10 self.screen.blit(image, rect) pygame.display.flip() nextframe = False while not nextframe: pygame.event.post(pygame.event.wait()) for event in pygame.event.get(): if event.type == NEXTFRAME: nextframe = True continue if self.inputting: if event.type == QUIT: self.inputting = False self.write_scores() if event.type == KEYDOWN: if event.key == K_RETURN or event.key == K_ESCAPE: self.inputting = False self.write_scores() elif event.key == K_BACKSPACE: if len(self.scores[self.input_score][0]) != 0: self.scores[self.input_score][0] = self.scores[self.input_score][0][:-1] elif event.key == K_SPACE or event.unicode != " ": if len(self.scores[self.input_score][0]) < 32: self.scores[self.input_score][0] += event.unicode else: if ( event.type == KEYDOWN or event.type == QUIT or event.type == JOYBUTTONDOWN or event.type == MOUSEBUTTONDOWN ): self.done = True nextframe = True