Esempio n. 1
0
def shoot():
    global shoot_start_tick_counter
    tick = pygame.time.get_ticks()

    if tick - shoot_start_tick_counter > 0.3 * 1000:
        shoot_start_tick_counter = tick

        global bullets
        bullets.append(
            objects.Bullet("resources/images/bullet.png", osman_pasa.get_pos(),
                           osman_pasa.width, osman_pasa.looking_left,
                           osman_pasa.y + 39))
Esempio n. 2
0
def makeObject(obj, x=config.show_width / 2, y=config.show_height / 2):
    if obj == "brick":
        return objects.Brick(7, 3, x, y)
    if obj == "coin":
        return objects.Coin(7, 3, x, y)
    if obj == "spring":
        return objects.Spring(7, 3, x, y)
    if obj == "specialbrick":
        return objects.SpecialBrick(14, 3, x, y)
    if obj == "goomba":
        return objects.Goomba(3, 2, x, y)
    if obj == "spikey":
        return objects.Spikey(4, 2, x, y)
    if obj == "stalker":
        return objects.Stalker(4, 2, x, y)
    if obj == "cloud":
        return objects.Cloud(14, 4, x, y)
    if obj == "castle":
        return objects.Castle(41, 15, x, y)
    if obj == "bullet":
        return objects.Bullet(4, 1, x, y)
    if obj == "boss":
        return objects.Boss(8, 4, x, y)
Esempio n. 3
0
def movedin():
    # moves the player
    char = kb.getinput()

    if char == 'd':
        if mando.xget(
        ) <= global_var.mp.start_index + config.columns - 4 - mando.get_width(
        ) and mando.xget() <= 1090:
            mando.xset(1)

    if char == 'a':
        if mando.xget() > global_var.mp.start_index + 4:
            mando.xset(-1)

    if char == 'w':
        if mando.yget() >= 5:
            mando.yset(-1)
            mando.set_air_pos(mando.yget())
            mando.set_air_time(time())

    if char == ' ' and mando.get_shield_allow() == 1:
        mando.set_shield_allow(0)
        mando.set_shield_time(time())
        mando.set_shield(1)

    if char == 'e':
        bullet = objects.Bullet(config.bullet,
                                mando.xget() + 4,
                                mando.yget() + 1)
        bullet.render()
        global_var.bullets.append(bullet)

    if char == 'q':
        message = "Y U Quit :'("
        global_funct.display_ending(message)
        quit()
Esempio n. 4
0
                for i in range(9, 18):
                    global_var.redbricks[i].clear()
                    global_var.redbricks[i].down_brick()
                for i in range(8, 16):
                    global_var.bluebricks[i].clear()
                    global_var.bluebricks[i].down_brick()
                for i in range(17, 26):
                    global_var.greenbricks[i].clear()
                    global_var.greenbricks[i].down_brick()
                brock1.clear()
                brock1.down_brick()
                config.gg = 0

            if (config.shoot_flag == 1):
                if (config.go % 4 == 0):
                    bullet1 = objects.Bullet(config.Bullet, paddle._posx,
                                             paddle._posy)
                    bullet2 = objects.Bullet(config.Bullet, paddle._posx + 11,
                                             paddle._posy)
                    bulletl.append(bullet1)
                    bulletr.append(bullet2)

                for i in range(0, config.go // 4):
                    bulletl[i].clear()
                    bulletl[i].move_bullet()
                    bulletl[i].render()

                    bulletr[i].clear()
                    bulletr[i].move_bullet()
                    bulletr[i].render()

                    if (bulletl[i]._posy <= 4):
Esempio n. 5
0
    def update(self, game):
        'Updates the game state from previous frame'
        # update all sprites
        self.sprites.update()
        # Sprites grouped in lists, ready to iterate through
        foods = self.food_1, self.food_2, self.food_3
        fighters = (self.fighter_1, self.fighter_2, self.fighter_3,
                    self.fighter_4, self.fighter_5, self.fighter_6,
                    self.fighter_7)
        lives = self.life_1, self.life_2, self.life_3

        self.bullet_1 = objects.Bullet(self.fighter_7.rect.left + 12,
                                       self.fighter_7.rect.centery + 63)
        self.bullet_2 = objects.Bullet(self.fighter_7.rect.right - 12,
                                       self.fighter_7.rect.centery + 63)

        keystate = pygame.key.get_pressed()

        if keystate[pygame.K_SPACE]:
            self.sprites.add(self.bullet_1)
            self.sprites.add(self.bullet_2)
            config.shoot_sound.play()

        bullets = self.bullet_1, self.bullet_2

        for bullet in bullets:
            if self.alien.touches(bullet):
                print('bullet on alien')
                self.explosion = objects.Explosion(self.alien.rect.center)
                self.sprites.add(self.explosion)
                random.choice(config.explosion_sound).play()

        for food in foods:
            for fighter in fighters:
                if fighter.touches(food):
                    food.hide()
                if fighter.landed:
                    fighter.reset()
                    self.fighter_remaining -= 1
                    if self.fighter_remaining == 0:
                        game.next_state = LevelCleared(self.number)

                if self.alien.touches(food):
                    food.hide()
                    self.lives_remaining += 1
                    config.extra_life_sound.play()
                    if self.lives_remaining == 1:
                        self.life_1.show()
                    if self.lives_remaining == 2:
                        self.life_2.show()
                    if self.lives_remaining == 3:
                        self.life_3.show()

                if fighter.touches(self.alien):
                    self.explosion = objects.Explosion(self.alien.rect.center)
                    self.sprites.add(self.explosion)
                    random.choice(config.explosion_sound).play()
                    fighter.reset()
                    self.lives_remaining -= 1
                    if self.lives_remaining == 2:
                        self.life_3.hide()
                    if self.lives_remaining == 1:
                        self.life_2.hide()
                    if self.lives_remaining == 0:
                        self.life_1.hide()
                    if self.lives_remaining < 0:
                        game.next_state = GameOver()