Mercurial > malikania
diff examples/01-bouncing/client.js @ 26:56cc058200b5
Client: add basic mlk-client code with an example, #472
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 08 Apr 2016 14:16:47 +0200 |
parents | |
children | 0a1adf7dcca0 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/01-bouncing/client.js Fri Apr 08 14:16:47 2016 +0200 @@ -0,0 +1,41 @@ +var x = 0; +var y = 0; + +var dx = 1; +var dy = 1; + +var font; +var clip; + +function start(window) +{ + font = new Malikania.Font("fonts/DejaVuSans.ttf", 10); + clip = font.clip("Malikania"); + + x = (640 / 2) - (clip.width / 2); + y = (480 / 2) - (clip.height / 2); +} + +function update() +{ + x += dx; + y += dy; + + if (x >= 640 - clip.width) + dx = -1; + else if (x <= 0) + dx = 1; + if (y >= 480 - clip.height) + dy = -1; + else if (y <= 0) + dy = 1; +} + +function draw(window) +{ + window.setDrawingColor('lightskyblue'); + window.clear(); + window.setDrawingColor('white'); + window.drawText('Malikania', font, { x: x, y: y }); + window.present(); +} \ No newline at end of file