-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
80 lines (56 loc) · 2.04 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Playlib } from './bin/playlib.js'
/** @description This is the testing page for modules and is used by the main page (index.html) */
document.getElementById("version").innerHTML = Playlib.version;
const canvas = document.getElementById("canvas");
canvas.width = window.outerWidth;
canvas.height = window.outerHeight;
const ScreenSize = new Playlib.Vec2(canvas.width, canvas.height);
let config = {
style: "background-color: white;",
width: ScreenSize.width,
height: ScreenSize.height,
canvas: canvas
}
class MainScene extends Playlib.Scene
{
colors = ["#FFFFFF", "#C0C0C0", "#FF00FF", "#808080", "#000000", "#FF0000", "#800000", "#FFFF00", "#808000", "#00FF00", "#008000", "#00FFFF"];
colorcount = 0;
ActivateDown = false;
square = new Playlib.Rect(new Playlib.Vec2(1, 1), new Playlib.Vec2(20, 20), ScreenSize);
constructor(canvas, ClearScreen)
{
super(canvas, ClearScreen);
this.ClearScreen = false;
this.square.color = "#545454"
}
create(ctx)
{
}
update(ctx, deltaTime)
{
// console.log(this.ActivateDown);
this.square.draw(ctx);
this.square.color = this.colors[this.colorcount];
this.colorcount++;
if (this.colorcount > this.colors.length) this.colorcount = 0;
if (this.square.position.y >= ScreenSize.x && this.ActivateDown) {
this.square.position = new Playlib.Vec2(1, 1);
this.ActivateDown = false;
ctx.clearRect(0, 0, ScreenSize.x, ScreenSize.y);
}
else if (this.square.position.y >= ScreenSize.x) {
this.ActivateDown = true;
this.square.position = new Playlib.Vec2(ScreenSize.x, 0);
}
else if (this.ActivateDown) {
this.square.position.y += 10;
this.square.position.x -= 10;
}
else {
this.square.position.x += 10;
this.square.position.y += 10;
}
}
}
let game = new Playlib.Game(config, [new MainScene()]);
game.run();