-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
41 lines (31 loc) · 790 Bytes
/
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
// data
//
//
/** @type CanvasRenderingContext2D */
const ctx = canvasContext2D;
const hopper = new Hopper(10, 40, {w: canvas.width, h: canvas.height});
resizeCallbacks.push((c) => hopper.onResize(c));
const flower = new Flower(120, {w: canvas.width, h: canvas.height});
resizeCallbacks.push((c) => flower.onResize(c));
const fish = new Fish(100, 100, {w: canvas.width, h: canvas.height});
resizeCallbacks.push((c) => fish.onResize(c));
// functions
//
//
// logic
const logic = (dt) => {
hopper.act(dt);
flower.act(dt);
fish.act(dt);
}
// render
const render = (_, cw, ch) => {
// clear what was drawn before
ctx.clearRect(0, 0, cw, ch);
// draw creatures
hopper.draw(ctx);
flower.draw(ctx);
fish.draw(ctx);
};
// start
loop([render, logic]);