import a.ggez import a.ggez::BLUE import a.ggez::RED import a.ggez::GREEN import a.ggez::WHITE def demo001() = { import a.time print(ggez::get_all_keycodes()) width = 0 height = 0 x = 0 y = 0 last_tick_time = nil init = false print_key = false app = ggez::App( name="demo", update=def(ctx) { nonlocal last_tick_time, x, y, width, height, init if !init { [width, height] = ctx.size() x = width / 2 y = height / 2 print('init, size -> ' + str(ctx.size())) init = true } now = time::now() last_tick_time = if last_tick_time is nil { now } else { last_tick_time } if now - last_tick_time > .4 { y = min(y + 20, height - 40) last_tick_time = now } }, draw=def(ctx) { ggez::MeshBuilder().rect(0, 0, width, height, ggez::BLACK).build(ctx).draw(ctx) ggez::MeshBuilder().circle([40, 40], 40, BLUE, 1.0).build(ctx).draw(ctx) ggez::MeshBuilder().circle([width - 40, height - 40], 40, RED, 1.0).build(ctx).draw(ctx) ( ggez::MeshBuilder() .circle([width - 40, 40], 40, GREEN, 1.0) .circle([40, height - 40], 40, WHITE, 1.0) .build(ctx) .draw(ctx) ) ggez::MeshBuilder().rect(0, 0, 80, 80, BLUE).build(ctx).draw(ctx, [x - 40, y - 40]) fps = ctx.fps() fps_text = ggez::SimpleText('fps = %r' % [fps]) fps_text.draw(ctx) ggez::SimpleText('multiline\n text').draw(ctx, [0, fps_text.height(ctx)]) }, mouse_down=def(ctx, button, cx, cy) = { nonlocal x, y print('button = %s, cx = %s, cy = %s' % [button, cx, cy]) if button == :left { x = cx y = cy } }, text_input=def(ctx, c) = { nonlocal x, y r###" print('text_input c = %r' % [c]) "### r###" if c == 'a' { x = x - 40 } elif c == 'd' { x = x + 40 } elif c == 'w' { y = y - 40 } elif c == 's' { y = y + 40 } "### }, key_down=def(ctx, key, mods) = { nonlocal x, y, print_key if print_key { print('key = %r, mods= %s' % [key, mods]) } if key is :Left or key is :A { x = x - 40 } elif key is :Right or key is :D { x = x + 40 } elif key is :Up or key is :W { y = y - 40 } elif key is :Down or key is :S { y = y + 40 } elif key is :P { print_key = !print_key } elif key is :Escape { ctx.quit() } } ) app.main() } if __name == __main() { demo001() }