Skip to content

Commit d8bdaf5

Browse files
committed
Fixed AI spawn bugs, cleaned up the solution.
1 parent b3198be commit d8bdaf5

File tree

4 files changed

+14
-64
lines changed

4 files changed

+14
-64
lines changed

gamescene.html

Lines changed: 0 additions & 27 deletions
This file was deleted.

index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
3-
43
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
55
<meta charset="UTF-8">
66
<script src="lib/jquery.min.js"></script>
77
<script src="lib/jquery.transit.min.js"></script>
@@ -18,10 +18,8 @@
1818
<link rel="stylesheet" type="text/css" href="css/ui.css">
1919
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
2020
</head>
21-
2221
<body>
2322
<div class="gamecont">
24-
2523
</body>
2624

2725
</html>

src/Enemy.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Enemy(_color1,blockID){
1515

1616
this.isDead = false;
1717
this._c ;
18-
grid.cell[grid.getCell(this.block)].setCellType('Enemy');
18+
grid.cell[grid.getCell(this.block)].type='Enemy';
1919
}
2020

2121
//$ INITIALIZATION $
@@ -73,7 +73,7 @@ Enemy.prototype.move = function(SwipeType){
7373
switch(SwipeType){
7474
case 'top':
7575
if(grid.cell[this._c].checkCell(SwipeType,this._c)
76-
||grid.cell[this._c - cellsCntX].type === 'Enemy'){
76+
&&grid.cell[this._c - cellsCntX].type !== 'Enemy'){
7777

7878
//Handle Top Swap
7979
grid.cell[this._c].setCellType('Normal');
@@ -87,7 +87,7 @@ Enemy.prototype.move = function(SwipeType){
8787
break;
8888
case 'bottom':
8989
if(grid.cell[this._c].checkCell(SwipeType,this._c)
90-
||grid.cell[this._c + cellsCntX].type === 'Enemy'){
90+
&&grid.cell[this._c + cellsCntX].type !== 'Enemy'){
9191

9292
//Handle Bottom Swap
9393
grid.cell[this._c].setCellType('Normal');
@@ -101,7 +101,7 @@ Enemy.prototype.move = function(SwipeType){
101101
break;
102102
case 'left':
103103
if(grid.cell[this._c].checkCell(SwipeType,this._c)
104-
||grid.cell[this._c - 1].type === 'Enemy'){
104+
&&grid.cell[this._c - 1].type !== 'Enemy'){
105105

106106
//Handle Left Swap
107107
grid.cell[this._c].setCellType('Normal');
@@ -115,7 +115,7 @@ Enemy.prototype.move = function(SwipeType){
115115
break;
116116
case 'right':
117117
if(grid.cell[this._c].checkCell(SwipeType,this._c)
118-
||grid.cell[this._c + 1].type === 'Enemy'){
118+
&&grid.cell[this._c + 1].type !== 'Enemy'){
119119

120120
//Handle Right Swap
121121
grid.cell[this._c].setCellType('Normal');

src/index.js

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ var gameStateRestarts = 0 ;
4141
//-----$*********$-----
4242

4343
var color ;
44-
var grid ;
44+
var grid ;
4545
var actor ;
46-
var enemy = [];
46+
var enemy ;
4747

4848
/*~~~~~$*********$~~~~~*/
4949
/*~~~~~$ CLASSES $~~~~~*/
@@ -60,6 +60,7 @@ var game = new Phaser.Game(Editor_Width, Editor_Height, Phaser.AUTO, 'SkipStack'
6060

6161
//$ preload function $
6262
function preload() {
63+
enemy = new Array();
6364
cellWidth = (Editor_Width - (2*cellsCntX + 2)) / (cellsCntX);
6465
cellHeight = (Editor_Width - (2*cellsCntY + 2)) / (cellsCntY);
6566
}
@@ -90,29 +91,7 @@ function create() {
9091
actor.init();
9192

9293
//enemies initialization ("geometry draw call")
93-
for(var i=0;i<3;i++){
94-
var x = '';
95-
if(randomBoolean[0]()==true){
96-
if(randomBoolean[0]()==true)
97-
x = '0-'+getRandomInt(0,cellsCntY);
98-
else
99-
x = getRandomInt(0,cellsCntX)+'-0';
100-
}
101-
else{
102-
if(randomBoolean[0]()==true)
103-
x = (cellsCntX-1)+'-'+getRandomInt(0,cellsCntY);
104-
else
105-
x = getRandomInt(0,cellsCntX)+'-'+(cellsCntY-1);
106-
}
107-
108-
if(grid.cell[grid.getCell(x)].type === 'Normal')
109-
enemy.push(new Enemy(enemiesColor,x));
110-
else
111-
i--;
112-
}
113-
114-
//Here's where we add additional enemies
115-
for(var i=0;i<gameStateRestarts;i++){
94+
for(var i=0;i<3+gameStateRestarts;i++){
11695
var x = '';
11796
if(randomBoolean[0]()==true){
11897
if(randomBoolean[0]()==true)
@@ -134,8 +113,8 @@ function create() {
134113
}
135114

136115
//enemy initialization ("geometry draw call")
137-
for(var i=0;i<enemy.length;i++)
138-
enemy[i].init();
116+
for(var x=0;x<enemy.length;x++)
117+
enemy[x].init();
139118

140119
EnemyMoveTimeout = game.time.time + beatRate
141120
}
@@ -145,7 +124,7 @@ function update() {
145124
for(var i=0;i<enemy.length;i++)
146125
enemy[i].update();
147126

148-
blips_sfx.play();
127+
//blips_sfx.play();
149128
EnemyMoveTimeout = game.time.time + beatRate;
150129
}
151130

@@ -162,7 +141,7 @@ function render() {
162141

163142
function gameOver(){
164143
if(enemy.length>Math.ceil(cellsCntX/2))
165-
cellsCntY = cellsCntX += 1;
144+
cellsCntY = ++ cellsCntX;
166145

167146
gameStateRestarts ++;
168147
game.state.start(game.state.current);

0 commit comments

Comments
 (0)