-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
79 lines (70 loc) · 2.2 KB
/
map.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
78
79
export class Map{
constructor(game){
this.game = game;
this.x = this.y = 0;
this.image;
this.width;
this.height;
this.imageIndex;
this.dimensions;
this.set(this.game.assetManager.images[3]);
}
set(world){
this.image = world;
//set x and y to 0
this.x = this.y = 0;
this.imageIndex = this.game.assetManager.images.indexOf(this.image);
this.dimensions = this.game.assetManager.imageDimensions[this.imageIndex];
this.width = this.dimensions[0];
this.height = this.dimensions[1];
}
render(ctx){
ctx.drawImage(this.image,
this.game.camera.viewportX,
this.game.camera.viewportY,
this.game.camera.viewportWidth,
this.game.camera.viewportHeight,
this.x,
this.y,
this.game.camera.viewportWidth,
this.game.camera.viewportHeight
)
}
}
//BACKGROUND LAYERS WITH PARALLAX SCROLLING
export class BackgroundLayer{
constructor(game, speedModifier){
this.game = game;
this.speedModifier = speedModifier || 1;
this.x = this.y = 0;
this.image;
this.width;
this.height;
this.imageIndex;
this.dimensions;
this.speedX = this.speedY = 0;
this.set(this.game.assetManager.images[3]);
}
set(world){
this.image = world;
//set x and y to 0
//this.x = this.y = 0;
//this.imageIndex = this.game.assetManager.images.indexOf(this.image);
//this.dimensions = this.game.assetManager.imageDimensions[this.imageIndex];
//this.width = this.dimensions[0];
//this.height = this.dimensions[1];
}
render(ctx){
ctx.drawImage(
this.image,
this.game.camera.viewportX * (this.speedModifier),
this.game.camera.viewportY * (this.speedModifier),
this.game.camera.viewportWidth,
this.game.camera.viewportHeight,
this.x,
this.y,
this.game.camera.viewportWidth,
this.game.camera.viewportHeight
)
}
}