Example #1
0
    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()
Example #2
0
    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