view examples/01-bouncing/client.js @ 72:b43f40857609

Common: add explicit move because of unique_ptr
author David Demelier <markand@malikania.fr>
date Thu, 22 Dec 2016 09:13:01 +0100
parents a1e80d991968
children
line wrap: on
line source

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();
}