Commit 4d27d9a 1 parent b5cb906 commit 4d27d9a Copy full SHA for 4d27d9a
File tree 2 files changed +20
-10
lines changed
2 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -228,7 +228,7 @@ let drawWalls = () => {
228
228
229
229
let createGhosts = ( ) => {
230
230
ghosts = [ ] ;
231
- for ( let i = 0 ; i < ghostCount ; i ++ ) {
231
+ for ( let i = 0 ; i < ghostCount * 2 ; i ++ ) {
232
232
let newGhost = new Ghost (
233
233
9 * oneBlockSize + ( i % 2 == 0 ? 0 : 1 ) * oneBlockSize ,
234
234
10 * oneBlockSize + ( i % 2 == 0 ? 0 : 1 ) * oneBlockSize ,
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ class Ghost {
26
26
this . target = randomTargetsForGhosts [ this . randomTargetIndex ] ;
27
27
setInterval ( ( ) => {
28
28
this . changeRandomDirection ( ) ;
29
- } , 3000 ) ;
29
+ } , 10000 ) ;
30
30
}
31
31
32
32
isInRange ( ) {
@@ -127,17 +127,27 @@ class Ghost {
127
127
this . direction = tempDirection ;
128
128
return ;
129
129
}
130
+ if (
131
+ this . getMapY ( ) != this . getMapYRightSide ( ) &&
132
+ ( this . direction == DIRECTION_LEFT ||
133
+ this . direction == DIRECTION_RIGHT )
134
+ ) {
135
+ this . direction = DIRECTION_UP ;
136
+ }
137
+ if (
138
+ this . getMapX ( ) != this . getMapXRightSide ( ) &&
139
+ this . direction == DIRECTION_UP
140
+ ) {
141
+ this . direction = DIRECTION_LEFT ;
142
+ }
130
143
this . moveForwards ( ) ;
131
144
if ( this . checkCollisions ( ) ) {
145
+ this . moveBackwards ( ) ;
146
+ this . direction = tempDirection ;
147
+ } else {
148
+ this . moveBackwards ( ) ;
132
149
}
133
- // let addition = 0;
134
- // while (this.checkCollisions()) {
135
- // this.moveBackwards();
136
- // this.direction = (tempDirection + addition) % 4;
137
- // this.moveForwards();
138
- // addition++;
139
- // }
140
- this . moveBackwards ( ) ;
150
+ console . log ( this . direction ) ;
141
151
}
142
152
143
153
calculateNewDirection ( map , destX , destY ) {
You can’t perform that action at this time.
0 commit comments