def __init__(self, color=arcade.color.WHITE, size=100, *args, **kwargs): super().__init__(*args, **kwargs) self.textures = [ arcade.make_soft_circle_texture(size, color, 255, 255), arcade.make_soft_circle_texture(size, arcade.color.GREEN, 255, 255) ] self.texture = self.textures[0] self.center_x = 70 self.center_y = 70
def draw(): """ Draws a mirror and returns it """ trans_blue = arcade.make_transparent_color( arcade.color.AIR_SUPERIORITY_BLUE, 0.66) mirror = arcade.make_soft_circle_texture(5, trans_blue, 240, 10) return mirror
def __init__(self, *args, **kwargs): size = kwargs.pop('size', 100) super().__init__(*args, **kwargs) self.textures = [ arcade.make_soft_circle_texture(size, arcade.color.WHITE, 255, 255), ] self.texture = self.textures[0]
def __init__(self, texture, x, y, r): super().__init__() self.texture = arcade.load_texture(texture) self.center_x = x self.center_y = y self.angle = r self.health = 50 self.should_die = False self.texture_smoke = arcade.make_soft_circle_texture( 40, arcade.color.GRAY) self.emitter = None
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 emitter_34(): """Dynamically generated textures, burst emitting, fading particles""" textures = [arcade.make_soft_circle_texture(48, p) for p in (arcade.color.GREEN, arcade.color.BLUE_GREEN)] e = arcade.Emitter( center_xy=CENTER_POS, emit_controller=arcade.EmitBurst(BURST_PARTICLE_COUNT), particle_factory=lambda emitter: arcade.FadeParticle( filename_or_texture=random.choice(textures), change_xy=arcade.rand_in_circle((0.0, 0.0), PARTICLE_SPEED_FAST), lifetime=DEFAULT_PARTICLE_LIFETIME, scale=DEFAULT_SCALE ) ) return emitter_34.__doc__, e
def __init__(self, radius: int, color: Color, soft: bool = False): """ :param float radius: Radius of the circle :param Color color: Color of the circle :param bool soft: If True, will add a alpha gradient """ super().__init__() if soft: self.texture = make_soft_circle_texture(radius * 2, color) else: self.texture = make_circle_texture(radius * 2, color) self._points = self.texture.hit_box_points
def emitter_35(): """Use most features""" soft_circle = arcade.make_soft_circle_texture(80, (255, 64, 64)) textures = (TEXTURE, TEXTURE2, TEXTURE3, TEXTURE4, TEXTURE5, TEXTURE6, TEXTURE7, soft_circle) e = arcade.Emitter( pos=CENTER_POS, emit_controller=arcade.EmitterIntervalWithTime(0.01, 1.0), particle_factory=lambda emitter: arcade.FadeParticle( filename_or_texture=random.choice(textures), vel=arcade.rand_in_circle(Vec2d.zero(), PARTICLE_SPEED_FAST * 2), lifetime=random.uniform(1.0, 3.5), angle=random.uniform(0, 360), change_angle=random.uniform(-3, 3), scale=random.uniform(0.1, 0.8))) return emitter_35.__doc__, e
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)
import random from typing import TYPE_CHECKING import PIL.Image import arcade from gnp.arcadelib import scriptutl from flapping import flapping_cfg as CFG if TYPE_CHECKING: from flapping.flap_app import Game DUST_TEXTURE = arcade.make_soft_circle_texture(diameter=20, color=arcade.color.GRAY) class ControllableEmitInterval(arcade.EmitController): """Emit particles on an interval and can manually stop emitting""" def __init__(self, emit_interval: float): self._emit_interval = emit_interval self._carryover_time = 0.0 self.active = False def how_many(self, delta_time: float, current_particle_count: int) -> int: if not self.active: return 0 self._carryover_time += delta_time emit_count = 0 while self._carryover_time >= self._emit_interval: self._carryover_time -= self._emit_interval emit_count += 1 return emit_count
def get_texture(self, size, color): return arcade.make_soft_circle_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
import os import os.path import arcade from gnp.arcadelib.timers import Timers from gnp.arcadelib.actor import ActorList from gnp.arcadelib import scriptutl from flapping import flapping_cfg as CFG from flapping import event from flapping import collision from flapping.player import Player from flapping.registration import Registration CIRCLE_TEXTURE = arcade.make_soft_circle_texture(diameter=20, color=arcade.color.WHITE) class Game(arcade.Window): # game states WELCOME = 'welcome' REGISTRATION = 'registration' PLAY = 'gameplay' SCOREBOARD = 'scoreboard' def on_resize(self, width: float, height: float): # prevent arcade.Window.on_resize from changing the viewport on startup pass def __init__(self, width, height, title, fullscreen): super().__init__(width, height, title, fullscreen)
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 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
import random import arcade # Define constants WINDOW_WIDTH = 500 WINDOW_HEIGHT = 500 BACKGROUND_COLOR = arcade.color.BLACK GAME_TITLE = "Red Dot Fetch" DOT_SIZE = 50 DOT_SPEED = 4 RED_DOT_IMAGE = arcade.make_soft_circle_texture(DOT_SIZE, arcade.color.RED, 255, 128) class RedDot(arcade.Sprite): def __init__(self): super().__init__() self.texture = RED_DOT_IMAGE self.center_x = random.randint(0, WINDOW_WIDTH) self.center_y = random.randint(0, WINDOW_HEIGHT) self.velocity = [random.randint(0, 4), random.randint(0, 4)] def update(self): super().update() if self.right > WINDOW_WIDTH: self.change_x *= -1 if self.left < 0: self.change_x *= -1 if self.top > WINDOW_HEIGHT: self.change_y *= -1 if self.bottom < 0: self.change_y *= -1
arcade.color.ELECTRIC_YELLOW, arcade.color.ELECTRIC_GREEN, arcade.color.ELECTRIC_CYAN, arcade.color.MEDIUM_ELECTRIC_BLUE, arcade.color.ELECTRIC_INDIGO, arcade.color.ELECTRIC_PURPLE, ) SPARK_TEXTURES = [ arcade.make_circle_texture(15, clr) for clr in RAINBOW_COLORS ] SPARK_PAIRS = [ [SPARK_TEXTURES[0], SPARK_TEXTURES[3]], [SPARK_TEXTURES[1], SPARK_TEXTURES[5]], [SPARK_TEXTURES[7], SPARK_TEXTURES[2]], ] ROCKET_SMOKE_TEXTURE = arcade.make_soft_circle_texture(15, arcade.color.GRAY) PUFF_TEXTURE = arcade.make_soft_circle_texture(80, (40, 40, 40)) FLASH_TEXTURE = arcade.make_soft_circle_texture(70, (128, 128, 90)) CLOUD_TEXTURES = [ arcade.make_soft_circle_texture(50, arcade.color.WHITE), arcade.make_soft_circle_texture(50, arcade.color.LIGHT_GRAY), arcade.make_soft_circle_texture(50, arcade.color.LIGHT_BLUE), ] STAR_TEXTURES = [ arcade.make_soft_circle_texture(6, arcade.color.WHITE), arcade.make_soft_circle_texture(6, arcade.color.PASTEL_YELLOW), ] SPINNER_HEIGHT = 75 def make_spinner():
import os import random import pyglet import imgui import imgui.core from imdemo.page import Page from imdemo.particle import AnimatedAlphaParticle SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 SCREEN_TITLE = "Particle based fireworks" CLOUD_TEXTURES = [ arcade.make_soft_circle_texture(50, arcade.color.WHITE), arcade.make_soft_circle_texture(50, arcade.color.LIGHT_GRAY), arcade.make_soft_circle_texture(50, arcade.color.LIGHT_BLUE), ] class CloudPage(Page): def reset(self): self.create_emitter() def on_show(self): arcade.set_background_color(arcade.color.BLACK) def create_emitter(self): self.emitter = arcade.Emitter( center_xy=(500, 500), change_xy=(0.15, 0),