def __init__(self, color, height=20, width=100, inverse=False, *args, **kwargs): SquareSprite.__init__(self, *args, **kwargs) self.width = width self.height = height self.color = color self.orientation = 'right' if inverse else 'left'
def powerup(sprite): flash = SquareSprite() flash.color = arcade.color.GOLD flash.position = sprite.position target = (sprite.center_x, sprite.center_y + 100) seq = Sequence() seq[0].frame = KeyFrame.from_sprite(sprite, ['position', 'scale', 'alpha']) seq[1].frame = KeyFrame(position=target, scale=1.5, alpha=0) seq[1].callback = flash.kill arcade.get_window().curtains.current_scene.flash_sprites.append(flash) return flash, seq
def setup(self): self.details = AnimationDetails() self.obj = SquareSprite(size=200, color=WHITE) self.obj.position = (300, 460) self.sprites = arcade.SpriteList() self.setup_ui() self.setup_tabs() self.setup_radio() self.drag_proxy = DragProxy(self.details) self.drag_proxy.current_attribute = 'position' self.events.drag(self.obj, self.drag_proxy) self.sprites.append(self.obj)
def setup_ui(self): self.frame = SquareSprite(size=600, color=TEAL) self.frame.position = (300, 460) self.sprites.append(self.frame) self.loop_checkbox = SquareSprite(color=BRICK_RED, size=40) self.loop_checkbox.position = (155, 80) self.sprites.append(self.loop_checkbox) def init_button(text, handler, x, y): btn = Button(text=text, events=self.events) self.events.click(btn, handler) btn.position = (x, y) self.sprites.append(btn) init_button('+1 Frame', self.add_keyframe, 70, 130) init_button('Loop', self.toggle_loop, 70, 80) init_button('Play', self.play, 70, 30) init_button('Stop', self.stop, 193, 30)
def __init__(self, name, rate=.02, *args, **kwargs): ObservableSprite.__init__(self, *args, **kwargs) SquareSprite.__init__(self, *args, **kwargs) self.skin_color = arcade.color.PERU self.color = self.skin_color self.name = name self.health = 100 self.stamina = 0 self.special = 0 self.flash_rate = 0.15 self.power_up_time = 1 self.opponent = None self.recovery_rate = rate self.current_recovery_time = 0 self.damage = 12.5 self.state = get_state()
def setup_widget(self, events, hero): backdrop = SquareSprite() backdrop.color = arcade.color.SADDLE_BROWN backdrop.width = 245 backdrop.height = 95 backdrop.bottomleft = (0, 0) attack = Button(text='Attack', events=events) haste = Button(text='Haste', events=events) ultimate = Button(text='Ultimate', events=events) self.sprites.extend([backdrop, attack, ultimate, haste]) events.click(attack, hero.attack) events.click(ultimate, hero.power_up) events.click(haste, hero.haste) attack.bottomleft = (5, 50) haste.bottomleft = (125, 50) ultimate.bottomleft = (5, 5) self._sequences = {} for sprite in self.sprites: sprite.alpha = 0
def setup_widget(self, inverse=False): c = arcade.color bars = [('health', c.RED), ('stamina', c.BLUE), ('special', c.GREEN)] self.bars = {} for idx, (bar_name, color) in enumerate(reversed(bars)): container = Bar(arcade.color.WHITE, height=23, width=103) bar = Bar(color, inverse=inverse) bar.topleft = (50, idx * 25) container.position = bar.position self.sprites.extend([container, bar]) self.bars[bar_name] = bar topleft = 0 if inverse: topleft = 121 padding = CircleSprite(size=80, color=c.SADDLE_BROWN) padding.topleft = (topleft, 55) portrait = CircleSprite(size=70, color=c.PERU) portrait.topleft = (topleft + 5, 50) backdrop = SquareSprite() backdrop.color = c.SADDLE_BROWN backdrop.width = 108 backdrop.height = 85 backdrop.position = self.bars['stamina'].position backdropleft = CircleSprite(size=85, color=c.SADDLE_BROWN) backdropleft.position = (backdrop.left, backdrop.center_y) backdropright = CircleSprite(size=85, color=c.SADDLE_BROWN) backdropright.position = (backdrop.right, backdrop.center_y) for sprite in [backdrop, backdropright, backdropleft]: self.sprites.insert(0, sprite) self.sprites.extend([padding, portrait])
class AppScene(BaseScene): def setup(self): self.details = AnimationDetails() self.obj = SquareSprite(size=200, color=WHITE) self.obj.position = (300, 460) self.sprites = arcade.SpriteList() self.setup_ui() self.setup_tabs() self.setup_radio() self.drag_proxy = DragProxy(self.details) self.drag_proxy.current_attribute = 'position' self.events.drag(self.obj, self.drag_proxy) self.sprites.append(self.obj) def setup_ui(self): self.frame = SquareSprite(size=600, color=TEAL) self.frame.position = (300, 460) self.sprites.append(self.frame) self.loop_checkbox = SquareSprite(color=BRICK_RED, size=40) self.loop_checkbox.position = (155, 80) self.sprites.append(self.loop_checkbox) def init_button(text, handler, x, y): btn = Button(text=text, events=self.events) self.events.click(btn, handler) btn.position = (x, y) self.sprites.append(btn) init_button('+1 Frame', self.add_keyframe, 70, 130) init_button('Loop', self.toggle_loop, 70, 80) init_button('Play', self.play, 70, 30) init_button('Stop', self.stop, 193, 30) def setup_tabs(self): tab_names = ['Position', 'Angle', 'Scale', 'Width', 'Height'] self.tabs = TabGroup(self.sprites, self.events, tab_names, 600, (300, 740), 4) self.tabs['Position'].active = True def set_mouse_to_value(sprite, *args, **kwargs): self.drag_proxy.current_attribute = sprite.text.lower() for name in tab_names: self.events.click(self.tabs[name], set_mouse_to_value) def setup_radio(self): self.keyframes_radio = RadioGroup(self.sprites, self.events, [], 560, (405, 130), 10) self.add_keyframe() def add_keyframe(self, *args, **kwargs): idx = len(self.details.keyframes) if idx >= 5: return self.keyframes_radio.add_button(str(idx)) self.keyframes_radio[str(idx)].on_click() self.details.add_keyframe(self.obj) self.events.click(self.keyframes_radio[str(idx)], self.select_keyframe) self.details.set_current_keyframe(int( self.keyframes_radio.active.text)) def select_keyframe(self, *args, **kwargs): self.details.set_current_keyframe(int( self.keyframes_radio.active.text)) seq = Sequence() seq.add_keyframe(0, self.details.current_keyframe) self.obj.animate(seq) def toggle_loop(self, *args, **kwargs): self.details.loop = not self.details.loop self.loop_checkbox.set_texture(int(self.details.loop)) def play(self, *args, **kwargs): seq = Sequence(loop=self.details.loop) seq.add_keyframes(*self.details.keyframes.items()) self.obj.animate(seq) def stop(self, *args, **kwargs): self.curtains.current_scene.animations.animations = []
def setup_widget(self, events): arcade.set_background_color(arcade.color.SKY_BLUE) grass = SquareSprite() grass.color = arcade.color.FOREST_GREEN grass.width = 500 grass.height = 200 grass.bottomleft = (0, 0) self.sprites.append(grass) class GrassBlade(SquareSprite): def __init__(self): self.wind = random.random() / 2 super().__init__() def blow_in_the_wind(self, delta): self.wind += delta if self.wind > 3: self.wind = 0 elif self.wind > 2.6: self.angle -= delta * 100 self.center_x += delta * 10 elif self.wind > 2.2: self.angle += delta * 100 self.center_x -= delta * 10 elif self.wind > 1.8: self.angle -= delta * 100 self.center_x += delta * 10 elif self.wind > 1.4: self.angle += delta * 100 self.center_x -= delta * 10 for i in range(1100): grassblade = GrassBlade() grassblade.color = (14, 119, 14) grassblade.width = 2 grassblade.height = 10 grassblade.bottomleft = (random.randint(0, 500), random.randint(0, 200)) self.sprites.append(grassblade) events.frame(grassblade.blow_in_the_wind) class Cloud(Widget): def setup_widget(self): base = CircleSprite() base.width = 256 base.height = 64 base.position = (0, 0) top1 = CircleSprite() top1.position = (88, 30) top2 = CircleSprite() top2.scale = 1.3 top2.position = (20, 50) top3 = CircleSprite() top3.scale = 0.9 top3.position = (-50, 20) self.sprites.extend([top1, top2, top3, base]) self.speed = random.randint(50, 100) def move(self, delta): self.center_x -= delta * self.speed if self.center_x < -150: self.center_x = 700 cloud1 = Cloud() cloud1.position = (random.randint(128, 372), 300) self.sprites.extend(cloud1.sprites) cloud2 = Cloud() cloud2.position = (random.randint(128, 372), 400) self.sprites.extend(cloud2.sprites) cloud3 = Cloud() cloud3.position = (random.randint(128, 372), 500) self.sprites.extend(cloud3.sprites) events.frame(cloud1.move) events.frame(cloud2.move) events.frame(cloud3.move)