-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmap.js
More file actions
145 lines (135 loc) · 4.36 KB
/
map.js
File metadata and controls
145 lines (135 loc) · 4.36 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Data structure for the map itself
* Handles getting a tile as well as collision detection
*/
class Map {
constructor(layout) {
this.layout = layout;
this.register = null;
}
/**
* Gets a tile at X, Y
* @param {Number} x The X coordinate of a tile to get
* @param {Number} y The Y coordinate of a tile to get
*/
getTile(x, y) {
return this.layout[y][x]
}
specialTiles(nextMove, player) {
switch(nextMove){
case "c":
//c = coffee stand
if(player.holding === "coffee") {
if(player.coffee >= 100){
player.speech.speak("Stand full. I am going to have to eat it.");
} else{
player.speech.speak("I put down the coffee at the stand.");
player.holding="nothing"
player.coffee += 10
}
}
break;
case "f":
//f = food stand
if (player.holding === "food"){
if(player.food >= 100){
player.speech.speak("Stand Full, I'm going to have to drink it.");
}else{
player.speech.speak("I put down the food at the stand");
player.holding = "nothing"
player.food += 10
}
}
break;
case "r":
//r = registration
if (player.holding !== "nothing"){
player.speech.speak("My hands are busy");
}else{
if(current_registering.length != 0) {
this.register = current_registering[0];
this.register.register_mob()
current_registering.shift()
queue_count -=1;
} else {
}
player.speech.speak("I am now registering people")
}
break;
case "r":
//r = registration
if (player.holding !== "nothing"){
player.speech.speak("My hands are busy");
}else{
player.speech.speak("I am now registering people")
}
break;
case "h":
//h = harbord coffee
if(player.holding === "nothing"){
player.holding = "coffee"
player.speech.speak("I have collected 10 coffees");
} else {
player.speech.speak("I already am holding something!");
}
break;
case "s":
//s = food Shop
if(player.holding === "nothing"){
player.holding = "food";
player.speech.speak("I have collected 10 food items");
} else {
player.speech.speak("I already am holding something!");
}
break;
case "z":
//z = food seats
if(player.holding === "food" || player.holding === "coffee"){
player.holding = "nothing";
player.speech.speak("Nom nom nom...");
}
break;
}
}
/**
* Handles collision detection and response between the tile map
* and the player
* @param {Player} player The player
*/
collisions(player) {
const image = document.getElementById("player");
const playerWidth = image.width;
const playerHeight = image.height;
const playerNextX = player.x + player.vx;
const playerNextY = player.y + player.vy;
let gridX = Math.floor(playerNextX / GRID_SIZE);
let gridY = Math.floor(playerNextY / GRID_SIZE);
if (player.vx > 0) {
gridX += 1;
} else gridX -= 1;
if (player.vy > 0) {
gridY += 1;
} else gridY -= 1;
const tile = this.getTile(gridX, gridY);
const tileYRIGHT = this.getTile(Math.floor(player.x / GRID_SIZE) + 1, gridY);
const tileY = this.getTile(Math.floor(player.x / GRID_SIZE), gridY);
const tileYLEFT = this.getTile(Math.floor(player.x / GRID_SIZE) - 1, gridY);
const tileXUP = this.getTile(gridX, Math.floor(player.y / GRID_SIZE) - 1);
const tileX = this.getTile(gridX, Math.floor(player.y / GRID_SIZE));
const tileXDOWN = this.getTile(gridX, Math.floor(player.y / GRID_SIZE) + 1);
if (player.vx != 0){
if (tileXUP == "w" || tileXDOWN == "w"){
player.x -= player.vx;
} else {
this.specialTiles(tileX,player);
}
}
if (player.vy != 0){
if (tileYRIGHT == "w" || tileYLEFT == "w"){
player.y -= player.vy;
} else {
this.specialTiles(tileY,player);
}
}
}
}