コード例 #1
0
ファイル: flappy.py プロジェクト: Klan300/flappy
class FlappyDotWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)

        arcade.set_background_color(arcade.color.WHITE)

        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)
        self.dot_sprite = ModelSprite('images/dot.png',
                                      model=self.world.player)
        self.pillar_pair_sprite = PillarPairSprite(
            model=self.world.pillar_pair)

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

    def on_draw(self):
        arcade.start_render()

        self.pillar_pair_sprite.draw()
        self.dot_sprite.draw()

    def on_key_press(self, key, key_modifiers):
        if not self.world.is_started():
            self.world.start()

        self.world.on_key_press(key, key_modifiers)
コード例 #2
0
ファイル: dotrun.py プロジェクト: KorawitRupanya/Dotrun
class DotRunWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)

        arcade.set_background_color(arcade.color.GRAY)

        self.start()

    def start(self):
        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)

        self.dot_sprite = ModelSprite('images/dot.png', model=self.world.dot)

        self.coin_texture = arcade.load_texture('images/coin.png')

    def update(self, delta):
        self.world.update(delta)
        if self.world.is_dead():
            self.start()

    def draw_platforms(self, platforms):
        for p in platforms:
            arcade.draw_rectangle_filled(p.x + p.width // 2,
                                         p.y - p.height // 2, p.width,
                                         p.height, arcade.color.WHITE)

    def draw_coins(self, coins):
        for c in coins:
            if not c.is_collected:
                arcade.draw_texture_rectangle(c.x, c.y, c.width, c.height,
                                              self.coin_texture)

    def on_draw(self):
        arcade.set_viewport(self.world.dot.x - SCREEN_WIDTH // 2,
                            self.world.dot.x + SCREEN_WIDTH // 2, 0,
                            SCREEN_HEIGHT)

        arcade.start_render()
        self.draw_platforms(self.world.platforms)
        self.draw_coins(self.world.coins)

        self.dot_sprite.draw()

        arcade.draw_text(str(self.world.score),
                         self.world.dot.x + (SCREEN_WIDTH // 2) - 60,
                         self.height - 30, arcade.color.WHITE, 20)

    def on_key_press(self, key, key_modifiers):
        if not self.world.is_started():
            self.world.start()
        self.world.on_key_press(key, key_modifiers)
コード例 #3
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)
コード例 #4
0
ファイル: flappy.py プロジェクト: KorawitRupanya/FlappyBird
class FlappyDotWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)

        arcade.set_background_color(arcade.color.WHITE)

        self.start()

    def start(self):
        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)

        self.dot_sprite = ModelSprite('images/1.png', model=self.world.player)

        self.pillar_pair_sprites = [
            PillarPairSprite(model=self.world.pillar_pairs[0]),
            PillarPairSprite(model=self.world.pillar_pairs[1])
        ]

    def on_key_press(self, key, key_modifiers):
        if not self.world.is_started():
            self.world.start()

        self.world.on_key_press(key, key_modifiers)

    def update(self, delta):
        self.world.update(delta)
        if self.world.is_dead():
            self.start()

    def on_draw(self):
        arcade.start_render()

        self.dot_sprite.draw()
        for pillar_pair_sprite in self.pillar_pair_sprites:
            pillar_pair_sprite.draw()

        arcade.draw_text(str(self.world.score), self.width - 30,
                         self.height - 30, arcade.color.BLACK, 20)
コード例 #5
0
class BurnWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)
        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)
        self.score = 0
        self.wizard_sprite = ModelSprite('images/Wizard.png',
                                         model=self.world.player)
        self.start_game = ModelSprite('images/Start.jpg',
                                      model=self.world.start_game)
        self.end = ModelSprite('images/End.jpg', model=self.world.end)
        self.help_button = False
        self.background = ModelSprite('images/RealBack_1.jpg',
                                      model=self.world.background)
        self.heart = ModelSprite('images/heart.png',
                                 model=self.world.heart_life)
        self.another_heart = ModelSprite('images/heart.png',
                                         model=self.world.another_heart)
        self.fire_1 = ModelSprite('images/fire.png', model=self.world.fire_1)
        self.fire_2 = ModelSprite('images/fire.png', model=self.world.fire_2)
        self.fire_3 = ModelSprite('images/fire.png', model=self.world.fire_3)
        self.another_fire = ModelSprite('images/fire.png',
                                        model=self.world.another_fire)
        self.bonus = ModelSprite('images/Bonus.png', model=self.world.bonus)
        self.bonus_1 = ModelSprite('images/Bonus_1.png',
                                   model=self.world.bonus_1)
        self.bonus_2 = ModelSprite('images/Bonus_2.png',
                                   model=self.world.bonus_2)
        self.zombie = ModelSprite('images/Zombie.png', model=self.world.zombie)
        self.grim = ModelSprite('images/Ghost_1.png', model=self.world.grim)
        self.ghost = ModelSprite('images/Ghost_2.png', model=self.world.ghost)
        self.witch = ModelSprite('images/Witch.png', model=self.world.witch)
        self.TinkerBell = ModelSprite('images/Tinker_Bell.png',
                                      model=self.world.TinkerBell)
        self.Ariel = ModelSprite('images/Royal_3.png', model=self.world.Ariel)
        self.help = ModelSprite('images/Help.jpg', model=self.world.help)

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

    def on_draw(self):
        arcade.start_render()
        if self.world.state == 2:
            self.background.draw()
            self.heart.draw()
            arcade.draw_text(str(self.world.life), 300, 550,
                             arcade.color.BLACK, 20)
            self.wizard_sprite.draw()
            self.score = f"Level {self.world.level} : {str(self.world.score) } / {str(self.world.score_reach)}"
            arcade.draw_text(str(self.score), 20, 550, arcade.color.BLACK, 20)
            if self.world.level >= 3 and self.world.fire_1.stat == [
                    True, False, False
            ]:
                self.world.another_fire.stat = True
                self.another_fire.draw()
            if self.world.level >= 7 and self.world.fire_1.stat == [
                    True, True, False
            ]:
                self.world.another_fire.stat = True
                self.another_fire.draw()
            if self.world.life >= 9:
                self.world.another_heart.stat = False
            else:
                self.another_heart.draw()
            if self.world.fire_1.stat[0]:
                self.fire_1.draw()
                if self.world.fire_1.stat[1]:
                    self.fire_2.draw()
                    if self.world.fire_1.stat[2]:
                        self.fire_3.draw()
            if self.world.bonus_stat:
                self.bonus_2.draw()
                arcade.draw_text(str(math.ceil(self.world.bonus_time)), 440,
                                 550, arcade.color.BLACK, 20)
            else:
                self.bonus_1.draw()
            self.bonus.draw()
            self.zombie.draw()
            self.grim.draw()
            self.ghost.draw()
            self.witch.draw()
            self.TinkerBell.draw()
            self.Ariel.draw()
        elif self.world.state == 3:
            self.end.draw()
            arcade.draw_text("Your score: " + str(self.world.score),
                             220,
                             345,
                             arcade.color.BLACK,
                             20,
                             align="center",
                             anchor_x="center",
                             anchor_y="center")
        else:
            self.start_game.draw()
            if self.help_button:
                self.help.draw()

    def on_key_press(self, key, key_modifiers):
        if not self.world.is_started() and key == arcade.key.ENTER:
            self.world.start()
        if self.help_button is not True and key == arcade.key.F1:
            self.help_button = True
        if self.help_button and key == arcade.key.ESCAPE:
            self.help_button = False
        self.world.reset_on_key_press(key, key_modifiers)
        self.world.fire_on_key_press(key, key_modifiers)
        self.world.player_on_key_press(key, key_modifiers)
コード例 #6
0
ファイル: Icarus.py プロジェクト: cynic4018/Icarus-Falls
class Window(arcade.Window):
    show_credit = False

    def __init__(self, width, height, title):
        super().__init__(width, height, title)

        self.start()

        self.menu = {
            'score':
            arcade.load_texture(
                ".././images/Back ground/loser-score-board.png"),
            'play':
            arcade.load_texture(".././images/button/replay.png"),
            'credit':
            arcade.load_texture(".././images/button/credit.png"),
            'quit':
            arcade.load_texture(".././images/button/QuitButton.png")
        }

        self.credit_background = arcade.load_texture(
            ".././images/Back ground/credit.jpg")

    def start(self):
        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)
        self.offset = 0
        self.credit_offset = 0
        self.check_credit = False
        self.arrows = []
        self.fires = []
        self.numArrow = 5
        self.bottomFires = []
        self.background = arcade.load_texture(
            ".././images/Back ground/sky.jpg")

        for i in range(self.numArrow):
            self.arrows.append(ArrowSprite(model=self.world.arrow[i]))
        self.arrow_sprite = self.arrows

        for n in range(self.world.fireNumbers):
            self.fires.append(FireSprite(model=self.world.fire[n]))
        self.fire_sprite = self.fires

        for i in range(10):
            self.bottomFires.append(BottomFire(model=self.world.bottomfire[i]))
        self.bottomfires_sprite = self.bottomFires

        self.player_sprite = PlayerSprite(model=self.world.player)

    def on_key_press(self, key, key_modifiers):
        if not self.world.is_started():
            self.world.start()

        self.world.on_key_press(key, key_modifiers)

    def draw_background(self):
        arcade.draw_texture_rectangle(SCREEN_WIDTH // 2,
                                      SCREEN_HEIGHT // 2 + self.offset,
                                      SCREEN_WIDTH, SCREEN_HEIGHT,
                                      self.background)
        arcade.draw_texture_rectangle(SCREEN_WIDTH // 2,
                                      (SCREEN_HEIGHT // 2 + self.offset) -
                                      SCREEN_HEIGHT, SCREEN_WIDTH,
                                      SCREEN_HEIGHT, self.background)

    def draw_lp(self):
        arcade.draw_rectangle_filled(
            (self.width - 120) + (100 - self.world.player.lp), 30,
            self.world.player.lp * 2, 20, arcade.color.CHERRY)

    def draw_credit(self):
        self.show_credit = True
        arcade.draw_texture_rectangle(SCREEN_WIDTH // 2,
                                      SCREEN_HEIGHT // 2 + self.credit_offset,
                                      SCREEN_WIDTH, SCREEN_HEIGHT,
                                      self.credit_background)
        arcade.draw_texture_rectangle(
            SCREEN_WIDTH // 2,
            (SCREEN_HEIGHT // 2 + self.credit_offset) - SCREEN_HEIGHT,
            SCREEN_WIDTH, SCREEN_HEIGHT, self.credit_background)

    def update(self, delta):
        self.world.update(delta)
        if self.world.is_dead():
            self.world.freeze()

        if self.world.is_started():
            self.offset -= 1
            self.offset %= SCREEN_HEIGHT

        if (self.world.arrowNumbers != self.numArrow):
            self.arrows.append(ArrowSprite(model=self.world.arrow[-1]))
            self.numArrow = self.world.arrowNumbers

        if self.check_credit:
            self.credit_offset += 1
            self.credit_offset %= SCREEN_HEIGHT

    def on_draw(self):
        arcade.start_render()

        self.draw_background()

        for arrow in self.arrow_sprite:
            arrow.draw()

        for fire in self.fire_sprite:
            fire.draw()

        for bf in self.bottomfires_sprite:
            bf.draw()

        arcade.draw_text(str(int(self.world.score)), 25, self.height - 40,
                         arcade.color.BLACK, 20)

        arcade.draw_text("LP", self.width - 35, 45, arcade.color.BLACK, 10)

        self.player_sprite.draw()

        self.draw_lp()

        if self.world.player.lp == -1:
            self.draw_gui()

    def draw_gui(self):
        texture = self.menu['score']
        arcade.draw_texture_rectangle(self.width // 2, self.height // 2 + 200,
                                      texture.width, texture.height, texture,
                                      0)
        arcade.draw_text(str(int(self.world.score)), self.width // 2 - 80, 475,
                         arcade.color.WHITE, 100)
        texture = self.menu['play']
        arcade.draw_texture_rectangle(self.width // 2, self.height // 2,
                                      texture.width, texture.height, texture,
                                      0)
        texture = self.menu['credit']
        arcade.draw_texture_rectangle(self.width // 2, self.height // 2 - 200,
                                      texture.width, texture.height, texture,
                                      0)
        texture = self.menu['quit']
        arcade.draw_texture_rectangle(self.width - 60, self.height - 55,
                                      texture.width, texture.height, texture,
                                      0)

        if self.check_credit:
            self.show_credit = True
            self.draw_credit()

    def replay(self, x, y):
        if self.world.player.lp == -1:
            if self.width // 2 - 205 <= x <= self.width // 2 + 205 and self.height // 2 - 70 <= y <= self.height // 2 + 70:
                self.start()
                self.world.start()

    def credit(self, x, y):
        if ((self.height // 2) - 200) - (95) <= y <= (
            (self.height // 2) - 200) + (
                95) and self.width // 2 - 95 <= x <= self.width // 2 + 95:
            self.check_credit = True

    def quit_game(self, x, y):
        if self.world.player.lp == -1:
            if self.height - 90 <= y <= self.height - 20 and self.width - 108 <= x <= self.width - 10:
                exit()

    def draw_gui_again(self, x, y):
        if y <= self.height and x <= self.width:
            self.check_credit = False
            self.show_credit = False

    def on_mouse_press(self, x, y, button, modifiers):
        if not self.show_credit:
            self.replay(x, y)
            self.credit(x, y)
            self.quit_game(x, y)
        else:
            self.draw_gui_again(x, y)
コード例 #7
0
class Pirate_Panda_Window(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)
        self.background = arcade.load_texture("pic/image1.png")

        self.setup()

    def setup(self):
        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)
        self.coin = arcade.load_texture('pic/coin.png')
        self.skull = arcade.load_texture('pic/skull-model.png')
        self.walk = arcade.load_texture('pic/sandHalf.png')
        self.panda_sprite = self.panda()
        self.backsprite = self.back()

    def back(self):
        ba = arcade.load_texture("pic/image1.png")
        return ba

    def panda(self):
        if self.world.panda.is_jump == False:
            panda_sprite = ModelSprite('pic/Panda.png', model=self.world.panda)
            return panda_sprite
        if self.world.panda.is_jump == True:
            panda_sprite = ModelSprite('pic/Panda_Jump2.png',
                                       model=self.world.panda)
            return panda_sprite

    def reset(self):
        self.background = arcade.load_texture("pic/image1.png")

        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)
        self.panda_sprite = ModelSprite('pic/Panda.png',
                                        model=self.world.panda)

    def update(self, delta):
        self.world.update(delta)
        self.panda_sprite = self.panda()
        self.backsprite = self.back()

        if self.world.panda.die():
            self.world.freeze()

            self.panda_sprite = ModelSprite('pic/Panda_Die.png',
                                            model=self.world.panda)
            self.background = arcade.load_texture("pic/game_over.jpg")

    def draw_platforms(self, platforms):
        for p in platforms:

            arcade.draw_texture_rectangle(p.x + p.width // 2,
                                          p.y - p.height // 2, p.width,
                                          p.height, self.walk)

    def draw_coins(self, coins):
        for c in coins:
            if not c.is_collected:
                if c.effect == False:
                    arcade.draw_texture_rectangle(c.x, c.y, c.width, c.height,
                                                  self.coin)

    def draw_skulls(self, skulls):
        for i in skulls:
            if not i.is_collected:
                if i.effect == False:
                    arcade.draw_texture_rectangle(i.x, i.y, i.width, i.height,
                                                  self.skull)

    def on_draw(self):
        arcade.set_viewport(self.world.panda.x - SCREEN_WIDTH // 2,
                            self.world.panda.x + SCREEN_WIDTH // 2, 0,
                            SCREEN_HEIGHT)

        arcade.start_render()
        arcade.draw_texture_rectangle(self.panda_sprite.center_x,
                                      SCREEN_HEIGHT // 2, SCREEN_WIDTH + 50,
                                      SCREEN_HEIGHT, self.background)

        self.draw_platforms(self.world.platforms)
        self.draw_coins(self.world.coins)
        arcade.draw_text("Space to Start", -100, self.height // 2,
                         arcade.color.RED, 30)
        self.panda_sprite.draw()

        arcade.draw_text(str(self.world.score),
                         self.world.panda.x + (SCREEN_WIDTH // 2) - 890,
                         self.height - 30, arcade.color.BLACK, 20)
        self.draw_skulls(self.world.skulls)

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

        if key == arcade.key.R:

            self.reset()
コード例 #8
0
ファイル: game.py プロジェクト: xorawish/throw-your-knives
class GameWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height, title="Throw your knives!")

        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)
        self.knife_sprite = None
        self.knife_sprite2 = None
        self.knife_sprite3 = None
        self.knife_sprite4 = None
        self.knife_sprite5 = None
        self.knife_sprite6 = None
        self.knife_sprite7 = None
        self.knife_sprite8 = None
        self.knife_sprite9 = None
        self.knife_sprite10 = None
        self.target_sprite = ModelSprite('images/target.png',
                                         model=self.world.target)

        self.total_time = 0.0

    def setup(self):

        arcade.set_background_color(arcade.color.BLACK)

        self.total_time = 0.0
        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)
        self.knife_sprite = ModelSprite('images/knife.png',
                                        model=self.world.knife)
        self.knife_sprite2 = ModelSprite('images/knife.png',
                                         model=self.world.knife2)
        self.knife_sprite3 = ModelSprite('images/knife.png',
                                         model=self.world.knife3)
        self.knife_sprite4 = ModelSprite('images/knife.png',
                                         model=self.world.knife4)
        self.knife_sprite5 = ModelSprite('images/knife.png',
                                         model=self.world.knife5)
        self.knife_sprite6 = ModelSprite('images/knife.png',
                                         model=self.world.knife6)
        self.knife_sprite7 = ModelSprite('images/knife.png',
                                         model=self.world.knife7)
        self.knife_sprite8 = ModelSprite('images/knife.png',
                                         model=self.world.knife8)
        self.knife_sprite9 = ModelSprite('images/knife.png',
                                         model=self.world.knife9)
        self.knife_sprite10 = ModelSprite('images/knife.png',
                                          model=self.world.knife10)
        self.target_sprite = ModelSprite('images/target.png',
                                         model=self.world.target)

    def update(self, delta):
        self.world.update(delta)
        self.total_time += delta

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

        if self.world.is_menued():
            start = "Press P to start"
            intruction = "Press Spacebar to throw a knife"
            caution = "Don't hit other knives on the target"
            arcade.draw_text("Throw your knives !" + "\n" + start + "\n" +
                             intruction + "\n" + caution,
                             400,
                             500,
                             arcade.color.WHITE,
                             18,
                             align="center",
                             anchor_x="center",
                             anchor_y="center")

        if self.world.is_started():
            minutes = int(self.total_time) // 60
            seconds = int(self.total_time) % 60
            timer = f"Timer: {minutes:02d}:{seconds:02d}"

            arcade.draw_text("Press P to pause" + "\n" + "Press R to restart" +
                             "\n" + "Score: " + str(self.world.score) + "\n" +
                             timer,
                             400,
                             500,
                             arcade.color.WHITE,
                             18,
                             align="center",
                             anchor_x="center",
                             anchor_y="center")

            self.knife_sprite.draw()
            self.knife_sprite2.draw()
            self.knife_sprite3.draw()
            self.knife_sprite4.draw()
            self.knife_sprite5.draw()
            self.knife_sprite6.draw()
            self.knife_sprite7.draw()
            self.knife_sprite8.draw()
            self.knife_sprite9.draw()
            self.knife_sprite10.draw()

        if self.world.is_frozened():
            start = "Press P to play"
            intruction = "Press Spacebar to throw a knife"
            caution = "Don't hit other knives on the target"
            arcade.draw_text("Paused" + "\n" + start + "\n" + intruction +
                             "\n" + caution,
                             400,
                             500,
                             arcade.color.WHITE,
                             18,
                             align="center",
                             anchor_x="center",
                             anchor_y="center")

        if self.world.is_overed():
            minutes = int(self.total_time) // 60
            seconds = int(self.total_time) % 60
            timer = f"Timer: {minutes:02d}:{seconds:02d}"
            arcade.draw_text("Game Over" + "\n" + "Press P to play again" +
                             "\n" + "Score: " + str(self.world.score - 1),
                             400,
                             500,
                             arcade.color.WHITE,
                             18,
                             align="center",
                             anchor_x="center",
                             anchor_y="center")

        if self.world.is_win():
            minutes = int(self.total_time) // 60
            seconds = int(self.total_time) % 60
            timer = f"Timer: {minutes:02d}:{seconds:02d}"
            arcade.draw_text("You win !!" + "\n" + "Press P to play again" +
                             "\n" + "Score: " + str(self.world.score),
                             400,
                             500,
                             arcade.color.WHITE,
                             18,
                             align="center",
                             anchor_x="center",
                             anchor_y="center")

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)
        if key == arcade.key.P:

            if self.world.state == self.world.STATE_MENU:
                self.setup()
                self.world.start()

            elif self.world.state == self.world.STATE_STARTED:
                self.world.freeze()

            elif self.world.state == self.world.STATE_FROZEN:
                self.world.start()

            elif self.world.state == self.world.STATE_OVER:
                self.setup()
                self.world.start()

            elif self.world.state == self.world.STATE_WIN:
                self.setup()
                self.world.start()

        if key == arcade.key.R:

            if self.world.state == self.world.STATE_STARTED:
                self.setup()
                self.world.start()

    def on_mouse_press(self, x, y, button, modifiers):
        self.world.on_mouse_press(x, y, button, modifiers)