-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDungeonGeneration.js
514 lines (444 loc) · 20.1 KB
/
DungeonGeneration.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
// ARTG/CMPM 120 Final Project
// Tomb of the Ancients
// DungeonGeneration.js
// Methods which handle dungeon generation
// DUNGEON GENERATION
// Dungeon generation methods, in the order that they are accessed: SpawnDungeon(), Shuffle(), MakeRoom(), MakePath(), MakeWalls(), InBounds()
// SpawnDungeon() determines the general layout of a dungeon while applying significant randomization.
// Shuffle() is a helper function that simply shuffles an array.
// MakeRoom() stores room values generated by SpawnDungeon().
// MakePath() calls MakeRoom() but shapes rooms in a hallway formation.
// MakeWalls() actually builds the walls by placing sprites in the way we ask it to.
// InBounds() is an important helper function that determines what kind of tile should be drawn.
// MakeRoom()
// stores all room values as subarrays in rooms[]. InBounds() will later check for these values.
// anything that can be initialized in a certain type of room will check for roomtype and save
// -the coordinates for where that entity should spawn, which can be accessed later.
function MakeRoom(x, y, width, height, roomtype){
rooms.push([x, y, width, height]);
if (roomtype == "normal"){
mainrooms.push([x, y, width, height]);
}
if (roomtype == "start") { // save player coordinates.
playercoords = [x, y];
}
if (roomtype == "hall") { // chance of spawning an arbitrary enemy in a hallway segment.
enemies.push([x, y]);
}
if (roomtype == "boss") { // save boss coordinates.
bosscoords = [x, y];
bossroom = [x, y, width, height];
}
}
// MakePath()
// creates 2 narrow rooms that connect (x1,y1) and (x2,y), resembling hallways.
// pathtype determines which side the path will appear on, spawnenemy determines if an enemy can spawn inside it.
function MakePath(x1, y1, x2, y2, pathtype, spawnenemy){
var halltype = "hall";
// bypass enemy spawning in hallway directly adjacent from spawn
var avgX = (x1+x2)/2;
var diffX = game.math.difference(x1, x2);
// spawn first hallway segment (in one of two directions)
if (pathtype == "in") {
if (spawnenemy == false) {
halltype = "cleanhall";
}
MakeRoom(avgX, y1, (diffX) + PATH_WIDTH, PATH_WIDTH, halltype);
} else if (pathtype == "out") {
MakeRoom(avgX, y2, (diffX) + PATH_WIDTH, PATH_WIDTH, halltype)
}
var halltype = "hall";
var avgY = (y1+y2)/2;
var diffY = game.math.difference(y1, y2);
// spawn second hallway segment (in one of two directions)
if (pathtype == "in") {
MakeRoom(x2, avgY, PATH_WIDTH, (diffY) + PATH_WIDTH, halltype);
} else if (pathtype == "out") {
if (spawnenemy == false) {
halltype = "cleanhall";
}
MakeRoom(x1, avgY, PATH_WIDTH, (diffY) + PATH_WIDTH, halltype);
}
}
// InBounds()
// checks if the (x,y) pair exists in a room, a wall, or a ledge and returns a status.
function InBounds(x,y){
var tilestatus = "wall";
var OOBcount = 0;
for (var i = 0; i < rooms.length; i++) { // check the bounds of all rooms
var boundX1 = rooms[i][0] - (rooms[i][2]/2);
var boundX2 = rooms[i][0] + (rooms[i][2]/2);
var boundY1 = rooms[i][1] - (rooms[i][3]/2);
var boundY2 = rooms[i][1] + (rooms[i][3]/2);
var extrabound = boundY1 - WALL_SIZE; // designate a small space above a room where a ledge can be placed
if ((x <= boundX1 - (WALL_SIZE*2)) || (x > boundX2 + (WALL_SIZE*2)) || (y <= boundY1 - (WALL_SIZE*2)) || (y > boundY2 + (WALL_SIZE*2))){
OOBcount++;
}
if (x > boundX1 && x <= boundX2) {
if (y > extrabound && y <= boundY1 && tilestatus != "air") {
tilestatus = "ledge";
}
if (y > boundY1 && y <= boundY2) {
tilestatus = "air";
}
}
}
// out of bounds
if (OOBcount == rooms.length){
tilestatus = "OOB";
}
return tilestatus;
}
// MakeWalls()
// places tiles across the map space. essentially a grid full of squares carved out by checking InBounds().
// the status returned by InBounds() indicates what kind of sprite should be placed.
function MakeWalls(){
for (var i = WALL_SIZE/2; i <= FLOOR_SIZE-(WALL_SIZE/2); i += WALL_SIZE) {
for (var j = WALL_SIZE/2; j <= FLOOR_SIZE-(WALL_SIZE/2); j += WALL_SIZE) {
var tilestatus = InBounds(i,j);
// tile sprites by: asalga (Andor Salga) and gtkampos from opengameart.org
if (tilestatus == "wall") {
var tile = walls.create(i, j, 'tile_atlas', 'wall'); // spawn a wall
tile.body.immovable = true;
tile.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tile.anchor.x = 0.5;
tile.anchor.y = 0.5;
} else if (tilestatus == "ledge") {
var tile = walls.create(i, j, 'tile_atlas', 'ledge'); // spawn a ledge
tile.body.immovable = true;
tile.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tile.anchor.x = 0.5;
tile.anchor.y = 0.5;
} else if (tilestatus == "air") { // if status == "air"
var tile = game.add.sprite(i, j, 'tile_atlas', 'floor1'); // spawn a floor tile
tile.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tile.anchor.x = 0.5;
tile.anchor.y = 0.5;
var rand = game.rnd.integerInRange(0, 12);
if (rand == 0) {
var overlay = game.add.sprite(i, j, 'tile_overlay', 'glyph1'); // spawn glyph
overlay.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
overlay.anchor.x = 0.5;
overlay.anchor.y = 0.5;
} else if (rand == 1) {
var overlay = game.add.sprite(i, j, 'tile_overlay', 'glyph2'); // spawn glyph
overlay.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
overlay.anchor.x = 0.5;
overlay.anchor.y = 0.5;
} else if (rand == 2) {
var overlay = game.add.sprite(i, j, 'tile_overlay', 'glyph3'); // spawn glyph
overlay.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
overlay.anchor.x = 0.5;
overlay.anchor.y = 0.5;
} else if (rand == 3) {
var overlay = game.add.sprite(i, j, 'tile_overlay', 'glyph4'); // spawn glyph
overlay.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
overlay.anchor.x = 0.5;
overlay.anchor.y = 0.5;
}
} else if (tilestatus == "OOB") {
var tile = game.add.sprite(i, j, 'tile_atlas', 'wall'); // spawn a wall
tile.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tile.anchor.x = 0.5;
tile.anchor.y = 0.5;
}
}
}
}
// Shuffle()
// shuffles elements of an array.
function Shuffle(t){
var n = t.length-1;
while (n >= 0) {
var k = game.rnd.integerInRange(0, n);
var temp = t[n];
t[n] = t[k];
t[k] = temp;
n--;
}
return t;
}
// SpawnDungeon()
// determines the general layout of the dungeon and spawns rooms and paths with SpawnRoom() and SpawnPath().
// room positions are determined by shuffling arrays of X and Y vertices using Shuffle()
// room information is stored in points[i], which can be referred to as the centerpoints of rooms or the
// -endpoints of paths. both are drawn out using the same set of points, with a bit of randomness variance.
function SpawnDungeon(){
var pointnum = game.rnd.integerInRange(6, 8);
var groupx = [];
var groupy = [];
// initialize default point values
for (var i = 0; i < pointnum; i++) {
groupx[i] = i;
groupy[i] = i;
}
// shuffle point values
groupx = Shuffle(groupx);
groupy = Shuffle(groupy);
// store room values in points[]
for (var i = 0; i < pointnum; i++) {
var pointX = (FLOOR_SIZE*((groupx[i]+1)/(pointnum+1))) + game.rnd.integerInRange(-WALL_SIZE/4, WALL_SIZE/4);
var pointY = (FLOOR_SIZE*((groupy[i]+1)/(pointnum+1))) + game.rnd.integerInRange(-WALL_SIZE/4, WALL_SIZE/4);
points[i] = [pointX, pointY];
}
// spawn rooms 1 to i-1. the last room is special, so it is added outside of the loop.
for (var i = 0; i < pointnum-1; i++) {
// spawn room.
if (i == 0) {
MakeRoom(points[i][0], points[i][1], START_ROOM*WALL_SIZE, START_ROOM*WALL_SIZE, "start");
} else {
MakeRoom(points[i][0], points[i][1], game.rnd.integerInRange(ROOM_MIN*WALL_SIZE, ROOM_MAX*WALL_SIZE), game.rnd.integerInRange(ROOM_MIN*WALL_SIZE, ROOM_MAX*WALL_SIZE), "normal");
}
// prevent enemy spawning in the first path that is always adjacent to the spawn.
var makeenemy = true;
if (i == 0) {
makeenemy = false;
}
// spawn a path that goes from the current room to the next one.
var temp = game.rnd.integerInRange(0, 1);
if (temp == 0) {
MakePath(points[i][0], points[i][1], points[i+1][0], points[i+1][1], "in", makeenemy);
} else {
MakePath(points[i][0], points[i][1], points[i+1][0], points[i+1][1], "out", makeenemy);
}
}
// spawn the boss room (this is special because no path needs to continue from it, and it spawns a boss.)
MakeRoom(points[pointnum-1][0], points[pointnum-1][1], BOSS_ROOM*WALL_SIZE, BOSS_ROOM*WALL_SIZE, "boss");
// draw the physical wall sprites.
MakeWalls();
}
//SpawnDungeon.prototype = Object.create();
SpawnDungeon.prototype.constructor = SpawnDungeon;
// Checks if the player is inside of a room.
function PlayerInBounds(x,y){
for (var i = 0; i < mainrooms.length; i++) { // check the bounds of all rooms
var skip = false;
for (var j = 0; j < completedrooms.length; j++){
if (i == completedrooms[j]) {
skip = true;
}
}
if (skip == false){
var boundX1 = mainrooms[i][0] - (mainrooms[i][2]/2);
var boundX2 = mainrooms[i][0] + (mainrooms[i][2]/2);
var boundY1 = mainrooms[i][1] - (mainrooms[i][3]/2);
var boundY2 = mainrooms[i][1] + (mainrooms[i][3]/2);
if (x > boundX1 - (boundX1 % WALL_SIZE) + (WALL_SIZE/2) && x <= boundX2 - (boundX2 % WALL_SIZE) - (WALL_SIZE/2)) {
if (y > boundY1 - (boundY1 % WALL_SIZE) + (WALL_SIZE/2) && y <= boundY2 - (boundY2 % WALL_SIZE) - (WALL_SIZE/2)) {
return i;
}
}
}
}
return -1;
}
// Checks if the player is inside of the boss room
function PlayerInBoss(x,y){
var boundX1 = bossroom[0] - (bossroom[2]/2);
var boundX2 = bossroom[0] + (bossroom[2]/2);
var boundY1 = bossroom[1] - (bossroom[3]/2);
var boundY2 = bossroom[1] + (bossroom[3]/2);
if (x > boundX1 - (boundX1 % WALL_SIZE) + (WALL_SIZE/2) && x <= boundX2 - (boundX2 % WALL_SIZE) - (WALL_SIZE/2)) {
if (y > boundY1 - (boundY1 % WALL_SIZE) + (WALL_SIZE/2) && y <= boundY2 - (boundY2 % WALL_SIZE) - (WALL_SIZE/2)) {
return true;
}
}
return false;
}
// Creates a border around the current room.
function MakeBounds(num){
var roombounds = mainrooms[num];
var boundX1 = roombounds[0] - (roombounds[2]/2);
var boundX2 = roombounds[0] + (roombounds[2]/2);
var boundY1 = roombounds[1] - (roombounds[3]/2);
var boundY2 = roombounds[1] + (roombounds[3]/2);
// create upper wall
for (var i = boundX1 - (WALL_SIZE/2); i <= boundX2 + (WALL_SIZE/2); i += WALL_SIZE){
var tileX = i;
var tileY = boundY1 - (WALL_SIZE/2);
var tile = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'ledge'); // spawn a wall
tile.body.immovable = true;
tile.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tile.anchor.x = 0.5;
tile.anchor.y = 0.5;
}
// create lower wall
for (var i = boundX1 - (WALL_SIZE/2); i <= boundX2 + (WALL_SIZE/2); i += WALL_SIZE){
var tileX = i;
var tileY = boundY2 + (WALL_SIZE/2);
var tile = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'wall'); // spawn a wall
tile.body.immovable = true;
tile.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tile.anchor.x = 0.5;
tile.anchor.y = 0.5;
}
// create left wall
for (var i = boundY1 - (WALL_SIZE/2); i <= boundY2 + (WALL_SIZE/2); i += WALL_SIZE){
var tileX = boundX1 - (WALL_SIZE/2);
var tileY = i;
var tile = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'wall'); // spawn a wall
tile.body.immovable = true;
tile.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tile.anchor.x = 0.5;
tile.anchor.y = 0.5;
}
// create right wall
for (var i = boundY1 - (WALL_SIZE/2); i <= boundY2 + (WALL_SIZE/2); i += WALL_SIZE){
var tileX = boundX2 + (WALL_SIZE/2);
var tileY = i;
var tile = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'wall'); // spawn a wall
tile.body.immovable = true;
tile.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tile.anchor.x = 0.5;
tile.anchor.y = 0.5;
}
// These are here to prevent the player from walking through the doors as they close.
// top boundary
tileTemp = [];
var tileCount = 0;
for (var i = ((boundX1+boundX2)/2) - (WALL_SIZE/2); i<= ((boundX1+boundX2)/2)+ (WALL_SIZE/2); i +=WALL_SIZE){ // spawns 2 tiles in the entrance
var tileX =i;
var tileY = boundY1 - (WALL_SIZE/2);
tileTemp[tileCount] = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'ledge'); // spawn a wall
tileTemp[tileCount].body.immovable = true;
tileTemp[tileCount].scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tileTemp[tileCount].anchor.x = 0.5;
tileTemp[tileCount].anchor.y = 0.5;
tileTemp[tileCount].alpha = 0;
tileCount++;
}
// bottom boundary
for (var i = ((boundX1+boundX2)/2) - (WALL_SIZE/2); i<= ((boundX1+boundX2)/2)+ (WALL_SIZE/2); i +=WALL_SIZE){ // spawns 2 tiles in the entrance
var tileX = i;
var tileY = boundY2 + (WALL_SIZE/2);
tileTemp[tileCount] = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'wall'); // spawn a wall
tileTemp[tileCount].body.immovable = true;
tileTemp[tileCount].scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tileTemp[tileCount].anchor.x = 0.5;
tileTemp[tileCount].anchor.y = 0.5;
tileTemp[tileCount].alpha = 0;
tileCount++;
}
// left boundary
for (var i = ((boundY1+boundY2)/2) - (WALL_SIZE/2); i<= ((boundY1+boundY2)/2) + (WALL_SIZE/2); i +=WALL_SIZE){ // spawns 2 tiles in the entrance
var tileX = boundX1 - (WALL_SIZE/2);
var tileY = i;
tileTemp[tileCount] = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'wall'); // spawn a wall
tileTemp[tileCount].body.immovable = true;
tileTemp[tileCount].scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tileTemp[tileCount].anchor.x = 0.5;
tileTemp[tileCount].anchor.y = 0.5;
tileTemp[tileCount].alpha = 0;
tileCount++;
}
// right boundary
for (var i = ((boundY1+boundY2)/2) - (WALL_SIZE/2); i<= ((boundY1+boundY2)/2) + (WALL_SIZE/2); i +=WALL_SIZE){ // spawns 2 tiles in the entrance
var tileX = boundX2 + (WALL_SIZE/2);
var tileY = i;
tileTemp[tileCount] = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'wall'); // spawn a wall
tileTemp[tileCount].body.immovable = true;
tileTemp[tileCount].scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tileTemp[tileCount].anchor.x = 0.5;
tileTemp[tileCount].anchor.y = 0.5;
tileTemp[tileCount].alpha = 0;
tileCount++;
}
}
// Makes a border around the bossroom.
function MakeBossBounds(){
var boundX1 = bossroom[0] - (bossroom[2]/2);
var boundX2 = bossroom[0] + (bossroom[2]/2);
var boundY1 = bossroom[1] - (bossroom[3]/2);
var boundY2 = bossroom[1] + (bossroom[3]/2);
// create upper wall
for (var i = boundX1 - (WALL_SIZE/2); i <= boundX2 + (WALL_SIZE/2); i += WALL_SIZE){
var tileX = i;
var tileY = boundY1 - (WALL_SIZE/2);
var tile = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'ledge'); // spawn a wall
tile.body.immovable = true;
tile.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tile.anchor.x = 0.5;
tile.anchor.y = 0.5;
}
// create lower wall
for (var i = boundX1 - (WALL_SIZE/2); i <= boundX2 + (WALL_SIZE/2); i += WALL_SIZE){
var tileX = i;
var tileY = boundY2 + (WALL_SIZE/2);
var tile = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'wall'); // spawn a wall
tile.body.immovable = true;
tile.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tile.anchor.x = 0.5;
tile.anchor.y = 0.5;
}
// create left wall
for (var i = boundY1 - (WALL_SIZE/2); i <= boundY2 + (WALL_SIZE/2); i += WALL_SIZE){
var tileX = boundX1 - (WALL_SIZE/2);
var tileY = i;
var tile = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'wall'); // spawn a wall
tile.body.immovable = true;
tile.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tile.anchor.x = 0.5;
tile.anchor.y = 0.5;
}
// create right wall
for (var i = boundY1 - (WALL_SIZE/2); i <= boundY2 + (WALL_SIZE/2); i += WALL_SIZE){
var tileX = boundX2 + (WALL_SIZE/2);
var tileY = i;
var tile = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'wall'); // spawn a wall
tile.body.immovable = true;
tile.scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tile.anchor.x = 0.5;
tile.anchor.y = 0.5;
}
// These are here to prevent the player from walking through the doors as they close.
// top boundary
tileTemp = [];
var tileCount = 0;
for (var i = ((boundX1+boundX2)/2) - (WALL_SIZE/2); i<= ((boundX1+boundX2)/2)+ (WALL_SIZE/2); i +=WALL_SIZE){ // spawns 2 tiles in the entrance
var tileX =i;
var tileY = boundY1 - (WALL_SIZE/2);
tileTemp[tileCount] = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'ledge'); // spawn a wall
tileTemp[tileCount].body.immovable = true;
tileTemp[tileCount].scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tileTemp[tileCount].anchor.x = 0.5;
tileTemp[tileCount].anchor.y = 0.5;
tileTemp[tileCount].alpha = 0;
tileCount++;
}
// bottom boundary
for (var i = ((boundX1+boundX2)/2) - (WALL_SIZE/2); i<= ((boundX1+boundX2)/2)+ (WALL_SIZE/2); i +=WALL_SIZE){ // spawns 2 tiles in the entrance
var tileX = i;
var tileY = boundY2 + (WALL_SIZE/2);
tileTemp[tileCount] = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'wall'); // spawn a wall
tileTemp[tileCount].body.immovable = true;
tileTemp[tileCount].scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tileTemp[tileCount].anchor.x = 0.5;
tileTemp[tileCount].anchor.y = 0.5;
tileTemp[tileCount].alpha = 0;
tileCount++;
}
// left boundary
for (var i = ((boundY1+boundY2)/2) - (WALL_SIZE/2); i<= ((boundY1+boundY2)/2) + (WALL_SIZE/2); i +=WALL_SIZE){ // spawns 2 tiles in the entrance
var tileX = boundX1 - (WALL_SIZE/2);
var tileY = i;
tileTemp[tileCount] = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'wall'); // spawn a wall
tileTemp[tileCount].body.immovable = true;
tileTemp[tileCount].scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tileTemp[tileCount].anchor.x = 0.5;
tileTemp[tileCount].anchor.y = 0.5;
tileTemp[tileCount].alpha = 0;
tileCount++;
}
// right boundary
for (var i = ((boundY1+boundY2)/2) - (WALL_SIZE/2); i<= ((boundY1+boundY2)/2) + (WALL_SIZE/2); i +=WALL_SIZE){ // spawns 2 tiles in the entrance
var tileX = boundX2 + (WALL_SIZE/2);
var tileY = i;
tileTemp[tileCount] = currentwalls.create(tileX - (tileX % WALL_SIZE) + (WALL_SIZE/2), tileY - (tileY % WALL_SIZE) + (WALL_SIZE/2), 'tile_atlas', 'wall'); // spawn a wall
tileTemp[tileCount].body.immovable = true;
tileTemp[tileCount].scale.setTo(WALL_SIZE/64, WALL_SIZE/64);
tileTemp[tileCount].anchor.x = 0.5;
tileTemp[tileCount].anchor.y = 0.5;
tileTemp[tileCount].alpha = 0;
tileCount++;
}
}