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])
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)