Exemplo n.º 1
1
    def __init__(self, width, height):
        """ Set up the game and initialize the variables. """

        super().__init__(width, height)

        # Sprite lists
        self.all_sprites_list = arcade.SpriteList()

        # Set up the player
        self.score = 0
        self.player_sprite = arcade.Sprite("images/playerShip1_orange.png", SCALE)
        self.player_sprite.center_x = 200
        self.player_sprite.center_y = 200
        self.all_sprites_list.append(self.player_sprite)

        # Make the asteroids
        enemy_sprite = arcade.Sprite("images/meteorGrey_big1.png", SCALE)
        enemy_sprite.center_y = 200
        enemy_sprite.center_x =  150
        enemy_sprite.size = 4
        self.all_sprites_list.append(enemy_sprite)

        enemy_sprite = arcade.Sprite("images/meteorGrey_big2.png", SCALE)
        enemy_sprite.center_y = 200
        enemy_sprite.center_x =  250
        enemy_sprite.size = 4
        self.all_sprites_list.append(enemy_sprite)

        enemy_sprite = arcade.Sprite("images/meteorGrey_big3.png", SCALE)
        enemy_sprite.center_y = 150
        enemy_sprite.center_x = 200
        enemy_sprite.size = 4
        self.all_sprites_list.append(enemy_sprite)

        self.background = arcade.load_texture("stars.jpg")
 def draw_instructions_page(self, page):
     """
     Draw an instruction page. Load the page as an image.
     """
     texture = arcade.load_texture("images/instructions_{}.png"
                                   .format(page))
     arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2,
                                   texture.width,
                                   texture.height, texture, 0)
Exemplo n.º 3
1
    def setup(self):
        """ Set up the game and initialize the variables. """

        # Sprite lists
        self.all_sprites_list = arcade.SpriteList()
        self.coin_list = arcade.SpriteList()

        # Set up the player
        self.score = 0
        self.player = arcade.AnimatedWalkingSprite()

        filename = "images/character_sheet.png"

        image_location_list = [[0, 6, 59, 92]]
        self.player.stand_right_textures = \
            arcade.load_textures(filename, image_location_list, False)
        self.player.stand_left_textures = \
            arcade.load_textures(filename, image_location_list, True)

        image_location_list = [[591, 5, 64, 93],
                               [655, 10, 75, 88],
                               [730, 7, 54, 91],
                               [784, 3, 59, 95],
                               [843, 6, 56, 92]]
        self.player.walk_right_textures = \
            arcade.load_textures(filename, image_location_list, False)
        self.player.walk_left_textures = \
            arcade.load_textures(filename, image_location_list, True)

        self.player.texture_change_distance = 20

        self.player.center_x = SCREEN_WIDTH // 2
        self.player.center_y = SCREEN_HEIGHT // 2
        self.player.scale = 0.8

        self.all_sprites_list.append(self.player)

        for i in range(COIN_COUNT):
            coin = arcade.AnimatedTimeSprite(scale=0.5)
            coin.center_x = random.randrange(SCREEN_WIDTH)
            coin.center_y = random.randrange(SCREEN_HEIGHT)
            coin.textures = []
            coin.textures.append(arcade.load_texture("images/gold_1.png",
                                                     scale=COIN_SCALE))
            coin.textures.append(arcade.load_texture("images/gold_2.png",
                                                     scale=COIN_SCALE))
            coin.textures.append(arcade.load_texture("images/gold_3.png",
                                                     scale=COIN_SCALE))
            coin.textures.append(arcade.load_texture("images/gold_4.png",
                                                     scale=COIN_SCALE))
            coin.textures.append(arcade.load_texture("images/gold_3.png",
                                                     scale=COIN_SCALE))
            coin.textures.append(arcade.load_texture("images/gold_2.png",
                                                     scale=COIN_SCALE))
            coin.cur_texture_index = random.randrange(len(coin.textures))
            self.coin_list.append(coin)
            self.all_sprites_list.append(coin)

        # Set the background color
        arcade.set_background_color(arcade.color.AMAZON)
Exemplo n.º 4
1
# Draw an rectangle outline
arcade.draw_text("draw_rect", 243, 3, arcade.color.BLACK, 10)
arcade.draw_rectangle_outline(295, 100, 45, 65,
                              arcade.color.BRITISH_RACING_GREEN)
arcade.draw_rectangle_outline(295, 160, 20, 45,
                              arcade.color.BRITISH_RACING_GREEN, 3, 45)

# Draw a filled in rectangle
arcade.draw_text("draw_filled_rect", 363, 3, arcade.color.BLACK, 10)
arcade.draw_rectangle_filled(420, 100, 45, 65, arcade.color.BLUSH)
arcade.draw_rectangle_filled(420, 160, 20, 40, arcade.color.BLUSH, 45)

# Load and draw an image to the screen
# Image from kenney.nl asset pack #1
arcade.draw_text("draw_bitmap", 483, 3, arcade.color.BLACK, 12)
# texture = arcade.load_texture("images/playerShip1_orange.png")
texture = arcade.load_texture("images/spaceRockets_001.png")
scale = .1
arcade.draw_texture_rectangle(540, 120, scale * texture.width,
                              scale * texture.height, texture, 0)
arcade.draw_texture_rectangle(540, 60, scale * texture.width,
                              scale * texture.height, texture, 45)

# Finish the render.
# Nothing will be drawn without this.
# Must happen after all draw commands
arcade.finish_render()

# Keep the window up until someone closes it.
arcade.run()
    def __init__(self, screen_width, screen_height):
        """ Constructor """
        # Call the parent constructor. Required and must be the first line.
        super().__init__(screen_width, screen_height)

        # Set the background color
        arcade.set_background_color(arcade.color.AMAZON)

        # Start 'state' will be showing the first page of instructions.
        self.current_state = INSTRUCTIONS_PAGE_0

        self.all_sprites_list = None
        self.coin_list = None

        # Set up the player
        self.score = 0
        self.player_sprite = None

        self.instructions = []
        texture = arcade.load_texture("images/instructions_0.png")
        self.instructions.append(texture)

        texture = arcade.load_texture("images/instructions_1.png")
        self.instructions.append(texture)
Exemplo n.º 6
0
    def animate(self, delta_time):
        """ Movement and game logic """

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

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

        # Loop through each colliding sprite, change it, and add to the score.
        for coin in hit_list:
            # Have we collected this?
            if not coin.changed:
                # No? Then do so
                coin.texture = arcade.load_texture("images/bumper.png")
                coin.changed = True
                coin.width = 30
                coin.height = 30
                self.score += 1
Exemplo n.º 7
0
 def on_key_press(self, key, key_modifies):
     if bg.index(self.background_filename) == 0:
         if key == arcade.key.ENTER:
             self.background_filename = bg[1]
             self.background = arcade.load_texture(self.background_filename)
     elif bg.index(self.background_filename) > 0:
         if key == arcade.key.ENTER:
             self.background_filename = bg[0]
             self.background = arcade.load_texture(self.background_filename)
         elif self.win == True or self.win == False:
             return
         elif key == arcade.key.R:
             self.is_rock = True
             self.is_paper = False
             self.is_scissors = False
             options.remove("rock")
             self.com_ans = random.choice(options)
             if self.com_ans == "paper":
                 self.is_craw = True
                 self.is_com_craw = False
                 self.com_is_rock = False
                 self.com_is_paper = True
                 self.com_is_scissors = False
                 self.is_missed = random.choice(tf)
                 if self.is_missed == True:
                     pass
                 else:
                     if self.weak_against == True:
                         self.player_lp -= 400
                     else:
                         self.player_lp -= 200
                     if self.player_lp <= 0:
                         self.player_lp = 0
                         self.win = False
             elif self.com_ans == "scissors":
                 self.is_craw = False
                 self.is_com_craw = True
                 self.com_is_rock = False
                 self.com_is_paper = False
                 self.com_is_scissors = True
                 if self.is_missed == True:
                     pass
                 else:
                     if self.weak_for == True:
                         self.com_lp -= 400
                     else:
                         self.com_lp -= 200
                     if self.com_lp <= 0:
                         self.com_lp = 0
                         self.win = True
             options.append("rock")
         elif key == arcade.key.P:
             self.is_rock = False
             self.is_paper = True
             self.is_scissors = False
             options.remove("paper")
             self.com_ans = random.choice(options)
             if self.com_ans == "rock":
                 self.is_craw = False
                 self.is_com_craw = True
                 self.com_is_rock = True
                 self.com_is_paper = False
                 self.com_is_scissors = False
                 if self.is_missed == True:
                     pass
                 else:
                     if self.weak_for == True:
                         self.com_lp -= 400
                     else:
                         self.com_lp -= 200
                     if self.com_lp <= 0:
                         self.com_lp = 0
                         self.win = True
             elif self.com_ans == "scissors":
                 self.is_craw = True
                 self.is_com_craw = False
                 self.com_is_rock = False
                 self.com_is_paper = False
                 self.com_is_scissors = True
                 self.is_missed = random.choice(tf)
                 if self.is_missed == True:
                     pass
                 else:
                     if self.weak_against == True:
                         self.player_lp -= 400
                     else:
                         self.player_lp -= 200
                     if self.player_lp <= 0:
                         self.player_lp = 0
                         self.win = False
             options.append("paper")
         elif key == arcade.key.S:
             self.is_rock = False
             self.is_paper = False
             self.is_scissors = True
             options.remove("scissors")
             self.com_ans = random.choice(options)
             if self.com_ans == "rock":
                 self.is_craw = True
                 self.is_com_craw = False
                 self.com_is_rock = True
                 self.com_is_paper = False
                 self.com_is_scissors = False
                 self.is_missed = random.choice(tf)
                 if self.is_missed == True:
                     pass
                 else:
                     if self.weak_against == True:
                         self.player_lp -= 400
                     else:
                         self.player_lp -= 200
                     if self.player_lp <= 0:
                         self.player_lp = 0
                         self.win = False
             elif self.com_ans == "paper":
                 self.is_craw = False
                 self.is_com_craw = True
                 self.com_is_rock = False
                 self.com_is_paper = True
                 self.com_is_scissors = False
                 self.is_missed = random.choice(tf)
                 if self.is_missed == True:
                     pass
                 else:
                     if self.weak_for == True:
                         self.com_lp -= 400
                     else:
                         self.com_lp -= 200
                     if self.com_lp <= 0:
                         self.com_lp = 0
                         self.win = True
             options.append("scissors")
Exemplo n.º 8
0
import arcade

WINDOW_WIDTH = 500
WINDOW_HEIGHT = 500
BACKGROUND_COLOR = arcade.color.BLACK
GAME_TITLE = "Ada or Potato?"
GAME_SPEED = 1 / 60
TIMER_MAXIMUM = 100

IMAGE_ADA = arcade.load_texture("images/ada.png")
IMAGE_POTATO = arcade.load_texture("images/potato.png")


class Image(arcade.Sprite):
    timer: int

    def __init__(self):
        super().__init__()
        self.timer = 0
        self.center_x = WINDOW_WIDTH / 2
        self.center_y = WINDOW_HEIGHT / 2
        self.texture = IMAGE_POTATO

    def update_timer(self):
        if self.timer < TIMER_MAXIMUM:
            self.timer += 1
        else:
            self.timer = 0

    def update(self):
        self.update_timer()
Exemplo n.º 9
0
    def setup(self) -> None:
        self.sprite_list = arcade.SpriteList()
        self.animation = AnimatedWalkingSprite(8,
                                               center_x=self.x,
                                               center_y=self.y,
                                               animations_per_second=10)
        self.animation.stand_left_textures

        self.textures_idle_right = [
            arcade.load_texture('resources/sprites/player/idle.png',
                                x=i * 9,
                                y=0,
                                width=9,
                                height=10) for i in range(5)
        ]

        self.textures_idle_left = [
            arcade.load_texture('resources/sprites/player/idle.png',
                                x=i * 9,
                                y=0,
                                width=9,
                                height=10,
                                mirrored=True) for i in range(5)
        ]

        self.textures_walking_right = [
            arcade.load_texture('resources/sprites/player/walking.png',
                                x=i * 9,
                                y=0,
                                width=9,
                                height=10) for i in range(5)
        ]

        self.textures_walking_left = [
            arcade.load_texture('resources/sprites/player/walking.png',
                                x=i * 9,
                                y=0,
                                width=9,
                                height=10,
                                mirrored=True) for i in range(5)
        ]

        self.textures_jumping_right = [
            arcade.load_texture('resources/sprites/player/jumping.png',
                                x=i * 9,
                                y=0,
                                width=9,
                                height=10) for i in range(3)
        ]

        self.textures_jumping_left = [
            arcade.load_texture('resources/sprites/player/jumping.png',
                                x=i * 9,
                                y=0,
                                width=9,
                                height=10,
                                mirrored=True) for i in range(3)
        ]

        self.animation.stand_right_textures = self.textures_idle_right
        self.animation.stand_left_textures = self.textures_idle_left
        self.animation.walk_right_textures = self.textures_walking_right
        self.animation.walk_left_textures = self.textures_walking_left
        self.animation.jumping_right_textures = self.textures_jumping_right
        self.animation.jumping_left_textures = self.textures_jumping_left

        self.sprite_list.append(self.animation)

        self.physics_engine = arcade.PhysicsEnginePlatformer(
            self.animation,
            arcade.SpriteList(),
            gravity_constant=Player.GRAVITY)

        super().setup()
Exemplo n.º 10
0
 def face_down(self):
     """ Turn card face-down """
     self.texture = arcade.load_texture(FACE_DOWN_IMAGE)
     self.is_face_up = False
Exemplo n.º 11
0
    def setup(self):
        self.player_list = arcade.SpriteList()
        self.player = arcade.AnimatedTimeSprite()
        self.player.textures = []

#! 111111111111111111111
        self.change_x = 50
        self.change_y = 50

# Figure out if we need to flip face left or right
        if self.change_x < 0 and self.character_face_direction == RIGHT_FACING:
            self.character_face_direction = LEFT_FACING
        elif self.change_x > 0 and self.character_face_direction == LEFT_FACING:
            self.character_face_direction = RIGHT_FACING

        # Climbing animation
        if self.is_on_ladder:
            self.climbing = True
        if not self.is_on_ladder and self.climbing:
            self.climbing = False
        if self.climbing and abs(self.change_y) > 1:
            self.cur_texture += 1
            if self.cur_texture > 7:
                self.cur_texture = 0
        if self.climbing:
            self.texture = self.climbing_textures[self.cur_texture // 4]
            return

        # Jumping animation
        if self.change_y > 0 and not self.is_on_ladder:
            self.texture = self.jump_textures[self.character_face_direction]
            return
        elif self.change_y < 0 and not self.is_on_ladder:
            self.texture = self.fall_textures[self.character_face_direction]
            return

        # Idle animation
        if self.change_x == 0:
            self.texture = self.idle_textures[self.character_face_direction]
            return

        # Walking animation
        self.cur_texture += 1
        if self.cur_texture > 7:
            self.cur_texture = 0
        self.texture = self.walk_textures[self.cur_texture][self.character_face_direction]
#! 111111111111111111111





        #!===================================================================

        self.wall_list = arcade.SpriteList()

        self.view_bottom = 0
        self.view_left = 0

        # Name of the layer in the file that has our platforms/walls
        platforms_layer_name = 'Platforms'
        moving_platforms_layer_name = 'Moving Platforms'

        # Name of the layer that has items for pick-up
        # coins_layer_name = 'Coins'

        # Map name
        map_name = f":resources:tmx_maps/map_with_ladders.tmx"

        # Read in the tiled map
        my_map = arcade.tilemap.read_tmx(map_name)

        # Calculate the right edge of the my_map in pixels
        self.end_of_map = my_map.map_size.width * GRID_PIXEL_SIZE

        # -- Platforms
        self.wall_list = arcade.tilemap.process_layer(my_map, platforms_layer_name, TILE_SCALING)

        # -- Moving Platforms
        # moving_platforms_list = arcade.tilemap.process_layer(my_map, moving_platforms_layer_name, TILE_SCALING)
        # for sprite in moving_platforms_list:
        #     self.wall_list.append(sprite)

        # -- Background objects
        self.background_list = arcade.tilemap.process_layer(my_map, "Background", TILE_SCALING)

        # -- Background objects
        # self.ladder_list = arcade.tilemap.process_layer(my_map, "Ladders", TILE_SCALING)

        # -- Coins
        # self.coin_list = arcade.tilemap.process_layer(my_map, coins_layer_name, TILE_SCALING)

        # --- Other stuff
        # Set the background color
        if my_map.background_color:
            arcade.set_background_color(my_map.background_color)

        # Create the 'physics engine'
        self.physics_engine = arcade.PhysicsEnginePlatformer(self.player,
                                                             self.wall_list,
                                                             gravity_constant=GRAVITY,
                                                             )   # ladders=self.ladder_list
        #!===================================================================











#!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  РОДНАЯ АНИМАЦИЯ  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        #* анимация стояния
        for i in range(15):
            self.player.textures.append(arcade.load_texture("sprites/player/knight/noBKG_KnightIdle_strip.png",
                                                                    x=i*64, y=0, width=64, height=64
                                                                    ))

        # for i in range():

        self.player.center_x = SCREEN_WIDTH // 2
        self.player.center_y = SCREEN_HEIGHT // 2

        self.player_list.append(self.player)
Exemplo n.º 12
0
    def on_update(self, delta_time):
        """ Update the sprites """

        # Keep track of how long this function takes.
        start_time = timeit.default_timer()

        # print(math.fmod(self.frame_count, delta_time))
        # print(self.frame_count)

        # See if all crates have been destroyed, if so that's game over
        if len(self.dynamic_sprite_list) - 1 <= 0:
            # logging.info("Game Over!")
            self.game_over = True
            if self.game_over_sound_did_play:
                self.player.texture = self.player.textures[TEXTURE_IDLE_2]
                return
            else:
                arcade.play_sound(self.game_over_sound)
                self.game_over_sound_did_play = True  # Only play sound once
                return  # Exit early / stop updating physics after game over

        # print(self.player.body.position)
        # # Print key states for debugging
        # logging.info("Left: %s", self.left_pressed)
        # logging.info("Right: %s", self.right_pressed)
        # logging.info("Up: %s", self.up_pressed)
        # print(self.force, self.player.shape.friction)
        # print(self.player.body.velocity[0])

        # # Debug grounding
        # grounding = check_grounding(self.player) # find out if player is standing on ground
        # if grounding['body'] is not None:
        #     logging.info("Grounding: %s", grounding['normal'].x / grounding['normal'].y)
        # logging.info("Player friction: %s", self.player.shape.friction)

        # See if the player is standing on an item.
        # If she is, apply opposite force to the item below her.
        # So if she moves left, the box below her will have
        # a force to move to the right.
        grounding = check_grounding(self.player)
        if self.force[0] and grounding and grounding['body']:
            grounding['body'].apply_force_at_world_point((-self.force[0], 0),
                                                         grounding['position'])

        # Apply force to monkey if direction keys pressed
        if self.up_pressed:
            grounding = check_grounding(
                self.player)  # find out if player is standing on ground
            if grounding['body'] is not None and abs(
                    grounding['normal'].x / grounding['normal'].y
            ) <= self.player.shape.friction and self.player.body.velocity[
                    1] < 1:
                # She is! Go ahead and jump
                self.player.body.apply_impulse_at_local_point(
                    (0, PLAYER_JUMP_IMPULSE))
                arcade.play_sound(self.jump_sound)
            # else:
            #     # print("Not on ground, cant jump")
            #     pass
        elif self.down_pressed and not self.up_pressed:
            # logging.info("Pressed down, not currently doing anything")
            pass

        if self.left_pressed and not self.right_pressed:
            if self.player.body.velocity[
                    0] >= 100:  # If player already running right, apply the brakes so we can switch directions faster
                self.force = (-4500, 0)
                self.player.shape.friction = PLAYER_FRICTION * 15
            else:  # Add force to the player, and set the player friction to zero
                self.force = (-PLAYER_MOVE_FORCE, 0)
                self.player.shape.friction = 0
        elif self.right_pressed and not self.left_pressed:
            if self.player.body.velocity[
                    0] <= -100:  # If player already running left, apply the brakes so we can switch directions faster
                self.force = (4500, 0)
                self.player.shape.friction = PLAYER_FRICTION * 15
            else:  # Add force to the player, and set the player friction to zero
                self.force = (PLAYER_MOVE_FORCE, 0)
                self.player.shape.friction = 0
        if not self.right_pressed and not self.left_pressed and not self.up_pressed:
            #If no directions pressed, stop player
            self.force = (0, 0)
            self.player.shape.friction = PLAYER_FRICTION * 15  # Greatly increase friction so player stops instead of sliding

        # Enforce player speed limit
        if self.player.body.velocity[0] >= PLAYER_SPEED_LIMIT:
            self.force = (-500, 0)
        if self.player.body.velocity[0] <= -PLAYER_SPEED_LIMIT:
            self.force = (500, 0)

        # If we have force to apply to the player (from hitting the arrow
        # keys), apply it.
        self.player.body.apply_force_at_local_point(self.force, (0, 0))

        # Update player sprites
        self.player.update(
            self.frame_count
        )  # Pass in frame_count so we can decide which frame of animation to use

        # Check sprites
        for sprite in self.dynamic_sprite_list:
            if sprite.shape.body.position.y < 0:  # Check for sprites that fall off the screen.
                # Remove sprites from physics space
                self.space.remove(sprite.shape, sprite.shape.body)
                # Remove sprites from physics list
                sprite.remove_from_sprite_lists()
            if sprite.shape.name == "Pymunk" and sprite.shape.HITCOUNT >= CONTAINER_HEALTH / 2:  # Change texture of crate if 50% damaged
                broken_texture = arcade.load_texture(
                    "./images/tiles/boxCrate_single.png")
                sprite.texture = broken_texture
                # print("Damanged crate")
            # if sprite.shape.name:
            #     print(sprite.shape.name)
            if sprite.shape.name == "Pymunk" and sprite.shape.HITCOUNT >= CONTAINER_HEALTH:  # Destroy container if hit CONTAINER_HEALTH times
                # logging.info("Destroying shape %s", sprite.shape)
                self.emitters.append(
                    explosion(
                        sprite.shape.body.position[0],
                        sprite.shape.body.position[1]))  # Make an explosion
                self.space.remove(sprite.body, sprite.shape)
                sprite.remove_from_sprite_lists()
                # print(len(self.space.shapes))
                arcade.play_sound(self.explode_sound)
                # Kill random pod!
                delete_thread = threading.Thread(target=self.kill_pod)
                delete_thread.start()

        # Check if we need to teleport
        self.check_teleport()

        # Update emitters
        emitters_to_update = self.emitters.copy()
        for e in emitters_to_update:
            e.update()

        # remove emitters that can be reaped
        to_del = [e for e in emitters_to_update if e.can_reap()]
        for e in to_del:
            self.emitters.remove(e)

        # Check for balls that fall off the screen
        for sprite in self.ball_sprite_list:
            if sprite.pymunk_shape.body.position.y < 0:
                # Remove balls from physics space
                self.space.remove(sprite.pymunk_shape,
                                  sprite.pymunk_shape.body)
                # Remove balls from physics list
                sprite.remove_from_sprite_lists()

        # Move ball sprites to where physics objects are
        for sprite in self.ball_sprite_list:
            sprite.center_x = sprite.pymunk_shape.body.position.x
            sprite.center_y = sprite.pymunk_shape.body.position.y
            sprite.angle = math.degrees(sprite.pymunk_shape.body.angle)

        # Update physics
        # Use a constant time step, don't use delta_time
        # http://www.pymunk.org/en/latest/overview.html#game-loop-moving-time-forward
        self.space.step(1 / 60.0)

        # If we are dragging an object, make sure it stays with the mouse. Otherwise
        # gravity will drag it down.
        if self.shape_being_dragged is not None:
            self.shape_being_dragged.shape.body.position = self.last_mouse_position
            self.shape_being_dragged.shape.body.velocity = 0, 0

        # Resync the sprites to the physics objects that shadow them
        resync_physics_sprites(self.dynamic_sprite_list)

        # Scroll the viewport if needed
        self.scroll_viewport()

        # Save the time it took to do this.
        self.processing_time = timeit.default_timer() - start_time
Exemplo n.º 13
0
	def __init__(self,owner = None):
		self.owner = owner
		if owner != None:
			self.owner_type = owners.PLAYER
		self.texture = arcade.load_texture(self.image)
		self.frozen = []
Exemplo n.º 14
0
 def create_new_sprite(self, obj):
     sprite = Sprite('wall.png', scale=0.5)
     sprite.append_texture(load_texture('box.png', scale=0.5))
     sprite.append_texture(load_texture('paddle.png', scale=2))
     sprite.append_texture(load_texture('ball.png', scale=0.5))
     return sprite
Exemplo n.º 15
0
    def setup(self):
        # Sprite Lists
        self.all_sprites_list = arcade.SpriteList()
        self.wall_list = arcade.SpriteList()

        # Player
        self.player = arcade.AnimatedWalkingSprite()

        self.player.stand_right_textures = []
        self.player.stand_right_textures.append(
            arcade.load_texture("images/ftr2_rt1.gif"))
        self.player.stand_left_textures = []
        self.player.stand_left_textures.append(
            arcade.load_texture("images/ftr2_lf1.gif"))
        self.player.stand_up_textures = []
        self.player.stand_up_textures.append(
            arcade.load_texture("images/ftr2_bk1.gif"))
        self.player.stand_down_textures = []
        self.player.stand_down_textures.append(
            arcade.load_texture("images/ftr2_fr1.gif"))
        self.player.walk_right_textures = []
        self.player.walk_right_textures.append(
            arcade.load_texture("images/ftr2_rt1.gif"))
        self.player.walk_right_textures.append(
            arcade.load_texture("images/ftr2_rt2.gif"))
        self.player.walk_left_textures = []
        self.player.walk_left_textures.append(
            arcade.load_texture("images/ftr2_lf1.gif"))
        self.player.walk_left_textures.append(
            arcade.load_texture("images/ftr2_lf2.gif"))
        self.player.walk_up_textures = []
        self.player.walk_up_textures.append(
            arcade.load_texture("images/ftr2_bk1.gif"))
        self.player.walk_up_textures.append(
            arcade.load_texture("images/ftr2_bk2.gif"))
        self.player.walk_down_textures = []
        self.player.walk_down_textures.append(
            arcade.load_texture("images/ftr2_fr1.gif"))
        self.player.walk_down_textures.append(
            arcade.load_texture("images/ftr2_fr2.gif"))

        self.player.texture_change_distance = 20  #20

        self.player.center_x = 320
        self.player.center_y = 240
        self.all_sprites_list.append(self.player)

        # Mauer
        wall = arcade.Sprite("images/wall.png")
        wall.center_x = 200
        wall.center_y = 200
        self.wall_list.append(wall)

        wall = arcade.Sprite("images/wall.png")
        wall.center_x = 232
        wall.center_y = 200
        self.wall_list.append(wall)

        wall = arcade.Sprite("images/wall.png")
        wall.center_x = 264
        wall.center_y = 200
        self.wall_list.append(wall)

        self.physics_engine = arcade.PhysicsEngineSimple(
            self.player, self.wall_list)
Exemplo n.º 16
0
    def setup(self):
        """ Set up the game and initialize the variables. """

        # Sprite lists
        # do not use is_static=True for animated sprites
        self.player_list = arcade.SpriteList()
        self.npc_list = arcade.SpriteList()
        self.wall_list = arcade.SpriteList(is_static=True)
        self.platform_list = arcade.SpriteList(is_static=True)
        self.background_list = arcade.SpriteList(is_static=True)
        self.coin_list = arcade.SpriteList()
        self.ice_list = arcade.SpriteList()
        self.laser_list = arcade.SpriteList()

        # Set up the player
        self.score = 0
        self.player = arcade.AnimatedWalkingSprite()

        character_scale = .5
        self.player.stand_right_textures = []
        self.player.stand_right_textures.append(
            arcade.load_texture("images/rock_stand_right.png",
                                scale=character_scale))
        self.player.stand_left_textures = []
        self.player.stand_left_textures.append(
            arcade.load_texture("images/rock_stand_left.png",
                                scale=character_scale))

        self.player.walk_right_textures = []

        self.player.walk_right_textures.append(
            arcade.load_texture("images/rock_walk_right_001.png",
                                scale=character_scale))
        self.player.walk_right_textures.append(
            arcade.load_texture("images/rock_walk_right_002.png",
                                scale=character_scale))
        self.player.walk_right_textures.append(
            arcade.load_texture("images/rock_walk_right_003.png",
                                scale=character_scale))
        self.player.walk_right_textures.append(
            arcade.load_texture("images/rock_walk_right_004.png",
                                scale=character_scale))
        self.player.walk_right_textures.append(
            arcade.load_texture("images/rock_walk_right_005.png",
                                scale=character_scale))
        self.player.walk_right_textures.append(
            arcade.load_texture("images/rock_walk_right_006.png",
                                scale=character_scale))
        self.player.walk_right_textures.append(
            arcade.load_texture("images/rock_walk_right_007.png",
                                scale=character_scale))
        self.player.walk_right_textures.append(
            arcade.load_texture("images/rock_walk_right_008.png",
                                scale=character_scale))
        self.player.walk_right_textures.append(
            arcade.load_texture("images/rock_walk_right_009.png",
                                scale=character_scale))

        self.player.walk_left_textures = []

        self.player.walk_left_textures.append(
            arcade.load_texture("images/rock_walk_left_001.png",
                                scale=character_scale))
        self.player.walk_left_textures.append(
            arcade.load_texture("images/rock_walk_left_002.png",
                                scale=character_scale))
        self.player.walk_left_textures.append(
            arcade.load_texture("images/rock_walk_left_003.png",
                                scale=character_scale))
        self.player.walk_left_textures.append(
            arcade.load_texture("images/rock_walk_left_004.png",
                                scale=character_scale))
        self.player.walk_left_textures.append(
            arcade.load_texture("images/rock_walk_left_005.png",
                                scale=character_scale))
        self.player.walk_left_textures.append(
            arcade.load_texture("images/rock_walk_left_006.png",
                                scale=character_scale))
        self.player.walk_left_textures.append(
            arcade.load_texture("images/rock_walk_left_007.png",
                                scale=character_scale))
        self.player.walk_left_textures.append(
            arcade.load_texture("images/rock_walk_left_008.png",
                                scale=character_scale))
        self.player.walk_left_textures.append(
            arcade.load_texture("images/rock_walk_left_009.png",
                                scale=character_scale))

        self.player.texture_change_distance = 20

        # Read in the tiled map
        map_name = "NLA-testLvL5.tmx"
        self.my_map = arcade.read_tiled_map(map_name, SPRITE_SCALING)

        # Grab the layer of items we can't move through
        map_array = self.my_map.layers_int_data["Walls"]

        # Calculate the right edge of the my_map in pixels
        self.end_of_map = len(map_array[0]) * GRID_PIXEL_SIZE
        self.player.boundary_left = 128
        self.player.boundary_right = self.end_of_map - 128

        # Starting position of the player
        self.player.center_x = 384
        self.player.center_y = 768
        self.player.scale = 0.5

        self.player_list.append(self.player)

        # --- Background ---
        read_sprite_list(self.my_map.layers["Background"],
                         self.background_list)
        # --- Walls ---
        read_sprite_list(self.my_map.layers["Walls"], self.wall_list)
        # --- Platforms ---
        read_sprite_list(self.my_map.layers["Platforms"], self.platform_list)
        # --- Static NPC's ---
        read_sprite_list(self.my_map.layers["NPC"], self.npc_list)
        # --- Ice ---
        read_sprite_list(self.my_map.layers["Ice"], self.ice_list)
        # --- Coins ---
        read_sprite_list(self.my_map.layers["Coins"], self.coin_list)
        for coin in self.coin_list:
            coin.angle = 0
            coin.change_angle = 5

        # --- Other stuff

        # Set the background color
        if self.my_map.backgroundcolor:
            arcade.set_background_color(self.my_map.backgroundcolor)

        # Set the image to be used for the texture of the menu/map overlay
        self.menu_mask = arcade.load_texture("images/background_mask3.png")

        # Set the image to be used for the texture of the menu/map overlay
        self.paused_mask = arcade.load_texture("images/paused_mask.png")

        # Apply gravity/ physics to sprites
        self.physics_engine = arcade.PhysicsEnginePlatformer(
            self.player, self.platform_list, gravity_constant=GRAVITY)

        # Set the view port boundaries
        # These numbers set where we have 'scrolled' to.
        self.view_left = 0
        self.view_bottom = 0

        self.game_over = False

        # Background sounds (MUSIC)
        self.music_player = pyglet.media.Player()
        self.level_music = pyglet.media.load("sounds/music.wav")
        self.pause_menu_music = pyglet.media.load("sounds/paused.wav")
        self.game_over_music = pyglet.media.load("sounds/gameover1.wav")

        # Game sounds (SFX)
        self.collect_coin_sound = arcade.load_sound("sounds/coin1.wav")
        self.jump_sound = arcade.load_sound("sounds/jump1.wav")
        self.wall_hit_sound = arcade.load_sound("sounds/hit4.wav")
        self.ice_hit_sound = arcade.load_sound("sounds/hit2.wav")
        self.gun_sound = arcade.sound.load_sound("sounds/laser1.wav")
Exemplo n.º 17
0
    def on_draw(self):
        """
        Render the screen.
        """

        # Start the render process. This must be done before any drawing commands.
        arcade.start_render()

        # Draw a grid
        # Draw vertical lines every 120 pixels
        for x in range(0, 601, 120):
            arcade.draw_line(x, 0, x, 600, arcade.color.BLACK, 2)

        # Draw horizontal lines every 200 pixels
        for y in range(0, 601, 200):
            arcade.draw_line(0, y, 800, y, arcade.color.BLACK, 2)

        # Draw a point
        arcade.draw_text("draw_point", 3, 405, arcade.color.BLACK, 12)
        arcade.draw_point(60, 495, arcade.color.RED, 10)

        # Draw a set of points
        arcade.draw_text("draw_points", 123, 405, arcade.color.BLACK, 12)
        point_list = ((165, 495), (165, 480), (165, 465), (195, 495),
                      (195, 480), (195, 465))
        arcade.draw_points(point_list, arcade.color.ZAFFRE, 10)

        # Draw a line
        arcade.draw_text("draw_line", 243, 405, arcade.color.BLACK, 12)
        arcade.draw_line(270, 495, 300, 450, arcade.color.WOOD_BROWN, 3)

        # Draw a set of lines
        arcade.draw_text("draw_lines", 363, 405, arcade.color.BLACK, 12)
        point_list = ((390, 450), (450, 450), (390, 480), (450, 480),
                      (390, 510), (450, 510))
        arcade.draw_lines(point_list, arcade.color.BLUE, 3)

        # Draw a line strip
        arcade.draw_text("draw_line_strip", 483, 405, arcade.color.BLACK, 12)
        point_list = ((510, 450), (570, 450), (510, 480), (570, 480),
                      (510, 510), (570, 510))
        arcade.draw_line_strip(point_list, arcade.color.TROPICAL_RAIN_FOREST,
                               3)
        arcade.draw_line_strip(point_list, arcade.color.BEIGE)

        # Draw a polygon
        arcade.draw_text("draw_polygon_outline", 3, 207, arcade.color.BLACK, 9)
        point_list = ((30, 240), (45, 240), (60, 255), (60, 285), (45, 300),
                      (30, 300))
        arcade.draw_polygon_outline(point_list, arcade.color.SPANISH_VIOLET, 3)

        # Draw a filled in polygon
        arcade.draw_text("draw_polygon_filled", 123, 207, arcade.color.BLACK,
                         9)
        point_list = ((150, 240), (165, 240), (180, 255), (180, 285),
                      (165, 300), (150, 300))
        arcade.draw_polygon_filled(point_list, arcade.color.SPANISH_VIOLET)

        # Draw an outline of a circle
        arcade.draw_text("draw_circle_outline", 243, 207, arcade.color.BLACK,
                         10)
        arcade.draw_circle_outline(300, 285, 18, arcade.color.WISTERIA, 3)
        arcade.draw_circle_outline(350, 285, 18, arcade.color.WISTERIA)

        # Draw a filled in circle
        arcade.draw_text("draw_circle_filled", 363, 207, arcade.color.BLACK,
                         10)
        arcade.draw_circle_filled(420, 285, 18, arcade.color.GREEN)

        # Draw an ellipse outline, and another one rotated
        arcade.draw_text("draw_ellipse_outline", 483, 207, arcade.color.BLACK,
                         10)
        arcade.draw_ellipse_outline(540, 273, 15, 36, arcade.color.AMBER, 3)
        arcade.draw_ellipse_outline(540, 336, 15, 36, arcade.color.BLACK_BEAN,
                                    3, 45)

        # Draw a filled ellipse, and another one rotated
        arcade.draw_text("draw_ellipse_filled", 3, 3, arcade.color.BLACK, 10)
        arcade.draw_ellipse_filled(60, 81, 15, 36, arcade.color.AMBER)
        arcade.draw_ellipse_filled(60, 144, 15, 36, arcade.color.BLACK_BEAN,
                                   45)

        # Draw an arc, and another one rotated
        arcade.draw_text("draw_arc/filled_arc", 123, 3, arcade.color.BLACK, 10)
        arcade.draw_arc_outline(150, 81, 15, 36, arcade.color.BRIGHT_MAROON,
                                90, 360)
        arcade.draw_arc_filled(150, 144, 15, 36, arcade.color.BOTTLE_GREEN, 90,
                               360, 45)

        # Draw an rectangle outline
        arcade.draw_text("draw_rect", 243, 3, arcade.color.BLACK, 10)
        arcade.draw_rectangle_outline(295, 100, 45, 65,
                                      arcade.color.BRITISH_RACING_GREEN)
        arcade.draw_rectangle_outline(295, 160, 20, 45,
                                      arcade.color.BRITISH_RACING_GREEN, 3, 45)

        # Draw a filled in rectangle
        arcade.draw_text("draw_filled_rect", 363, 3, arcade.color.BLACK, 10)
        arcade.draw_rectangle_filled(420, 100, 45, 65, arcade.color.BLUSH)
        arcade.draw_rectangle_filled(420, 160, 20, 40, arcade.color.BLUSH, 45)

        # Load and draw an image to the screen
        # Image from kenney.nl asset pack #1
        arcade.draw_text("draw_bitmap", 483, 3, arcade.color.BLACK, 12)
        texture = arcade.load_texture(
            ":resources:images/space_shooter/playerShip1_orange.png")
        scale = .6
        # arcade.draw_texture_rectangle(540, 120, scale * texture.width,
        #                               scale * texture.height, texture, 0)
        # arcade.draw_texture_rectangle(540, 60, scale * texture.width,
        #                               scale * texture.height, texture, 45)
        #
        # Overlapping, with transparency test
        # Draw
        arcade.draw_rectangle_filled(650, 100, 50, 50, (255, 0, 0))
        arcade.draw_rectangle_filled(670, 100, 50, 50, (0, 255, 0, 127))

        import sys
        # TODO: Fix. See https://github.com/pvcraven/arcade/issues/539
        if sys.platform != "darwin":
            # Test colors
            color = arcade.get_pixel(635, 100)
            assert color == (255, 0, 0)
            color = arcade.get_pixel(670, 100)
            assert color == (128, 127, 0)
            color = arcade.get_pixel(690, 100)
            assert color == (128, 255, 128)

            # Test this other thing
            color = arcade.get_pixel(100, 100)
            assert color == (255, 255, 255)

        # Run the get image. Ideally we'd test the output
        arcade.get_image()
Exemplo n.º 18
0
 def setup(self):
     self.background = arcade.load_texture('../images/bg-texture.jpg')
     self.button_list = []
Exemplo n.º 19
0
    def setup(self):
        self.snake_list = arcade.SpriteList()
        self.apple_list = arcade.SpriteList()

        self.score = 0

        self.snake_sprite = Snake("Snake.png", SPRITE_SCALING_SNAKE)

        self.snake_sprite.center_x = SCREEN_WIDTH / 2
        self.snake_sprite.center_y = SCREEN_HEIGHT / 2

        self.snake_list.append(self.snake_sprite)

        name = "Snake.png"
        self.texture1 = arcade.load_texture(name, 0, 0, 0, 0, False, False,
                                            1.25)
        self.snake_sprite.append_texture(self.texture1)
        self.texture2 = arcade.load_texture(name, 0, 0, 0, 0, False, False,
                                            1.4)
        self.snake_sprite.append_texture(self.texture2)
        self.texture3 = arcade.load_texture(name, 0, 0, 0, 0, False, False,
                                            1.55)
        self.snake_sprite.append_texture(self.texture3)
        self.texture4 = arcade.load_texture(name, 0, 0, 0, 0, False, False,
                                            1.70)
        self.snake_sprite.append_texture(self.texture4)
        self.texture5 = arcade.load_texture(name, 0, 0, 0, 0, False, False,
                                            1.85)
        self.snake_sprite.append_texture(self.texture5)
        self.texture6 = arcade.load_texture(name, 0, 0, 0, 0, False, False, 2)
        self.snake_sprite.append_texture(self.texture6)
        self.texture7 = arcade.load_texture(name, 0, 0, 0, 0, False, False,
                                            2.15)
        self.snake_sprite.append_texture(self.texture7)
        self.texture8 = arcade.load_texture(name, 0, 0, 0, 0, False, False,
                                            2.3)
        self.snake_sprite.append_texture(self.texture8)
        self.texture9 = arcade.load_texture(name, 0, 0, 0, 0, False, False,
                                            2.45)
        self.snake_sprite.append_texture(self.texture9)
        self.texture10 = arcade.load_texture(name, 0, 0, 0, 0, False, False,
                                             2.6)
        self.snake_sprite.append_texture(self.texture10)
        self.texture11 = arcade.load_texture(name, 0, 0, 0, 0, False, False,
                                             2.75)
        self.snake_sprite.append_texture(self.texture11)
        self.texture12 = arcade.load_texture(name, 0, 0, 0, 0, False, False,
                                             2.9)
        self.snake_sprite.append_texture(self.texture12)

        print(self.snake_sprite.get_texture())

        for i in range(APPLE_COUNT):
            apple = Apple("Apple.png", SPRITE_SCALING_APPLE)

            apple.center_x = random.randint(50, SCREEN_WIDTH - 50)
            apple.center_y = random.randint(50, SCREEN_HEIGHT - 50)

            self.apple_list.append(apple)
Exemplo n.º 20
0
def on_draw():

    global pressure
    global power_output
    global decreasing_pressure
    global decreasing_power

    # Logic:
    # Pressure
    if pressure == 0:
        decreasing_pressure = False
    if not decreasing_pressure:
        pressure += 3
    if pressure == 165:
        decreasing_pressure = True
    if decreasing_pressure:
        pressure -= 55

    # Power
    if power_output == 0:
        decreasing_power = False
    if pressure == 18:
        decreasing_power = False
    if not decreasing_power and pressure > 21:
        power_output += 2
    if pressure == 55:
        decreasing_power = True
    if decreasing_power:
        power_output = (power_output // 3)
    print(power_output)

    arcade.start_render()

    # Loading Sprites
    # General
    arrow = arcade.load_texture('arrow.png', 0, 0, 512, 512)

    # Graphs
    barometer = arcade.load_texture('barometer.png', 0, 0, 512, 512)
    power = arcade.load_texture('electricity.png', 0, 0, 2273, 2400)

    # Container
    liquid = arcade.load_texture('liquid.png', 0, 0, 1600, 450)

    # Gas
    gas = arcade.load_texture('gas.png', 0, 0, 512, 512)

    # Condensation
    drop = arcade.load_texture('condensation.png', 0, 0, 400, 428)

    # Graphs
    arcade.draw_line(950, 525, 1150, 525, arcade.color.BLACK, 1)  # x - axis
    arcade.draw_line(950, 525, 950, 690, arcade.color.BLACK, 1)  # y - axis
    arcade.draw_texture_rectangle(990, 505, 30, 30, barometer)  # Pressure
    arcade.draw_texture_rectangle(1100, 505, 30, 30, power)  # Power output

    # Bars
    arcade.draw_line(990, 525, 990, 526 + pressure, arcade.color.BLUE, 25)
    arcade.draw_line(1100, 525, 1100, 526 + power_output, arcade.color.RED, 25)

    # Container
    arcade.draw_texture_rectangle(250, 235, 200, 110, liquid)  # Liquid
    arcade.draw_rectangle_filled(
        250, 180, 200, 35,
        arcade.color.WHITE)  # Covers the bit that extends too much
    arcade.draw_xywh_rectangle_outline(150, 200, 200, 120, arcade.color.BLACK,
                                       7)
    arcade.draw_rectangle_outline(250, 251, 400, 27, arcade.color.BLACK, 7)

    # Temperature Gradient for Water
    x_gradient = 51
    red = 255
    blue = 0
    for i in range(200):
        arcade.draw_line(x_gradient, 238, x_gradient, 264, [red, 0, blue], 2)
        x_gradient += 2
        red -= 0.6375 * 2
        blue += 0.6375 * 2

    # Radiator
    x_radiator = 175
    for i in range(7):
        arcade.draw_line(x_radiator, 225, x_radiator, 280, arcade.color.BLACK,
                         5)
        x_radiator += 25

    # Water Direction Arrows
    arcade.draw_texture_rectangle(25, 250, 40, 40, arrow)
    arcade.draw_texture_rectangle(475, 250, 40, 40, arrow)

    # Gas
    arcade.draw_texture_rectangle(random.randint(175, 345),
                                  random.randint(290, 300), 25, 25, gas)

    # Actual Power Generation Part
    arcade.draw_xywh_rectangle_outline(150, 400, 200, 120, arcade.color.BLACK,
                                       7)  # Piston Section 1
    arcade.draw_rectangle_outline(250, 360, 50, 75, arcade.color.BLACK,
                                  7)  # Tubing
    arcade.draw_rectangle_filled(250, 360, 43, 87,
                                 arcade.color.WHITE)  # Removing Lines

    # Piston
    y_piston = (pressure / 165) * 45
    arcade.draw_xywh_rectangle_filled(154, 402, 193, 70,
                                      arcade.color.LIGHT_BLUE)  # 'Gas'
    arcade.draw_xywh_rectangle_filled(154, (402 + y_piston), 193, 70,
                                      arcade.color.LIGHT_GRAY)  # Piston
    arcade.draw_xywh_rectangle_filled(
        154, (416 + y_piston), 193, 20,
        arcade.color.GRAY)  # Gasket to prevent leaking

    # Shaft
    arcade.draw_rectangle_filled(250.5, (545 + y_piston), 30, 150,
                                 arcade.color.LIGHT_GRAY)

    # Pressure Release things
    arcade.draw_xywh_rectangle_outline(
        400, 400, 400, 120, arcade.color.BLACK,
        7)  # Release container (more volume than the storage container
    arcade.draw_xywh_rectangle_outline(350, 425, 70, 15, arcade.color.BLACK,
                                       7)  # Connecting tube
    if decreasing_pressure:
        arcade.draw_rectangle_filled(400, 432, 20, 8,
                                     arcade.color.WHITE)  # Valve Open Close
        # Water drops -> Condensation
        arcade.draw_texture_rectangle(random.randint(410, 780),
                                      random.randint(410, 460), 20, 25, drop)
        arcade.draw_texture_rectangle(random.randint(410, 780),
                                      random.randint(410, 460), 20, 25, drop)
        arcade.draw_texture_rectangle(random.randint(410, 780),
                                      random.randint(410, 460), 20, 25, drop)
        arcade.draw_texture_rectangle(random.randint(410, 780),
                                      random.randint(410, 460), 20, 25, drop)
        arcade.draw_texture_rectangle(random.randint(410, 780),
                                      random.randint(410, 460), 20, 25, drop)
        arcade.draw_texture_rectangle(random.randint(410, 780),
                                      random.randint(410, 460), 20, 25, drop)
        arcade.draw_texture_rectangle(random.randint(410, 780),
                                      random.randint(410, 460), 20, 25, drop)
        arcade.draw_texture_rectangle(random.randint(410, 780),
                                      random.randint(410, 460), 20, 25, drop)
    arcade.draw_line(320, 280, 410, 400, arcade.color.BLACK, 8)  # Refill tube

    # Pressure Bar

    arcade.draw_rectangle_outline(1000, 250, 40, 370, arcade.color.BLACK,
                                  7)  # Bar outline
    arcade.draw_texture_rectangle(
        960, 390, 20, 20, arrow)  # arrow is positioned at 330 because 2x 165
    # Gradient for pressure. Green  = low pressure, red = high pressure
    red = 0
    green = 255
    blue = 0
    y_gradient = 68
    for i in range(pressure):
        arcade.draw_line(983, y_gradient, 1016, y_gradient, [red, green, blue],
                         2)
        y_gradient += 2
        red += 1.54
        green -= 1.54

    if pressure % 55 == 0:
        arcade.draw_text('Valve Open', 575, 680, arcade.color.RED,
                         20)  # Indicates if valve is open or closed
Exemplo n.º 21
0
    assets = list(map(lambda n: loader(f"{path}/{n}"), asset_names))

    return {name: image for name, image in zip(names, assets)}


persons = load_dir(PERSON_DIR, arcade.load_texture)
items = load_dir(ITEM_DIR, arcade.load_texture)
sounds = load_dir(SOUND_DIR, arcade.load_sound)
backgrounds = load_dir(BACKGROUND_DIR, arcade.load_texture)
descriptions = {}

with open(DESC_DIR + "items.txt", 'r') as file:
    lines = file.readlines()

for line in lines:
    split_line = line.split(': ')
    descriptions[split_line[0]] = split_line[1]

clock_image = arcade.load_texture("res/image/clock.png")
note_image = arcade.load_texture("res/image/note.png")
picture_image = arcade.load_texture("res/image/picture.png")
bg_image = arcade.load_texture("res/image/bg.png")
button_image = arcade.load_texture("res/image/button.png")
kallellse_image = arcade.load_texture("res/image/kallellse.png")
kallellse_wrong_image = arcade.load_texture("res/image/kallellse_wrong.png")
strike_image = arcade.load_texture("res/image/strike.png")
not_strike_image = arcade.load_texture("res/image/not_strike.png")
intro_image = arcade.load_texture("res/image/intro.png")
guide_image = arcade.load_texture("res/image/guide.png")
close_image = arcade.load_texture("res/image/close.png")
Exemplo n.º 22
0
import arcade
import json
import random
import time
import timeit
from arcade import gui
from arcade.gui import UIManager

# declaring constants and default values
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
SCREEN_TITLE = "MapGame"
DEFAULT_BACKGROUND = arcade.load_texture(
    f"sprites/backgrounds/backg_clean.png")

DEFAULT_PLAYER_SPRITE = arcade.Sprite(
    "sprites/player_sprites/crossh_cross.png", 0.1)

DEFAULT_TARGET = arcade.Sprite("sprites/targets/target_default.png", 0.1)


def load_sprite_scales():
    with open("utils/sprite_scales.json", "r") as scales_json:
        data = json.load(scales_json)
        return data


# classes that will be used within the views
class MenuButton(gui.UIFlatButton):
    def __init__(self,
                 view,
Exemplo n.º 23
0
    def __init__(self):
        super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)

        arcade.set_background_color(arcade.color.SKY_BLUE)


        self.player_list = None
        self.player = None

        self.left_pressed = False
        self.right_pressed = False
        self.up_pressed = False
        self.down_pressed = False
        self.jump_needs_reset = False



#!============================================================================================
        # These are 'lists' that keep track of our sprites. Each sprite should
        # go into a list.
        # self.coin_list = None
        self.wall_list = None
        # self.background_list = None
        # self.ladder_list = None
        # self.player_list = None
        self.physics_engine = None

        self.jump_sound = arcade.load_sound(":resources:sounds/jump1.wav")
#!============================================================================================



#! 00000000000000000000
# Default to face-right
        self.character_face_direction = RIGHT_FACING

        # Used for flipping between image sequences
        self.cur_texture = 0
        self.scale = CHARACTER_SCALING

        # Track our state
        self.jumping = False
        self.climbing = False
        self.is_on_ladder = False

        self.idle_textures = []
        for i in range(15):
            right_idle_texture = arcade.load_texture("sprites/player/Knight/noBKG_KnightIdle_strip.png", x=i*64, y=0, width=64, height=64)
            self.idle_textures.append(right_idle_texture)
            left_idle_texture = arcade.load_texture("sprites/player/Knight/noBKG_KnightIdle_strip.png", x=i*64, y=0, width=64, height=64, mirrored=True)
            self.idle_textures.append(left_idle_texture)

        self.jump_textures = []
        for i in range(14):
            right_jump_texture = arcade.load_texture("sprites/player/Knight/noBKG_KnightJumpAndFall_strip.png", x=i*144, y=0, width=144, height=64)
            self.jump_textures.append(right_jump_texture)
            left_jump_texture = arcade.load_texture("sprites/player/Knight/noBKG_KnightJumpAndFall_strip.png", x=i*144, y=0, width=144, height=64, mirrored=True)
            self.jump_textures.append(left_jump_texture)

        self.fall_textures = []
        for i in range(14):
            right_fall_texture = arcade.load_texture("sprites/player/Knight/noBKG_KnightJumpAndFall_strip.png", x=i*144, y=0, width=144, height=64)
            self.fall_textures.append(right_fall_texture)
            left_fall_texture = arcade.load_texture("sprites/player/Knight/noBKG_KnightJumpAndFall_strip.png", x=i*144, y=0, width=144, height=64, mirrored=True)
            self.fall_textures.append(left_fall_texture)

        self.walk_textures = []
        for i in range(8):
            right_walk_texture = arcade.load_texture("sprites/player/Knight/noBKG_KnightRun_strip.png", x=i*64, y=0, width=64, height=64)
            self.walk_textures.append(right_walk_texture)
            left_walk_texture = arcade.load_texture("sprites/player/Knight/noBKG_KnightRun_strip.png", x=i*64, y=0, width=64, height=64, mirrored=True)
            self.walk_textures.append(left_walk_texture)

        # Load textures for climbing
        self.climbing_textures = []
        texture = arcade.load_texture("sprites/player/Knight/noBKG_KnightIdle_strip.png")
        self.climbing_textures.append(texture)
        texture = arcade.load_texture("sprites/player/Knight/noBKG_KnightIdle_strip.png")
        self.climbing_textures.append(texture)

        # Set the initial texture
        self.texture = self.idle_textures[0]

        # Hit box will be set based on the first image used. If you want to specify
        # a different hit box, you can do it like the code below.
        # self.set_hit_box([[-22, -64], [22, -64], [22, 28], [-22, 28]])
        # self.set_hit_box(self.texture.hit_box_points)
#! 00000000000000000000



        self.setup()
Exemplo n.º 24
0
def load_texture_pair(filename):
    # load two sprites facing either direction
    return [
        arcade.load_texture(filename),
        arcade.load_texture(filename, mirrored=True)
    ]
Exemplo n.º 25
0
 def face_up(self):
     """ Turn card face-up """
     self.texture = arcade.load_texture(self.image_file_name)
     self.is_face_up = True
Exemplo n.º 26
0
    def update(self, delta_time):
        if self.game_state == PresentCatchGameState.COUNTDOWN or self.game_state == PresentCatchGameState.PLAYING:
            # move if keys are being pressed and state is countdown or playing
            if arcade.key.RIGHT in self.pressed_keys and arcade.key.LEFT in self.pressed_keys:
                # if both keys are pressed, do the one that was pressed last
                if self.pressed_keys.index(
                        arcade.key.RIGHT) > self.pressed_keys.index(
                            arcade.key.LEFT
                        ) and self.player.center_x < self.game.SCREEN_WIDTH:
                    self.player.change_x = self.player.MOVEMENT_SPEED
                elif self.player.center_x > 0:
                    self.player.change_x = -self.player.MOVEMENT_SPEED
                else:
                    self.player.change_x = 0

            elif arcade.key.RIGHT in self.pressed_keys and self.player.center_x < self.game.SCREEN_WIDTH:
                # just right key
                self.player.change_x = self.player.MOVEMENT_SPEED

            elif arcade.key.LEFT in self.pressed_keys and self.player.center_x > 0:
                # just left key
                self.player.change_x = -self.player.MOVEMENT_SPEED

            else:
                self.player.change_x = 0

        # if all the presents have been caught, the game is over
        if self.presents_fallen == self.PRESENTS_TO_DROP:
            self.game_state = PresentCatchGameState.GAME_OVER

        # countdown state
        if self.game_state == PresentCatchGameState.COUNTDOWN:
            self.countdown -= delta_time
            if self.countdown <= 0:
                self.game_state = PresentCatchGameState.PLAYING

        elif self.game_state == PresentCatchGameState.PLAYING:
            # only run collision checks and summon presents if in playing state
            # check for present collisions with player
            player_present_hit_list = arcade.check_for_collision_with_list(
                self.player, self.present_list)
            for present in player_present_hit_list:
                # light up the score indicator with the correct texture
                self.score_icon_list[present.id].texture = arcade.load_texture(
                    present.texture_string, scale=0.45)
                self.score_icon_list[present.id].alpha = 200

                # remove the present and increment score
                present.remove_from_sprite_lists()
                self.presents_fallen += 1
                self.score += 1

            # check for presents hitting the ground
            for present in self.present_list:
                if present.center_y - present.height / 2 <= 128:
                    # remove present if it hits the ground
                    present.remove_from_sprite_lists()
                    self.presents_fallen += 1

            # summon a present every self.PRESENT_FREQUENCY seconds
            self.time_since_present += delta_time
            if self.time_since_present >= self.PRESENT_FREQUENCY and self.present_count < self.PRESENTS_TO_DROP:
                self.summon_present()
                self.present_count += 1
                self.time_since_present = 0

        # game over state
        elif self.game_state == PresentCatchGameState.GAME_OVER:
            self.player.change_x = 0
            self.present_list = arcade.SpriteList()

            if self.player.action not in [DANCING_1, DANCING_2, DANCING_3]:
                self.player.action = random.choice(
                    [DANCING_1, DANCING_2, DANCING_3])

        # update the player and their animation state
        self.player.update()
        self.player.update_animation(delta_time)

        # update the presents
        self.present_list.update()
Exemplo n.º 27
0
def load_texture_pair(filename):
    return [
        arcade.load_texture(filename),
        arcade.load_texture(filename, mirrored=True)
    ]
# Set the dimensions of each grid location on the board
WIDTH = 50
HEIGHT = 50
RADIUS = 23

# Set the dimensions of the header text
TEXT_HEIGHT = 50

# Compute the Screen's dimensions and set the title
SCREEN_WIDTH = WIDTH * COLUMN_COUNT
SCREEN_HEIGHT = HEIGHT * ROW_COUNT + TEXT_HEIGHT
SCREEN_TITLE = "Connect 4 Game"

# Set dimensions for uploaded texure/logo
texture = arcade.load_texture("logo.jpeg")
scale = 0.120
texture_width = texture.width * scale
texture_height = texture.height * scale

# Set starting y point for animated pieces in menu and centre point for text and other features
y_start = SCREEN_HEIGHT
centre_x = SCREEN_WIDTH // 2

# Assign the states/modes the game can be in
MENU = 0
ONE_PLAYER = 1
TWO_PLAYER = 2

# Assign player and AI to different values for single player mode
player = 1
Exemplo n.º 29
0
 def set_up(self):
     self.background_filename = bg[0]
     self.background = arcade.load_texture(self.background_filename)
Exemplo n.º 30
0
    def setup(self):
        global ammo1, ammo2, ammo3
        """ Set up the game and initialize the variables. """
        self.background = arcade.load_texture("images/background.png",
                                              scale=0.5)
        self.background1 = arcade.load_texture("images/background1.png",
                                               scale=0.5)
        self.title = arcade.load_texture("images/title.png")

        self.red_texture = arcade.load_texture("images/gun_0.png")
        self.red_texture1 = arcade.load_texture("images/gun_1.png")
        self.red_texture2 = arcade.load_texture("images/gun_0.png",
                                                mirrored=True)
        self.red_texture3 = arcade.load_texture("images/gun_1.png",
                                                mirrored=True)
        self.brown_texture = arcade.load_texture("images/gunBrown_0.png")
        self.brown_texture1 = arcade.load_texture("images/gunBrown_1.png")
        self.brown_texture2 = arcade.load_texture("images/gunBrown_0.png",
                                                  mirrored=True)
        self.brown_texture3 = arcade.load_texture("images/gunBrown_1.png",
                                                  mirrored=True)

        self.enemy_gun = arcade.load_texture("images/tank_1.png")
        self.boss_gun = arcade.load_texture("images/boss_1.png")

        self.hp = []
        self.hp.append(arcade.load_texture("images/dead.png"))
        self.hp.append(arcade.load_texture("images/hp_4.png"))
        self.hp.append(arcade.load_texture("images/hp_3.png"))
        self.hp.append(arcade.load_texture("images/hp_2.png"))
        self.hp.append(arcade.load_texture("images/hp_1.png"))
        self.hp.append(arcade.load_texture("images/hp_0.png"))
        self.god = arcade.load_texture("images/god.png")

        self.player_list = arcade.SpriteList()
        self.wall_list = arcade.SpriteList()
        self.bullet_list = arcade.SpriteList()
        self.enemy_list = arcade.SpriteList()
        self.enemy_bullet_list = arcade.SpriteList()
        self.pickup_list = arcade.SpriteList()
        self.toxin_list = arcade.SpriteList()
        self.boss_list = arcade.SpriteList()
        self.boss_bullet_list = arcade.SpriteList()

        self.player_sprite = Player()
        self.player_sprite.center_x = 80
        self.player_sprite.center_y = SCREEN_HEIGHT // 2
        self.player_list.append(self.player_sprite)
        self.view_left = 0
        self.view_bottom = 0

        ammo1 = 40
        ammo2 = 0
        ammo3 = 0

        # draw boxes function

        def draw_box_horizontal(type, start_x, num, y, scaling):
            if type == -1:
                wall_sprite = "images/boxFloor.png"
            if type == 0:
                wall_sprite = "images/blank128x128.png"
            if type == 1:
                wall_sprite = "images/platform.png"
            if type == 2:
                wall_sprite = "images/box.png"
            if type == 3:
                wall_sprite = "images/frame.png"
            for x in range(start_x, start_x + num * int(128 * scaling),
                           int(128 * scaling)):
                wall = arcade.Sprite(wall_sprite, scaling)
                if type == 4:
                    wall.death = True
                wall.center_x = x
                wall.center_y = y
                self.wall_list.append(wall)

        def draw_box_vertical(type, start_y, num, x, scaling):
            if type == 0:
                wall_sprite = "images/blank128x128.png"
            if type == 1:
                wall_sprite = "images/platform.png"
            if type == 2:
                wall_sprite = "images/box.png"
            if type == 3:
                wall_sprite = "images/frame.png"
            for y in range(start_y, start_y + num * int(128 * scaling),
                           int(128 * scaling)):
                wall = arcade.Sprite(wall_sprite, scaling)
                wall.center_x = x
                wall.center_y = y
                self.wall_list.append(wall)

        def pickup_spawn(type, x, y, amount):
            if type == 0:
                pickup = arcade.Sprite("images/heart.png", 0.5)
            if type == 1:
                pickup = arcade.Sprite("images/ammo_0.png", 1.5)
            if type == 2:
                pickup = arcade.Sprite("images/ammo_1.png", 1.5)
            if type == 3:
                pickup = arcade.Sprite("images/ammo_2.png", 1.5)
            pickup.type = type
            pickup.center_y = y
            pickup.center_x = x
            pickup.amount = amount
            self.pickup_list.append(pickup)

        def toxin_spawn(start_x, num, y, scaling):
            for x in range(start_x, start_x + num * int(128 * scaling),
                           int(128 * scaling)):
                toxin = arcade.Sprite("images/toxin.png", scaling)
                toxin.center_x = x
                toxin.center_y = y
                self.toxin_list.append(toxin)

        def enemy_spawn(x, y, start_x, end_x, stationary, detection_range):
            enemy = arcade.Sprite('images/tank_0.png')
            if stationary is True:
                enemy.change_x = 0
            else:
                enemy.change_x = 1
            enemy.boundary_left = start_x
            enemy.boundary_right = end_x
            enemy.bottom = y + 32
            enemy.left = x
            enemy.clock = 0
            enemy.health = 10
            enemy.gun_angle = 90
            enemy.detection_range = detection_range
            self.enemy_list.append(enemy)

        # drawing map
        draw_box_horizontal(-1, -640, 400, 16 - 28 * 2, 1 / 4)
        draw_box_horizontal(-1, -640 - 16, 400, 16 - 28, 1 / 4)
        draw_box_horizontal(-1, -640, 400, 16, 1 / 4)
        draw_box_vertical(0, 1, 50, -256, 1 / 4)

        enemy_spawn(580, 412, None, None, True, 600)
        pickup_spawn(2, 700, 460, 5)

        draw_box_horizontal(1, 173, 20, 140, 3 / 16)
        pickup_spawn(1, 1060, 48, 50)

        draw_box_vertical(2, 184, 2, 465, 1 / 2)
        draw_box_vertical(2, 380, 1, 630, 1)
        draw_box_horizontal(1, 758 - 48, 2, 380 + 48, 1 / 4)

        draw_box_horizontal(3, 792 + 48, 1, 300, 1 / 4)
        draw_box_horizontal(1, 806, 6, 180, 1 / 4)

        enemy_spawn(1300, 192, 1170, 1420, False, 400)

        draw_box_horizontal(2, 1200, 2, 64, 1 / 2)
        draw_box_horizontal(2, 1200, 1, 128, 1 / 2)
        draw_box_horizontal(3, 1264, 1, 128, 1 / 2)
        draw_box_horizontal(2, 1200, 1, 192, 1 / 2)
        draw_box_horizontal(2, 1264, 3, 192, 1 / 2)
        draw_box_horizontal(1, 1296 + 8, 8, 192 - 40, 1 / 8)
        draw_box_horizontal(2, 1264 + 64 * 5, 1, 128, 1 / 2)
        draw_box_horizontal(1, 1584 - 24, 4, 40, 1 / 8)
        draw_box_horizontal(1, 1584 - 24, 4, 40 + 3 * 16, 1 / 8)
        draw_box_horizontal(2, 1560 + 160, 1, 44, 3 / 16)

        enemy_spawn(1400, 0, None, None, True, 450)
        pickup_spawn(2, 1325, 48, 10)
        pickup_spawn(0, 1950, 200, 0)

        draw_box_horizontal(1, 2500 - 64 - 32, 1, 48, 1 / 4)
        draw_box_horizontal(2, 2500 - 48, 1, 64, 1 / 2)
        toxin_spawn(2500, 6, 48, 1 / 4)

        draw_box_vertical(2, 48, 2, 3200, 1 / 4)
        draw_box_horizontal(3, 3360, 1, 140, 1 / 4)
        draw_box_horizontal(3, 3360 + 192, 1, 140, 1 / 4)
        draw_box_horizontal(3, 3360 + 192 * 2, 1, 140, 1 / 4)
        draw_box_horizontal(3, 3360 + 192 * 3, 1, 140, 1 / 4)
        draw_box_horizontal(3, 3360 + 192 * 4, 1, 140, 1 / 4)
        pickup_spawn(3, 4128, 400, 100)
        draw_box_horizontal(3, 4256, 1, 200, 1 / 4)

        enemy_spawn(3300, 0, None, None, False, 600)
        enemy_spawn(3780, 0, None, None, True, 600)
        enemy_spawn(3780, 0, None, None, False, 600)
        enemy_spawn(4380 - 128, 0, None, None, False, 400)
        draw_box_vertical(2, 40, 1, 4380, 1 / 8)

        draw_box_horizontal(1, 4890, 20, 140, 3 / 16)
        toxin_spawn(4980, 2, 164, 3 / 16)
        toxin_spawn(4980, 2, 164 + 24, 3 / 16)
        pickup_spawn(0, 5100, 170, None)
        toxin_spawn(5250, 3, 164, 3 / 16)
        enemy_spawn(5000, 0, None, None, True, 500)
        enemy_spawn(5512, 0, None, None, True, 500)
        pickup_spawn(2, 5930, 64, 20)

        boss = arcade.Sprite("images/boss_0.png")
        boss.bottom = 32
        boss.left = 7000
        boss.change_x = 0
        boss.health = 150
        boss.gun_angle = 180
        boss.clock = 0
        boss.random_clock = 0
        self.boss_list.append(boss)

        self.physics_engine = arcade.PhysicsEnginePlatformer(
            self.player_sprite, self.wall_list, gravity_constant=GRAVITY)
Exemplo n.º 31
0
def _create_sprite_from_tile(map_object: pytiled_parser.objects.TileMap,
                             tile: pytiled_parser.objects.Tile,
                             scaling: float = 1.0,
                             base_directory: str = None,
                             hit_box_algorithm="Simple",
                             hit_box_detail: float = 4.5):
    """
    Given a tile from the parser, see if we can create a sprite from it
    """

    # --- Step 1, find a reference to an image this is going to be based off of
    map_source = map_object.tmx_file
    map_directory = os.path.dirname(map_source)
    image_file = _get_image_source(tile, base_directory, map_directory)

    # print(f"Creating tile: {tmx_file}")
    if tile.animation:
        # my_sprite = AnimatedTimeSprite(tmx_file, scaling)
        my_sprite: Sprite = AnimatedTimeBasedSprite(image_file, scaling)
    else:
        image_x, image_y, width, height = _get_image_info_from_tileset(tile)
        my_sprite = Sprite(image_file,
                           scaling,
                           image_x,
                           image_y,
                           width,
                           height,
                           flipped_horizontally=tile.flipped_horizontally,
                           flipped_vertically=tile.flipped_vertically,
                           flipped_diagonally=tile.flipped_diagonally,
                           hit_box_algorithm=hit_box_algorithm,
                           hit_box_detail=hit_box_detail)

    if tile.properties is not None and len(tile.properties) > 0:
        for my_property in tile.properties:
            my_sprite.properties[my_property.name] = my_property.value

    if tile.type_:
        my_sprite.properties['type'] = tile.type_

        # print(tile.image.source, my_sprite.center_x, my_sprite.center_y)
    if tile.objectgroup is not None:

        if len(tile.objectgroup) > 1:
            print(
                f"Warning, only one hit box supported for tile with image {tile.image.source}."
            )

        for hitbox in tile.objectgroup:
            points: List[Point] = []
            if isinstance(hitbox, pytiled_parser.objects.RectangleObject):
                if hitbox.size is None:
                    print(
                        f"Warning: Rectangle hitbox created for without a "
                        f"height or width for {tile.image.source}. Ignoring.")
                    continue

                # print(my_sprite.width, my_sprite.height)
                sx = hitbox.location[0] - (my_sprite.width / (scaling * 2))
                sy = -(hitbox.location[1] - (my_sprite.height / (scaling * 2)))
                ex = (hitbox.location[0] + hitbox.size[0]) - (my_sprite.width /
                                                              (scaling * 2))
                ey = -((hitbox.location[1] + hitbox.size[1]) -
                       (my_sprite.height / (scaling * 2)))

                # print(f"Size: {hitbox.size} Location: {hitbox.location}")
                p1 = [sx, sy]
                p2 = [ex, sy]
                p3 = [ex, ey]
                p4 = [sx, ey]
                # print(f"w:{my_sprite.width:.1f}, h:{my_sprite.height:.1f}", end=", ")
                points = [p1, p2, p3, p4]
                # for point in points:
                #     print(f"({point[0]:.1f}, {point[1]:.1f}) ")
                # print()

            elif isinstance(hitbox, pytiled_parser.objects.PolygonObject) \
                    or isinstance(hitbox, pytiled_parser.objects.PolylineObject):
                for point in hitbox.points:
                    adj_x = point[0] + hitbox.location[0] - my_sprite.width / (
                        scaling * 2)
                    adj_y = -(point[1] + hitbox.location[1] -
                              my_sprite.height / (scaling * 2))
                    adj_point = [adj_x, adj_y]
                    points.append(adj_point)

                # If we have a polyline, and it is closed, we need to
                # remove the duplicate end-point
                if points[0][0] == points[-1][0] and points[0][1] == points[
                        -1][1]:
                    points.pop()

            elif isinstance(hitbox, pytiled_parser.objects.ElipseObject):
                if hitbox.size is None:
                    print(
                        f"Warning: Ellipse hitbox created for without a height "
                        f"or width for {tile.image.source}. Ignoring.")
                    continue

                # print(f"Size: {hitbox.size} Location: {hitbox.location}")

                hw = hitbox.size[0] / 2
                hh = hitbox.size[1] / 2
                cx = hitbox.location[0] + hw
                cy = hitbox.location[1] + hh

                acx = cx - (my_sprite.width / (scaling * 2))
                acy = cy - (my_sprite.height / (scaling * 2))

                # print(f"acx: {acx} acy: {acy} cx: {cx} cy: {cy} hh: {hh} hw: {hw}")

                total_steps = 8
                angles = [
                    step / total_steps * 2 * math.pi
                    for step in range(total_steps)
                ]
                for angle in angles:
                    x = (hw * math.cos(angle) + acx)
                    y = (-(hh * math.sin(angle) + acy))
                    point = [x, y]
                    points.append(point)

                # for point in points:
                #     print(f"({point[0]:.1f}, {point[1]:.1f}) ")
                # print()

            else:
                print(f"Warning: Hitbox type {type(hitbox)} not supported.")

            my_sprite.set_hit_box(points)

    if tile.animation is not None:
        # Animated image
        key_frame_list = []
        # Loop through each frame
        for frame in tile.animation:
            # Get the tile for the frame
            frame_tile = _get_tile_by_id(map_object, tile.tileset,
                                         frame.tile_id)
            if frame_tile:

                image_file = _get_image_source(frame_tile, base_directory,
                                               map_directory)

                # Does the tile have an image?
                if frame_tile.image:
                    # Yes, use it
                    texture = load_texture(image_file)
                else:
                    # No image for tile? Pull from tilesheet
                    image_x, image_y, width, height = _get_image_info_from_tileset(
                        frame_tile)

                    texture = load_texture(image_file, image_x, image_y, width,
                                           height)

                key_frame = AnimationKeyframe(frame.tile_id, frame.duration,
                                              texture)
                key_frame_list.append(key_frame)
                # If this is the first texture in the animation, go ahead and
                # set it as the current texture.
                if len(key_frame_list) == 1:
                    my_sprite.texture = key_frame.texture
                # print(f"Add tile {frame.tile_id} for keyframe. Source: {frame_tile.image.source}")

        cast(AnimatedTimeBasedSprite, my_sprite).frames = key_frame_list

    return my_sprite
Exemplo n.º 32
0
                       arcade.color.YELLOW, 90, 360, -45)

# Draw an rectangle outline
arcade.draw_text("draw_rect", 243, 3, arcade.color.WHITE, 10)
arcade.draw_rectangle_outline(295, 100, 45, 65,
                              arcade.color.BRITISH_RACING_GREEN)
arcade.draw_rectangle_outline(295, 160, 20, 45,
                              arcade.color.BRITISH_RACING_GREEN, 3, 45)

# Draw a filled in rectangle
arcade.draw_text("draw_filled_rect", 363, 3, arcade.color.WHITE, 10)
arcade.draw_rectangle_filled(420, 100, 45, 65, arcade.color.BLUSH)
arcade.draw_rectangle_filled(420, 160, 20, 40, arcade.color.BLUSH, 45)

# Load and draw an image to the screen
# Image from kenney.nl asset pack #1
arcade.draw_text("draw_bitmap", 483, 3, arcade.color.WHITE, 12)
texture = arcade.load_texture("images/playerShip1_orange.png")
scale = .6
arcade.draw_texture_rectangle(540, 120, scale * texture.width,
                               scale * texture.height, texture, 0)
arcade.draw_texture_rectangle(540, 60, scale * texture.width,
                               scale * texture.height, texture, 45)

# Finish the render.
# Nothing will be drawn without this.
# Must happen after all draw commands
arcade.finish_render()

# Keep the window up until someone closes it.
arcade.run()
Exemplo n.º 33
0
    def __init__(self):
        super().__init__()
        self.side_check = 1
        self.texture_check = 0
        self.LSPRITE_TEXTURE = 0
        self.RSPRITE_TEXTURE = 2
        self.health = 5
        # player_0 standing
        # player_1 leg up1
        # player_2 leg up2

        # gun 1, 0-5
        texture = arcade.load_texture("images/player_0.png",
                                      mirrored=True,
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/player_1.png",
                                      mirrored=True,
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/player_2.png",
                                      mirrored=True,
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/player_0.png",
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/player_1.png",
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/player_2.png",
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        # gun 2. 6-11
        texture = arcade.load_texture("images/playerRED_0.png",
                                      mirrored=True,
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/playerRED_1.png",
                                      mirrored=True,
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/playerRED_2.png",
                                      mirrored=True,
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/playerRED_0.png",
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/playerRED_1.png",
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/playerRED_2.png",
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        # gun 3. 12-17
        texture = arcade.load_texture("images/playerBROWN_0.png",
                                      mirrored=True,
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/playerBROWN_1.png",
                                      mirrored=True,
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/playerBROWN_2.png",
                                      mirrored=True,
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/playerBROWN_0.png",
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/playerBROWN_1.png",
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        texture = arcade.load_texture("images/playerBROWN_2.png",
                                      scale=SPRITE_SCALING)
        self.textures.append(texture)
        # By default, face right.
        self.set_texture(3)
Exemplo n.º 34
0
 def __init__(self, x, y, imgPath1, imgPath2):
     super().__init__(x, y)
     self.texture1 = arcade.load_texture(imgPath1)
     self.texture2 = arcade.load_texture(imgPath2)
Exemplo n.º 35
0
    def set_asset(self):
        self.background = []

        for i in range(4):
            self.background.append(
                arcade.Sprite('asset/b' + (str)(i + 1) + '.png'))
            self.background[i].set_position(400, 330)

        self.star_texture = {}
        for i in range(17):
            self.star_texture[2**(i + 1)] = arcade.load_texture('asset/s' +
                                                                (str)(i + 1) +
                                                                '.png')
        #for i in range(12,17):
        #    self.star_texture[2**(i+1)] = arcade.load_texture('asset/s12.png')
        self.star_texture[-3] = arcade.load_texture('asset/h4.png')
        self.star_texture[-2] = arcade.load_texture('asset/h5.png')
        self.star_texture[-1] = arcade.load_texture('asset/h6.png')

        self.item_texture = {}
        for i in range(4):
            self.item_texture[i] = arcade.load_texture('asset/h' + (str)(i) +
                                                       '.png')
        self.item_texture[4] = arcade.load_texture('asset/h7.png')
        self.item_texture[5] = arcade.load_texture('asset/h8.png')
        self.item_texture[6] = arcade.load_texture('asset/p0.png')
        self.item_texture[7] = arcade.load_texture('asset/p1.png')

        self.item_texture[8] = arcade.load_texture('asset/first.png')
        self.item_texture[9] = arcade.load_texture('asset/over.png')
        self.item_texture[10] = arcade.load_texture('asset/tutorial.png')
        self.item_texture[11] = arcade.load_texture('asset/pause.png')
        self.item_texture[12] = arcade.load_texture('asset/win.png')
Exemplo n.º 36
0
class StartGame(arcade.View):
    Hero = hero(100, "Zkiller")
    Barriers = Barrier(25, 341)
    backdrop = arcade.load_texture("../../SpriteLists/backdrop.png")
    direction = ""
    valueFor = 5
    valueForX = 5
    wave = 1
    score = 0
    enemyList = []

    def setupHeroBoundary(self, lowerYbarrier, upperYbarrier, heroY,
                          leftXbarrier, rightXbarrier, heroX):
        """ partial """
        if heroY > upperYbarrier:
            self.valueFor = 0
            if self.direction == "DOWN":
                self.Hero.setSpeed(self.valueForX)
                self.valueFor = 5
            if self.direction == "UP":
                self.Hero.setSpeed(self.valueFor)

        if heroY < lowerYbarrier + 50:
            self.valueFor = 0
            if self.direction == "UP":
                self.valueFor = 5
                self.Hero.setSpeed(self.valueForX)
            if self.direction == "DOWN":
                self.Hero.setSpeed(self.valueFor)

        if heroX > rightXbarrier:
            self.valueForX = 0
            if self.direction == "LEFT":
                self.Hero.setSpeed(self.valueFor)
                self.valueForX = 5
            if self.direction == "RIGHT":
                self.Hero.setSpeed(self.valueForX)

        if heroX < leftXbarrier:
            self.valueForX = 0
            if self.direction == "RIGHT":
                self.valueForX = 5
                self.Hero.setSpeed(self.valueFor)
            if self.direction == "LEFT":
                self.Hero.setSpeed(self.valueForX)

    def on_show(self):
        arcade.set_background_color((123, 156, 24, 255))

    def on_draw(self):
        arcade.start_render()
        arcade.draw_lrwh_rectangle_textured(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
                                            self.backdrop)
        arcade.draw_rectangle_filled(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 50,
                                     SCREEN_WIDTH, 100, (127, 212, 23, 127))
        arcade.draw_text_2(f"score:{self.score}",
                           100,
                           SCREEN_HEIGHT - 100,
                           arcade.color.WHITE,
                           15,
                           align="center")
        self.Barriers.draw_wall_up()
        self.Hero.draw_hero()
        self.Barriers.draw_wall_down()
        self.Hero.bulletDraw()

    def on_key_press(self, key, modifier):
        if key == arcade.key.LEFT:
            self.Hero.setDirection("LEFT")
            self.Hero.setSpeed(self.valueForX)
            self.direction = "LEFT"
        if key == arcade.key.RIGHT:
            self.Hero.setDirection("RIGHT")
            self.Hero.setSpeed(self.valueForX)
            self.direction = "RIGHT"
        if key == arcade.key.DOWN:
            self.Hero.setDirection("DOWN")
            self.Hero.setSpeed(self.valueFor)
            self.direction = "DOWN"
        if key == arcade.key.UP:
            self.Hero.setDirection("UP")
            self.Hero.setSpeed(self.valueFor)
            self.direction = "UP"
        if key == arcade.key.A:
            self.Hero.hero_attact()

    def on_key_release(self, key, modifier):
        self.Hero.setSpeed(0)

    def on_update(self, delta_time):
        self.Hero.update_hero()
        self.Hero.move()
        self.setupHeroBoundary(self.Barriers.getWalllistDown(),
                               self.Barriers.getWalllistUp(),
                               self.Hero.getHeroY(), 50, SCREEN_WIDTH - 50,
                               self.Hero.getHeroX())

        self.Hero.bulletUpadate()

        self.Hero.bulletCheck()
        '''change = False 
Exemplo n.º 37
0
import arcade
import os

# set the text for the meme
line1 = "1goodVariableName"
line2 = "good_variable_name1"

# set the dimensions of the window, based on the image
height = 640
width = 550
arcade.open_window(height, width, "Meme Generator")

arcade.set_background_color(arcade.color.WHITE)

arcade.start_render()

# load the image
texture = arcade.load_texture("images/drake_meme.jpg")
arcade.draw_texture_rectangle(texture.width//2, texture.height//2, texture.width,
                              texture.height, texture, 0)

# render the text
arcade.draw_text(line1, width//2 + 100, height - height//3, arcade.color.BLACK, 12)
arcade.draw_text(line2, width//2 + 100, height//2 - height//4,
                 arcade.color.BLACK, 12)

arcade.finish_render()

arcade.run()
Exemplo n.º 38
0
    def on_draw(self):
        arcade.start_render()
        if self.page_number == 0:
            arcade.draw_circle_filled(50, 50, 500, arcade.color.WHITE)
            arcade.set_background_color(arcade.color.GRAY)
            if time() - self.time_check >= 1:
                self.motion = randint(0, 2)
                self.time_check = time()
            pic = [
                arcade.load_texture('pics/menu/menu1.png'),
                arcade.load_texture('pics/menu/menu2.png', ),
                arcade.load_texture('pics/menu/menu3.png')
            ]
            # For menu pic
            for each_pic in pic:
                self.set_center(each_pic)
            arcade.draw_texture_rectangle(pic[self.motion].center_x,
                                          pic[self.motion].center_y,
                                          texture=pic[self.motion],
                                          height=700,
                                          width=900)
            #For 1.3.7
            #arcade.draw_text('Press ENTER to start the game', 0, 100, arcade.color.AMETHYST, width=self.width,
            #                    font_size=35)
            arcade.draw_text('Press ENTER to start the game',
                             0,
                             100,
                             arcade.color.AMETHYST,
                             font_size=35)
            arcade.draw_text('Just An Ordinary Dungeon Crawler game',
                             0,
                             200,
                             arcade.color.GOLD_FUSION,
                             font_size=50,
                             width=3500)

        elif self.page_number == -1:
            self.menu.draw()

        elif self.page_number == 1:
            arcade.draw_texture_rectangle(self.bg.center_x,
                                          self.bg.center_y,
                                          texture=self.bg,
                                          height=600,
                                          width=800)
            self.player.draw()
            self.enemy_type.draw()
            self.player.attack(self.time_check)
            self.map.map_component()
            arcade.draw_text(f'The current level is {self.level}',
                             self.width - 200, self.height - 100,
                             arcade.color.BLACK)
            arcade.draw_text(f'Current life {self.player.life}', 100,
                             self.height - 100, arcade.color.BLACK)
            arcade.draw_text(f'Current Money {self.MONEY}',
                             self.width // 2 - 50, self.height - 100,
                             arcade.color.BLACK)
            self.shield.draw()
            if self.hurt_status:
                arcade.draw_rectangle_outline(self.width // 2,
                                              self.height // 2, self.width,
                                              self.height, arcade.color.RED,
                                              10)
                if time() - self.hurt_time >= 1.5:
                    self.hurt_status = False

        elif self.page_number == -3 or self.page_number == -2:
            tutorial = arcade.load_texture('pics/scene/t2.png')
            if self.page_number == -2:
                tutorial = arcade.load_texture('pics/scene/t1.png')
            self.set_center(tutorial)
            arcade.draw_texture_rectangle(tutorial.center_x,
                                          tutorial.center_y,
                                          texture=tutorial,
                                          height=600,
                                          width=800)

        elif self.page_number == 3:
            bonus = arcade.load_texture('pics/game_over/game.png')
            self.set_center(bonus)
            arcade.draw_texture_rectangle(bonus.center_x,
                                          bonus.center_y,
                                          texture=bonus,
                                          height=700,
                                          width=900)
        self.dialog.on_draw(self.dialog_status)