Example #1
0
class CheckerGameWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)
        self.world = World()
        self.worldRenderer = WorldRenderer(self.world)
        self.src = [
            "images/start.fw.png", "images/board.fw.png", "images/win.fw.png",
            "images/lose.fw.png"
        ]
        self.texture = []
        for src in self.src:
            self.texture.append(arcade.load_texture(src))

    def on_draw(self):
        arcade.start_render()
        arcade.draw_texture_rectangle(const.SCREEN_WIDTH // 2,
                                      const.SCREEN_HEIGHT // 2,
                                      self.texture[const.GAME_STATE].width,
                                      self.texture[const.GAME_STATE].height,
                                      self.texture[const.GAME_STATE], 0)
        if const.GAME_STATE == 1:
            self.worldRenderer.on_draw()

    def animate(self, delta):
        if const.GAME_STATE == 1:
            self.world.animate(delta)

    def on_mouse_release(self, x, y, button, modifiers):
        if const.GAME_STATE != 1:
            self.world = World()
            self.worldRenderer = WorldRenderer(self.world)
            const.GAME_STATE = 1
        else:
            self.world.on_mouse_release(x, y, button)
Example #2
0
class SpaceGameWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)

        arcade.set_background_color(arcade.color.PINK)

        self.world = World(width, height)
        self.ship_sprite = ModelSprite('images/ship.png',
                                       model=self.world.ship)
        self.gold_sprite = ModelSprite('images/gold.png',
                                       model=self.world.gold)

        self.asteroid_sprites = []
        for asteroid in self.world.asteroids:
            self.asteroid_sprites.append(
                ModelSprite('images/ship.png', scale=0.5, model=asteroid))

    def on_draw(self):
        arcade.start_render()
        self.ship_sprite.draw()
        self.gold_sprite.draw()

        for sprite in self.asteroid_sprites:
            sprite.draw()

        arcade.draw_text(str(self.world.score), self.width - 60,
                         self.height - 60, arcade.color.BLACK, 20)

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

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)
Example #3
0
class SpaceGameWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)

        arcade.set_background_color(arcade.color.BLACK)

        self.ship_sprite = arcade.Sprite('images/ship.png')
        self.gold_sprite = arcade.Sprite('images/gold.png')
        self.world = World(width, height)
        self.ship_sprite = ModelSprite('images/ship.png',
                                       model=self.world.ship)
        self.gold_sprite = ModelSprite('images/gold.png',
                                       model=self.world.gold)

    def on_draw(self):
        arcade.start_render()
        self.ship_sprite.draw()
        self.gold_sprite.draw()

        arcade.draw_text(str(self.world.score), self.width - 30,
                         self.height - 30, arcade.color.WHITE, 20)

    def animate(self, delta):
        self.world.animate(delta)
        # self.ship_sprite.set_position(self.world.ship.x, self.world.ship.y)

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)
Example #4
0
class WallRunnerGameWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)

        arcade.set_background_color(arcade.color.AMAZON)

        self.current_state = GAME_RUNNING

        self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT)

        self.man_sprite = ModelSprite('images/man.png', model=self.world.man)
        self.rip_sprite = ModelSprite('images/rip.png', model=self.world.man)
        self.heart_sprite = ModelSprite('images/heart.png',
                                        model=self.world.heart)

        self.rock_sprites = []
        for rock in self.world.rocks:
            self.rock_sprites.append(ModelSprite('images/rock.png',
                                                 model=rock))

    def animate(self, delta):
        self.world.animate(delta)
        if (self.world.hp <= 0):
            self.current_state = GAME_OVER

    def game_over_screen(self):
        self.rip_sprite.draw()
        arcade.draw_text("YOU DEAD!", self.width / 2 - 105,
                         self.height / 2 + 100, arcade.color.BLACK, 30)
        arcade.draw_text("SURVIVE TIME : " + str(int(self.world.time)),
                         self.width / 2 - 170, self.height / 2,
                         arcade.color.BLACK, 30)

    def on_draw(self):
        arcade.start_render()
        if (self.current_state == GAME_RUNNING):
            self.heart_sprite.draw()
            for sprite in self.rock_sprites:
                sprite.draw()
            self.man_sprite.draw()

            arcade.draw_text("SURVIVE TIME : " + str(int(self.world.time)),
                             self.width - 260, self.height - 40,
                             arcade.color.BURNT_SIENNA, 20)
            arcade.draw_text("HP : " + str(self.world.hp), self.width - 570,
                             self.height - 40, arcade.color.BURNT_SIENNA, 20)

        else:
            self.game_over_screen()

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)
Example #5
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.ship_sprite = ModelSprite('img/ship.png', model=self.world.ship)

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

    def on_draw(self):
        arcade.start_render()
        self.ship_sprite.draw()
Example #6
0
class SpaceGameWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)

        arcade.set_background_color(arcade.color.BLACK)

        self.ship_sprite = arcade.Sprite('images/ship.png')

        self.world = World(width, height)

    def animate(self, delta):
        self.world.animate(delta)
        self.ship_sprite.set_position(self.world.ship.x, self.world.ship.y)

    def on_draw(self):
        arcade.start_render()
        self.ship_sprite.draw()
Example #7
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.worldRenderer = WorldRenderer(width, height, self.world)

    def on_draw(self):
        arcade.start_render()
        self.worldRenderer.on_draw()
        # self.bg.draw()

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

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)
Example #8
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/wolf.png',
                                         model=self.world.player)

        self.end_sprites = []
        for end in self.world.ends:
            self.end_sprites.append(ModelSprite('images/warp.png', model=end))

        self.wall_sprites = []
        for wall in self.world.wall:
            self.wall_sprites.append(
                ModelSprite('images/block.png', model=wall))

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

        self.gameover_texture = arcade.load_texture('images/meat.png')

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

    def on_draw(self):
        arcade.start_render()
        self.draw_coins(self.world.coins, self.world.player)
        self.player_sprite.draw()
        self.enemy_sprites = []
        for enemy in self.world.enemies:
            self.enemy_sprites.append(
                ModelSprite('images/pig.png', model=enemy))

        for sprite in self.enemy_sprites:
            sprite.draw()

        for sprite in self.wall_sprites:
            sprite.draw()

        for sprite in self.end_sprites:
            sprite.draw()

        if (self.world.GAMEOVER == 0):
            arcade.draw_text(str(self.world.score), 750, 550,
                             arcade.color.WHITE, 20)
        else:
            arcade.draw_text(str(0), 750, 550, arcade.color.WHITE, 20)

        if self.world.GAMEOVER == 1 and self.world.WIN == 0:
            arcade.draw_text("GAMEOVER", 340, 550, arcade.color.WHITE, 20)

        elif self.world.WIN == 1 and self.world.GAMEOVER == 0:
            arcade.draw_text("YOU WIN", 375, 570, arcade.color.WHITE, 15)
            arcade.draw_text("SCORE " + str(self.world.score), 370, 550,
                             arcade.color.WHITE, 15)

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

    def on_key_press(self, key, key_modifiers):
        self.world.on_key_press(key, key_modifiers)
Example #9
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))
Example #10
0
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)
Example #11
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)
Example #12
0
class TowerDefense(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height, title="Tower Defense")

        self.bullet_list = arcade.SpriteList()

        arcade.set_background_color(arcade.color.WHITE)

        self.text_angle = 0
        self.time_elapsed = 0
        self.money = 0

        self.world = World(width, height)

        self.tower_sprite = Model("assets/Tower1.png", model=self.world.tower)
        self.monster_sprite = []
        for monster in self.world.monsters:
            self.monster_sprites.append(
                ModelSprite("assets/Monster_easy1.png",
                            scale=0.5,
                            model=monster))

        self.bullet_sprite = []
        for bullet in self.world.bullets:
            self.monster_sprites.append(
                ModelSprite("assets/bulletOne.png", scale=0.5, model=bullet))

        for i in range(100):
            self.monster = arcade.Sprite("assets/Monster_easy1.png")
            self.monster.center_x = 50
            self.monster.center_y = 175
            self.all_sprites_list.append(self.monster)
            self.monster_list.append(self.monster)

        bullet = Bullet("assets/bulletOne.png", 0.5 * 1.5)

        bullet.center_x = self.tower_sprite.center_x
        bullet.center_y = self.tower_sprite.center_y

        self.all_sprites_list.append(bullet)
        self.bullet_list.append(bullet)

        ##self.tower = Tower(300, 400)
        ##self.tower_sprite = arcade.Sprite("assets/Tower1.png")

        ##self.bulletOne = Bullet(165, 175)
        ##self.bulletOne_sprite = arcade.Sprite("assets/bulletOne.png")

        self.gameBoard = arcade.Sprite("assets/gameBoard.png")
        self.gameBoard.set_position(350, 300)

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

        self.all_sprites_list.update()

        for bullet in self.bullet_list:
            hit_list = arcade.check_for_collision_with_list(
                bullet, self.monster_list)
        if len(hit_list) > 0:
            bullet.kill()

        for monster in self.monster_list:
            monster.kill()
            self.money += 20

##		if bullet.bottom > SCREEN_HEIGHT:
##			bullet.kill()

    def on_draw(self):
        arcade.start_render()

        self.all_sprites_list.draw()
        self.gameBoard.draw()

        self.tower_sprite.draw()
        self.monster_sprite.draw()
        self.bullet.draw()
        for sprite in self.monster_sprites:
            sprite.draw()

        arcade.draw_text("Time: {:5.1f}".format(self.time_elapsed), 500, 30,
                         arcade.color.BLACK, 20)
        arcade.draw_text("MONEY: {:5d}".format(self.money), 100, 75,
                         arcade.color.YELLOW)

        ##if self.time_elapsed % 5 == 0:
        ##self.sprite_list.append(self.easyMonster)

        self.money += 10