def __init__(self, width, height, title): super().__init__(width, height, title) arcade.set_background_color(arcade.color.WHITE) self.player = arcade.Sprite(center_x=100, center_y=100) self.player.texture = arcade.make_soft_square_texture( 50, arcade.color.BLUE, outer_alpha=255) self.enemy_texture = arcade.make_soft_square_texture(50, arcade.color.RED, outer_alpha=255) self.enemies = arcade.SpriteList() # create an enemy for _ in range(3): enemy = arcade.Sprite() enemy.center_x = random.randrange(0, WIDTH) enemy.center_y = random.randrange(HEIGHT // 2, HEIGHT) enemy.texture = self.enemy_texture self.enemies.append(enemy) self.laser_texture = arcade.make_soft_square_texture( 30, arcade.color.ORANGE, outer_alpha=255) self.lasers = arcade.SpriteList()
def __init__(self): super().__init__() self.director = None arcade.set_background_color(arcade.color.BLACK) # self.set_location(400, 200) self.player_x = 40 self.player_y = 590 self.speed = 1 self.playerRight = False self.playerLeft = False self.playerUp = False self.playerDown = False self.sprite_player = arcade.Sprite(center_x=self.player_x, center_y=self.player_y) self.sprite_player.texture = arcade.make_soft_square_texture( 16, arcade.color.WHITE, outer_alpha=255) self.spriteList = arcade.SpriteList() for y in range(len(LEVEL)): for x in range(len(LEVEL[y])): # Get the Character at each x, y coordinate # NOTE the order of the y and x in the next line character = LEVEL[y][x] # Calculate the screen x, y coordinates screen_x = 10 + (x * 20) screen_y = 590 - (y * 20) if character == "X": self.sprite2 = arcade.Sprite(center_x=screen_x, center_y=screen_y) self.sprite2.texture = arcade.make_soft_square_texture( 20, arcade.color.RED, outer_alpha=255) self.spriteList.append(self.sprite2)
def __init__(self, width, height, title): super().__init__(width, height, title) arcade.set_background_color(arcade.color.WHITE) self.sprite1 = arcade.Sprite(center_x=100, center_y=200) self.sprite1.change_x = 1 self.sprite1.texture = arcade.make_soft_square_texture( 50, arcade.color.BLACK, outer_alpha=255) self.sprite2 = arcade.Sprite(center_x=WIDTH - 100, center_y=200) self.sprite2.texture = arcade.make_soft_square_texture( 50, arcade.color.BLUE, outer_alpha=255)
def __init__(self, center_x, center_y, angle): super().__init__() self.center_x = center_x self.center_y = center_y self.angle = angle self.texture = arcade.make_soft_square_texture(310, arcade.color.RED, outer_alpha=255) self.width = 10
def __init__(self, center_x: int, center_y: int, owner: 'Player'): super().__init__(center_x=center_x, center_y=center_y) self.texture = arcade.make_soft_square_texture(20, arcade.color.ORANGE, outer_alpha=255) self.target_queue = [] self.current_target = None self.owner = owner
def __init__(self): super().__init__() arcade.set_background_color(arcade.color.BLACK) centerx_of_screen = WIDTH / 2 centery_of_screen = HEIGHT / 2 self.MOVEMENT_SPEED = 5 self.STARTING_ENEMY_COUNT = 15 self.sprite1 = arcade.Sprite(center_x=centerx_of_screen, center_y=centery_of_screen) self.sprite1.texture = arcade.make_soft_square_texture( 30, arcade.color.WHITE, outer_alpha=255) self.player1 = arcade.SpriteList() self.player1.append(self.sprite1) self.lives = 3 self.left_pressed = False self.right_pressed = False self.up_pressed = False self.down_pressed = False self.enemy_texture = arcade.make_soft_square_texture(30, arcade.color.RED, outer_alpha=255) self.enemies = arcade.SpriteList() for i in range(self.STARTING_ENEMY_COUNT): enemy = arcade.Sprite() enemy.center_x = random.randrange(0, WIDTH - 15) enemy.center_y = random.randrange(0, HEIGHT - 15) enemy.texture = self.enemy_texture enemy.change_x = random.random() * 3 enemy.change_y = random.random() * 3 enemy.change_angle = random.random() * 0 self.enemies.append(enemy) self.laser_texture = arcade.make_soft_square_texture(5, arcade.color.BLUE, outer_alpha=255) self.lasers = arcade.SpriteList()
def __init__(self, width, height, title): super().__init__(width, height, title) arcade.set_background_color(arcade.color.WHITE) self.sprite1 = arcade.Sprite(center_x=100, center_y=200) self.sprite1.texture = arcade.make_soft_square_texture( 50, arcade.color.BLACK, outer_alpha=255) self.sprite1.change_x = 3 # add a sprite2 # give it a texture (Blue) # place it at the opposite end of the screen # draw in draw self.sprite2 = arcade.Sprite(center_x=700, center_y=200) self.sprite2.texture = arcade.make_soft_square_texture( 30, arcade.color.BLUE, outer_alpha=255)
def test_it_has_correct_orientation_after_dimension_change( orientation, dimension): sprite = arcade.Sprite() sprite.texture = arcade.make_soft_square_texture(100, arcade.color.RED, 255, 255) sprite.position = (50, 50) original_orientation_value = getattr(sprite, orientation) assert getattr(sprite, orientation) == original_orientation_value setattr(sprite, dimension, 50) assert getattr(sprite, orientation) != original_orientation_value
def __init__(self, width, height, title): super().__init__(width, height, title) arcade.set_background_color(arcade.color.WHITE) self.player = Player(center_x=50, center_y=50) self.player.texture = arcade.make_soft_square_texture( 50, arcade.color.BLUE, outer_alpha=255) self.player.dart = Dart(self.player.center_x, self.player.center_y, self.player)
def __init__(self, image, turret): super().__init__(image) self.center_x = turret.center_x self.center_y = turret.center_y self.angle = turret.angle self.change_x = math.cos(math.radians(self.angle +90)) *5 self.change_y = math.sin(math.radians(self.angle +90)) *5 self.texture = arcade.make_soft_square_texture(30, arcade.color.ORANGE, outer_alpha=255) self.width = 5
def __init__(self, width, height, title): super().__init__(width, height, title) arcade.set_background_color(arcade.color.WHITE) self.player = arcade.Sprite(center_x=100, center_y=200) self.player.texture = arcade.make_soft_square_texture( 20, arcade.color.BLUE) self.player.width = 10 self.turret1 = arcade.Sprite(center_x=500, center_y=700) self.turret1.texture = arcade.make_soft_square_texture( 50, arcade.color.ORANGE, outer_alpha=255) self.turret1.width = 80 self.laser_texture = arcade.make_soft_square_texture( 30, arcade.color.ORANGE, outer_alpha=255) self.lasers = arcade.SpriteList() self.frame_count = 0
def lasor(self, turret): laser = arcade.Sprite() laser.center_x = turret.center_x laser.center_y = turret.center_y laser.angle = turret.angle laser.texture = arcade.make_soft_square_texture(30, arcade.color.ORANGE, outer_alpha=255) laser.width = 5 laser.change_x = math.cos(math.radians(laser.angle)) laser.change_y = math.sin(math.radians(laser.angle)) self.lasers.append(laser)
def __init__(self): self.w = 600 self.h = 600 arcade.Window.__init__(self, self.w, self.h, "Particles!") arcade.set_background_color(arcade.color.EERIE_BLACK) # Sprite for particle from image (try changing to other item numbers! 17 is hearts!) self.text_blue = arcade.load_texture( "Sprites/PNG/Items/platformPack_item001.png") # Sprite for particle pregenerated self.text_red = arcade.make_soft_circle_texture(20, arcade.color.RED) self.text_green = arcade.make_soft_square_texture( 50, arcade.color.GREEN, 200, 150) # Timer for cosine/sine purposes later self.timer = 0 # Empty list to store our emitters for easy drawing and updating self.emitters = [] # Make the center, moving emitter self.fountain = arcade.Emitter( center_xy=(self.w / 2, self.h / 2), # Position emit_controller=arcade.EmitInterval( 0.01), # When to make more particles particle_factory=lambda emitter: arcade. FadeParticle( # Type of particle filename_or_texture=self.text_blue, # Particle texture change_xy=arcade.rand_in_circle( (0, 0), 4.5), # Particle velocity lifetime=1.0, # Particle lifetime scale=0.5, # Particle scaling ), ) self.cursor = arcade.Emitter( center_xy=(self.w / 2, self.h / 2), emit_controller=arcade.EmitMaintainCount( 30), # Alway keep 30 on screen particle_factory=lambda emitter: arcade. LifetimeParticle( # Stay bright till end filename_or_texture=self.text_red, change_xy=(random.uniform(-1, 1), random.uniform(-1, 1)), lifetime=random.random( ), # die out at random times, or else this looked weird scale=1, ), ) # Add our current, always-on emitters to the list self.emitters.extend([self.fountain, self.cursor])
def __init__(self, width, height, title): super().__init__(width, height, title) arcade.set_background_color(arcade.color.AMAZON) self.texture = arcade.load_texture(":resources:images/space_shooter/playerShip1_orange.png") assert self.texture.width == 99 assert self.texture.height == 75 self.circle_texture = arcade.make_circle_texture(10, arcade.color.RED) self.soft_circle_texture = arcade.make_soft_circle_texture(10, arcade.color.RED, 255, 0) self.soft_square_texture = arcade.make_soft_square_texture(10, arcade.color.RED, 255, 0) columns = 16 count = 60 sprite_width = 256 sprite_height = 256 file_name = ":resources:images/spritesheets/explosion.png" # Load the explosions from a sprite sheet self.explosion_texture_list = arcade.load_spritesheet(file_name, sprite_width, sprite_height, columns, count)
def __init__(self, width, height, title): super().__init__(width, height, title) head_radius = 10 chest_height = 50 chest_width = 30 leg_width = 20 leg_height = 20 arm_width = 5 arm_length = 20 arm_gap = 5 shoulder_height = 5 self.shape_list = make_character(head_radius, chest_height, chest_width, leg_width, leg_height, arm_width, arm_length, arm_gap, shoulder_height) arcade.set_background_color(arcade.color.AMAZON) self.shape_list.center_x , self.shape_list.center_y = WIDTH//2, HEIGHT//2 self.shape_list.change_y -= GRAVITY self.obstacles_list = [] self.random_x = bubbleSort(random.sample(range(0, WIDTH, 75), 4)) self.random_y = bubbleSort(random.sample(range(0, HEIGHT, 50), 6)) for (i, j) in zip(self.random_x, self.random_y): self.obstacle = arcade.Sprite(center_x=i, center_y=j) self.obstacle.texture = arcade.make_soft_square_texture(50, arcade.color.BLUE, outer_alpha=255) self.obstacles_list.append(self.obstacle)
def __init__(self, width, height, title): super().__init__(width, height, title) arcade.set_background_color(arcade.color.WHITE) circle_texture = arcade.make_circle_texture(50, arcade.color.BLUE) square_texture = arcade.make_soft_square_texture(50, arcade.color.ORANGE, outer_alpha=255) self.sprites = arcade.SpriteList() for _ in range(1000): x, y = random.randrange(WIDTH), random.randrange(HEIGHT) sprite = arcade.Sprite(center_x=x, center_y=y) sprite.collides_with_list dx = random.randrange(-3, 3) dy = random.randrange(-3, 3) sprite.change_x = dx sprite.change_y = dy if random.randrange(2) == 0: # circle texture sprite.texture = circle_texture else: # square texture sprite.texture = square_texture self.sprites.append(sprite)
def on_show(self): arcade.set_background_color(arcade.color.WHITE_SMOKE) global x x = 0 self.counter = 35 self.prevsel = -1 # indicates which colour was last selected self.timer = 60 self.gsqsprites = [] self.ysqsprites = [] self.rcirsprites = [] self.bcirsprites = [] self.gsqselected = [] self.ysqselected = [] self.rcirselected = [] self.bcirselected = [] # randomly draws all sprites for i in range(self.counter): speedgsq = random.uniform(0.01, 1) speedysq = random.uniform(-1, -0.01) speedrcir = random.uniform(-1, -0.01) speedbcir = random.uniform(0.01, 1) gsq_posy = random.randrange(0, SCREEN_HEIGHT) ysq_posy = random.randrange(0, SCREEN_HEIGHT) rcir_posy = random.randrange(0, SCREEN_HEIGHT) bcir_posy = random.randrange(0, SCREEN_HEIGHT) gsq_posx = random.randrange(-1750, SCREEN_WIDTH) ysq_posx = random.randrange(SCREEN_WIDTH, 1750) rcir_posx = random.randrange(SCREEN_WIDTH, 1750) bcir_posx = random.randrange(-1750, SCREEN_WIDTH) # define greensquare self.gsq = arcade.Sprite(center_x=gsq_posx, center_y=gsq_posy) texture = arcade.make_soft_square_texture(50, arcade.color.AO, outer_alpha=200) self.gsq.texture = texture self.gsq.change_x = speedgsq self.gsqsprites.append(self.gsq) self.gsqselected.append(False) # False means not selected # define yellowsquare self.ysq = arcade.Sprite(center_x=ysq_posx, center_y=ysq_posy) texture = arcade.make_soft_square_texture(50, arcade.color.GOLD, outer_alpha=200) self.ysq.texture = texture self.ysq.change_x = speedysq self.ysqsprites.append(self.ysq) self.ysqselected.append(False) # False means not selected # define redcircle self.rcir = arcade.Sprite(center_x=rcir_posx, center_y=rcir_posy) texture = arcade.make_soft_circle_texture(50, arcade.color.RED, outer_alpha=200) self.rcir.texture = texture self.rcir.change_x = speedrcir self.rcirsprites.append(self.rcir) self.rcirselected.append(False) # False means not selected # define bluecircle self.bcir = arcade.Sprite(center_x=bcir_posx, center_y=bcir_posy) texture = arcade.make_soft_circle_texture(50, arcade.color.COAL, outer_alpha=200) self.bcir.texture = texture self.bcir.change_x = speedbcir self.bcirsprites.append(self.bcir) self.bcirselected.append(False) # False means not selected
your game sprites. To make it run faster, have arcade create a texture from a primitive shape and use it as the sprite's texture. """ import random import arcade WIDTH = 640 HEIGHT = 480 window = arcade.open_window(WIDTH, HEIGHT, "My Arcade Game") player = arcade.Sprite(center_x=0, center_y=0) # Set player texture to some created square texture player.texture = arcade.make_soft_square_texture(40, arcade.color.BLUE, outer_alpha=255) player.velocity = [1, 1] # save a coin texture for later use coin_texture = arcade.make_circle_texture(40, arcade.color.GOLD) # generate coins coins = arcade.SpriteList() for _ in range(100): # Get random location and speeds x = random.randrange(0, WIDTH) y = random.randrange(0, HEIGHT) dx = random.randrange(-5, 5) dy = random.randrange(-5, 5)
def on_mouse_press(self, x: float, y: float, button: int, modifiers: int): global total_points self.select = [ self.gsqselected, self.ysqselected, self.rcirselected, self.bcirselected ] self.sprite = [ self.gsqsprites, self.ysqsprites, self.rcirsprites, self.bcirsprites ] self.color = [ arcade.make_soft_square_texture(50, arcade.color.AO, outer_alpha=200), arcade.make_soft_square_texture(50, arcade.color.GOLD, outer_alpha=200), arcade.make_soft_circle_texture(50, arcade.color.RED, outer_alpha=200), arcade.make_soft_circle_texture(50, arcade.color.COAL, outer_alpha=200) ] self.gsqrid = [] self.ysqrid = [] self.rcirrid = [] self.bcirrid = [] self.gsqclicked = 0 self.ysqclicked = 0 self.rcirclicked = 0 self.bcirclicked = 0 # invalid selection for i in range(len(self.gsqsprites)): if self.gsqsprites[i].collides_with_point((x, y)): if self.prevsel != 0: for j in range(len(self.select[self.prevsel])): self.select[self.prevsel][j] = False color = self.color[self.prevsel] self.sprite[self.prevsel][j].texture = color self.prevsel = 0 for i in range(len(self.ysqsprites)): if self.ysqsprites[i].collides_with_point((x, y)): if self.prevsel != 1: for j in range(len(self.select[self.prevsel])): self.select[self.prevsel][j] = False color = self.color[self.prevsel] self.sprite[self.prevsel][j].texture = color self.prevsel = 1 for i in range(len(self.rcirsprites)): if self.rcirsprites[i].collides_with_point((x, y)): if self.prevsel != 2: for j in range(len(self.select[self.prevsel])): self.select[self.prevsel][j] = False color = self.color[self.prevsel] self.sprite[self.prevsel][j].texture = color self.prevsel = 2 for i in range(len(self.bcirsprites)): if self.bcirsprites[i].collides_with_point((x, y)): if self.prevsel != 3: for j in range(len(self.select[self.prevsel])): self.select[self.prevsel][j] = False color = self.color[self.prevsel] self.sprite[self.prevsel][j].texture = color self.prevsel = 3 for i in range(len(self.gsqsprites)): if self.gsqsprites[i].collides_with_point((x, y)): # character has not been clicked on before if not self.gsqselected[i]: texture = arcade.make_soft_square_texture( 50, arcade.color.AO) self.gsqsprites[i].texture = texture # character texture is returned to before being tampered with elif self.gsqselected[i]: texture = arcade.make_soft_square_texture(50, arcade.color.AO, outer_alpha=200) self.gsqsprites[i].texture = texture self.gsqselected[i] = not (self.gsqselected[i]) for i in range(len(self.ysqsprites)): if self.ysqsprites[i].collides_with_point((x, y)): # character has not been clicked on before if not self.ysqselected[i]: texture = arcade.make_soft_square_texture( 50, arcade.color.GOLD) self.ysqsprites[i].texture = texture # character texture is returned to before being tampered with elif self.ysqselected[i]: texture = arcade.make_soft_square_texture( 50, arcade.color.GOLD, outer_alpha=200) self.ysqsprites[i].texture = texture self.ysqselected[i] = not (self.ysqselected[i]) for i in range(len(self.rcirsprites)): if self.rcirsprites[i].collides_with_point((x, y)): # character has not been clicked on before if not self.rcirselected[i]: texture = arcade.make_soft_circle_texture( 50, arcade.color.RED) self.rcirsprites[i].texture = texture # character texture is returned to before being tampered with elif self.rcirselected[i]: texture = arcade.make_soft_circle_texture(50, arcade.color.RED, outer_alpha=200) self.rcirsprites[i].texture = texture self.rcirselected[i] = not (self.rcirselected[i]) for i in range(len(self.bcirsprites)): if self.bcirsprites[i].collides_with_point((x, y)): # character has not been clicked on before if not self.bcirselected[i]: texture = arcade.make_soft_circle_texture( 50, arcade.color.COAL) self.bcirsprites[i].texture = texture # character texture is returned to before being tampered with elif self.bcirselected[i]: texture = arcade.make_soft_circle_texture( 50, arcade.color.COAL, outer_alpha=200) self.bcirsprites[i].texture = texture self.bcirselected[i] = not (self.bcirselected[i]) # removes greensquare triplets for i in range(len(self.gsqselected)): if self.gsqselected[i]: self.gsqclicked += 1 if self.gsqclicked >= 3: for i in range(len(self.gsqselected)): if self.gsqselected[i]: self.gsqrid.append(i) total_points = str( int(total_points) + calc_points(self.gsqclicked)) # bubble sort to reverse list gsq_sorted = False while not gsq_sorted: gsq_sorted = True for i in range(len(self.gsqrid) - 1): b = self.gsqrid[i] a = self.gsqrid[i + 1] if a > b: self.gsqrid[i] = a self.gsqrid[i + 1] = b gsq_sorted = False for i in self.gsqrid: del self.gsqselected[i] del self.gsqsprites[i] # removes yellowsquare triplets for i in range(len(self.ysqselected)): if self.ysqselected[i]: self.ysqclicked += 1 if self.ysqclicked >= 3: for i in range(len(self.ysqselected)): if self.ysqselected[i]: self.ysqrid.append(i) total_points = str( int(total_points) + calc_points(self.ysqclicked)) # bubble sort to reverse list ysq_sorted = False while not ysq_sorted: ysq_sorted = True for i in range(len(self.ysqrid) - 1): b = self.ysqrid[i] a = self.ysqrid[i + 1] if a > b: self.ysqrid[i] = a self.ysqrid[i + 1] = b ysq_sorted = False for i in self.ysqrid: del self.ysqselected[i] del self.ysqsprites[i] # removes redcircle triplets for i in range(len(self.rcirselected)): if self.rcirselected[i]: self.rcirclicked += 1 if self.rcirclicked >= 3: for i in range(len(self.rcirselected)): if self.rcirselected[i]: self.rcirrid.append(i) total_points = str( int(total_points) + calc_points(self.rcirclicked)) # bubble sort to reverse list rcir_sorted = False while not rcir_sorted: rcir_sorted = True for i in range(len(self.rcirrid) - 1): b = self.rcirrid[i] a = self.rcirrid[i + 1] if a > b: self.rcirrid[i] = a self.rcirrid[i + 1] = b rcir_sorted = False for i in self.rcirrid: del self.rcirselected[i] del self.rcirsprites[i] # removes bluecircle triplets for i in range(len(self.bcirselected)): if self.bcirselected[i]: self.bcirclicked += 1 if self.bcirclicked >= 3: for i in range(len(self.bcirselected)): if self.bcirselected[i]: self.bcirrid.append(i) total_points = str( int(total_points) + calc_points(self.bcirclicked)) # bubble sort to reverse list bcir_sorted = False while not bcir_sorted: bcir_sorted = True for i in range(len(self.bcirrid) - 1): b = self.bcirrid[i] a = self.bcirrid[i + 1] if a > b: self.bcirrid[i] = a self.bcirrid[i + 1] = b bcir_sorted = False for i in self.bcirrid: del self.bcirselected[i] del self.bcirsprites[i]
def get_texture(self, size, color): return arcade.make_soft_square_texture(size, color, 255, 255)
def __init__(self): super().__init__() self.wall_list = arcade.SpriteList() self.cure_list = arcade.SpriteList() self.powerup_list = arcade.SpriteList() self.virus_list = arcade.SpriteList() self.score = 0 self.total_time = 0.0 self.lives = 3 arcade.set_background_color(arcade.color.BLACK) wall_texture = arcade.make_soft_square_texture(70, arcade.color.BLACK, outer_alpha=255) # Walls for x in range(32, WIDTH, 64): wall = arcade.Sprite() wall.center_x = x wall.center_y = 32 wall.texture = wall_texture self.wall_list.append(wall) wall = arcade.Sprite() wall.center_x = x wall.center_y = HEIGHT - 32 wall.texture = wall_texture self.wall_list.append(wall) for y in range(96, HEIGHT, 64): wall = arcade.Sprite() wall.center_x = 32 wall.center_y = y wall.texture = wall_texture self.wall_list.append(wall) wall = arcade.Sprite() wall.center_x = WIDTH - 32 wall.center_y = y wall.texture = wall_texture self.wall_list.append(wall) #Sprites virus_texture = arcade.make_soft_square_texture(30, arcade.color.RED, outer_alpha=255) for i in range(5): virus = arcade.Sprite() virus.texture = virus_texture virus.center_x = random.randrange(100, 900) virus.center_y = random.randrange(100, 500) while virus.change_x == 0 and virus.change_y == 0: virus.change_x = random.randrange(-2, 2) virus.change_y = random.randrange(-2, 2) self.virus_list.append(virus) cure_texture = arcade.make_soft_square_texture(40, arcade.color.NAVY_BLUE, outer_alpha=255) for i in range(25): cure = arcade.Sprite() cure.texture = cure_texture cure.center_x = random.randrange(100, 900) cure.center_y = random.randrange(100, 500) while cure.change_x == 0 and cure.change_y == 0: cure.change_x = random.randrange(-3, 3) cure.change_y = random.randrange(-3, 3) self.cure_list.append(cure) powerup_texture = arcade.make_soft_square_texture(30, arcade.color.GOLD, outer_alpha=255) for i in range(2): powerup = arcade.Sprite(center_x=1000, center_y=1200) powerup.texture = powerup_texture self.powerup_list.append(powerup) self.user = arcade.Sprite(center_x=100, center_y=90) self.user.texture = arcade.make_soft_circle_texture(30, arcade.color.WHITE, outer_alpha=255) self.left_pressed = False self.right_pressed = False self.up_pressed = False self.down_pressed = False