added entitys, enemys, bats and custom attack hitboxes for players
added map loading and one-way collision (needs to move to tiled attribute tho) Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2020. Pascal Syma <pascal@syma.dev>
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
import Entity from "./Entity";
|
||||
import AttackA from "./Attacks/AttackA";
|
||||
|
||||
export default class Player extends Entity {
|
||||
|
||||
constructor(scene, spawnPoint, texture) {
|
||||
super(scene, spawnPoint.x, spawnPoint.y, texture);
|
||||
this.setData("speed", 100);
|
||||
this.setData('hp', 20);
|
||||
this.setOrigin(0.5, 1).setScale(32 / 48);
|
||||
|
||||
this.body.setSize(48, 48, false);
|
||||
this.body.setOffset(4, 16);
|
||||
|
||||
this.body.setCollideWorldBounds(true);
|
||||
this.play('idle');
|
||||
|
||||
this.attackA = new AttackA(this);
|
||||
this.attackHitbox = this.scene.add.group([
|
||||
this.attackA
|
||||
]);
|
||||
}
|
||||
|
||||
update(...args) {
|
||||
if (this.scene.dieActive()) {
|
||||
this.pause = true;
|
||||
this.play('die', true)
|
||||
.on('animationcomplete', () => {
|
||||
this.setFrame(51);
|
||||
this.scene.scene.pause();
|
||||
})
|
||||
}
|
||||
|
||||
if (this.pause)
|
||||
return;
|
||||
|
||||
this.body.velocity.x = 0;
|
||||
|
||||
// Jumping, Dashing
|
||||
if (this.scene.upActive() && this.body.blocked.down) {
|
||||
this.body.velocity.y = -this.getData('speed') * 1.5;
|
||||
} else if (this.scene.downActive() && !this.body.blocked.down) {
|
||||
this.body.velocity.y = this.getData('speed');
|
||||
}
|
||||
|
||||
// Walking L R
|
||||
if (this.scene.leftActive()) {
|
||||
this.body.velocity.x = -this.getData('speed');
|
||||
if (!this.flipX)
|
||||
this.x -= 16;
|
||||
this.setFlipX(true);
|
||||
this.body.setOffset(32 - 4, 16);
|
||||
} else if (this.scene.rightActive()) {
|
||||
this.body.velocity.x = this.getData('speed');
|
||||
if (this.flipX)
|
||||
this.x += 16;
|
||||
this.setFlipX(false);
|
||||
this.body.setOffset(4, 16);
|
||||
}
|
||||
|
||||
this.setData('speed', 100);
|
||||
|
||||
// animation
|
||||
if (this.anims.getCurrentKey().startsWith('attack_')) {
|
||||
this.setData('speed', 50);
|
||||
} else if (this.scene.keySpace.isDown) {
|
||||
// const nextAttack = [this.attackA].sort(() => 0.5 - Math.random())[0];
|
||||
// nextAttack.start();
|
||||
this.attackA.start();
|
||||
} else if (this.body.blocked.down) {
|
||||
if (this.body.velocity.x !== 0) {
|
||||
this.play('run', true);
|
||||
} else {
|
||||
this.play('idle', true);
|
||||
}
|
||||
} else if (this.anims.getCurrentKey() !== 'jump_start' && this.anims.getCurrentKey() !== 'jump') {
|
||||
// this.play('jump', true)
|
||||
this.play('jump_start', true).on('animationcomplete', () => this.play('jump', true));
|
||||
}
|
||||
|
||||
this.attackHitbox.getChildren().forEach(c => {
|
||||
c.update()
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user