mirror of
https://github.com/danbulant/heaventaker
synced 2026-07-07 20:20:47 +00:00
preserve wind
This commit is contained in:
parent
5d7db80f3d
commit
13d23ce5f1
1 changed files with 12 additions and 13 deletions
|
|
@ -60,16 +60,19 @@ export class GameScene extends Phaser.Scene {
|
||||||
* @type {{ type: string, direction?: number, sprite: Phaser.GameObjects.Sprite, animated: boolean }[][]}
|
* @type {{ type: string, direction?: number, sprite: Phaser.GameObjects.Sprite, animated: boolean }[][]}
|
||||||
*/
|
*/
|
||||||
this.items = new Array(this.map.map.length);
|
this.items = new Array(this.map.map.length);
|
||||||
|
this.winds = new Array(this.map.map.length);
|
||||||
for(var y in this.map.map) {
|
for(var y in this.map.map) {
|
||||||
var row = this.map.map[y];
|
var row = this.map.map[y];
|
||||||
|
|
||||||
for(var x in row) {
|
for(var x in row) {
|
||||||
if(!this.items[x]) {
|
if(!this.items[x]) {
|
||||||
this.items[x] = new Array(row.length);
|
this.items[x] = new Array(row.length);
|
||||||
|
this.winds[x] = new Array(row.length);
|
||||||
}
|
}
|
||||||
var item = row[x];
|
var item = row[x];
|
||||||
if(!item) {
|
if(!item) {
|
||||||
this.items[x][y] = null;
|
this.items[x][y] = null;
|
||||||
|
this.winds[x][y] = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(typeof item === "string") {
|
if(typeof item === "string") {
|
||||||
|
|
@ -117,7 +120,13 @@ export class GameScene extends Phaser.Scene {
|
||||||
} else {
|
} else {
|
||||||
item.sprite = null;
|
item.sprite = null;
|
||||||
}
|
}
|
||||||
this.items[x][y] = item;
|
if(item.type !== "wind") {
|
||||||
|
this.items[x][y] = item;
|
||||||
|
this.winds[x][y] = null;
|
||||||
|
} else {
|
||||||
|
this.items[x][y] = null;
|
||||||
|
this.winds[x][y] = item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -135,8 +144,6 @@ export class GameScene extends Phaser.Scene {
|
||||||
this.items[toX][toY] = item;
|
this.items[toX][toY] = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
underPlace = null;
|
|
||||||
|
|
||||||
getMovementFromDirection(direction) {
|
getMovementFromDirection(direction) {
|
||||||
switch(direction) {
|
switch(direction) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|
@ -156,28 +163,20 @@ export class GameScene extends Phaser.Scene {
|
||||||
if(!this.canMove) return;
|
if(!this.canMove) return;
|
||||||
var toX = this.player.x + moveX;
|
var toX = this.player.x + moveX;
|
||||||
var toY = this.player.y + moveY;
|
var toY = this.player.y + moveY;
|
||||||
console.log("Moving", this.player.x, this.player.y, toX, toY);
|
|
||||||
if(toX > this.map.size.x - 1 || toX < 0 || toY > this.map.size.y - 1 || toY < 0) return;
|
if(toX > this.map.size.x - 1 || toX < 0 || toY > this.map.size.y - 1 || toY < 0) return;
|
||||||
var underPlace = this.underPlace;
|
|
||||||
this.underPlace = null;
|
|
||||||
if(this.items[toX][toY]) {
|
if(this.items[toX][toY]) {
|
||||||
if(this.items[toX][toY].type === "wind") {
|
|
||||||
this.underPlace = this.items[toX][toY];
|
|
||||||
} else {
|
|
||||||
if(this.items[toX][toY].type !== "lyre") return;
|
if(this.items[toX][toY].type !== "lyre") return;
|
||||||
if(toX + moveX > this.map.size.x - 1|| toX + moveX < 0 || toY + moveY > this.map.size.y - 1 || toY + moveY < 0) return;
|
if(toX + moveX > this.map.size.x - 1|| toX + moveX < 0 || toY + moveY > this.map.size.y - 1 || toY + moveY < 0) return;
|
||||||
if(this.items[toX + moveX][toY + moveY] && this.items[toX + moveX][toY + moveY].type !== "wind") return;
|
if(this.items[toX + moveX][toY + moveY] && this.items[toX + moveX][toY + moveY].type !== "wind") return;
|
||||||
this.move(toX, toY, toX + moveX, toY + moveY);
|
this.move(toX, toY, toX + moveX, toY + moveY);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.canMove = false;
|
this.canMove = false;
|
||||||
this.move(this.player.x, this.player.y, toX, toY, () => {
|
this.move(this.player.x, this.player.y, toX, toY, () => {
|
||||||
this.canMove = true;
|
this.canMove = true;
|
||||||
this.items[this.player.x][this.player.y] = underPlace;
|
|
||||||
this.player.x = toX;
|
this.player.x = toX;
|
||||||
this.player.y = toY;
|
this.player.y = toY;
|
||||||
if(this.underPlace) {
|
if(this.winds[toX][toY]) {
|
||||||
var movement = this.getMovementFromDirection(this.underPlace.direction);
|
var movement = this.getMovementFromDirection(this.winds[toX][toY].direction);
|
||||||
this.movePlayer(movement.x, movement.y);
|
this.movePlayer(movement.x, movement.y);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue