-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewHandler.js
36 lines (35 loc) · 1.21 KB
/
ViewHandler.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
import { BLOCK_SIZE, LEVEL_HEIGHT, LEVEL_WIDTH } from './constants.js';
import PlayerHandler from './PlayerHandler.js';
export default {
init(game) {
this.x = LEVEL_WIDTH * BLOCK_SIZE * 0.5;
this.y = 300;
this.canvas = game.canvas;
},
enterFrame() {
this.x += (PlayerHandler.x - this.x) * 0.05;
if (this.x < PlayerHandler.x + 1 && this.x > PlayerHandler.x - 1) {
this.x = PlayerHandler.x;
}
this.y += (PlayerHandler.y - this.y) * 0.05;
if (this.y < PlayerHandler.y + 1 && this.y > PlayerHandler.y - 1) {
this.y = PlayerHandler.y;
}
if (this.x < this.canvas.width * 0.5) {
this.x = this.canvas.width * 0.5;
} else if (
this.x >
LEVEL_WIDTH * BLOCK_SIZE - this.canvas.width * 0.5
) {
this.x = LEVEL_WIDTH * BLOCK_SIZE - this.canvas.width * 0.5;
}
if (this.y < this.canvas.height * 0.5) {
this.y = this.canvas.height * 0.5;
} else if (
this.y >
LEVEL_HEIGHT * BLOCK_SIZE - this.canvas.height * 0.5
) {
this.y = LEVEL_HEIGHT * BLOCK_SIZE - this.canvas.height * 0.5;
}
},
};