added zombie texture and basic ki

Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
2020-07-16 05:45:59 +02:00
parent f1d6c7d69f
commit 0004849110
12 changed files with 161 additions and 23 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
export default class TextElement { export default class TextElement {
constructor(scene, item) { constructor(scene, item) {
this.scene = scene; this.scene = scene;
this.text = scene.add.text(item.x, item.y, item.text.text, { this.text = scene.add.text(Math.ceil(item.x), Math.ceil(item.y), item.text.text, {
fontFamily: item.text.fontfamily || "Consolas", fontFamily: item.text.fontfamily || "Consolas",
fontSize: item.text.pixelsize || 16, fontSize: item.text.pixelsize || 16,
align: item.text.halign || "center", align: item.text.halign || "center",
+28 -4
View File
@@ -845,15 +845,15 @@
{ {
"name": "velocity", "name": "velocity",
"type": "int", "type": "int",
"value": 70 "value": 40
} }
], ],
"rotation": 0, "rotation": 0,
"type": "", "type": "",
"visible": true, "visible": true,
"width": 0, "width": 0,
"x": 181.75, "x": 143.75,
"y": 41.5 "y": 400.166666666667
}, },
{ {
"height": 0, "height": 0,
@@ -2768,6 +2768,30 @@
"width": 4800.67, "width": 4800.67,
"x": 5.66667, "x": 5.66667,
"y": 475.667 "y": 475.667
},
{
"height": 0,
"id": 131,
"name": "skelleton",
"point": true,
"properties": [
{
"name": "flipped",
"type": "bool",
"value": false
},
{
"name": "velocity",
"type": "int",
"value": 20
}
],
"rotation": 0,
"type": "",
"visible": true,
"width": 0,
"x": 279.333333333333,
"y": 452
} }
], ],
"opacity": 1, "opacity": 1,
@@ -2792,7 +2816,7 @@
} }
], ],
"nextlayerid": 9, "nextlayerid": 9,
"nextobjectid": 131, "nextobjectid": 132,
"orientation": "orthogonal", "orientation": "orthogonal",
"renderorder": "right-down", "renderorder": "right-down",
"tiledversion": "1.4.1", "tiledversion": "1.4.1",
+10 -3
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<map version="1.4" tiledversion="1.4.1" orientation="orthogonal" renderorder="right-down" width="300" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="9" nextobjectid="131"> <map version="1.4" tiledversion="1.4.1" orientation="orthogonal" renderorder="right-down" width="300" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="9" nextobjectid="132">
<editorsettings> <editorsettings>
<export target="lvl1.json" format="json"/> <export target="lvl1.json" format="json"/>
</editorsettings> </editorsettings>
@@ -243,9 +243,9 @@
</properties> </properties>
<point/> <point/>
</object> </object>
<object id="42" name="zombie" x="181.75" y="41.5"> <object id="42" name="zombie" x="143.75" y="400.167">
<properties> <properties>
<property name="velocity" type="int" value="70"/> <property name="velocity" type="int" value="40"/>
</properties> </properties>
<point/> <point/>
</object> </object>
@@ -803,6 +803,13 @@
<property name="dmg" type="int" value="69"/> <property name="dmg" type="int" value="69"/>
</properties> </properties>
</object> </object>
<object id="131" name="skelleton" x="279.333" y="452">
<properties>
<property name="flipped" type="bool" value="false"/>
<property name="velocity" type="int" value="20"/>
</properties>
<point/>
</object>
</objectgroup> </objectgroup>
<layer id="8" name="Foreground" width="300" height="30"> <layer id="8" name="Foreground" width="300" height="30">
<data encoding="base64"> <data encoding="base64">
Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

-8
View File
@@ -14,7 +14,6 @@ export default class Bat extends FlyingEnemy {
this.dieAnimation = 'batDie'; this.dieAnimation = 'batDie';
this.body.setCollideWorldBounds(true);
this.body.setBounceX(1); this.body.setBounceX(1);
this.play('batIdle'); this.play('batIdle');
} }
@@ -23,11 +22,4 @@ export default class Bat extends FlyingEnemy {
super.update(args) super.update(args)
this.setFlipX(this.body.velocity.x > 0); this.setFlipX(this.body.velocity.x > 0);
} }
die() {
if (this.body.velocity.x !== 0) {
this.body.velocity.x = 0;
super.die();
}
}
} }
+1
View File
@@ -14,6 +14,7 @@ export default class DamageEntity extends Entity {
this.alpha = 0; this.alpha = 0;
this.setDisplaySize(item.width, item.height); this.setDisplaySize(item.width, item.height);
this.setData('active', true);
this.setData('dmg', item.properties.filter(obj => obj.name === 'dmg')[0].value); this.setData('dmg', item.properties.filter(obj => obj.name === 'dmg')[0].value);
} }
} }
+6 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2020. Pascal Syma <pascal@syma.dev> * Copyright (c) 2020. Antonio Martinez Casadesus and Pascal Syma.
* All rights reserved. * All rights reserved.
*/ */
@@ -12,6 +12,10 @@ export default class Enemy extends Entity {
this.spawnPoint = spawnPoint; this.spawnPoint = spawnPoint;
this.setActive(false) this.setActive(false)
this.setData('active', false);
this.body.setCollideWorldBounds(true);
this.body.setBounceX(1);
} }
turnedActive() { turnedActive() {
@@ -23,6 +27,7 @@ export default class Enemy extends Entity {
if (!this.active && this.scene.cameras.main.worldView.x + this.scene.cameras.main.worldView.width >= this.x - this.width) { if (!this.active && this.scene.cameras.main.worldView.x + this.scene.cameras.main.worldView.width >= this.x - this.width) {
this.turnedActive(); this.turnedActive();
this.setActive(true) this.setActive(true)
this.setData('active', true);
} }
} }
} }
+23
View File
@@ -9,6 +9,16 @@ export default class Skeleton extends Enemy {
constructor(scene, item) { constructor(scene, item) {
super(scene, item, "skeleton_archer_style_A/idle/frame1"); super(scene, item, "skeleton_archer_style_A/idle/frame1");
this.setOrigin(0.5, 1).setScale(40 / 62);
this.body.setSize(31, 50, false);
this.body.setOffset(4, 2);
this.body.setBounceX(1);
this.setData('dmg', 0)
this.dieAnimation = 'skeleton_die';
this.hitAnimation = 'skeleton_hit';
} }
turnedActive() { turnedActive() {
@@ -17,4 +27,17 @@ export default class Skeleton extends Enemy {
this.body.velocity.x = vel; this.body.velocity.x = vel;
this.play('skeleton_run'); this.play('skeleton_run');
} }
update(...args) {
super.update(...args);
if (this.body.velocity.x <= 0) {
this.setFlipX(true);
this.body.setOffset(31 - 4, 2);
} else {
this.setFlipX(false)
this.body.setOffset(4, 2);
}
}
} }
+24 -1
View File
@@ -9,13 +9,36 @@ export default class Zombie extends Enemy {
constructor(scene, item) { constructor(scene, item) {
super(scene, item, "zombie"); super(scene, item, "zombie");
this.setOrigin(0.5, 1).setScale(32 / 43);
this.body.setSize(43, 43, false);
this.body.setOffset(4, 12);
this.body.setBounceX(1);
this.dieAnimation = 'zombie_die';
this.hitAnimation = 'zombie_hit';
} }
turnedActive() { turnedActive() {
super.turnedActive(); super.turnedActive();
const vel = this.spawnPoint.properties.filter(obj => obj.name === "velocity")[0].value; let vel = this.spawnPoint.properties.filter(obj => obj.name === "velocity");
if (vel.leave > 0)
vel = vel[0].value;
else
vel = 40;
this.play("zombie_emerge")
.once('animationcomplete', () => {
this.body.velocity.x = vel; this.body.velocity.x = vel;
this.play('zombie_walk');
});
}
update(...args) {
super.update(...args);
this.setFlipX(this.body.velocity.x <= 0);
} }
} }
+10 -2
View File
@@ -17,19 +17,26 @@ export default class Entity extends Phaser.GameObjects.Sprite {
} }
hit(dmg) { hit(dmg) {
if (dmg <= 0)
return;
if (this.hitCooldown) if (this.hitCooldown)
return; return;
this.hitCooldown = true; this.hitCooldown = true;
setTimeout(() => this.hitCooldown = false, 1000);
this.setData('hp', this.getData('hp') - dmg); this.setData('hp', this.getData('hp') - dmg);
console.log(this, this.getData('hp')); console.log(this, this.getData('hp'));
// play hit animation // play hit animation
const shouldDie = this.getData('hp') <= 0; const shouldDie = this.getData('hp') <= 0;
if (shouldDie) {
this.body.velocity.x = 0;
this.setData('active', false);
} else {
setTimeout(() => this.hitCooldown = false, 1000);
}
if (this.hitAnimation !== null) { if (this.hitAnimation !== null) {
this.anims.stop(); this.anims.stop();
this.play(this.hitAnimation) this.play(this.hitAnimation)
@@ -44,6 +51,7 @@ export default class Entity extends Phaser.GameObjects.Sprite {
die() { die() {
if (this.dieAnimation !== null && this.active) { if (this.dieAnimation !== null && this.active) {
this.setData('active', false);
this.play(this.dieAnimation) this.play(this.dieAnimation)
.once('animationcomplete', () => this.destroy()); .once('animationcomplete', () => this.destroy());
} else } else
+54 -1
View File
@@ -24,7 +24,7 @@ export default class Game extends Phaser.Scene {
default: 'arcade', default: 'arcade',
arcade: { arcade: {
gravity: {y: 300}, gravity: {y: 300},
// debug: true debug: true
} }
} }
}); });
@@ -87,6 +87,58 @@ export default class Game extends Phaser.Scene {
repeat: -1 repeat: -1
}); });
this.anims.create({
key: 'skeleton_hit',
frames: this.anims.generateFrameNames('skeleton', {
start: 1,
end: 11,
prefix: 'skeleton_archer_style_A/get_hit/frame'
}),
frameRate: 10
});
this.anims.create({
key: 'skeleton_die',
frames: this.anims.generateFrameNames('skeleton', {
start: 1,
end: 21,
prefix: 'skeleton_archer_style_A/die/frame'
}),
frameRate: 20
});
this.anims.create({
key: 'zombie_die',
frames: this.anims.generateFrameNumbers('zombie', {start: 128, end: 159}),
frameRate: 20,
});
this.anims.create({
key: 'zombie_emerge',
frames: this.anims.generateFrameNumbers('zombie', {start: 160, end: 179}),
frameRate: 10,
});
this.anims.create({
key: 'zombie_hit',
frames: this.anims.generateFrameNumbers('zombie', {start: 224, end: 231}),
frameRate: 10
});
this.anims.create({
key: 'zombie_idle',
frames: this.anims.generateFrameNumbers('zombie', {start: 256, end: 267}),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: 'zombie_walk',
frames: this.anims.generateFrameNumbers('zombie', {start: 288, end: 300}),
frameRate: 10,
repeat: -1
});
this.anims.create({ this.anims.create({
key: 'run', key: 'run',
frames: this.anims.generateFrameNumbers('char', {start: 154, end: 161}), frames: this.anims.generateFrameNumbers('char', {start: 154, end: 161}),
@@ -227,6 +279,7 @@ export default class Game extends Phaser.Scene {
}); });
this.physics.add.overlap(this.player, this.enemys, (p, e) => { this.physics.add.overlap(this.player, this.enemys, (p, e) => {
if (e.getData('active'))
this.player.hit(e.getData('dmg')); this.player.hit(e.getData('dmg'));
}) })
+2
View File
@@ -12,6 +12,7 @@ import charA from "../assets/char_a/spritesheet.png";
import charB from "../assets/char_b/spritesheet.png"; import charB from "../assets/char_b/spritesheet.png";
import charC from "../assets/char_c/spritesheet.png"; import charC from "../assets/char_c/spritesheet.png";
import charD from "../assets/char_d/spritesheet.png"; import charD from "../assets/char_d/spritesheet.png";
import zombie from "../assets/zombie/zombie.png";
import tiles from "../assets/newtiles.png"; import tiles from "../assets/newtiles.png";
import menutiles from "../assets/menu.png"; import menutiles from "../assets/menu.png";
import buttontiles from "../assets/buttons.png"; import buttontiles from "../assets/buttons.png";
@@ -37,6 +38,7 @@ export default class Preload extends Phaser.Scene {
this.load.spritesheet('charB', charB, {frameWidth: 79, frameHeight: 63, margin: 1, spacing: 2}); this.load.spritesheet('charB', charB, {frameWidth: 79, frameHeight: 63, margin: 1, spacing: 2});
this.load.spritesheet('charC', charC, {frameWidth: 79, frameHeight: 63, margin: 1, spacing: 2}); this.load.spritesheet('charC', charC, {frameWidth: 79, frameHeight: 63, margin: 1, spacing: 2});
this.load.spritesheet('charD', charD, {frameWidth: 79, frameHeight: 63, margin: 1, spacing: 2}); this.load.spritesheet('charD', charD, {frameWidth: 79, frameHeight: 63, margin: 1, spacing: 2});
this.load.spritesheet('zombie', zombie, {frameWidth: 43, frameHeight: 55, margin: 1, spacing: 2});
this.load.spritesheet('tiles', tiles, {frameWidth: 16, frameHeight: 16, margin: 1, spacing: 2}); this.load.spritesheet('tiles', tiles, {frameWidth: 16, frameHeight: 16, margin: 1, spacing: 2});
this.load.spritesheet('menutiles', menutiles, {frameWidth: 16, frameHeight: 16, margin: 1, spacing: 2}); this.load.spritesheet('menutiles', menutiles, {frameWidth: 16, frameHeight: 16, margin: 1, spacing: 2});
this.load.spritesheet('buttontiles', buttontiles, {frameWidth: 16, frameHeight: 16, margin: 1, spacing: 2}); this.load.spritesheet('buttontiles', buttontiles, {frameWidth: 16, frameHeight: 16, margin: 1, spacing: 2});