view examples/01-bouncing/client.js @ 28:80736513d699

Client: prepare client targets, #473
author David Demelier <markand@malikania.fr>
date Tue, 19 Apr 2016 21:13:23 +0200
parents 0a1adf7dcca0
children a1e80d991968
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();
}