def __init__(self, settings): pyasge.ASGEGame.__init__(self, settings) """load background""" self.sprite = pyasge.Sprite() if not self.sprite.loadTexture("/data/images/menu_buttons.png"): print("error: failed to load") """print sprite dimensions""" dims = self.sprite.dimensions() print(dims) """print sprite colour""" print(self.sprite.colour) self.sprite.colour = pyasge.COLOURS.PINK print(self.sprite.colour) """sprite sheet""" self.sprite_sheet = pyasge.Sprite() self.sprite_sheet.loadTexture("/data/images/character_robot_idle.png") self.sprite_sheet.src_rect[pyasge.Sprite.SourceRectIndex.START_X] = 227 self.sprite_sheet.src_rect[pyasge.Sprite.SourceRectIndex.LENGTH_X] = 44 self.sprite_sheet.width = 44 self.flipped_sprite = pyasge.Sprite() self.flipped_sprite.loadTexture( "/data/images/character_zombie_idle.png") self.flipped_sprite.x = 300 self.flipped_sprite.y = 100 self.flipped_sprite.flip_flags = pyasge.Sprite.FlipFlags.FLIP_X bb = self.flipped_sprite.getLocalBounds() print(bb) gb = self.flipped_sprite.getWorldBounds() print(gb)
def __init__(self, settings): pyasge.ASGEGame.__init__(self, settings) self.camera = pyasge.Camera(1024, 768) self.camera.lookAt(pyasge.Point2D(0, 0)) self.bg = pyasge.Sprite() self.bg.loadTexture("/data/images/background.png") self.bg.z_order = -10 self.bg.x = -750 self.bg.y = -500 self.sprite = pyasge.Sprite() self.sprite.loadTexture("/data/images/character_zombie_idle.png") self.inputs.addCallback(pyasge.EventType.E_KEY, self.input) """load font and create text instance""" self.font = self.renderer.loadFont("/data/fonts/kenvector_future.ttf", 40) self.text = pyasge.Text(self.font, "[BRAINS]") self.ui_text = pyasge.Text(self.font, "Lives: XXX") self.ui_text.position = [1020 - self.ui_text.width, 35] self.ui_text.colour = pyasge.COLOURS.CHOCOLATE """track key states""" self.keys = { pyasge.KEYS.KEY_A: False, pyasge.KEYS.KEY_D: False, pyasge.KEYS.KEY_W: False, pyasge.KEYS.KEY_S: False, pyasge.KEYS.KEY_EQUAL: False, pyasge.KEYS.KEY_MINUS: False, }
def __init__(self, settings): pyasge.ASGEGame.__init__(self, settings) """Load a backdrop and then change to mimic scan lines""" self.sprite = pyasge.Sprite() self.sprite.loadTexture("/data/images/character_robot_idle.png") texture = self.sprite.getTexture() data = texture.buffer.data with numpy.nditer(data[:, ::3], op_flags=["readwrite"], order="C") as it: for x in it: x[...] = 100 texture.buffer.upload() print(texture.buffer.data[1]) """Create a non-cached texture, this is memory managed by Python""" self.animated_sprite = pyasge.Sprite() self.animated_sprite.x = 750 self.animated_sprite.width = 50 self.animated_sprite.height = 50 self.blank_texture = self.renderer.createNonCachedTexture( 50, 50, pyasge.Texture.Format.RGB, None ) self.animated_sprite.attach(self.blank_texture) """Upload pixel data directly""" blocks = numpy.full((200, 600), 65, dtype="B") self.uploaded_sprite = pyasge.Sprite() self.uploaded_sprite.x = 200 self.uploaded_sprite.y = 200 self.uploaded_sprite.width = 200 self.uploaded_sprite.height = 200 self.uploaded_texture = self.renderer.createNonCachedTexture( 200, 200, pyasge.Texture.Format.RGB, None ) self.uploaded_sprite.attach(self.uploaded_texture) self.uploaded_texture.buffer.upload(blocks, 0) print(self.uploaded_texture) print(self.blank_texture.buffer) repr(self.blank_texture.buffer) print(self.blank_texture.width) print(self.blank_texture.height) print(self.blank_texture.buffer.width) print(self.blank_texture.buffer.height)
def __init__(self, texture): self.clicked = None self.sprite = pyasge.Sprite() self.sprite.loadTexture(texture) self.velocity = pyasge.Point2D(0, 0) self.sprite.setMagFilter(pyasge.MagFilter.LINEAR) self.colour = pyasge.Colour(0, 0, 0)
def __init__(self, settings): pyasge.ASGEGame.__init__(self, settings) # self.toggleFPS() self.camera = pyasge.Camera(384 * 0.5, 256) self.camera.lookAt([192 * 0.5, 128]) self.sprite = pyasge.Sprite() self.sprite.loadTexture("/data/images/character_zombie_idle.png") self.sprite.scale = 1.0 self.sprite.y = -25 self.sprite2 = pyasge.Sprite() self.sprite2.loadTexture("/data/images/character_robot_idle.png") self.sprite2.scale = 1.0 self.sprite2.y = -25 """load font and create text instance""" self.font = self.renderer.loadFont("/data/fonts/kenvector_future.ttf", 40) self.text = pyasge.Text(self.font, "Hello World")
def __init__(self, settings): pyasge.ASGEGame.__init__(self, settings) """sprite sheet""" self.sprite_sheet = pyasge.Sprite() self.sprite_sheet.loadTexture("/data/Textures/spritesheet.png") self.sprite_sheet.src_rect[pyasge.Sprite.SourceRectIndex.START_X] = 227 self.sprite_sheet.src_rect[pyasge.Sprite.SourceRectIndex.LENGTH_X] = 44 self.sprite_sheet.width = 44 self.sprite_sheet.x = 200 self.sprite_sheet.y = 50 self.sprite_sheet.scale = 5 self.sprite_sheet.setMagFilter(pyasge.MagFilter.NEAREST)
def __init__(self, settings): pyasge.ASGEGame.__init__(self, settings) self.inline_shader = self.renderer.initPixelShader(frag_shader) self.sprite = pyasge.Sprite() self.sprite.loadTexture("/data/images/character_robot_idle.png") self.sprite.width = 332 self.sprite.height = 452 self.alpha_sprite = pyasge.Sprite() self.alpha_sprite.loadTexture("/data/images/character_robot_idle.png") self.alpha_sprite.x = 332 self.alpha_shader = self.renderer.loadPixelShader( "/data/shaders/alpha.frag") self.uniform = self.alpha_shader.uniform("alpha") print(self.uniform.value) self.red_sprite = pyasge.Sprite() self.red_sprite.loadTexture("/data/images/character_robot_idle.png") self.red_sprite.x = 332 * 2 self.red_shader = self.renderer.loadPixelShader( "/data/shaders/red.frag") self.red_sprite.shader = self.red_shader
def __init__(self, settings): pyasge.ASGEGame.__init__(self, settings) self.inputs.addCallback(pyasge.EventType.E_KEY, self.input) """a sprite to render in to the offscreen target""" self.sprite = pyasge.Sprite() self.sprite.loadTexture("/data/images/character_robot_idle.png") self.sprite.width = 192 self.sprite.height = 256 self.sprite.x = 500 self.sprite.y = 100 """create a new render target and sprite to store the render texture""" self.rt = pyasge.RenderTarget(self.renderer, 1024 / 2, 768 / 2, pyasge.Texture.Format.RGB, 1) self.rt_texture = pyasge.Sprite() self.rt_texture.x = 1024 / 2 self.rt_texture.y = 768 / 2 self.rt_texture.width = 1024 / 2 self.rt_texture.height = 768 / 2 self.rt_texture.attach(self.rt.buffers[0]) """track key states""" self.keys = { pyasge.KEYS.KEY_A: False, pyasge.KEYS.KEY_D: False, pyasge.KEYS.KEY_W: False, pyasge.KEYS.KEY_S: False, pyasge.KEYS.KEY_EQUAL: False, pyasge.KEYS.KEY_MINUS: False, } """load font and create text instance""" self.font = self.renderer.loadFont("/data/fonts/kenvector_future.ttf", 28) self.text = pyasge.Text(self.font, "RenderTarget with 50%\nsized viewport") self.text.y = self.rt_texture.y + 28 self.text.x = self.rt_texture.x