animations

This commit is contained in:
Daniel Bulant 2021-10-15 16:45:29 +02:00
parent 836e64d23a
commit 067ae8200c
5 changed files with 47 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 KiB

View file

@ -62,6 +62,7 @@ export class GameScene extends Phaser.Scene {
this.load.spritesheet("gabriel", "./images/sprites/angels_chibi/gabriel.png", { frameWidth: textureWidth }); this.load.spritesheet("gabriel", "./images/sprites/angels_chibi/gabriel.png", { frameWidth: textureWidth });
this.load.spritesheet("uziel", "./images/sprites/angels_chibi/uziel.png", { frameWidth: textureWidth }); this.load.spritesheet("uziel", "./images/sprites/angels_chibi/uziel.png", { frameWidth: textureWidth });
this.load.spritesheet("yahweh", "./images/sprites/angels_chibi/yahweh.png", { frameWidth: textureWidth }); this.load.spritesheet("yahweh", "./images/sprites/angels_chibi/yahweh.png", { frameWidth: textureWidth });
this.load.spritesheet("kick", "./images/sprites/taker/kick.png", { frameWidth: textureWidth });
this.load.bitmapFont("gem", "fonts/gem/font.png", "fonts/gem/font.xml"); this.load.bitmapFont("gem", "fonts/gem/font.png", "fonts/gem/font.xml");
} }
@ -88,6 +89,16 @@ export class GameScene extends Phaser.Scene {
this.container.scale = Math.min(xScale, yScale); this.container.scale = Math.min(xScale, yScale);
} }
createAnimationFor(type, length) {
console.log("Created anim", type);
const frames = this.anims.generateFrameNumbers(type);
this.anims.create({
key: type,
frames,
frameRate: frames.length / (length / 1000)
});
}
createMap() { createMap() {
console.log(this.map); console.log(this.map);
@ -102,6 +113,9 @@ export class GameScene extends Phaser.Scene {
this.container.add(this.background); this.container.add(this.background);
this.container.add(this.grid); this.container.add(this.grid);
this.createAnimationFor("move", 400);
this.createAnimationFor("kick", 400);
/** /**
* @type {{ type: string, direction?: number, sprite: Phaser.GameObjects.Sprite, animated: boolean }[][]} * @type {{ type: string, direction?: number, sprite: Phaser.GameObjects.Sprite, animated: boolean }[][]}
*/ */
@ -262,7 +276,7 @@ export class GameScene extends Phaser.Scene {
if(x < 0 || y < 0 || x > this.map.size.x || y > this.map.size.y) throw new Error(`Wind out of bounds at ${x} ${y} in map ${this.map.background}`); if(x < 0 || y < 0 || x > this.map.size.x || y > this.map.size.y) throw new Error(`Wind out of bounds at ${x} ${y} in map ${this.map.background}`);
var mov = this.getMovementFromDirection(this.winds[x][y].direction); var mov = this.getMovementFromDirection(this.winds[x][y].direction);
if(mov.x === 0 && mov.y === 0) throw new Error(`Wind without direction at ${x} ${y} in map ${this.map.background}`); if(mov.x === 0 && mov.y === 0) throw new Error(`Wind without direction at ${x} ${y} in map ${this.map.background}`);
if(this.items[x][y] && this.items[x][y].type !== "wind" && this.items[x][y].type !== "spawn") { if(this.items[x] && this.items[x][y] && this.items[x][y].type !== "wind" && this.items[x][y].type !== "spawn") {
return false; return false;
} }
if(!this.winds[x-mov.x] || !this.winds[x-mov.x][y-mov.y]) { if(!this.winds[x-mov.x] || !this.winds[x-mov.x][y-mov.y]) {
@ -382,6 +396,13 @@ export class GameScene extends Phaser.Scene {
var toX = this.player.x + moveX; var toX = this.player.x + moveX;
var toY = this.player.y + moveY; var toY = this.player.y + moveY;
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;
if(toX < this.player.x) { // moving left
this.items[this.player.x][this.player.y].sprite.flipX = true;
} else if(toX > this.player.x) { // moving right
this.items[this.player.x][this.player.y].sprite.flipX = false;
}
if(this.items[toX][toY] && this.items[toX][toY].type) { if(this.items[toX][toY] && this.items[toX][toY].type) {
if(this.items[toX][toY].type === "key") { if(this.items[toX][toY].type === "key") {
this.items[toX][toY].sprite.destroy(); this.items[toX][toY].sprite.destroy();
@ -394,6 +415,10 @@ export class GameScene extends Phaser.Scene {
this.items[toX][toY] = null; this.items[toX][toY] = null;
this.propagateWinds(); this.propagateWinds();
} else if(this.items[toX][toY].type !== "lyre" && this.tryDestroy(toX, toY)) { } else if(this.items[toX][toY].type !== "lyre" && this.tryDestroy(toX, toY)) {
this.items[this.player.x][this.player.y].sprite.play("kick");
setTimeout(() => {
this.items[this.player.x][this.player.y].sprite.play("spawn");
}, 399)
steps.update(t => --t); steps.update(t => --t);
if(stepNum <= 0) { if(stepNum <= 0) {
this.unload(); this.unload();
@ -412,9 +437,11 @@ export class GameScene extends Phaser.Scene {
} }
// steps.update(t => --t); // steps.update(t => --t);
this.canMove = false; this.canMove = false;
this.items[this.player.x][this.player.y].sprite.play("kick");
this.move(toX, toY, toX + moveX, toY + moveY, () => { this.move(toX, toY, toX + moveX, toY + moveY, () => {
this.canMove = true; this.canMove = true;
this.propagateWinds(); this.propagateWinds();
this.items[this.player.x][this.player.y].sprite.play("spawn");
}); });
return; return;
} else return; } else return;
@ -428,10 +455,12 @@ export class GameScene extends Phaser.Scene {
if(!fromWind) { if(!fromWind) {
steps.update(t => --t); steps.update(t => --t);
} }
this.items[this.player.x][this.player.y].sprite.play("move");
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.player.x = toX; this.player.x = toX;
this.player.y = toY; this.player.y = toY;
this.items[this.player.x][this.player.y].sprite.play("spawn");
}); });
} }

View file

@ -125,6 +125,10 @@ class KeyHandler {
this.keysWasPressed.set("down", true); this.keysWasPressed.set("down", true);
}); });
this.hammertime.get('swipe').set({ direction: Hammer.DIRECTION_ALL }); this.hammertime.get('swipe').set({ direction: Hammer.DIRECTION_ALL });
this.hammertime.get('pinch').set({ enable: true })
this.hammertime.on("pinchin", (ev) => {
this.keysWasPressed.set("pause", true);
});
} }
mountHandlers() { mountHandlers() {
for(var { type, listener, options } of this.handlers) { for(var { type, listener, options } of this.handlers) {

View file

@ -29,7 +29,7 @@
} }
var activeButton = -1; var activeButton = -1;
function select(i) { async function select(i) {
if(!allowSwitch) return; if(!allowSwitch) return;
var next; var next;
if(d.flags && d.flags.includes("chapters") && chaptersDone.length) { if(d.flags && d.flags.includes("chapters") && chaptersDone.length) {
@ -51,16 +51,14 @@
showText = false; showText = false;
art = "/images/death/1.webp"; art = "/images/death/1.webp";
failure = true; failure = true;
(async() => { await asleep(150);
await asleep(150); art = "/images/death/2.webp";
art = "/images/death/2.webp"; await asleep(150);
await asleep(150); art = "/images/death/3.webp";
art = "/images/death/3.webp"; await asleep(150);
await asleep(150); art = "/images/death/4.webp";
art = "/images/death/4.webp"; allowSwitch = true;
allowSwitch = true; failureShown = true;
failureShown = true;
})();
return; return;
} }
} }
@ -69,6 +67,9 @@
failureShown = false; failureShown = false;
failure = false; failure = false;
current = next; current = next;
if(dialog[next].map) {
await asleep(500);
}
d = dialog[current]; d = dialog[current];
art = !character ? null : "/images/angels/" + (d.character_art || d.pose && character.poses ? character.poses[d.pose] : character.art) + ".webp"; art = !character ? null : "/images/angels/" + (d.character_art || d.pose && character.poses ? character.poses[d.pose] : character.art) + ".webp";
background = d.background; background = d.background;

View file

@ -25,7 +25,7 @@ export const characters = t({
poses: { poses: {
semi_angry: "uriel_normal", semi_angry: "uriel_normal",
side_happy: "uriel_happy", side_happy: "uriel_happy",
bat: "uriel_angry" bat: "uriel_unhappy"
} }
}, { }, {
name: c("Michael"), name: c("Michael"),