|
|
|
@ -31,6 +31,12 @@ export class Player extends AcGameObject { |
|
|
|
|
this.press_keys = this.root.gamemap.controller.press_keys; // 用户按下的所有键值
|
|
|
|
|
this.animations = new Map(); // 每个动作动画的配置
|
|
|
|
|
this.current_frame_cnt = 0; // 当前加载了多少帧
|
|
|
|
|
|
|
|
|
|
this.hp = 100; // 初始血量为100
|
|
|
|
|
this.$hp = this.root.$kof.find(`.kof-head-hp-${this.id}>div`); // 控制血槽
|
|
|
|
|
this.$hp_div = this.$hp.find('div'); |
|
|
|
|
|
|
|
|
|
this.damage = 20; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
start() { |
|
|
|
@ -84,6 +90,7 @@ export class Player extends AcGameObject { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
update_direction() { // 保证两个人物是对称的
|
|
|
|
|
if (this.status === 6) return; //如果人物已经gg,不再修改方向
|
|
|
|
|
let players = this.root.players; |
|
|
|
|
if (players[0] && players[1]) { |
|
|
|
|
let me = this, you = players[1 - this.id]; |
|
|
|
@ -113,11 +120,83 @@ export class Player extends AcGameObject { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 是否攻击到对方
|
|
|
|
|
is_collision(r1, r2) { |
|
|
|
|
if (Math.max(r1.x1, r2.x1) > Math.min(r1.x2, r2.x2)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (Math.max(r1.y1, r2.y1) > Math.min(r1.y2, r2.y2)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 是否被攻击
|
|
|
|
|
is_attack() { |
|
|
|
|
if (this.status === 6) return; //如果人物已经gg,不再受到攻击
|
|
|
|
|
this.status = 5; |
|
|
|
|
this.current_frame_cnt = 0; |
|
|
|
|
this.hp = Math.max(this.hp - this.damage, 0); |
|
|
|
|
|
|
|
|
|
this.$hp_div.animate({ |
|
|
|
|
width: this.$hp.parent().width() * this.hp / 100 |
|
|
|
|
},300); |
|
|
|
|
|
|
|
|
|
this.$hp.animate({ |
|
|
|
|
width: this.$hp.parent().width() * this.hp / 100 |
|
|
|
|
},600); |
|
|
|
|
|
|
|
|
|
this.$hp_div.html(`${this.hp}`); |
|
|
|
|
|
|
|
|
|
if (this.hp <= this.damage) { |
|
|
|
|
this.$hp_div.css({"background-color":"red"}); |
|
|
|
|
} |
|
|
|
|
if (this.hp === 0) { |
|
|
|
|
this.status = 6; // gg
|
|
|
|
|
this.current_frame_cnt = 0; |
|
|
|
|
this.vx = 0; // 被ko之后速度为0
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
update_attack() { |
|
|
|
|
if (this.status === 4 && this.current_frame_cnt === 17) { |
|
|
|
|
let me = this, you = this.root.players[1 - this.id]; |
|
|
|
|
let r1; // 自己的攻击矩形
|
|
|
|
|
if (me.direction > 0) { |
|
|
|
|
r1 = { |
|
|
|
|
x1: me.x + 120, |
|
|
|
|
y1: me.y + 40, |
|
|
|
|
x2: me.x + 120 + 105, |
|
|
|
|
y2: me.y + 40 + 20, |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
r1 = { |
|
|
|
|
x1: me.x - 105, |
|
|
|
|
y1: me.y + 40, |
|
|
|
|
x2: me.x - 105 + 105, |
|
|
|
|
y2: me.y + 40 + 20, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 对手的人物矩形
|
|
|
|
|
let r2 = { |
|
|
|
|
x1: you.x, |
|
|
|
|
y1: you.y, |
|
|
|
|
x2: you.x + you.width, |
|
|
|
|
y2: you.y + you.height, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.is_collision(r1, r2)) { |
|
|
|
|
you.is_attack(); // 成功攻击到对方
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
update() { |
|
|
|
|
this.update_controll(); |
|
|
|
|
this.update_move(); |
|
|
|
|
this.update_direction(); |
|
|
|
|
|
|
|
|
|
this.update_attack(); |
|
|
|
|
|
|
|
|
|
this.render(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -125,6 +204,19 @@ export class Player extends AcGameObject { |
|
|
|
|
// this.ctx.fillStyle = this.color; // 画布的颜色
|
|
|
|
|
// this.ctx.fillRect(this.x, this.y, this.width, this.height); // 画人物
|
|
|
|
|
|
|
|
|
|
// this.ctx.fillStyle = "blue";
|
|
|
|
|
// this.ctx.fillRect(this.x,this.y,this.width,this.height);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (this.direction > 0) {
|
|
|
|
|
// this.ctx.fillStyle = "red";
|
|
|
|
|
// this.ctx.fillRect(this.x + 120,this.y + 40,105,20);
|
|
|
|
|
// }else {
|
|
|
|
|
// this.ctx.fillStyle = "green";
|
|
|
|
|
// this.ctx.fillRect(this.x - 105,this.y + 40,105,20);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let status = this.status; |
|
|
|
|
|
|
|
|
|
if (this.status === 1 && this.direction * this.vx < 0) status = 2; |
|
|
|
@ -150,9 +242,12 @@ export class Player extends AcGameObject { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (status === 4) { |
|
|
|
|
if (status === 4 || status === 5 || status === 6) { // 动画演示完结束
|
|
|
|
|
if (this.current_frame_cnt === obj.frame_rate * (obj.frame_cnt - 1)) { |
|
|
|
|
this.status = 0; |
|
|
|
|
if (status === 6) { |
|
|
|
|
this.current_frame_cnt--; |
|
|
|
|
} |
|
|
|
|
else this.status = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|