Example #1
0
    def update(self, delta_time):
        self.bullet_list.update()
        self.enemyBullet_list.update()
        if self.enemy_list:
            for e in self.enemy_list:
                x = e.center_x
                y = e.center_y
                eBullet = enemyBullet((x, y), (0, -10), BULLET_DAMAGE)
                self.enemyBullet_list.append(eBullet)
                time.sleep(3)
                collision = arcade.check_for_collision_with_list(
                    e, self.bullet_list)
                for c in collision:
                    e.hp -= c.damage
                    c.kill()
                    self.score += HIT_SCORE
                    if e.hp <= 0:
                        e.kill()
                        self.score += KILL_SCORE
        else:
            arcade.close_window()
            print("You Win!")

            # check for collision
            # for every bullet that hits, decrease the hp and then see if it dies
            # increase the score
            # e.kill() will remove the enemy sprite from the game
            # the pass statement is a placeholder. Remove line 81 when you add your code
            pass
Example #2
0
    def on_key_press(self, symbol: int, modifiers: int):
        """Handle user keyboard input
        Q: Quit
        P: Pause/Un-pause
        I/J/K//L: Move Up, Left, Down, Right
        Arrows: Move Up, Left, Down, Right

        :arg symbol: which key was pressed
        :arg modifiers: which modifiers were pressed
        """
        if self.game_over and symbol == arcade.key.ENTER:
            arcade.close_window()
        if symbol == arcade.key.Q:
            # Quit the game
            arcade.close_window()

        if symbol == arcade.key.P:
            # Pause the game if not paused or
            # Play the game if paused
            self.paused = not self.paused

        if symbol == arcade.key.I or symbol == arcade.key.UP:
            self.player.change_y = 5
        if symbol == arcade.key.K or symbol == arcade.key.DOWN:
            self.player.change_y = -5
        if symbol == arcade.key.J or symbol == arcade.key.LEFT:
            self.player.change_x = -5
        if symbol == arcade.key.L or symbol == arcade.key.RIGHT:
            self.player.change_x = 5
    def on_key_press(self, symbol, modifiers):
        """Handle user keyboard input
        Q: Quit the game
        P: Pause/Unpause
        I/J/K/L: Move up, left, down, right
        Arrows: Move up, left, down, right

        Args:
            symbol {int} -- Which key was pressed
            modifier {int} -- Which modifiers were pressed
        """

        if symbol == arcade.key.Q:
            # Quit immediately
            arcade.close_window()

        if symbol == arcade.key.P:
            self.paused = not self.paused

        if symbol == arcade.key.I or symbol == arcade.key.UP:
            self.player.change_y = 250
            arcade.play_sound(self.move_up_sound)

        if symbol == arcade.key.J or symbol == arcade.key.LEFT:
            self.player.change_x = -250

        if symbol == arcade.key.K or symbol == arcade.key.DOWN:
            self.player.change_y = -250
            arcade.play_sound(self.move_down_sound)

        if symbol == arcade.key.L or symbol == arcade.key.RIGHT:
            self.player.change_x = 250
Example #4
0
    def on_key_press(self, key, modifiers):
        if self.depiction == "all bombs" and key == arcade.key.H:
            bar_width = max(
                1, int(sqrt(sqrt(self.nr_of_bombs / self.grid_size**2))))
            tmp = list(
                self.d.values()) + [0] * (self.grid_size**2 - len(self.d))
            print(tmp)
            #            plt.hist(tmp, density = True, bins=range(int(min(tmp)), int(max(tmp)) + 1, 1), align = "left", rwidth = 0.5)
            #            plt.hist(tmp, rwidth = 1)
            #            plt.show()
            plt.hist(tmp,
                     bins=range(int(min(tmp)),
                                int(max(tmp)) + 1, 1),
                     align="left",
                     rwidth=0.5,
                     density=True)
            # plt.hist(tmp, density = True, rwidth = 1)
            plt.show()
        if key == arcade.key.P:
            print(len(self.d))
        if key == arcade.key.F:
            self.set_fullscreen(not self.fullscreen)
            self.set_viewport(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT)

        if key == arcade.key.ESCAPE:
            arcade.close_window()
Example #5
0
    def on_key_press(self, symbol, modifiers):
        """Handle user keyboard input
        Q: Quit the game
        P: Pause/unpause the game
        W/A/S/D: Move Up, Left, Down, Right
        Arrows: Move Up, Left, Down, Right

        Arguments:
            symbol {int} -- Which key was pressed
            modifiers {int} -- Which modifiers were pressed
        """
        if symbol == arcade.key.Q:
            # Quit immediately
            arcade.close_window()

        if symbol == arcade.key.P:
            self.paused = not self.paused

        if symbol == arcade.key.SPACE:
            self.fire_missile()

        if symbol == arcade.key.W or symbol == arcade.key.UP:
            self.move_up_sound.play()
            self.player.change_y = 200
        elif symbol == arcade.key.A or symbol == arcade.key.LEFT:
            self.player.change_x = -200
        elif symbol == arcade.key.S or symbol == arcade.key.DOWN:
            self.move_down_sound.play()
            self.player.change_y = -200
        elif symbol == arcade.key.D or symbol == arcade.key.RIGHT:
            self.player.change_x = 200
Example #6
0
    def on_key_press(self, key, _modifiers):
        if key == arcade.key.ESCAPE:
            arcade.close_window()  # Sayonara!

        if key == arcade.key.DOWN and self.menu_item_selected < len(self.menu) - 1:
            self.menu_item_selected += 1

        if key == arcade.key.UP and self.menu_item_selected > 0:
            self.menu_item_selected -= 1

        if key == arcade.key.ENTER:
            if self.menu[self.menu_item_selected] == "1 Player":
                self.player.delete()                                # Stop background music
                difficulty_view = DifficultyView()                  # Show Difficulty selection screen
                self.window.show_view(difficulty_view)

            if self.menu[self.menu_item_selected] == "2 Players":
                self.player.delete()                                # Stop background music
                game_view = gameview.GameView(0)                    # Start two player game on same keyboard
                self.window.show_view(game_view)

            if self.menu[self.menu_item_selected] == "2 Players LAN":
                self.player.delete()                                # Stop background music
                langame_view = LanGameView()                        # Show LAN Game selection screen
                self.window.show_view(langame_view)

            if self.menu[self.menu_item_selected] == "Controls":
                controls_view = ControlsView()                      # Show Controls screen
                self.window.show_view(controls_view)

            if self.menu[self.menu_item_selected] == "Exit":
                arcade.close_window()                               # Sayonara!
Example #7
0
    def on_key_press(self, symbol, modifiers):
        # allows player to "sprint"
        if symbol == arcade.key.LSHIFT:
            self.player.change_x *= 1.5
            self.player.change_y *= 1.5

        # up
        if symbol == arcade.key.W:
            self.player.change_y = PLAYER_SPEED

        # down
        if symbol == arcade.key.S:
            self.player.change_y = -PLAYER_SPEED

        # left
        if symbol == arcade.key.A:
            self.player.change_x = -PLAYER_SPEED

        # right
        if symbol == arcade.key.D:
            self.player.change_x = PLAYER_SPEED

        # quit game
        if symbol == arcade.key.ESCAPE:
            arcade.close_window()
Example #8
0
    def on_update(self, deltatime):
        self.car.change_x = 0
        self.car.change_y = 0
        if self.car.direction == "left":
            self.car.change_x = -150 * deltatime
            self.car.angle = 90
        if self.car.direction == "right":
            self.car.change_x = 150 * deltatime
            self.car.angle = 270
        if self.car.direction == "up":
            self.car.angle = 360
            self.car.change_y = 150 * deltatime
        if self.car.direction == "down":
            self.car.angle = 180
            self.car.change_y = -150 * deltatime
        self.car.update()

        squarex = int(self.car.center_x / (128 * SPRITE_SCALING))
        squarey = len(self.map[0]) - int(self.car.center_y /
                                         (128 * SPRITE_SCALING)) - 1
        print(squarex, squarey)
        Height_of_map = len(self.map)
        width_of_map = len(self.map[0])
        try:
            cords = (self.map[squarey][squarex])
            if cords == 16:
                self.health = self.health - 1
                self.car.direction = "left"
                self.car.position = (400, 635)
            if self.health == 0:
                arcade.close_window()

        except:
            pass
Example #9
0
    def check_keys(self):
        """
        This function checks for keys that are being held down.
        You will need to put your own method calls in here.
        """
        if (self.ship.alive):
            if arcade.key.LEFT in self.held_keys:
                self.ship.turn_left()

            if arcade.key.RIGHT in self.held_keys:
                self.ship.turn_right()

            if arcade.key.UP in self.held_keys:
                self.ship.thrust()

            if arcade.key.DOWN in self.held_keys:
                self.ship.brake()

            # Machine gun mode... bullet_regulator keeps the laser from
            # firing every single frame.
            if arcade.key.SPACE in self.held_keys:
                if self.bullet_regulator > 0:
                    self.bullets.append(self.ship.fire())
                self.bullet_regulator *= -1
        else:
            if not self.held_keys.isdisjoint(Game.START_KEYS):
                self.restart()
            elif arcade.key.Q in self.held_keys:
                arcade.close_window()
    def on_update(self, delta_time: float):
        if self.paused:
            return

        if self.dead:
            self.dead_counter -= 1
            if self.dead_counter == 0:
                arcade.close_window()
            for sprite in self.all_sprites:
                sprite.alpha = max(0, sprite.alpha - 2)

        if self.player.collides_with_list(self.mines_list) and not self.dead:
            self.dead = True
            self.dead_counter = 160

        for s in self.all_sprites:
            s.center_x += s.change_x * delta_time
            s.center_y += s.change_y * delta_time
            if s.right < 0:
                s.remove_from_sprite_lists()

        if self.player.top > self.height:
            self.player.top = self.height
        if self.player.right > self.width:
            self.player.right = self.width
        if self.player.bottom < 0:
            self.player.bottom = 0
        if self.player.left < 0:
            self.player.left = 0
Example #11
0
def display(q):
    global queue
    global commander
    queue = q
    commander = Commander()

    import arcade
    try:
        # Open up our window
        arcade.open_window(conf.get_int(section="screen", key="width"),
                           conf.get_int(section="screen", key="height"),
                           "Gimbal Simulator")
        arcade.set_background_color(arcade.color.BLACK)

        # Tell the computer to call the draw command at the specified interval.
        arcade.schedule(lambda delta_time: commander.event_loop(), 1 / 80)

        # Run the program
        arcade.run()

        # When done running the program, close the window.
        arcade.close_window()
    except Exception as exc:
        print(exc)
        print("visual error")
        print("Error")
 def on_key_press(self, symbol, modifiers):
     if symbol == arc.key.ESCAPE:
         arc.close_window()
     if symbol == arc.key.A:
         self.player.move_left()
     if symbol == arc.key.D:
         self.player.move_right()
Example #13
0
 def on_key_press(self, key, modifiers):
     if key == arcade.key.ESCAPE:
         # kill the game
         arcade.close_window()
     elif key == arcade.key.F2:
         # start a new game with same difficulty
         self.new_game(self.difficulty)
Example #14
0
 def on_draw(self):
     arcade.start_render()
     if self.flags["on_start_screen"]:
         self.draw_start_screen()
         if self.flags["start_key_pressed"]:
             if self.flags["color_code"] > 0:
                 arcade.set_background_color(
                     (self.flags["color_code"], self.flags["color_code"],
                      self.flags["color_code"]))
                 self.flags["color_code"] -= 3
             else:
                 self.flags["on_start_screen"] = False
                 self.flags["on_play_screen"] = True
     elif self.flags["on_play_screen"]:
         arcade.draw_texture_rectangle(SCREEN_WIDTH // 2,
                                       SCREEN_HEIGHT // 2, SCREEN_WIDTH,
                                       SCREEN_HEIGHT, self.background)
         self.draw_snake(self.snake1, SNAKE_1_COLOR)
         self.draw_snake(self.snake2, SNAKE_2_COLOR)
     elif self.flags["win_state"] == 1:
         print("Win state 1, exiting...")
         arcade.close_window()
     elif self.flags["win_state"] == 2:
         print("Win state 2, exiting...")
         arcade.close_window()
Example #15
0
    def on_update(self, delta_time: float):
        # update the player and branches
        self.entity_list.update()

        # make a list of branches that were collected
        collected_branches = arcade.check_for_collision_with_list(
            self.player, self.branch_list)

        # remove branches, add to the score, and make a sound
        for branch in collected_branches:
            branch.remove_from_sprite_lists()
            self.score += 1
            self.sound = arcade.Sound(":resources:sounds/coin5.wav")
            self.sound.play(0.5)

        # detect if the player has touched a tree or the camping equipment
        if self.player.collides_with_list(self.collision_list):
            self.player.change_x = 0
            self.player.change_y = 0

        # if a player returns to camp with at least 4 branches, they win
        if self.player.collides_with_list(self.camp_list) and self.score > 3:
            self.player.change_x = 0
            self.player.change_y = 0
            arcade.close_window()
Example #16
0
    def on_key_press(self, key, modifiers):
        """Called whenever a key is pressed. """

        if key == arcade.key.ENTER:
            if self.selected == 1:
                arcade.play_sound(self.click_sound)
                game_view = GameView()
                game_view.setup(1)
                self.window.show_view(game_view)
            elif self.selected == 2:
                arcade.play_sound(self.click_sound)
                game_view = LevelSelectView()
                self.window.show_view(game_view)
            elif self.selected == 3:
                arcade.play_sound(self.click_sound)
                arcade.close_window()
            else:
                arcade.play_sound(self.click_sound)
        if key == arcade.key.DOWN:
            self.selected += 1
            arcade.play_sound(self.select_sound)
            if self.selected > 3:
                self.selected = 1
        if key == arcade.key.UP:
            self.selected -= 1
            arcade.play_sound(self.select_sound)
            if self.selected < 1:
                self.selected = 3
Example #17
0
 def on_update(self, delta_time):
     if self.ExitButton.is_clicked:
         arcade.close_window()
     if self.RestartButton.is_clicked:
         self.ui_manager.purge_ui_elements()
         view = GameStart()
         self.window.show_view(view)
Example #18
0
    def create_target(self):
        # Close task if end of trials
        print('trialNum: ' + str(self.trialNum))
        print('len(trialType): ' + str(len(self.trialType)))
        if self.trialNum >= len(self.trialType):
            arcade.close_window()
        else:
            # Create the target
            im = Image.open('Images/target.png')
            img_width, img_height = im.size
            scaling_factor = min(WIDTH / img_width, HEIGHT / img_height)
            self.target_sprite = arcade.Sprite('Images/target.png',
                                               scale=scaling_factor)

            # Place to either the left or right
            if self.trialType[self.trialNum] > 0.5:
                # Target on the right
                self.target_sprite.center_x = (WIDTH + MARGIN) * (
                    COLUMN_COUNT - 1) - WIDTH / 2 - MARGIN
                self.target_sprite.center_y = (HEIGHT + MARGIN) * (
                    ROW_COUNT) / 2 + MARGIN
            else:
                # Target on the left
                self.target_sprite.center_x = (WIDTH + MARGIN) * (
                    1) + WIDTH / 2 + MARGIN
                self.target_sprite.center_y = (HEIGHT + MARGIN) * (
                    ROW_COUNT) / 2 + MARGIN

            self.target_list.append(self.target_sprite)
        self.trialNum += 1
Example #19
0
 def on_key_press(self, key, modifiers):
     if key == arcade.key.ENTER:
         ch3 = Ch3View()
         self.window.show_view(ch3)
     elif key == arcade.key.ESCAPE:
         arcade.close_window()
         self.director.next_view()
Example #20
0
    def on_key_press(self, symbol, modifiers):
        """Handle user keyboard input
        Q: Quit the game
        P: Pause/Unpause the game
        I/J/K/L: Move Up, Left, Down, Right
        Arrows: Move Up, Left, Down, Right

        Arguments:
            symbol {int} -- Which key was pressed
            modifiers {int} -- Which modifiers were pressed
        """
        if symbol == arcade.key.Q:
            # Quit immediately
            arcade.close_window()
        """
        if symbol == arcade.key.P:
            self.paused = not self.paused
        """
        if symbol == arcade.key.I or symbol == arcade.key.UP:
            self.player.center_y += 5

        if symbol == arcade.key.K or symbol == arcade.key.DOWN:
            self.player.center_y += -5

        if symbol == arcade.key.J or symbol == arcade.key.LEFT:
            self.player.center_x += -5

        if symbol == arcade.key.L or symbol == arcade.key.RIGHT:
            self.player.center_x += 5
Example #21
0
    def on_key_press(self, key, modifiers):
        """ Called whenever the user presses a key. """
        if self.gameOver and self.gameOverTimer + self.gameOverTextTime < self.uptime:
            arcade.close_window()

        if getCurrKeybinds() == 1:
            if key == arcade.key.A:
                self.flags.left = True
            if key == arcade.key.D:
                self.flags.right = True
            if key == arcade.key.W:
                self.flags.up = True
            if key == arcade.key.S:
                self.flags.down = True
        else:
            if key == arcade.key.LEFT:
                self.flags.left = True
            if key == arcade.key.RIGHT:
                self.flags.right = True
            if key == arcade.key.UP:
                self.flags.up = True
            if key == arcade.key.DOWN:
                self.flags.down = True

        if key == arcade.key.SPACE:
            self.flags.space = True
Example #22
0
    def on_key_press(self, symbol: int, modifiers: int):
        """Manipular a entrada do teclado
        Q: Sai do jogo
        P: Pausa o Jogo
        Setas: Move para cima, para a esquerda,
        para baixo e para a direita

        Argumentos:
            symbol {int} -- Qual tecla foi pressionada
            modifiers {int} -- Quais modificadores foram
             pressionados (shift, ctrl, alt)
        """
        if symbol == arcade.key.Q:
            arcade.close_window()

        if symbol == arcade.key.P:
            self.paused = not self.paused

        if symbol == arcade.key.UP:
            self.player.change_y = 250

        if symbol == arcade.key.DOWN:
            self.player.change_y = -250

        if symbol == arcade.key.LEFT:
            self.player.change_x = -250

        if symbol == arcade.key.RIGHT:
            self.player.change_x = 250
    def on_mouse_press(self, _x, _y, button, _modifiers):

        menu_hit_list = arcade.check_for_collision_with_list(
            self.mouse_sprite, self.menu_list)

        for menu_index in menu_hit_list:

            if button == arcade.MOUSE_BUTTON_LEFT:

                if menu_index == self.menu_list[0]:  # start
                    game_view = Game.GameView()
                    game_view.setup()
                    self.window.show_view(game_view)

                if menu_index == self.menu_list[1]:  # setting
                    setting_view = Setting.SettingView()
                    setting_view.setup()
                    self.window.show_view(setting_view)

                if menu_index == self.menu_list[2]:  # map edit
                    mapedit_view = Mapedit.MapeditView()
                    mapedit_view.setup()
                    self.window.show_view(mapedit_view)

                if menu_index == self.menu_list[3]:  # quit
                    arcade.close_window()
                    return 0

                if menu_index == self.menu_list[4]:  # back
                    return 0
Example #24
0
    def on_key_press(self, key, modifiers):
        # Quit game with ESCAPE
        if key == arcade.key.ESCAPE:
            self.get_name()
            #Send score to server
            self.send_score()
            arcade.close_window()

        # Submit Name with ENTER
        if key == arcade.key.ENTER:
            self.name = self.inputBox.text
            self.gui._ui_elements.remove(self.inputBox)

        # Restart with F2
        if key == arcade.key.F2:
            self.get_name()
            try:
                self.gui._ui_elements.remove(self.inputBox)
            except:
                print("something happened")
            self.window.show_view(GameView())
            self.send_score()
        # Change screen size
        if key == arcade.key.F1:
            # User hits s. Flip between full and not full screen.
            self.window.set_fullscreen(not self.window.fullscreen)
            # Instead of a one-to-one mapping, stretch/squash window to match the
            # constants. This does NOT respect aspect ratio. You'd need to
            # do a bit of math for that.
            self.window.set_viewport(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT)
 def execute(self, ui_arcade):
     if ui_arcade.sim.result is not None:
         arcade.close_window()
     else:
         ui_arcade.clock.pause()
         ui_arcade.sim.step()
         ui_arcade.tape_drawer.next_step()
Example #26
0
    def on_key_press(self, key, modifiers):
        if key == arcade.key.ESCAPE:
            # kill the game
            arcade.close_window()
        elif key == arcade.key.F2:
            # restart current level
            self.play_level(self.active_level_index)
        elif key == arcade.key.F1:
            # toggle FPS meter
            self.show_fps = not self.show_fps
        elif key == arcade.key.F3:
            # skip level
            self.play_level(self.active_level_index + 1)

        elif self.active_level and not self.finished_level:
            # handle movement and check for win
            if key == arcade.key.LEFT:
                self.active_level.move_player(-1, 0)
                self.finished_level = self.active_level.check_win()
            elif key == arcade.key.RIGHT:
                self.active_level.move_player(1, 0)
                self.finished_level = self.active_level.check_win()
            elif key == arcade.key.UP:
                self.active_level.move_player(0, -1)
                self.finished_level = self.active_level.check_win()
            elif key == arcade.key.DOWN:
                self.active_level.move_player(0, 1)
                self.finished_level = self.active_level.check_win()

        elif self.active_level and self.finished_level and key == arcade.key.SPACE:
            # advance to next level
            next_level_index = self.active_level_index + 1
            if next_level_index >= len(self.levels):
                next_level_index = 0
            self.play_level(next_level_index)
    def on_key_press(self, key: int, modifiers: int):
        """
        Puts the current key in the set of keys that are being held.
        You will need to add things here to handle firing the bullet.
        """
        if self.ship.alive:  # Only fire if ship is alive
            self.held_keys.add(key)

            if key == arcade.key.SPACE:
                # DONE: Fire the bullet here!
                bullet = Bullet()
                bullet_angle = self.ship.angle
                bullet.angle = self.ship.angle + 90
                bullet.center.x = self.ship.center.x
                bullet.center.y = self.ship.center.y
                ship_velocity_dx = self.ship.velocity.dx
                ship_velocity_dy = self.ship.velocity.dy
                bullet.fire(bullet_angle, ship_velocity_dx, ship_velocity_dy)
                self.bullets.append(bullet)

        if self.game_over:
            if key == arcade.key.SPACE:
                arcade.close_window()
                window = Game(SCREEN_WIDTH, SCREEN_HEIGHT)
                window.setup()
                arcade.run()

            else:
                print("Game Finalized by User")
Example #28
0
def main():
    game = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
    game.setup()
    try:
        arcade.run()
    except:
        arcade.close_window()
Example #29
0
    def on_draw(self):
        arcade.start_render()
        self.deck_back.draw()
        self.dealer_card_back1.draw()
        self.dealer_card_back2.draw()
        self.player_card_back1.draw()
        self.player_card_back2.draw()

        super().on_draw()

        arcade.draw_text(f"Place your bid:\n Your bet is {self.bet}",
                         self.WIDTH / 2,
                         self.HEIGHT / 2,
                         arcade.color.BLACK,
                         24,
                         anchor_x="center")

        for button in self.button_list:

            # if player made input
            if button.on_release():
                if self.bet + button.get_value() < 1:
                    continue
                # print(self.button_list[0].on_release)
                self.bet += button.get_value()
            if self.exit_button.pressed:
                arcade.close_window()
Example #30
0
    def on_key_press(self, key, modifiers):
        """ Handles key press events. """
        if self.current_state == "instructions":
            self.setup()
            self.construct_level(self.current_level)
            self.current_state = "running"
        elif self.current_state == "lose":
            self.setup()
            self.construct_level(0)
            self.current_state = "running"
        else:  # so we are in game
            if key == arcade.key.LSHIFT or modifiers % 2:
                self.player.set_precise_mode(True)
            if key in [
                    arcade.key.UP,
                    arcade.key.DOWN,
                    arcade.key.RIGHT,
                    arcade.key.LEFT,
            ]:
                self.player.add_key(key)

            if key == arcade.key.SPACE:
                self.player_bullet_list.append(self.player.fire())
                self.emitters.append(self.make_gun_fire_emitter())
                self.shot += 1

        if key == arcade.key.Q:
            # close the window if 'Q' is pressed
            arcade.close_window()
Example #31
0
def main():
    # Open up our window
    arcade.open_window("Bouncing Ball", SCREEN_WIDTH, SCREEN_HEIGHT)
    arcade.set_background_color(arcade.color.WHITE)

    # Tell the computer to call the draw command at the specified interval.
    arcade.schedule(draw, 1 / 80)

    # Run the program
    arcade.run()

    # When done running the program, close the window.
    arcade.close_window()
Example #32
0
    if draw.y < CIRCLE_RADIUS and draw.delta_y < 0:
        # If we bounce with a decent velocity, do a normal bounce.
        # Otherwise we won't have enough time resolution to accurate represent
        # the bounce and it will bounce forever. So we'll divide the bounciness
        # by half to let it settle out.
        if draw.delta_y * -1 > GRAVITY_CONSTANT * 15:
            draw.delta_y *= -BOUNCINESS
        else:
            draw.delta_y *= -BOUNCINESS / 2

# These are function-specific variables. Before we
# use them in our function, we need to give them initial
# values.
draw.x = CIRCLE_RADIUS
draw.y = SCREEN_HEIGHT - CIRCLE_RADIUS
draw.delta_x = 2
draw.delta_y = 0

# Open up our window
arcade.open_window("Bouncing Ball", SCREEN_WIDTH, SCREEN_HEIGHT)
arcade.set_background_color(arcade.color.WHITE)

# Tell the computer to call the draw command at the specified interval.
arcade.schedule(draw, 1 / 80)

# Run the program
arcade.run()

# When done running the program, close the window.
arcade.close_window()