Mercurial > malikania
annotate examples/01-bouncing/client.js @ 50:697bf85e8e19
CMake: move executables into fakeroot/bin
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 15 Dec 2016 13:42:13 +0100 |
parents | a1e80d991968 |
children |
rev | line source |
---|---|
26
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
1 var x = 0; |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
2 var y = 0; |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
3 |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
4 var dx = 1; |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
5 var dy = 1; |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
6 |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
7 var font; |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
8 var clip; |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
9 |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
10 function start(window) |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
11 { |
30
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
12 font = new Malikania.Font("fonts/DejaVuSans.ttf", 10); |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
13 clip = font.clip("Malikania"); |
26
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
14 |
30
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
15 x = (640 / 2) - (clip.width / 2); |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
16 y = (480 / 2) - (clip.height / 2); |
26
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
17 } |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
18 |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
19 function update() |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
20 { |
30
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
21 x += dx; |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
22 y += dy; |
26
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
23 |
30
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
24 if (x >= 640 - clip.width) |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
25 dx = -1; |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
26 else if (x <= 0) |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
27 dx = 1; |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
28 if (y >= 480 - clip.height) |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
29 dy = -1; |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
30 else if (y <= 0) |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
31 dy = 1; |
26
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
32 } |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
33 |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
34 function draw(window) |
56cc058200b5
Client: add basic mlk-client code with an example, #472
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
35 { |
30
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
36 window.setDrawingColor('lightskyblue'); |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
37 window.clear(); |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
38 window.setDrawingColor('white'); |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
39 window.drawText('Malikania', font, { x: x, y: y }); |
a1e80d991968
Misc: convert to spaces, #519
David Demelier <markand@malikania.fr>
parents:
27
diff
changeset
|
40 window.present(); |
27
0a1adf7dcca0
Common: update libjs and adapt code
David Demelier <markand@malikania.fr>
parents:
26
diff
changeset
|
41 } |