Пример #1
0
 def update(self):
     if self.score < 0:
         return
     else:
         self.throw += 1
         self.movement()
         if self.throw == 30:
             self.create()
             self.throw = 0
         for Cookie in self.Cookie:
             if arcade.check_for_collision(Cookie, self.Snoopy):
                 self.Cookie.remove(Cookie)
                 if self.score > 100:
                     self.score += 2
                 else:
                     self.score += 2
             if Cookie.center_y < 0:
                 self.Cookie.remove(Cookie)
             Cookie.update()
         for Bomb in self.Bomb:
             if arcade.check_for_collision(Bomb, self.Snoopy):
                 self.Bomb.remove(Bomb)
                 if self.score > 100:
                     # self.score -= randint(35,115)
                     self.score -= 5
                 else:
                     # self.score -= randint(15,40)
                     self.score -= 5
             if Bomb.center_y < 0:
                 self.Bomb.remove(Bomb)
             Bomb.update()
Пример #2
0
    def on_update(self, delta_time):

        self.physics_engine1.update()
        self.physics_engine2.update()
        self.ball_Sprite.update()
        self.total_time += delta_time

        if arcade.check_for_collision_with_list(self.ball_Sprite,
                                                self.limite_list_L):
            self.Rscore += 1
            #            self.counter_time = self.total_time
            #            self.message = str(int(self.counter_time))
            self.ball_Sprite.center_y = 300
            self.ball_Sprite.center_x = 500
            self.ball_Sprite.change_x = random.randrange(1, 3)
            self.ball_Sprite.change_y = random.randrange(1, 3)

        if arcade.check_for_collision_with_list(self.ball_Sprite,
                                                self.limite_list_R):
            self.Lscore += 1
            self.ball_Sprite.center_y = 300
            self.ball_Sprite.center_x = 500
            self.ball_Sprite.change_x = random.randrange(1, 3)
            self.ball_Sprite.change_y = random.randrange(1, 3)

        elif arcade.check_for_collision(self.ball_Sprite, self.barre1_Sprite):
            self.ball_Sprite.change_x *= -1.2
        elif arcade.check_for_collision(self.ball_Sprite, self.barre2_Sprite):
            self.ball_Sprite.change_x *= -1.2
        elif arcade.check_for_collision_with_list(self.ball_Sprite,
                                                  self.wall_list):
            self.ball_Sprite.change_y *= -1
Пример #3
0
    def on_draw(self):

        arcade.start_render()

        self.border = arcade.draw_rectangle_outline(165, 300, 310, 580, arcade.color.GRAY, border_width=3)
        self.center_line = arcade.draw_line(10, 300, 320, 300, arcade.color.GRAY)
        self.background_image.draw()
        self.shooting_circle1 = arcade.draw_circle_outline(165,10,55,arcade.color.BLUE,border_width=3)
        self.shooting_circle2 = arcade.draw_circle_outline(165,590,55,arcade.color.RED,border_width=3)
        self.shooting_circles_list.append(self.shooting_circle1)
        self.shooting_circles_list.append(self.shooting_circle2)
        self.hoops.draw()
        self.ball.draw()
        self.player_list.draw()

        player1_scored = arcade.check_for_collision(self.hoop1, self.ball)
        if not self.player_1_scoring:
            if player1_scored:
                self.player_1_scoring = True
                self.score1 += 1
                arcade.draw_text("Player 1 Won!", 100, 400, arcade.color.BLUE, 20, font_name='comicsansms')

        player2_scored = arcade.check_for_collision(self.hoop2, self.ball)
        if not self.player_2_scoring:
            if player2_scored:
                self.player_2_scoring = True
                self.score1 += 1
                arcade.draw_text("Player 2 Won!", 100, 200, arcade.color.RED, 20, font_name='comicsansms')
Пример #4
0
    def update(self, delta_time):

        self.character.update()
        self.character_2.update()

        self.brick.update()

        if arcade.check_for_collision(self.character, self.brick):

            self.brick.left = self.character.right + 1
            self.brick.change_x *= -1
            self.brick.change_y = random.randint(-30, 30)

        if arcade.check_for_collision(self.character_2, self.brick):

            self.brick.right = self.character_2.left - 1
            self.brick.change_x *= -1
            self.brick.change_y = random.randint(-30, 30)

        if self.brick.bottom < 0:
            self.brick.bottom = 1
            self.brick.change_y *= -1

        if self.brick.top > SCREEN_HEIGHT:
            self.brick.top = SCREEN_HEIGHT - 1
            self.brick.change_y *= -1

        if self.brick.right < 0 or self.brick.left > SCREEN_WIDTH:
            self.brick.center_x = SCREEN_WIDTH / 2
            self.brick.center_y = SCREEN_HEIGHT / 2
            self.brick.change_x = 0
            self.brick.change_y = 0
Пример #5
0
    def update(self, delta_time):
        """Movement and game logic"""
        # Call update on all sprites
        # This moves the sprites based on each of their update functions (either the default or one you wrote)
        self.player_list.update()
        self.alien_list.update()
        self.wall_list.update()

        # Add any other game logic here

        # ----------COLLISIONS CODE-----------

        # Check for collisions with all walls
        if arcade.check_for_collision(self.player_sprite, self.leftWall):
            self.player_sprite.change_x *= -1

        if arcade.check_for_collision(self.player_sprite, self.topWall):
            self.player_sprite.change_y *= -1

        # check if any of the aliens have collided with a wall
        for alien in self.alien_list:
            if arcade.check_for_collision(alien, self.leftWall):
                alien.change_x *= -1

            if arcade.check_for_collision(alien, self.topWall):
                alien.change_y *= -1

        alien_hit_list = arcade.check_for_collision_with_list(
            self.player_sprite, self.alien_list)
        if len(alien_hit_list) > 0:
            self.level = GAME_OVER
Пример #6
0
    def on_update(self, delta_time: float):
        self.player_list.update()
        self.ball_list.update()

        # Score
        if self.ball1_sprite.center_x < 0 or self.ball1_sprite.center_x > SCREEN_WIDTH:
            if self.ball1_sprite.center_x < 0:
                self.score2 += 1
            if self.ball1_sprite.center_x > SCREEN_WIDTH:
                self.score1 += 1
            self.set_default_ball_position()
            arcade.play_sound(self.sound_score)
            if self.score1 == GAME_WIN_SCORE or self.score2 == GAME_WIN_SCORE:
                self.set_game_state(GAME_STATE_END)
            else:
                self.set_game_state(GAME_STATE_WAIT)

        # If ball hits wall, bounce off
        if self.ball1_sprite.center_y < 0 or self.ball1_sprite.center_y > SCREEN_HEIGHT:
            self.ball1_sprite.change_y = -self.ball1_sprite.change_y
            arcade.play_sound(self.sound_bounce)

        # If ball hits a player kick it in opposite direction
        if arcade.check_for_collision(self.ball1_sprite, self.player1_sprite):
            rand_speed_x = random.randint(BALL_MOVEMENT_SPEED_MIN_X,
                                          BALL_MOVEMENT_SPEED_X)
            self.ball1_sprite.change_x = abs(rand_speed_x)
            arcade.play_sound(self.sound_hit_player1)
        if arcade.check_for_collision(self.ball1_sprite, self.player2_sprite):
            rand_speed_x = random.randint(BALL_MOVEMENT_SPEED_MIN_X,
                                          BALL_MOVEMENT_SPEED_X)
            self.ball1_sprite.change_x = -abs(rand_speed_x)
            arcade.play_sound(self.sound_hit_player2)
Пример #7
0
    def on_key_press(self, key: int, modifiers: int):
        if key == arcade.key.LEFT:
            if self.sprite.center_x < 50:
                pass
            else:
                self.sprite.center_x = self.sprite.center_x - 50
            for box in self.bottom_row:
                if self.sprite and arcade.check_for_collision(
                        self.sprite, box):
                    self.sprite.center_x = self.sprite.center_x + 50

        if key == arcade.key.RIGHT:
            if self.sprite.center_x > SCREEN_WIDTH - 50:
                pass
            else:
                self.sprite.center_x = self.sprite.center_x + 50
            for box in self.bottom_row:
                if self.sprite and arcade.check_for_collision(
                        self.sprite, box):
                    self.sprite.center_x = self.sprite.center_x - 50

        if key == arcade.key.DOWN:
            self.sprite.change_y = -25

        if key == arcade.key.M:
            # Toggle mute
            if not self.mute % 2 == 0:
                self.music.stop()
                self.mute = self.mute + 1
            else:
                self.music.play(0.5)
                self.mute = self.mute + 1
Пример #8
0
    def on_update(self, delta_time: float):

        if self.player_list[0].center_x > 320 or self.player_list[0].center_x < 10:
            self.player_list[0].center_x -= 10
        if self.player_list[0].center_y > 295 or self.player_list[0].center_y < 10:
            self.player_list[0].center_y -= 10
        if self.player_list[1].center_x > 320 or self.player_list[1].center_x < 10:
            self.player_list[1].center_x -= 10
        if self.player_list[1].center_y > 590 or self.player_list[1].center_y < 295:
            self.player_list[1].center_y -= 10
        self.player_list[0].update()
        self.player_list[1].update()
        # Keeps the ball moving
        self.ball.center_x += self.x_speed * delta_time
        self.ball.center_y += self.y_speed * delta_time
        if self.ball.center_x > 310 or self.ball.center_x < 20:
            self.x_speed *= -1
        if self.ball.center_y > 580 or self.ball.center_y < 20:
            self.y_speed *= -1

        first_player_collision = arcade.check_for_collision(self.player_list[0], self.ball)
        if first_player_collision:
            self.x_speed *= -1
            self.y_speed *= -1

        second_player_collision = arcade.check_for_collision(self.player_list[1], self.ball)
        if second_player_collision:
            self.x_speed *= -1
            self.y_speed *= -1
 def on_mouse_press(self, x: float, y: float, button: int, modifiers: int):
     if button == arcade.MOUSE_BUTTON_LEFT and arcade.check_for_collision(self.cursor, self.start_button):
         self.story_path += "1"
         self.level = "game in progress"
     elif button == arcade.MOUSE_BUTTON_LEFT and arcade.check_for_collision(self.cursor, self.left_box):
         self.story_path += "1"
     elif button == arcade.MOUSE_BUTTON_LEFT and arcade.check_for_collision(self.cursor, self.right_box):
         self.story_path += "2"
Пример #10
0
    def HandleCollisions(self):
        #Alien and floor
        if len(self.aliens) > 0:
            if self.aliens[0].center_y < 30:
                self.aliens[0].remove_from_sprite_lists()
                self.levelCounter += 1

        #Powerup and floor
        if len(self.powerups) > 0:
            if self.powerups[0].center_y < 30:
                self.powerups[0].remove_from_sprite_lists()

        #Powerups and toasty!
        for to in range(len(self.toasty)):
            for po in range(len(self.powerups)):
                if arcade.check_for_collision(self.powerups[po],
                                              self.toasty[to]):
                    if self.powerups[po].alpha > 0:
                        #Lightning:
                        if self.powerups[po].name == "Lightning":
                            self.powerups[po].alpha = 0
                            print("Pug time!")
                            self.powerupTimer = 0
                            self.isInvincible = False
                            self.isPugShooting = True
                        #Coffee
                        elif self.powerups[po].name == "Coffee":
                            self.powerups[po].alpha = 0
                            print("Coffee time!")
                            self.powerupTimer = 0
                            self.isPugShooting = False
                            self.isInvincible = True
                            self.coffee.append(Coffee(0, 0))

        #Projectile and an alien
        for p in range(len(self.projectiles)):
            for a2 in range(len(self.aliens)):
                if arcade.check_for_collision(self.projectiles[p],
                                              self.aliens[a2]):
                    if self.projectiles[p].alpha > 0 and self.aliens[
                            a2].alpha > 0:
                        self.aliens[a2].alpha = 0
                        self.projectiles[p].alpha = 0
                        self.score += 50
                        self.levelCounter += 1

        #Toasty and an alien
        for t in range(len(self.toasty)):
            for a3 in range(len(self.aliens)):
                if arcade.check_for_collision(self.toasty[0], self.aliens[a3]):
                    if self.aliens[a3].alpha > 0:
                        if not self.isInvincible:
                            self.aliens[a3].alpha = 0
                            self.lives -= 1
                        else:
                            self.aliens[a3].alpha = 0
                            self.score += 50
Пример #11
0
    def update(self, delta_time):
        self.bullet_list.update()
        self.player.update()
        self.enemy_list.update()

        '''
        if all enemies have been killed: restart
        '''
        if (len(self.enemy_list) == 0):
            self.score += 1
            self.setup()
            #increase enemy movement speed
            self.speed += 5
            self.player.health = 10

        '''
        if player has been killed: restart
        '''

        if self.player.health == 0:
            
            print("Game Over")
            print(self.score)
            sys.exit()
        '''
        check for collison with player
        '''
        for b in self.bullet_list:
                # check for collision
                collision = arcade.check_for_collision(self.player, b)
                # for every bullet that hits, decrease the hp and then see if it dies
                if collision and b.goodbullet == False:
                # e.kill() will remove the enemy sprite from the game
                    self.player.health -= 1
                    b.kill()

        for e in self.enemy_list:
            if e.timesincebullet > random.randint(200, 400):
                x = e.center_x
                y = e.center_y - 15
                bullet = Bullet((x,y),(0,-10),BULLET_DAMAGE, False)
                self.bullet_list.append(bullet)
                e.timesincebullet = 0
            else:
                e.timesincebullet += 1

            for b in self.bullet_list:
                if b.goodbullet == True:
                    # check for collision
                    collision = arcade.check_for_collision(e, b)
                    # for every bullet that hits, decrease the hp and then see if it dies
                    if collision:
                        print("this was ran")
                    # e.kill() will remove the enemy sprite from the game
                        e.kill()
                        b.kill()
Пример #12
0
    def __check_collision(self):
        """
        Verifica le collisioni
        :return:
        """
        # ball vs paddle
        if arcade.check_for_collision(self.__paddle, self.__ball):
            # cambia direzione x, y
            # se la palla è sotto il bottom, setta la y di ball sopra
            self.__ball.change_y *= -1
            self.__ball.change_x = (
                self.__ball.center_x -
                self.__paddle.center_x) / self.__paddle.width
            if self.__ball.center_y <= Costanti.LEVEL_INFO['bottom']:
                self.__ball.center_y = Costanti.LEVEL_INFO[
                    'bottom'] + Costanti.Ball_RADIUS + 1

        # ball vs fine schermo
        if self.__ball.bottom < 0:
            # ferma la palla, scala una vita, se non ci sono più vite chiama game_over
            self.__ball.stop()
            self.__player['life'] -= 1
            if self.__player['life'] == 0:
                self.__game_over()

        # ball vs brick
        for brick in self.__bricks:
            if arcade.check_for_collision(self.__ball, brick):
                # aggiorna il punteggio, se il brick è dead lo rimuove e aggiorna brick_count
                self.__player['score'] += brick.on_collide()
                if brick.dead:
                    self.__bricks.remove(brick)
                    self.__brick_count -= 1

                # aggiusta le coordinate di ball a seconda di dove a colpito il brick
                if self.__ball.bottom - Costanti.Ball_RADIUS <= brick.top <= self.__ball.bottom + Costanti.Ball_RADIUS:
                    # il brick è stato colpito da sopra
                    self.__ball.change_y = (self.__ball.center_y -
                                            brick.center_y) / brick.height
                    self.__ball.bottom = brick.top
                elif self.__ball.top - Costanti.Ball_RADIUS <= brick.bottom <= self.__ball.top + Costanti.Ball_RADIUS:
                    # il brick è stato colpito da sotto
                    self.__ball.change_y = (self.__ball.center_y -
                                            brick.center_y) / brick.height
                    self.__ball.top = brick.bottom

                if self.__ball.right - Costanti.Ball_RADIUS <= brick.left <= self.__ball.right + Costanti.Ball_RADIUS:
                    # il brick è stato colpito a sinistra
                    self.__ball.change_x = (self.__ball.center_x -
                                            brick.center_x) / brick.width
                    self.__ball.right = brick.left
                elif self.__ball.left - Costanti.Ball_RADIUS <= brick.right <= self.__ball.left + Costanti.Ball_RADIUS:
                    # il brick è stato colpito a destra
                    self.__ball.change_x = (self.__ball.center_x -
                                            brick.center_x) / brick.width
                    self.__ball.left = brick.right
Пример #13
0
    def update(self, delta_time):
        self.physics_engine.update()
        self.player.update_animation()
        self.player.update()
        self.enemy_list.update()

        #code dlya otskoka
        for enemy in self.enemy_list:

            if self.hp <= 0:
                return

            # collisia
            if ar.check_for_collision_with_list(enemy, self.collision_list):
                #code vupolnenie
                enemy.change_x *= -1

        for coin in self.coin_list:
            if ar.check_for_collision(coin, self.player):
                self.coin += 1
                coin.remove_from_sprite_lists()
                self.coin_sound.play(0.05)

        # if ar.check_for_collision(enemy,self.player):
        #     self.hp -=1
        #     # self.player.center_x = 300
        #     # self.player.center_y = 300
        #     self.damage_sound.play(0.05)

        # for self.enemy_list in self.task:
        #     if ar.check_for_collision(self.enemy_list,self.player):

        for vxod in self.vxod_list:
            if ar.check_for_collision(vxod,
                                      self.player) and self.map_number < 0:
                self.map_number *= -1
                self.setup()

        for vxod in self.vxod_list:
            if ar.check_for_collision(vxod,
                                      self.player) and self.map_number > 0:
                self.map_number *= -1
                self.comback = True
                self.setup()

        for finish in self.finish:
            if ar.check_for_collision(finish, self.player):
                game_over = GameOver()  # присвоение основного класса игры
                self.window.show_view(game_over)  # переход на другое окно

        for enemy_list in self.enemy_list:
            if ar.check_for_collision(self.player, enemy_list):
                self.question = True
                enemy_list.remove_from_sprite_lists()
                self.ran = random.randint(0, 2)
Пример #14
0
 def on_update(self, delta_time):
     if self.escape == True:
         if arcade.check_for_collision(self.atrium_view.char5, self.atrium_view.opus):
             self.atrium_view.char5.update()
             self.atrium_view.char5.change_x = -1
             self.atrium_view.char5.change_y = -1
         elif arcade.check_for_collision(self.atrium_view.char5, self.atrium_view.opus) == False:
             self.escape = False
             atrium = self.atrium_view
             self.window.show_view(atrium)
             self.atrium_view.char5.change_x = 0
             self.atrium_view.char5.change_y = 0
Пример #15
0
 def add_ice(self):
     """ Adds ice to drinks. """
     if self.drink != "Frappuccino":
         if arcade.check_for_collision(self.you, self.ice_station) and self.cup_empty == True:
             self.cup = arcade.Sprite("game1_images/ice_cup.png", scale=0.18, center_x=400, center_y=305)
             self.ice_done = True
             self.cup_empty = False
     elif self.drink == "Frappuccino":
         if arcade.check_for_collision(self.you, self.ice_station) and self.syrup_done == True:
             self.cup = arcade.Sprite("game1_images/syrup_ice.png", scale=0.18, center_x=400, center_y=305)
             self.ice_done = True
             self.syrup_done = False
Пример #16
0
 def process_mouse_click(self) -> bool:
     """Processes the mouseclicks targeting the popup menu."""
     if arcade.check_for_collision(self.cursor, self.bg):
         if arcade.check_for_collision(self.cursor, self.exit_button):
             while len(self.sprite_list) > 0:
                 self.sprite_list.pop()
             del self
             return True
         self.dragged = True
         return True
     else:
         return False
Пример #17
0
    def update(self, dt):
        if not self.is_on_ladder():
            self.player.change_y -= self.gravity_constant * self.player.speed_multiplier * (
                dt / (1 / 60))

        _move_sprite(self.player, self.platforms, dt)

        for platform in self.platforms:
            if platform.change_x != 0 or platform.change_y != 0:
                platform.center_x += platform.change_x * self.player.speed_multiplier * (
                    dt / (1 / 60))

                if platform.boundary_left is not None \
                        and platform.center_x <= platform.boundary_left:
                    platform.center_x = platform.boundary_left
                    if platform.change_x < 0:
                        platform.change_x *= -1

                if platform.boundary_right is not None \
                        and platform.center_x >= platform.boundary_right:
                    platform.center_x = platform.boundary_right
                    if platform.change_x > 0:
                        platform.change_x *= -1

                collision = arcade.check_for_collision(self.player, platform)
                if collision and not platform.change_y:
                    if platform.change_x < 0:
                        self.player.right = platform.left
                    if platform.change_x > 0:
                        self.player.left = platform.right

                platform.center_y += platform.change_y * self.player.speed_multiplier * (
                    dt / (1 / 60))

                if platform.boundary_top is not None \
                        and platform.center_y >= platform.boundary_top:
                    platform.center_y = platform.boundary_top
                    if platform.change_y > 0:
                        platform.change_y *= -1

                if platform.boundary_bottom is not None \
                        and platform.center_y <= platform.boundary_bottom:
                    platform.center_y = platform.boundary_bottom
                    if platform.change_y < 0:
                        platform.change_y *= -1

                collision = arcade.check_for_collision(self.player, platform)
                if collision:
                    if platform.change_y < 0 and self.player.change_y > 0:
                        self.player.top = platform.bottom
                        self.player.change_y = -3
Пример #18
0
    def on_draw(self):
        arcade.start_render()
        #sprite lists
        self.tree_list.draw()
        self.chair_list.draw()
        self.table_list.draw()
        arcade.draw_rectangle_filled(745, 350, 95, 400, arcade.color.BANANA_MANIA)
        self.opus = arcade.Sprite("game1_images/opus.png",center_x=745,center_y=430,scale=0.1525)
        self.opus.draw()

        #characters
        self.char1.draw()
        self.char2.draw()
        self.char3.draw()
        self.char4.draw()
        self.char5.draw()

        #check collision -- THERE HAS TO BE A CLEANER WAY TO DO THIS??
        if arcade.check_for_collision(self.char5,self.char1):
            self.speech1 = arcade.Sprite("game1_images/dialogue.png",scale=0.07,
                          center_x=270,center_y=475)
            self.speech1.draw()
            arcade.draw_text("Have you\ntried Opus\ntoday?",272,477,arcade.color.BLACK,10,
                             anchor_x="center",anchor_y="center",rotation=20)

        if arcade.check_for_collision(self.char5,self.char2):
            self.speech2 = arcade.Sprite("game1_images/dialogue270.png",scale=0.07,
                                         center_x=460,center_y=465)
            self.speech2.draw()
            arcade.draw_text("Aren't\nyou late\nfor\nwork??",461,465,arcade.color.BLACK,10,
                             anchor_x="center",anchor_y="center",align="center",rotation=9)

        if arcade.check_for_collision(self.char5,self.char3):
            self.speech3 = arcade.Sprite("game1_images/dialogue90.png",scale=0.07,
                                         center_x=470,center_y=45)
            self.speech3.draw()
            arcade.draw_text("Have\nfun at\nwork!",467,49,arcade.color.BLACK,10,
                             anchor_x="center",anchor_y="center",align="center",rotation=9)

        if arcade.check_for_collision(self.char5, self.char4):
            self.speech4 = arcade.Sprite("game1_images/dialogue270.png", scale=0.07,
                                         center_x=580, center_y=300)
            self.speech4.draw()
            arcade.draw_text("Have\nyou\ndone the\nhome-\nwork?", 580, 300, arcade.color.BLACK, 9,
                             anchor_x="center",anchor_y="center",align="center",rotation=9)

        if arcade.check_for_collision(self.char5,self.opus):
            pause = PauseView(self)
            self.window.show_view(pause)
Пример #19
0
    def update(self, delta_time):
        self.bottompipe_sprite.update()
        self.toppipe_sprite.update()

        self.all_sprites_list.update()

        thit = arcade.check_for_collision(self.player_sprite, self.toppipe_sprite)
        bhit = arcade.check_for_collision(self.player_sprite, self.bottompipe_sprite)

        if self.toppipe_sprite.center_x == 0:
            self.score += 1

        if thit or bhit:
            self.player_sprite.kill()
            sys.exit()
Пример #20
0
    def update(self, delta_time):
        """ Movement and game logic """
        if self.game_over:
            return

        if arcade.check_for_collision(self.cactus, self.dino):
            arcade.play_sound(self.game_over_sound)
            self.game_over = True

        if self.going_up:
            self.dino.bottom += self.dino_up_speed
            if self.dino.bottom > 400: # This controls how high dino would jump
                self.going_up = False
                
        elif self.dino.bottom > 200:
            self.dino.bottom -= self.dino_down_speed
            if self.dino.bottom < 200: 
                self.dino.bottom = 200
        
        if self.cactus.right > 0:
            self.cactus.left -= self.cactus_speed
        else:
            self.score += 1
            if self.score % 2  == 0 :
                self.dino_down_speed += 1 
                self.dino_up_speed += 5
                self.cactus_speed += 1
                arcade.play_sound(self.level_up_sound)
            self.cactus = random.choice(self.cactus_list)
            self.cactus.left = SCREEN_WIDTH
Пример #21
0
    def on_update(self, delta_time):
        """
        All the logic to move, and the game logic goes here.
        Normally, you'll call update() on the sprite lists that
        need it.
        """

        # Calculate speed based on the keys pressed
        self.player_sprite.change_x = 0
        self.player_sprite.change_y = 0

        if self.W_pressed and not self.S_pressed:
            if self.player_sprite.center_y >= SCREEN_HEIGHT - 25:
                self.player_sprite.change_y = 0
            else:
                self.player_sprite.change_y = MOVEMENT_SPEED
        elif self.S_pressed and not self.W_pressed:
            if self.player_sprite.center_y <= 105:
                self.player_sprite.change_y = 0
            else:
                self.player_sprite.change_y = -MOVEMENT_SPEED
        if self.A_pressed and not self.D_pressed:
            if self.player_sprite.center_x <= 69:
                self.player_sprite.change_x = 0
            else:
                self.player_sprite.change_x = -MOVEMENT_SPEED
        elif self.D_pressed and not self.A_pressed:
            if self.player_sprite.center_x >= SCREEN_WIDTH - 65:
                self.player_sprite.change_x = 0
            else:
                self.player_sprite.change_x = MOVEMENT_SPEED

        # Check if zombie is hit by player attack
        for zombie in self.zombie_list:
            zombie.follow_sprite(self.player_sprite)
            if self.player_sprite.alpha == 254:
                if (self.player_sprite.center_y - 30 <= zombie.center_y <= self.player_sprite.center_y + 90) and \
                        (self.player_sprite.center_x - 80 <= zombie.center_x <= self.player_sprite.center_x + 80):
                    if (self.player_sprite.right_facing() and not zombie.right_facing()) or \
                            (not self.player_sprite.right_facing() and zombie.right_facing()) or \
                            ((self.player_sprite.center_y - 30 <= zombie.center_y <= self.player_sprite.center_y + 90)
                             and (self.player_sprite.center_x - 30 <= zombie.center_x <= self.player_sprite.center_x +
                                  30)):
                        zombie.alpha = 150
            if arcade.check_for_collision(self.player_sprite, zombie) and zombie.alpha == 255:
                if self.health_bar.width > 0:
                    self.health_bar.width -= ZOMBIE_DAMAGE
                    self.health_bar.x -= ZOMBIE_DAMAGE/2
                else:
                    game_over = GameOverView()
                    self.window.show_view(game_over)

        if not self.zombie_list:
            game_won = VictoryView()
            self.window.show_view(game_won)

        # Call update to move the sprite
        self.player_list.update()
        self.player_list.update_animation()
        self.zombie_list.update_animation()
Пример #22
0
 def on_draw(self):
     arcade.start_render()
     arcade.draw_lrwh_rectangle_textured(
         0, 0,
         constants.LEVEL_WIDTH, self.window.h,  # 100 x 9 level
         self.background)
     self.platform_list.draw()
     self.enemy_list.draw()
     self.cashier.draw()
     self.player_list.draw()
     self.window.item_list.draw()
     tp_amount = arcade.load_texture(
         "assets/amounts/toilet_paper_amount.png")
     scale = 1
     arcade.draw_scaled_texture_rectangle(
         max(120, self.view_left + 70), self.window.h - 35, tp_amount, scale, 0)
     score_text = f"{self.window.score}"
     arcade.draw_text(score_text, max(94, self.view_left + 44), self.window.h - 50,
                      arcade.csscolor.BLACK, 18)
     if self.window.score < self.window.goal and arcade.check_for_collision(self.player, self.cashier):
         arcade.draw_text("Come back with 15 items", self.view_left + self.window.w / 2, self.window.h - 50,
                          arcade.csscolor.CRIMSON, 24, anchor_x="center")
     elif self.window.score >= self.window.goal:
         arcade.draw_text("Find the cashier to checkout", self.view_left + self.window.w / 2, self.window.h - 50,
                          arcade.csscolor.CRIMSON, 24, anchor_x="center")
Пример #23
0
    def on_mouse_release(self, x: float, y: float, button: int,
                         modifiers: int):
        """ Called when the user presses a mouse button. """

        # If we don't have any cards, who cares
        if len(self.held_cards) == 0:
            return

        # Find the closest pile, in case we are in contact with more than one
        pile, distance = arcade.get_closest_sprite(self.held_cards[0],
                                                   self.pile_mat_list)
        reset_position = True

        # See if we are in contact with the closest pile
        if arcade.check_for_collision(self.held_cards[0], pile):

            # For each held card, move it to the pile we dropped on
            for i, dropped_card in enumerate(self.held_cards):
                # Move cards to proper position
                dropped_card.position = pile.center_x, pile.center_y

            # Success, don't reset position of cards
            reset_position = False

            # Release on top play pile? And only one card held?
        if reset_position:
            # Where-ever we were dropped, it wasn't valid. Reset the each card's position
            # to its original spot.
            for pile_index, card in enumerate(self.held_cards):
                card.position = self.held_cards_original_position[pile_index]

        # We are no longer holding cards
        self.held_cards = []
Пример #24
0
    def on_update(self, delta_time):
        # Check for WADS keys and perform movement
        dx, dy = 0, 0
        if 'w' in self.keys_pressed:
            dy += self.movement

        if 's' in self.keys_pressed:
            dy -= self.movement

        if 'a' in self.keys_pressed:
            dx -= self.movement

        if 'd' in self.keys_pressed:
            dx += self.movement

        self.player_sprite.change_x = dx
        self.player_sprite.change_y = dy

        mouse_x, mouse_y = self.mouse_location
        angle_deg = angle_to_point(self.player_sprite, mouse_x, mouse_y)
        self.player_sprite.angle = angle_deg - 90

        # Orient all enemies to player location
        for enemy in self.enemies_list:
            angle_deg = angle_to_sprite(enemy, self.player_sprite)
            enemy.angle = angle_deg + 90
            if arcade.check_for_collision(enemy, self.player_sprite):
                enemy.change_x = 0
                enemy.change_y = 0
            else:
                dx, dy = vector_from_angle(enemy.angle - 90)
                enemy_speed = 1
                enemy.change_x = dx * enemy_speed
                enemy.change_y = dy * enemy_speed

        # Update our sprites
        self.player_sprite.update()
        self.powerup_list.update()
        self.bullet_list.update()
        self.enemies_list.update()

        # Update the viewport
        self.reset_viewport()

        # Do collision detection
        powerup_hit_list = arcade.check_for_collision_with_list(
            self.player_sprite, self.powerup_list)

        for powerup in powerup_hit_list:
            powerup.remove_from_sprite_lists()
            self.score += 1
        if powerup_hit_list:
            print(self.score)

        # Test for bullets leaving viewport
        v_min_x, v_max_x, v_min_y, v_max_y = self.viewport
        for bullet in self.bullet_list:
            bx, by = bullet.position
            if bx > v_max_x or bx < v_min_x or by < v_min_y or by > v_max_y:
                bullet.remove_from_sprite_lists()
Пример #25
0
    def coffee_booster(self):

        image_source = "/Users/lutelillo/Desktop/DebugTheBug/lib/python3.8/" \
                       "site-packages/arcade/resources/images/createdSprites/coffee_boost.png"

        # Create the booster
        if self.actual_round == 1 and self.coffee_count < 1:
            self.coffee_sprite = arcade.Sprite(image_source, BOOSTER_SCALING)
            rand_center_x = random.randrange(SCREEN_WIDTH)
            rand_center_y = random.randrange(SCREEN_HEIGHT)
            self.coffee_sprite.center_x = rand_center_x
            self.coffee_sprite.center_y = rand_center_y
            self.coffee_list.append(self.coffee_sprite)
            self.coffee_count += 1

        # Check if player picks it up
        for coffee in self.coffee_list:
            if arcade.check_for_collision(self.player1.player_sprite, coffee):
                arcade.play_sound(self.pick_booster_sound)
                self.coffee_list.pop().remove_from_sprite_lists()
                self.boosted = True

                # Create visual aid to indicate that the booster has been picked up
                boost_source = "/Users/lutelillo/Desktop/DebugTheBug/lib/python3.8/" \
                               "site-packages/arcade/resources/images/createdSprites/powerup.png"

                self.booster_sprite = arcade.Sprite(boost_source,
                                                    BOOSTER_SCALING)
                self.booster_sprite.center_x = 50
                self.booster_sprite.center_y = SCREEN_HEIGHT - 50
                self.boost_list.append(self.booster_sprite)
    def on_update(self, delta_time):
        """ Movement and game logic """

        # Call update on all sprites (The sprites don't do much in this
        # example though.)
        self.coin_list.update()

        # Generate a list of all sprites that collided with the player.
        coins_hit_list = arcade.check_for_collision_with_list(
            self.player_sprite, self.coin_list)

        # Loop through each colliding sprite to set intensity=bright
        for coin in coins_hit_list:
            coin.intensity = 'bright'
            coin.alpha = 255

        hit_trigger = arcade.check_for_collision(self.player_sprite,
                                                 self.trigger_sprite)
        if hit_trigger:
            intense_sprites = [
                sprite for sprite in self.coin_list
                if sprite.intensity == 'bright'
            ]
            for coin in intense_sprites:
                coin.remove_from_sprite_lists()
Пример #27
0
    def update(self, delta_time):
        if self.running:
            self.player_sprite.update()
            for enemy in self.enemy_list:
                enemy.change_x = -ENEMY_MOVEMENT_SPEED * delta_time
                enemy.change_y = 0

                enemy.update()

            for shot in self.shot_list:
                shot.change_x = SHOT_MOVEMENT_SPEED * delta_time
                shot.change_y = 0
                shot.update()

            if random.random() < ENEMY_GENERATION_PROBABILITY:
                enemy_sprite = Enemy(os.path.join(IMG_FOLDER, "enemy.png"),
                                     SPRITE_SCALING_ENEMY)
                self.enemy_list.append(enemy_sprite)
                enemy_sprite.center_x = SCREEN_WIDTH
                enemy_sprite.center_y = random.randint(
                    ENEMY_SCREEN_SPACING, SCREEN_HEIGHT - ENEMY_SCREEN_SPACING)

            for enemy in self.enemy_list:
                for shot in self.shot_list:
                    if arcade.check_for_collision(enemy, shot):
                        self.enemy_list.remove(enemy)
                        self.shot_list.remove(shot)
                        self.score += 1
                if enemy.center_x - enemy.width / 2 < 0:
                    self.stop_game()

            self.total_time += delta_time
            if self.total_time > GAME_TIME:
                self.win = True
                self.stop_game()
Пример #28
0
    def update(self, delta_time):
        """ All the logic to move, and the game logic goes here. """

        for monster in self.monster_list:

            monster.center_x += sign(self.player_sprite.center_x -
                                     monster.center_x)
            monster.center_y += sign(self.player_sprite.center_y -
                                     monster.center_y)

        caught = arcade.check_for_collision(self.player_sprite,
                                            self.rabbit_sprite)
        if caught:
            self.alive = False
            self.player_sprite.texture = arcade.load_texture(
                'bloodsplats_0004.png')
            self.player_list.draw()
            self.monster_list.draw()

        self.physics_engine.update()
        if self.player_sprite.center_x > SCREEN_WIDTH:
            self.won = True
            self.score += 100

        while not self.clap_queue.empty():
            self.clap_queue.get()
            self.player_sprite.center_x += MOVEMENT_SPEED
Пример #29
0
def fly_carole_fly():
    global jump_score

    carole = part_list[3]
    body = part_list[2]
    carole.change_x += 0.1
    if jumping and 0 <= carole.change_y:
        carole.change_y += 4.5
    if falling:
        carole.change_y -= 1

    if carole.center_y > jump_score:
        jump_score = carole.center_y

    if carole.center_y <= body.center_y - 18:
        global carole_is_flying

        carole.change_x = 0
        carole.change_y = 0
        carole.center_y = body.center_y + 10
        catch = arcade.check_for_collision(carole, part_list[2])
        if catch:
            if carole.center_x <= body.center_x - 50 or carole.center_x >= body.center_x + 50:
                game_over()
            else:
                add_points(jump_score - GROUND)
                jump_score = 0

        else:
            game_over()

        carole_is_flying = False
Пример #30
0
    def on_update(self, delta_time):

        self.ball_sprite.center_x += self.dx
        self.ball_sprite.center_y += self.dy

        self.box_rec_list.update()

        if self.ball_sprite.center_x < 5 or self.ball_sprite.center_x > SCREEN_WIDTH - 5:
            self.dx *= -1
        if self.ball_sprite.center_y > SCREEN_HEIGHT - 5:
            self.dy *= -1
        if arcade.check_for_collision(
                self.player_sprite, self.ball_sprite
        ) and self.player_sprite.center_y < self.ball_sprite.center_y:
            self.dy *= -1

        hit_list_blue = arcade.check_for_collision_with_list(
            self.ball_sprite, self.box_rec_list)
        for box_rec in hit_list_blue:
            if self.ball_sprite.center_y <= box_rec.center_y - 32 or self.ball_sprite.center_y >= box_rec.center_y + 32:
                self.dx *= 1
                self.dy *= -1
            else:
                self.dx *= -1
                self.dy *= 1
            box_rec.remove_from_sprite_lists()
            self.score += 1

        if self.ball_sprite.center_y < 0:
            start = StartView()
            self.window.show_view(start)