예제 #1
0
class BualoiWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)
        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)

        arcade.set_background_color(arcade.color.WHITE_SMOKE)

        self.pan = ModelSprite('images/handpan3.png', model=self.world.pan)
        self.circle = ModelSprite('images/cir.png', model=self.world.circle)
        self.spoon = ModelSprite('images/spoon.png', model=self.world.spoon)

    def on_draw(self):
        arcade.start_render()
        self.pan.draw()

        radius = self.world.bowl.radius
        color = self.world.bowl.color
        arcade.draw_circle_filled(self.world.bowl.x, self.world.bowl.y, radius,
                                  color)
        self.circle.draw()
        self.spoon.draw()
        self.draw_score()

    def draw_score(self):
        arcade.draw_text(
            'Score : ' + str(self.world.score),
            self.width - 150,
            self.height - 30,
            arcade.color.BLACK,
            20,
        )

    def on_key_press(self, key, key_modifiers):
        if not self.world.is_started():
            self.world.start()
        if key == arcade.key.SPACE:
            if self.world.count == 1:
                self.world.on_key_press(key, key_modifiers)
            self.world.on_key_press(key, key_modifiers)

    def on_key_release(self, key, key_modifiers):
        self.world.on_key_release(key, key_modifiers)

    def update(self, delta):
        self.world.update(delta)
예제 #2
0
class Gameplay:
    def __init__(self):
        self.world = None
        self.player_sprite = None
        self.bullet_sprite = None
        self.monster_bullet_sprite = None
        self.game_over_cover = False
        self.enable_sound = False
        self.sound = Sound()

    def set_up(self):
        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)
        self.player_sprite = self.player()
        self.bullet_sprite = BulletSprite(self.world.bullet)
        self.monster_bullet_sprite = BulletSprite(self.world.monster_bullet)

    def background(self):
        arcade.draw_texture_rectangle(
            SCREEN_WIDTH // 2,
            SCREEN_HEIGHT // 2,
            SCREEN_WIDTH,
            SCREEN_HEIGHT,
            texture=arcade.load_texture('images/background.png'))

    def player(self):
        if self.world.player.current_direction == DIR_LEFT:
            player_sprite = ModelSprite('images/player/player-' +
                                        str(self.world.player.element) +
                                        '_left.png',
                                        model=self.world.player,
                                        scale=0.24)
        else:
            player_sprite = ModelSprite('images//player/player-' +
                                        str(self.world.player.element) +
                                        '_right.png',
                                        model=self.world.player,
                                        scale=0.24)
        return player_sprite

    def draw_idle(self):
        if self.world.player.idle:
            arcade.draw_triangle_filled(50, 130, 40, 147.3, 60, 147.3,
                                        arcade.color.LEMON_GLACIER)
            arcade.draw_triangle_outline(50,
                                         130,
                                         40,
                                         147.3,
                                         60,
                                         147.3,
                                         arcade.color.WHITE,
                                         border_width=2)
        else:
            pass

    def draw_melee(self):
        melee_sprite = ModelSprite('images/melee/melee.png',
                                   model=self.world.player,
                                   scale=0.24)
        if 0 <= self.world.player_melee.frame <= MELEE_FRAME_UPDATE:
            if self.world.player.current_direction == DIR_LEFT:
                direction = 'left'
            else:
                direction = 'right'
            melee_sprite = ModelSprite('images/melee/'+ direction +'/melee-'+\
                    str(self.world.player.element) + str(self.world.player_melee.melee_update)+'.png',
                    model=self.world.player,scale=0.24)
        return melee_sprite

    def player_sprite_hit(self):
        if self.world.player.current_direction == DIR_LEFT:
            direction = 'left'
        else:
            direction = 'right'
        return ModelSprite('images/player/player-hit_' + direction + '.png',
                           model=self.world.player,
                           scale=0.24)

    def draw_platforms(self, platforms):
        for p in platforms:
            arcade.draw_xywh_rectangle_textured(
                p.x,
                p.y - PLATFORM_DRAW_Y_OFFSET,
                p.width,
                PLATFORM_DRAW_THICKNESS,
                texture=arcade.load_texture('images/platform.png'))

    def monster_sprite(self, m):
        if m.current_direction == DIR_LEFT:
            monster_sprite = ModelSprite('images/monster/monster-' +
                                         str(m.element) + '_left.png',
                                         model=m,
                                         scale=0.35)
        else:
            monster_sprite = ModelSprite('images/monster/monster-' +
                                         str(m.element) + '_right.png',
                                         model=m,
                                         scale=0.35)
        return monster_sprite

    def monster_sprite_hit(self, m):
        if m.current_direction == DIR_LEFT:
            direction = 'left'
        else:
            direction = 'right'
        return ModelSprite('images/monster/monster-hit_' + direction + '.png',
                           model=m,
                           scale=0.35)

        if self.world.player.shield:
            arcade.draw_xywh_rectangle_filled(20, SCREEN_HEIGHT - 50, 50, 50,
                                              arcade.color.GREEN)
        else:
            arcade.draw_xywh_rectangle_filled(20, SCREEN_HEIGHT - 50, 50, 50,
                                              arcade.color.YELLOW)

    def hp_bar(self):
        color = arcade.color.PANSY_PURPLE
        if self.world.player.element == 0:
            color = arcade.color.FIRE_ENGINE_RED
        elif self.world.player.element == 1:
            color = arcade.color.OCEAN_BOAT_BLUE
        elif self.world.player.element == 2:
            color = arcade.color.WINDSOR_TAN
        elif self.world.player.element == 3:
            color = arcade.color.SHEEN_GREEN

        if self.world.player.health >= (1000 / 11):
            arcade.draw_polygon_filled(
                [[75, SCREEN_HEIGHT - 25],
                 [75 + (self.world.player.health) * 2.75, SCREEN_HEIGHT - 25],
                 [
                     75 + (self.world.player.health) * 2.75, SCREEN_HEIGHT -
                     (25 + (275 - (self.world.player.health) * 2.75))
                 ], [325, SCREEN_HEIGHT - 50], [75, SCREEN_HEIGHT - 50]],
                color)
            self.draw_number(f'{self.world.player.health:.0f}' + '/100', 90,
                             SCREEN_HEIGHT - 45)
        elif 0 < self.world.player.health < (1000 / 11):
            arcade.draw_polygon_filled(
                [[75, SCREEN_HEIGHT - 25],
                 [75 + (self.world.player.health) * 2.75, SCREEN_HEIGHT - 25],
                 [75 + (self.world.player.health) * 2.75, SCREEN_HEIGHT - 50],
                 [75, SCREEN_HEIGHT - 50]], color)
            self.draw_number(f'{self.world.player.health:.0f}' + '/100', 90,
                             SCREEN_HEIGHT - 45)
        else:
            self.draw_number('0/100', 90, SCREEN_HEIGHT - 45)

    def power_bar(self):
        color = arcade.color.BLUE
        if self.world.player.power == 100 or self.world.player.shield:
            color = arcade.color.PUMPKIN
        else:
            color = arcade.color.LEMON
        if self.world.player.power >= (4700 / 49):
            arcade.draw_polygon_filled(
                [[75, SCREEN_HEIGHT - 55],
                 [75 + (self.world.player.power) * 2.45, SCREEN_HEIGHT - 55],
                 [
                     75 + (self.world.player.power) * 2.45, SCREEN_HEIGHT -
                     (55 + (245 - (self.world.player.power) * 2.45))
                 ], [310, SCREEN_HEIGHT - 65], [75, SCREEN_HEIGHT - 65]],
                color)
        elif 0 < self.world.player.power < (4700 / 49):
            arcade.draw_polygon_filled(
                [[75, SCREEN_HEIGHT - 55],
                 [75 + (self.world.player.power) * 2.45, SCREEN_HEIGHT - 55],
                 [75 + (self.world.player.power) * 2.45, SCREEN_HEIGHT - 65],
                 [75, SCREEN_HEIGHT - 65]], color)
        else:
            pass

    def bar_outline(self):
        arcade.draw_polygon_outline(
            [[75, SCREEN_HEIGHT - 25], [350, SCREEN_HEIGHT - 25],
             [325, SCREEN_HEIGHT - 50], [75, SCREEN_HEIGHT - 50]],
            arcade.color.BLACK,
            line_width=2)
        arcade.draw_polygon_outline(
            [[75, SCREEN_HEIGHT - 55], [320, SCREEN_HEIGHT - 55],
             [310, SCREEN_HEIGHT - 65], [75, SCREEN_HEIGHT - 65]],
            arcade.color.BLACK,
            line_width=2)
        # arcade.draw_circle_filled(50,SCREEN_HEIGHT-50,35,arcade.color.WHITE)
        # arcade.draw_circle_outline(50,SCREEN_HEIGHT-50,35,arcade.color.BLACK,border_width=2)

    def draw_number(self, string, x, y, size=16, color='white'):
        x0 = x
        for s in string:
            if s == '/':
                arcade.draw_xywh_rectangle_textured(
                    x0, y, size / 2, size,
                    arcade.load_texture('images/char/' + str(color) +
                                        '/slash.png'))
            else:
                arcade.draw_xywh_rectangle_textured(
                    x0, y, size / 2, size,
                    arcade.load_texture('images/char/' + str(color) + '/' +
                                        str(s) + '.png'))
            x0 += size / 2

    def floor(self, x, y, size):
        arcade.draw_xywh_rectangle_textured(
            x, y, size * 3, size, arcade.load_texture('images/char/floor.png'))
        self.draw_number(str(self.world.floor), x + size * 3.1, y, size)

    def score(self, x, y, size):
        arcade.draw_xywh_rectangle_textured(
            x, y, size * 3, size, arcade.load_texture('images/char/score.png'))
        self.draw_number(str(self.world.score), x + size * 3.1, y, size)

    def gui(self):
        self.hp_bar()
        self.power_bar()
        self.bar_outline()
        self.floor(SCREEN_WIDTH - 135, SCREEN_HEIGHT - 45, 20)
        self.score(SCREEN_WIDTH - 135, SCREEN_HEIGHT - 70, 20)

    def game_over(self):
        if self.world.player.is_dead:
            arcade.draw_xywh_rectangle_textured(
                0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
                arcade.load_texture("images/game_over/game_over.png"))
            self.floor(200, SCREEN_HEIGHT // 2 - 50, 40)
            self.score(SCREEN_WIDTH // 2 + 30, SCREEN_HEIGHT // 2 - 50, 40)

    def draw_gameplay(self):
        self.draw_melee().draw()
        self.draw_platforms(self.world.platforms)
        self.draw_idle()
        if not self.world.player.is_dead:
            self.bullet_sprite.draw()
            self.player_sprite.draw()
            if self.world.player.is_hit:
                self.player_sprite_hit().draw()
            self.monster_bullet_sprite.draw()
        for m in self.world.monster:
            self.monster_sprite(m).draw()
            if m.is_hit:
                self.monster_sprite_hit(m).draw()

    def draw_gameplay_update(self):
        self.player_sprite = self.player()

    def sound_fx(self):
        if self.world.player.health <= 30 and not self.world.player.is_dead:
            self.sound.play_low_hp()
        else:
            self.sound.reset_health_play()
        if not self.world.monster:
            self.sound.play_next_floor()
        else:
            self.sound.reset_floor_play()
        if self.world.player.power == 100:
            self.sound.play_pw_full()
        elif self.world.player.shield:
            self.sound.play_pw_proc()
        else:
            self.sound.reset_power_play()

    def sound_on_key_press(self, key, key_modifiers):
        if key == arcade.key.J:
            self.sound.play_melee()
        if key == arcade.key.K:
            self.sound.play_range()

    def on_draw(self):
        self.background()
        self.draw_gameplay()
        self.gui()
        self.game_over()

    def update(self, delta):
        self.draw_gameplay_update()
        if self.enable_sound:
            self.sound_fx()
        self.world.update(delta)

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)
        if self.enable_sound:
            self.sound_on_key_press(key, key_modifiers)

    def on_key_release(self, key, key_modifiers):
        self.world.on_key_release(key, key_modifiers)
예제 #3
0
class AHwindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)

        arcade.set_background_color(arcade.color.BLACK)

        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)

        self.board = ModelSprite('board.png', model=self.world.board)
        self.board.set_position(width // 2, height // 2)

        self.puck = ModelSprite('puck.png', model=self.world.puck)
        self.puck.set_position(width // 2, height // 2)

        self.player1 = ModelSprite('player1.png', model=self.world.player1)
        self.player1.set_position(100, height // 2)

        self.player2 = ModelSprite('player2.png', model=self.world.player2)
        self.player2.set_position(width - 100, height // 2)

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)

    def on_key_release(self, key, key_modifiers):
        self.world.on_key_release(key, key_modifiers)

    def on_draw(self):
        arcade.start_render()
        self.board.draw()
        self.puck.draw()
        self.player1.draw()
        self.player2.draw()

        arcade.render_text(self.world.scoreboard, SCREEN_WIDTH // 2, 83.5 // 2)

        if self.world.end == True:
            if self.world.player1_score > self.world.player2_score:
                arcade.render_text(
                    arcade.create_text("PLAYER 1 WIN!!!!!",
                                       arcade.color.RED,
                                       50,
                                       align="center",
                                       anchor_x="center",
                                       anchor_y="center"), SCREEN_WIDTH // 2,
                    SCREEN_HEIGHT // 2)
            else:
                arcade.render_text(
                    arcade.create_text("PLAYER 2 WIN!!!!!",
                                       arcade.color.BLUE,
                                       50,
                                       align="center",
                                       anchor_x="center",
                                       anchor_y="center"), SCREEN_WIDTH // 2,
                    SCREEN_HEIGHT // 2)

            arcade.render_text(
                arcade.create_text("Press \"Enter\" to restart.",
                                   arcade.color.CAMOUFLAGE_GREEN,
                                   15,
                                   align="center",
                                   anchor_x="center",
                                   anchor_y="center"), SCREEN_WIDTH // 2,
                SCREEN_HEIGHT // 2 - 50)

    def update(self, delta):
        self.world.update(delta)
예제 #4
0
class TaLaLapWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height, "TaLaLap")
        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)
        self.coin_list = self.world.coin_list
        self.plus_dam = arcade.Sprite("images/DoubleDam.png", scale=0.7)
        self.double_dam = arcade.Sprite("images/DoubleDamT.png", scale=0.7)
        self.plus_dam.set_position(SCREEN_WIDTH - 40, SCREEN_HEIGHT - 385)
        self.double_dam.set_position(SCREEN_WIDTH - 100, SCREEN_HEIGHT - 385)

    def update(self, delta):
        self.world.update(delta)
        self.player = ModelSprite(
            "images/stand.png"
            if self.world.player.player_frame == 0 else "images/hit.png",
            scale=0.4,
            model=self.world.player)
        self.monster = ModelSprite(
            "images/monster/" + str(self.world.monster.monster_folder) + "/" +
            self.world.monster.monster_frame,
            scale=0.5,
            model=self.world.monster)

    def display_information(self):
        arcade.draw_text("Coin: " + str(self.world.coin), self.width - 590,
                         self.height - 60, FONT_COLOR, 20)
        arcade.draw_text("HP: " + str(self.world.monster.hp), self.width - 590,
                         self.height - 30, FONT_COLOR, 20)
        arcade.draw_text("Damage: " + str(self.world.player.damage),
                         self.width - 590, self.height - 410, FONT_COLOR, 20)
        arcade.draw_text("Level: " + str(self.world.world_level),
                         self.width - 350, self.height - 20, FONT_COLOR, 20)
        if self.world.item.item_time > 0:
            arcade.draw_text("Item_time: " + str(self.world.item.item_time),
                             self.width - 590, self.height - 90, FONT_COLOR,
                             20)
        if self.world.world_stage == "Fight":
            arcade.draw_text("Time: " + str(self.world.stage_time),
                             self.width - 106, self.height - 20, FONT_COLOR,
                             20)

    def on_draw(self):
        arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2,
                                      SCREEN_WIDTH, SCREEN_HEIGHT,
                                      arcade.load_texture("images/bg2.jpg"))
        self.display_information()
        if self.world.on_fight_stage():
            self.monster.draw()
            self.double_dam.draw()
            self.plus_dam.draw()
        else:
            self.coin_list.coin.draw()
        self.player.draw()

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)

    def on_key_release(self, key, key_modifiers):
        self.world.on_key_release(key, key_modifiers)

    def on_mouse_press(self, x: float, y: float, button: int, modifiers: int):
        self.world.on_mouse_press(x, y, button, modifiers)
예제 #5
0
class MazeWindow(arcade.Window):
    def __init__(self, width, height):
        self.car_list = []
        super().__init__(width, height)
        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)
        self.background = arcade.load_texture("Wallpaper2.jpg")
        self.spot_sprite = Spot(100, 50, angle=0)
        self.spot_sprite.add_texture('car_move.png')
        self.world.add_car(self.spot_sprite)
        park_car_list = ['parking_car1.png', 'parking_car2.png']
        for i in self.world.car_park:
            self.car_list.append(
                ModelSprite(random.choice(park_car_list), model=i))

    def update(self, delta):
        self.world.update(delta)

    def on_draw(self):
        arcade.start_render()
        arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2,
                                      SCREEN_WIDTH, SCREEN_HEIGHT,
                                      self.background)
        self.world.spot.draw()
        if self.world.state != self.world.STATE_FROZEN:
            arcade.draw_text(f"Time: {self.world.start_time:.0f}", 23, 450,
                             arcade.color.RED, 30)

        if self.world.state == self.world.STATE_FROZEN:

            arcade.draw_text(f"CAR PARKING GAME", 210, 440, arcade.color.RED,
                             30)
            arcade.draw_text(f"Press any key to start", 180, 30,
                             arcade.color.BLACK, 15)
        for i in self.car_list:
            i.draw()
        if self.world.state == self.world.STATE_DEAD:
            self.background = arcade.load_texture("Wallpaper2END.jpg")
            if self.world.start_time < 15:
                ModelSprite('star_score3.png', model=self.world.win).draw()
                arcade.draw_text(f"You get 3 star!!!!!", 300, 250,
                                 arcade.color.BLUE, 25)

            elif self.world.start_time < 20:
                ModelSprite('star_score2.png', model=self.world.win).draw()
                arcade.draw_text(f"You get 2 star!!!!!", 300, 250,
                                 arcade.color.BLUE, 25)

            elif self.world.start_time > 20:
                ModelSprite('star_score1.png', model=self.world.win).draw()
                arcade.draw_text(f"You get 1 star!!!!!", 300, 250,
                                 arcade.color.BLUE, 25)

            arcade.draw_text(f"Thank you for playing", 240, 200,
                             arcade.color.BLUE, 30)
            arcade.draw_text("Press any key to restart.", 235, 150,
                             arcade.color.BLACK, 30)
            self.world.die()

    def restart(self):
        self.car_list = []
        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)
        self.background = arcade.load_texture("Wallpaper2.jpg")
        self.spot_sprite = Spot(100, 50, angle=0)
        self.spot_sprite.add_texture('car_move.png')
        self.world.add_car(self.spot_sprite)
        park_car_list = ['parking_car1.png', 'parking_car2.png']
        for i in self.world.car_park:
            self.car_list.append(
                ModelSprite(random.choice(park_car_list), model=i))

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)
        if self.world.state == World.STATE_RESTART:
            self.restart()

        if not self.world.is_dead():
            self.world.start()

    def on_key_release(self, key, key_modifiers):
        self.world.on_key_release(key, key_modifiers)
예제 #6
0
class SpaceGameWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)

        arcade.set_background_color(arcade.color.BLACK)

        self.world = World(width, height)
        self.player_sprite = ModelSprite('images/jar1.png',
                                         model=self.world.player)
        self.background = arcade.load_texture("images/background.jpg")
        self.bullet_sprites = []

        self.current_state = GAME_MENU

    def on_draw(self):
        arcade.start_render()
        arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2,
                                      self.background.width,
                                      self.background.height, self.background,
                                      0)

        if self.world.current_state == GAME_MENU:
            self.draw_menu()
        elif self.world.current_state == GAME_RUNNING:
            self.draw_game()
        elif self.world.current_state == GAME_PAUSE:
            self.draw_pause()
        else:
            self.draw_game_over()
            self.setup()

    def setup(self):
        # del self.bullet_sprites[:]
        self.bullet_sprites.clear()

    def draw_game(self):
        self.update()
        # self.player_sprite.draw()
        self.draw_player()
        for sprite in self.bullet_sprites:
            sprite.draw()
        arcade.draw_text(
            "time: " + "%.2f" % (GAME_TIME - self.world.current_time),
            self.width - 155, self.height - 30, arcade.color.WHITE, 20)
        arcade.draw_text("Jar: " + str(self.world.jar), self.width - 155,
                         self.height - 60, arcade.color.WHITE, 20)

    def draw_player(self):
        jar = self.world.score % 4
        self.player_sprite = ModelSprite('images/jar' +
                                         str(self.world.score % 4) + '.png',
                                         model=self.world.player)
        self.player_sprite.draw()

    def draw_game_over(self):
        output = "Game Over"
        arcade.draw_text(output, 175, 400, arcade.color.WHITE, 36)

        output = "Space to restart"
        arcade.draw_text(output, 175, 300, arcade.color.WHITE, 24)

        output = "Jar: " + str(self.world.jar)
        arcade.draw_text(output, 175, 200, arcade.color.WHITE, 24)

    def draw_pause(self):
        output = "Pause"
        arcade.draw_text(output, 150, 400, arcade.color.WHITE, 36)

    def draw_menu(self):
        output = "water jar game"
        arcade.draw_text(output, 125, 400, arcade.color.WHITE, 36)

    def animate(self, delta):
        self.world.animate(delta)

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)

    def on_key_release(self, key, key_modifiers):
        self.world.on_key_release(key, key_modifiers)

    def update(self):
        for bullet in self.world.bullets.bulletsList:
            if bullet.isToxic == False:
                self.bullet_sprites.append(
                    ModelSprite('images/bullet.png', model=bullet))
            elif bullet.isToxic == True:
                self.bullet_sprites.append(
                    ModelSprite('images/bullet_toxic.png', model=bullet))
예제 #7
0
class FieldWindow(arcade.Window):
    GAME_MODE = 0
    H2P = 1

    def __init__(self, width, height):
        super().__init__(width, height, "・2 DotThrough")

        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)

        self.color_status_text = arcade.color.RED_ORANGE

        self.color_map_in_stage = arcade.color.ORANGE_RED
        self.color_map_not_in_stage = arcade.color.LIGHT_GRAY

        self.star_sprite = self.world.star_list

        self.exit_gate_sprite = ModelSprite('images/Exit_gate.png',
                                            model=self.world.exit_gate,
                                            scale=1)
        self.start_button = arcade.Sprite('images/Start.png',
                                          scale=0.35,
                                          center_x=SCREEN_WIDTH // 2,
                                          center_y=SCREEN_HEIGHT // 4)

    def on_key_press(self, key, key_modifiers):
        if key == arcade.key.ENTER and self.GAME_MODE == 1:
            self.H2P += 1
        if self.GAME_MODE == 2:
            self.world.on_key_press(key, key_modifiers)

    def on_key_release(self, key, key_modifiers):
        if self.GAME_MODE == 2:
            self.world.on_key_release(key, key_modifiers)

    def on_mouse_press(self, x: float, y: float, button, key_modifiers):
        if self.GAME_MODE == 0:
            if button == arcade.MOUSE_BUTTON_LEFT:
                if self.start_button.center_y - 25 <= y <= self.start_button.center_y + 25\
                    and self.start_button.center_x - 85 <= x <= self.start_button.center_x + 85:

                    self.GAME_MODE = 1

    def update(self, delta):
        self.world.update(delta)

        self.character_sprite = ModelSprite(
            'images/character.png' if self.world.character.animation == 1 else
            'images/character2.png' if self.world.character.animation == 2 else
            'images/character3.png' if self.world.character.animation == 3 else
            'images/character4.png',
            model=self.world.character)

        self.object_cant_touch_stage_sprite = self.world.object_list

    def on_draw(self):
        arcade.start_render()

        if self.GAME_MODE == 0:
            arcade.draw_texture_rectangle(
                SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH,
                SCREEN_HEIGHT, arcade.load_texture("images/Interface.png"))

            self.start_button.draw()

        elif self.GAME_MODE == 1:
            if self.H2P == 1:
                arcade.draw_texture_rectangle(
                    SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH,
                    SCREEN_HEIGHT, arcade.load_texture("images/ControlG.png"))
            elif self.H2P == 2:
                arcade.draw_texture_rectangle(
                    SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH,
                    SCREEN_HEIGHT, arcade.load_texture("images/H2P1.png"))
            elif self.H2P == 3:
                arcade.draw_texture_rectangle(
                    SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH,
                    SCREEN_HEIGHT, arcade.load_texture("images/H2P2.png"))
            elif self.H2P == 4:
                arcade.draw_texture_rectangle(
                    SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH,
                    SCREEN_HEIGHT, arcade.load_texture("images/H2P3.png"))
            elif self.H2P == 5:
                self.H2P = 1
                self.GAME_MODE = 2

        elif self.GAME_MODE == 2:
            arcade.set_background_color(arcade.color.BLACK_OLIVE)
            self.character_sprite.draw()
            self.object_cant_touch_stage_sprite.draw()
            self.star_sprite.draw()
            self.exit_gate_sprite.draw()

            #define the stage location in map
            arcade.draw_rectangle_filled(
                30, SCREEN_HEIGHT - 30, 15, 15,
                self.color_map_in_stage if self.world.stage_objects.stage_count
                == 1 else self.color_map_not_in_stage)

            arcade.draw_rectangle_filled(
                50, SCREEN_HEIGHT - 30, 15, 15,
                self.color_map_in_stage if self.world.stage_objects.stage_count
                == 2 else self.color_map_not_in_stage)

            arcade.draw_rectangle_filled(
                70, SCREEN_HEIGHT - 30, 15, 15,
                self.color_map_in_stage if self.world.stage_objects.stage_count
                == 3 else self.color_map_not_in_stage)

            arcade.draw_rectangle_filled(
                30, SCREEN_HEIGHT - 50, 15, 15,
                self.color_map_in_stage if self.world.stage_objects.stage_count
                == 8 else self.color_map_not_in_stage)

            arcade.draw_rectangle_filled(
                50, SCREEN_HEIGHT - 50, 15, 15,
                self.color_map_in_stage if self.world.stage_objects.stage_count
                == 9 else self.color_map_not_in_stage)

            arcade.draw_rectangle_filled(
                70, SCREEN_HEIGHT - 50, 15, 15,
                self.color_map_in_stage if self.world.stage_objects.stage_count
                == 4 else self.color_map_not_in_stage)

            arcade.draw_rectangle_filled(
                30, SCREEN_HEIGHT - 70, 15, 15,
                self.color_map_in_stage if self.world.stage_objects.stage_count
                == 7 else self.color_map_not_in_stage)

            arcade.draw_rectangle_filled(
                50, SCREEN_HEIGHT - 70, 15, 15,
                self.color_map_in_stage if self.world.stage_objects.stage_count
                == 6 else self.color_map_not_in_stage)

            arcade.draw_rectangle_filled(
                70, SCREEN_HEIGHT - 70, 15, 15,
                self.color_map_in_stage if self.world.stage_objects.stage_count
                == 5 else self.color_map_not_in_stage)

            arcade.draw_text(self.world.stage_objects.stage_name,
                             15,
                             SCREEN_HEIGHT - 105,
                             self.color_map_in_stage,
                             15,
                             bold=True)

            #star collects
            if self.world.stage_objects.stage_count != 0:
                arcade.draw_rectangle_filled(SCREEN_WIDTH-90,
                                            SCREEN_HEIGHT-30,
                                            20,
                                            20,
                                            arcade.color.GOLDEN_POPPY
                                            if len(self.world.star_list) <= 2 \
                                               and self.world.character.keep_star == True
                                            else arcade.color.EERIE_BLACK,
                                            tilt_angle = 45)

                arcade.draw_rectangle_filled(SCREEN_WIDTH - 60,
                                            SCREEN_HEIGHT - 30,
                                            20,
                                            20,
                                            arcade.color.YELLOW_ORANGE
                                            if len(self.world.star_list) <= 1 \
                                               and self.world.character.keep_star == True
                                            else arcade.color.EERIE_BLACK,
                                            tilt_angle=45)

                arcade.draw_rectangle_filled(SCREEN_WIDTH - 30,
                                            SCREEN_HEIGHT - 30,
                                            20,
                                            20,
                                            arcade.color.ORANGE
                                            if len(self.world.star_list) == 0 \
                                               and self.world.character.keep_star == True
                                            else arcade.color.EERIE_BLACK,
                                            tilt_angle=45)

            if self.world.character.hit == True:
                self.color_status_text = arcade.color.RED_ORANGE
            elif self.world.character.exit_hit == True:
                if self.world.stage_objects.stage_count < self.world.stage_objects.MAX_STAGE:
                    self.color_status_text = arcade.color.GREEN
                else:
                    self.color_status_text = arcade.color.ORANGE_PEEL

            arcade.draw_text(self.world.stage_objects.status,
                             SCREEN_WIDTH // 3.25,
                             SCREEN_HEIGHT // 1.25,
                             self.color_status_text,
                             font_size=50,
                             bold=True)

            arcade.draw_text(self.world.stage_objects.desc_status,
                             SCREEN_WIDTH // 2.8,
                             SCREEN_HEIGHT // 1.35,
                             self.color_status_text,
                             font_size=15,
                             bold=True)

            arcade.draw_text(self.world.stage_objects.tutorial_text,
                             SCREEN_WIDTH // 2,
                             SCREEN_HEIGHT // 2.15,
                             arcade.color.ORANGE_RED,
                             font_size=30,
                             bold=True)
예제 #8
0
class GunnerWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)

        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT, BLOCK_SIZE)

        self.world.player.turn = 0
        self.player_right_sprite = ModelSprite('images/Gunner_right.png',
                                               model=self.world.player)
        self.player_left_sprite = ModelSprite('images/Gunner_left.png',
                                              model=self.world.player)
        self.bullet_sprite = BulletSprite()
        self.slime_sprite = SlimeSprite()
        self.kingslime_sprite = KingslimeSprite()
        self.checkpoint_sprite = CheckpointSprite()

        ##        if self.world.currentmap == 0:
        ##            self.background = arcade.Sprite("images/background1.jpg")
        ##        if self.world.currentmap == 1:
        ##            self.background = arcade.Sprite("images/background2.png")
        ##        if self.world.currentmap == 2:
        ##            self.background = arcade.Sprite("images/background3.jpg")
        ##        if self.world.currentmap == 3:
        ##            self.background = arcade.Sprite("images/background4.png")
        ##
        self.stage_drawer = StageDrawer(self.world.stage)

    def update(self, delta):
        self.world.update(delta)

    def on_draw(self):
        arcade.start_render()
        self.background = arcade.Sprite("images/forest.png")
        ##        self.background = arcade.Sprite(BG[self.world.currentmap])
        self.background.set_position(400, 300)
        self.background.draw()
        if self.world.player.turn == 0:
            self.player_right_sprite.draw()
        if self.world.player.turn == 1:
            self.player_left_sprite.draw()

        self.slime_sprite.draw(self.world.slime)
        self.kingslime_sprite.draw(self.world.kingslime)
        self.bullet_sprite.draw(self.world.bullet)
        self.checkpoint_sprite.draw(self.world.checkpoint)

        self.stage_drawer.draw()

        if self.world.time == 1:
            if self.world.player.life > 0:
                arcade.draw_text(f"PRESS 'R' TO RESPAWN", 50, 300,
                                 arcade.color.WHITE, 60)
            if self.world.player.life == 0:
                arcade.draw_text(f"PRESS 'R' TO RESTART", 50, 300,
                                 arcade.color.WHITE, 60)

        arcade.draw_text(f"LIFE: {self.world.player.life}", 25, 550,
                         arcade.color.RED, 30)
        arcade.draw_text(f"SCORE: {self.world.player.kill}", 600, 550,
                         arcade.color.WHITE, 30)

        if self.world.time == 2:
            arcade.draw_text("YOU WON!", 75, 300, arcade.color.GOLD, 120)

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)

    def on_key_release(self, key, key_modifiers):
        self.world.on_key_release(key, key_modifiers)
예제 #9
0
파일: dragon.py 프로젝트: noltontarn/dragon
class DragonGameWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)
        self.high_score = 0
        self.bgm_sound = arcade.sound.load_sound("sounds/sound2.mp3")
        arcade.sound.play_sound(self.bgm_sound)
        self.setup(width, height)

    def setup(self, width, height):
        arcade.set_background_color(arcade.color.BLACK)
        self.world = World(width, height)
        self.background_texture = arcade.load_texture('images/background.png')
        self.dragon_sprite = ModelSprite('images/dragon.png',
                                         model=self.world.dragon)
        self.man_texture = arcade.load_texture('images/man.png')
        self.steak_texture = arcade.load_texture('images/steak.png')
        self.fire_texture = arcade.load_texture('images/fire.png')

    def draw_men(self, men):
        for m in men:
            if m.state == m.STATE_ALIVE:
                arcade.draw_texture_rectangle(m.x, m.y, m.width, m.height,
                                              self.man_texture)
            if m.state == m.STATE_STEAK:
                arcade.draw_texture_rectangle(m.x, m.y, m.width, m.height,
                                              self.steak_texture)

    def draw_fire(self, fire):
        for f in fire:
            if not f.is_hit:
                arcade.draw_texture_rectangle(f.x, f.y, f.width, f.height,
                                              self.fire_texture)

    def on_draw(self):
        arcade.start_render()
        arcade.draw_texture_rectangle(640, 360, 1280, 720,
                                      self.background_texture)
        self.draw_men(self.world.men)
        self.draw_fire(self.world.fire)
        self.dragon_sprite.draw()
        minutes = int(self.world.total_time) // 60
        seconds = int(self.world.total_time) % 60

        output = "Time: {:02d}:{:02d}".format(minutes, seconds)
        arcade.draw_text(output, 0, 690, arcade.color.WHITE, 20)

        arcade.draw_text(str("HUNGER: "), self.width - 550, self.height - 30,
                         arcade.color.WHITE, 20)
        arcade.draw_text(str(self.world.hunger), self.width - 430,
                         self.height - 30, arcade.color.WHITE, 20)
        arcade.draw_text(str("/100"), self.width - 380, self.height - 30,
                         arcade.color.WHITE, 20)

        arcade.draw_text(str("SCORE: "), self.width - 300, self.height - 30,
                         arcade.color.WHITE, 20)
        arcade.draw_text(str(self.world.score), self.width - 200,
                         self.height - 30, arcade.color.WHITE, 20)

        if self.world.current_state == GAME_OVER:
            arcade.draw_text("Game Over", 440, 360, arcade.color.WHITE, 70)
            arcade.draw_text("Click to restart.", 445, 250, arcade.color.WHITE,
                             50)
            if self.world.score > self.high_score:
                self.high_score = self.world.score
            arcade.draw_text("High Score:", 400, 150, arcade.color.WHITE, 50)
            arcade.draw_text(str(self.high_score), 750, 150,
                             arcade.color.WHITE, 50)

    def animate(self, delta_time):
        if self.world.current_state == GAME_RUNNING:
            self.world.animate(delta_time)

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)

    def on_key_release(self, key, key_modifiers):
        self.world.on_key_release(key, key_modifiers)

    def on_mouse_press(self, x, y, button, modifiers):
        if self.world.current_state == GAME_OVER:
            self.setup(1280, 720)
예제 #10
0
class GameWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)
        self.bgm_sound = arcade.sound.load_sound("sounds/bgm.mp3")
        arcade.sound.play_sound(self.bgm_sound)
        self.setup(width, height)

    def setup(self, width, height):
        arcade.set_background_color(arcade.color.GREEN)
        self.world = World(width, height)

        self.me_sprite = ModelSprite('images/Me.png', model=self.world.me)
        self.her_sprite = ModelSprite('images/Her.png', model=self.world.her)
        self.vega_sprite = ModelSprite('images/Orange.png',
                                       model=self.world.vega)
        self.vegb_sprite = ModelSprite('images/Banana.png',
                                       model=self.world.vegb)
        self.vegc_sprite = ModelSprite('images/Grape.png',
                                       model=self.world.vegc)
        self.vegd_sprite = ModelSprite('images/Watermelon.png',
                                       model=self.world.vegd)
        self.vege_sprite = ModelSprite('images/Strawberry.png',
                                       model=self.world.vege)
        self.shovel_sprite = ModelSprite('images/Shovel.png',
                                         model=self.world.shovel)
        self.trash_sprite = ModelSprite('images/Trash.png',
                                        model=self.world.trash)
        self.wateringcan_sprite = ModelSprite('images/WateringCan.png',
                                              model=self.world.wateringcan)
        self.shop_sprite = ModelSprite('images/Shop.png',
                                       model=self.world.shop)

        self.plant1_texture = arcade.load_texture('images/Plant1.png')
        self.plant2_texture = arcade.load_texture('images/Plant2.png')
        self.grass_texture = arcade.load_texture('images/Grass.png')
        self.vega_texture = arcade.load_texture('images/Orange.png')
        self.vegb_texture = arcade.load_texture('images/Banana.png')
        self.vegc_texture = arcade.load_texture('images/Grape.png')
        self.vegd_texture = arcade.load_texture('images/Watermelon.png')
        self.vege_texture = arcade.load_texture('images/Strawberry.png')
        self.soil_texture = arcade.load_texture('images/Soil.png')
        self.shovel_texture = arcade.load_texture('images/Shovel.png')
        self.wateringcan_texture = arcade.load_texture(
            'images/WateringCan.png')
        self.deadplant_texture = arcade.load_texture('images/DeadPlant.png')
        self.ground_texture = arcade.load_texture('images/Ground.png')
        self.ground2_texture = arcade.load_texture('images/Ground2.png')
        self.ground3_texture = arcade.load_texture('images/Ground3.png')

    def draw_me_state(self):
        if self.world.me.STATE == 'a':
            arcade.draw_texture_rectangle(self.world.me.x,
                                          self.world.me.y + 20, 10, 10,
                                          self.vega_texture)
            arcade.draw_texture_rectangle(380, 50, 75, 75, self.vega_texture)
        if self.world.me.STATE == 'a2':
            arcade.draw_texture_rectangle(self.world.me.x,
                                          self.world.me.y + 20, 30, 30,
                                          self.vega_texture)
            arcade.draw_texture_rectangle(380, 50, 75, 75, self.vega_texture)
        if self.world.me.STATE == 'b':
            arcade.draw_texture_rectangle(self.world.me.x,
                                          self.world.me.y + 20, 10, 10,
                                          self.vegb_texture)
            arcade.draw_texture_rectangle(380, 50, 75, 75, self.vegb_texture)
        if self.world.me.STATE == 'b2':
            arcade.draw_texture_rectangle(self.world.me.x,
                                          self.world.me.y + 20, 30, 30,
                                          self.vegb_texture)
            arcade.draw_texture_rectangle(380, 50, 75, 75, self.vegb_texture)
        if self.world.me.STATE == 'c':
            arcade.draw_texture_rectangle(self.world.me.x,
                                          self.world.me.y + 20, 10, 10,
                                          self.vegc_texture)
            arcade.draw_texture_rectangle(380, 50, 75, 75, self.vegc_texture)
        if self.world.me.STATE == 'c2':
            arcade.draw_texture_rectangle(self.world.me.x,
                                          self.world.me.y + 20, 30, 30,
                                          self.vegc_texture)
            arcade.draw_texture_rectangle(380, 50, 75, 75, self.vegc_texture)
        if self.world.me.STATE == 'd':
            arcade.draw_texture_rectangle(self.world.me.x,
                                          self.world.me.y + 20, 10, 10,
                                          self.vegd_texture)
            arcade.draw_texture_rectangle(380, 50, 75, 75, self.vegd_texture)
        if self.world.me.STATE == 'd2':
            arcade.draw_texture_rectangle(self.world.me.x,
                                          self.world.me.y + 20, 30, 30,
                                          self.vegd_texture)
            arcade.draw_texture_rectangle(380, 50, 75, 75, self.vegd_texture)
        if self.world.me.STATE == 'e':
            arcade.draw_texture_rectangle(self.world.me.x,
                                          self.world.me.y + 20, 10, 10,
                                          self.vege_texture)
            arcade.draw_texture_rectangle(380, 50, 75, 75, self.vege_texture)
        if self.world.me.STATE == 'e2':
            arcade.draw_texture_rectangle(self.world.me.x,
                                          self.world.me.y + 20, 30, 30,
                                          self.vege_texture)
            arcade.draw_texture_rectangle(380, 50, 75, 75, self.vege_texture)
        if self.world.me.STATE == 's':
            arcade.draw_texture_rectangle(self.world.me.x,
                                          self.world.me.y + 20, 20, 20,
                                          self.shovel_texture)
            arcade.draw_texture_rectangle(380, 50, 75, 75, self.shovel_texture)
        if self.world.me.STATE == 'w':
            arcade.draw_texture_rectangle(self.world.me.x,
                                          self.world.me.y + 20, 20, 20,
                                          self.wateringcan_texture)
            arcade.draw_texture_rectangle(380, 50, 75, 75,
                                          self.wateringcan_texture)

    def draw_soils_state(self):
        for s in self.world.soils:
            arcade.draw_texture_rectangle(s.x, s.y, 50, 50, self.soil_texture)
            if s.plant_dead == True:
                s.watered = False
                arcade.draw_texture_rectangle(s.x, s.y, 15, 15,
                                              self.deadplant_texture)

            elif s.STATE == 'a':
                arcade.draw_texture_rectangle(s.x, s.y, 15, 15,
                                              self.plant1_texture)
            elif s.STATE == 'a2':
                arcade.draw_texture_rectangle(s.x, s.y, 20, 20,
                                              self.plant2_texture)
            elif s.STATE == 'a3':
                arcade.draw_texture_rectangle(s.x, s.y, 30, 30,
                                              self.vega_texture)

            elif s.STATE == 'b':
                arcade.draw_texture_rectangle(s.x, s.y, 15, 15,
                                              self.plant1_texture)
            elif s.STATE == 'b2':
                arcade.draw_texture_rectangle(s.x, s.y, 20, 20,
                                              self.plant2_texture)
            elif s.STATE == 'b3':
                arcade.draw_texture_rectangle(s.x, s.y, 30, 30,
                                              self.vegb_texture)

            elif s.STATE == 'c':
                arcade.draw_texture_rectangle(s.x, s.y, 15, 15,
                                              self.plant1_texture)
            elif s.STATE == 'c2':
                arcade.draw_texture_rectangle(s.x, s.y, 20, 20,
                                              self.plant2_texture)
            elif s.STATE == 'c3':
                arcade.draw_texture_rectangle(s.x, s.y, 30, 30,
                                              self.vegc_texture)

            elif s.STATE == 'd':
                arcade.draw_texture_rectangle(s.x, s.y, 15, 15,
                                              self.plant1_texture)
            elif s.STATE == 'd2':
                arcade.draw_texture_rectangle(s.x, s.y, 20, 20,
                                              self.plant2_texture)
            elif s.STATE == 'd3':
                arcade.draw_texture_rectangle(s.x, s.y, 30, 30,
                                              self.vegd_texture)

            elif s.STATE == 'e':
                arcade.draw_texture_rectangle(s.x, s.y, 15, 15,
                                              self.plant1_texture)
            elif s.STATE == 'e2':
                arcade.draw_texture_rectangle(s.x, s.y, 20, 20,
                                              self.plant2_texture)
            elif s.STATE == 'e3':
                arcade.draw_texture_rectangle(s.x, s.y, 30, 30,
                                              self.vege_texture)

            timer = s.timer
            if s.timer_on == True:
                seconds2 = int(timer) % 60
                output2 = "{:02d}".format(seconds2)
                arcade.draw_text(output2, s.x - 5, s.y + 25,
                                 arcade.color.WHITE, 10)

            timer2 = s.timer2
            if s.timer2_on == True:
                seconds3 = int(timer2) % 60
                output3 = "{:02d}".format(seconds3)
                arcade.draw_text(output3, s.x - 5, s.y + 25,
                                 arcade.color.WHITE, 10)

    def on_draw(self):
        arcade.start_render()
        arcade.draw_texture_rectangle(425, 325, 850, 650, self.grass_texture)
        arcade.draw_texture_rectangle(275, 575, 550, 50, self.ground3_texture)
        arcade.draw_texture_rectangle(25, 325, 50, 450, self.ground2_texture)
        arcade.draw_texture_rectangle(445, 50, 900, 100, self.ground_texture)
        arcade.draw_texture_rectangle(700, 575, 300, 50, self.ground_texture)
        self.draw_soils_state()
        self.shovel_sprite.draw()
        self.wateringcan_sprite.draw()
        self.trash_sprite.draw()
        self.vega_sprite.draw()
        self.vegb_sprite.draw()
        self.vegc_sprite.draw()
        self.vegd_sprite.draw()
        self.vege_sprite.draw()
        self.shop_sprite.draw()
        self.her_sprite.draw()
        self.me_sprite.draw()
        self.draw_me_state()
        minutes = int(self.world.total_time) // 60
        seconds = int(self.world.total_time) % 60
        money = int(self.world.me.MONEY)
        strawberry = int(self.world.me.STRAWBERRY_GIVEN)

        output = "Time: {:02d}:{:02d}".format(minutes, seconds)
        moneyShow = "Money: {:02d}".format(money)
        output2 = "Current Equipment :"
        strawberryshow = "Strawberries Given: {:d}/3".format(strawberry)
        arcade.draw_text("Cost: 50", 100, 585, arcade.color.WHITE, 10)
        arcade.draw_text("Cost: 100", 200, 585, arcade.color.WHITE, 10)
        arcade.draw_text("Cost: 200", 300, 585, arcade.color.WHITE, 10)
        arcade.draw_text("Cost: 300", 400, 585, arcade.color.WHITE, 10)
        arcade.draw_text("Cost: 500", 500, 585, arcade.color.WHITE, 10)
        arcade.draw_text("Sell: 75", 100, 555, arcade.color.WHITE, 10)
        arcade.draw_text("Sell: 150", 200, 555, arcade.color.WHITE, 10)
        arcade.draw_text("Sell: 275", 300, 555, arcade.color.WHITE, 10)
        arcade.draw_text("Sell: 400", 400, 555, arcade.color.WHITE, 10)
        arcade.draw_text("Sell: 625", 500, 555, arcade.color.WHITE, 10)

        arcade.draw_text(output, 560, 565, arcade.color.WHITE, 20)
        arcade.draw_text(moneyShow, 700, 565, arcade.color.WHITE, 20)
        arcade.draw_text(output2, 75, 40, arcade.color.WHITE, 20)
        arcade.draw_text(strawberryshow, 525, 40, arcade.color.WHITE, 20)

        if self.world.END_STATE == 1:
            arcade.draw_text("Game Over", 250, 450, arcade.color.WHITE, 30)
            arcade.draw_text("Press Space Bar to Restart", 250, 250,
                             arcade.color.WHITE, 30)
            Eminutes = int(self.world.end_time) // 60
            Eseconds = int(self.world.end_time) % 60
            endtime = "Time Spent: {:02d}:{:02d}".format(Eminutes, Eseconds)
            arcade.draw_text(endtime, 250, 350, arcade.color.WHITE, 30)

    def animate(self, delta):
        if self.world.END_STATE == 0:
            self.world.animate(delta)

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)

    def on_key_release(self, key, key_modifiers):
        self.world.on_key_release(key, key_modifiers)
        if self.world.END_STATE == 1 and key == arcade.key.SPACE:
            self.setup(850, 600)
예제 #11
0
class MyGame(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)
 
        self.current_route = routes['menu']
        self.selecting_choice = 0
        self.car_choice = 1
        self.background = arcade.load_texture("images/Background.png")
        self.cartexture = Car[self.car_choice]
        self.menu_setup()
        self.car_setup()
        self.game_setup(width,height)

    def menu_setup(self):
        self.choice_list = arcade.SpriteList()

        self.start = MenuChoiceSprite()
        self.start.textures.append(arcade.load_texture("images/start.png"))
        self.start.textures.append(arcade.load_texture("images/start1.png"))
        self.start.set_texture(0)
        self.start.texture_change_frames = 10

        self.car = MenuChoiceSprite()
        self.car.textures.append(arcade.load_texture("images/car.png"))
        self.car.textures.append(arcade.load_texture("images/car1.png"))
        self.car.set_texture(1)
        self.car.texture_change_frames = 10

        self.exit = MenuChoiceSprite()
        self.exit.textures.append(arcade.load_texture("images/exit.png"))
        self.exit.textures.append(arcade.load_texture("images/exit1.png"))
        self.exit.set_texture(1)
        self.exit.texture_change_frames = 10

        self.start.center_x,self.start.center_y = self.width//2,self.height//2 +50
        self.car.center_x,self.car.center_y = self.width//2,self.height//2 -20
        self.exit.center_x,self.exit.center_y = self.width//2,self.height//2 -90
        
        self.start.select()
        self.choice_list.append(self.start)
        self.choice_list.append(self.car)
        self.choice_list.append(self.exit)

    def car_setup(self):
        self.car_choice_list = arcade.SpriteList()
        self.car_show = arcade.Sprite(Car[self.car_choice])
        self.car_show.set_position(self.width//2,self.height//2 +50)

    def game_setup(self, width, height):
        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)
        self.background_sprite = ModelSprite("images/Background.png",
                                      model=self.world.background)
        self.background_sprite2 = ModelSprite("images/Background.png",
                                      model=self.world.background2)                              
        self.car_sprite = ModelSprite(self.cartexture,
                                      model=self.world.car)
        self.enemylist = []                              
        self.fpscounter = Fpscounter()
        self.set_update_rate(1/70)
    
    def car_sprite_selected(self):
        self.car_sprite = ModelSprite(self.cartexture,
                                      model=self.world.car)

    def draw_menu(self):
        self.choice_list.draw()

    def draw_car_menu(self):
        self.car_show.draw()                                  
        
    def update(self, delta):
        if self.current_route == routes['menu']:
            for choice in self.choice_list:
                if choice.is_select == True:
                    choice.update()
                    choice.update_animation()
                   
        elif self.current_route == routes['car']:
            self.draw_car_menu()

        elif self.current_route == routes['exit']:
            sys.exit()    

        elif self.current_route == routes['game']:
            self.creteenemy()
            self.update_enemylist()
            self.world.update(delta)
        
    def on_draw(self):
        arcade.start_render()
        arcade.draw_texture_rectangle(self.width//2 , self.height//2 ,self.width, self.height,self.background)

        if self.current_route == routes['menu']:
            self.draw_menu()  

        elif self.current_route == routes['car']:
            self.car_setup()
            self.draw_car_menu()    
       
        elif self.current_route == routes['game']:
            self.car_sprite_selected()
            self.background_sprite.draw()
            self.background_sprite2.draw()
            self.car_sprite.draw()
            self.fpscounter.tick()
            self.check_state()

            fps = f"fps{self.fpscounter.fps():.2f}"
            score = f"Score {self.world.score}"
            arcade.draw_text(score,670,770,arcade.color.DARK_CANDY_APPLE_RED,24)
            arcade.draw_text(fps,750,560,arcade.color.BLACK)
            for enemy in self.enemylist:
                enemy.draw()
            
    def update_selected_choice(self):
        for choice in self.choice_list:
            choice.unselect()
            choice.set_texture(1)
        self.choice_list[self.selecting_choice].select()    

    def on_key_press(self, key, key_modifiers):
        if self.current_route == routes['menu']:
            if key == arcade.key.DOWN:
                if self.selecting_choice < 2:
                    self.selecting_choice += 1
                else:
                    self.selecting_choice = 0
                self.update_selected_choice()
                press_sound = arcade.load_sound("soundtrack/pressmusic.wav")
                arcade.play_sound(press_sound)
                
            elif key == arcade.key.UP:
                if self.selecting_choice > 0 :  
                    self.selecting_choice -= 1
                else:
                    self.selecting_choice = 2
                self.update_selected_choice()
                press_sound = arcade.load_sound("soundtrack/pressmusic.wav")
                arcade.play_sound(press_sound)        
            elif key == arcade.key.ENTER:
                self.current_route = routes[choices[self.selecting_choice]]

        elif self.current_route == routes['car']:
            if key == arcade.key.RIGHT:
                if self.car_choice < 6:
                    self.car_choice += 1
                else:
                    self.car_choice = 0    
            
            elif key == arcade.key.LEFT:
                if self.car_choice > 0:
                    self.car_choice -= 1
                else:
                    self.car_choice = 4
            elif key == arcade.key.ENTER:
                self.cartexture = Car[self.car_choice]
                self.current_route = routes['menu']
                
        elif self.current_route == routes['game']:
            self.world.on_key_press(key, key_modifiers)
            if not self.world.is_dead():
                self.world.start()       
            elif key == arcade.key.R and self.world.state == World.STATE_DEAD:
                self.game_setup(SCREEN_WIDTH,SCREEN_HEIGHT)

            elif key == arcade.key.M and self.world.state == World.STATE_DEAD:
                self.current_route = routes['menu']
                self.draw_menu()
                self.game_setup(SCREEN_WIDTH,SCREEN_HEIGHT)

    def on_key_release(self, key, key_modifiers):
        if self.current_route == routes['game']:
            self.world.on_key_release(key, key_modifiers)

    def creteenemy(self):
        for enemy in self.world.enemylist:
            if enemy in (enemy_sprite.model for enemy_sprite in self.enemylist):
                pass
            else:
                self.enemylist.append(ModelSprite(self.randomsprite(), 
                model=enemy))
   
    def randomsprite(self):
        enemyspritelist = ['images/EnemyCar2.png','images/Enemycarwhite.png','images/redcar.png','images/pinkcar.png']
        randomnum = randint(0,3)
        return enemyspritelist[randomnum]

    def update_enemylist(self):
        for enemy_sprite in [_ for _ in self.enemylist]:
            if enemy_sprite.model not in self.world.enemylist:
                self.enemylist.remove(enemy_sprite)

    def draw_game_over(self):
        output = f"Score {self.world.score}"
        arcade.draw_text(output, 285, 500, arcade.color.BALL_BLUE, 54)
        
        output = "Game Over"
        arcade.draw_text(output, 225, 400, arcade.color.BALL_BLUE, 54)

        output = "Press R to restart"
        arcade.draw_text(output, 280, 300, arcade.color.BALL_BLUE, 24)

        output = "Press M to mainmenu"
        arcade.draw_text(output,250,230,arcade.color.BALL_BLUE, 24)

    def check_state(self):
        if self.world.state == World.STATE_DEAD:
            self.draw_game_over()        
예제 #12
0
class SurviveWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)

        self.world = World(width, height)
        arcade.set_background_color(arcade.color.DARK_SLATE_GRAY)
        self.timer_text = None
        self.background = arcade.load_texture("images/background.png")
        self.intro = arcade.load_texture("images/intro.png")
        self.score_text = None
        self.energy_text = None

        self.wall_1 = ModelSprite("images/wall_01.png",
                                  model=self.world.wall_1)
        self.wall_2 = ModelSprite("images/wall_02.png",
                                  model=self.world.wall_2)
        self.wall_3 = ModelSprite("images/wall_03.png",
                                  model=self.world.wall_3)
        self.wall_4 = ModelSprite("images/wall_04.png",
                                  model=self.world.wall_4)
        self.wall_5 = ModelSprite("images/wall_05.png",
                                  model=self.world.wall_5)
        self.wall_6 = ModelSprite("images/wall_06.png",
                                  model=self.world.wall_6)
        self.wall_7 = ModelSprite("images/wall_09.png",
                                  model=self.world.wall_7)
        self.wall_8 = ModelSprite("images/wall_10.png",
                                  model=self.world.wall_8)
        self.wall_9 = ModelSprite("images/wall_09.png",
                                  model=self.world.wall_9)
        self.wall_10 = ModelSprite("images/wall_10.png",
                                   model=self.world.wall_10)

    def on_key_press(self, key, modifiers):
        self.world.on_key_press(key, modifiers)
        if key == arcade.key.ENTER:
            if not self.world.start_game:
                self.world.start_game = True

    def on_key_release(self, key, modifiers):
        self.world.on_key_release(key, modifiers)

    def on_draw(self):
        arcade.start_render()

        arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2,
                                      SCREEN_WIDTH, SCREEN_HEIGHT,
                                      self.background)
        self.wall_1.draw()
        self.wall_7.draw()
        self.wall_2.draw()
        self.wall_9.draw()
        self.wall_3.draw()
        self.wall_4.draw()
        self.wall_5.draw()
        self.wall_6.draw()
        self.wall_8.draw()
        self.wall_10.draw()

        self.world.ghost_list.draw()
        self.world.player_list.draw()
        self.world.item_list.draw()
        self.world.food_list.draw()
        self.world.bullet_list.draw()

        #######################################################
        output = f"Score: {self.world.score}"
        if not self.score_text or output != self.score_text.text:
            self.score_text = arcade.create_text(output, arcade.color.WHITE,
                                                 14)
        arcade.render_text(self.score_text, 10, 20)
        #######################################################
        output = f"Energy: {self.world.energy} %"
        if not self.energy_text or output != self.energy_text.text:
            self.energy_text = arcade.create_text(output, arcade.color.WHITE,
                                                  14)
        arcade.render_text(self.energy_text, 140, 20)

        if self.world.game_over:
            arcade.draw_texture_rectangle(SCREEN_WIDTH // 2,
                                          SCREEN_HEIGHT // 2, SCREEN_WIDTH,
                                          SCREEN_HEIGHT, self.background)
            output = f"Your Score: {self.world.score}"
            if not self.score_text or output != self.score_text.text:
                self.score_text = arcade.create_text(output,
                                                     arcade.color.WHITE, 30)
            arcade.render_text(self.score_text, 300, 300)
        if not self.world.start_game:
            arcade.draw_texture_rectangle(SCREEN_WIDTH // 2,
                                          SCREEN_HEIGHT // 2, SCREEN_WIDTH,
                                          SCREEN_HEIGHT, self.intro)

    def update(self, delta):
        self.world.update(delta)