def __init__(self, frametime=seconds(0.1), paused=False, looped=True): super(AnimatedSprite, self).__init__() self.animation = None self.frametime = frametime self.paused = paused self.looped = looped self.current_time = None self.current_frame = 0 self.texture = None self.vertices = VertexArray(PrimitiveType.QUADS, 4)
def __init__(self): # Load Assets self.load_content() self.window = RenderWindow(VideoMode(WIDTH, HEIGHT, BPP), TITLE, Style.CLOSE | Style.TITLEBAR, SETTINGS) self.window.framerate_limit = 60 self.window.icon = self.icon.pixels # Clock self.clock = Clock() self.time_since_last_update = Time.ZERO self.FPS = seconds(1.0/30.0) # View self.view = View(Rectangle((0, 0), (WIDTH, HEIGHT))) # self.view.reset(Rectangle((0, 0), (WIDTH, HEIGHT))) self.view.viewport = (0.0, 0.0, 1.0, 1.0) self.hud = View(Rectangle((0, 0), (WIDTH, HEIGHT))) self.hud.viewport = (0.0, 0.0, 1, 1.0) # attr: font, text, pos, color=Color.GREEN self.fps_pos = Vector2(15, 15) self.fps_text_content = '...' self.fps_text = Text(self.fps_text_content, self.fps_font, 14) self.fps = FPS(self.fps_text, self.fps_pos) # PLAYER self.player_spt = Sprite(self.player_texture) self.player = Player(self.window, self.player_spt, self.player_texture, 0, 0) self.bg = Sprite(self.bg)
def __init__(self, window, sprite, texture, x, y): super(Player, self).__init__() self.window = window self.sprite = sprite self.texture = texture self.x = x self.y = y self.speed = 40.0 # Animations self.animation = load_animations("assets/animations/player.anim") # Animation Walk R self.walk_r = Animation("walk", self.animation, self.texture) # Animation Walk L self.walk_l = Animation("walk", self.animation, self.texture) # Animation Stopped self.stopped = Animation("stopped", self.animation, self.texture) self.current_animation = self.stopped self.anim_sprite = AnimatedSprite(seconds(0.1), True, False) self.anim_sprite.position = Vector2(0, 0)
def time(): return dict( micro=sf.microseconds(5000000), milli=sf.milliseconds(5000), sec=sf.seconds(5))
def test_sleep(clock): sf.sleep(sf.seconds(1)) assert clock.elapsed_time >= sf.seconds(1)