Web应用课中期项目-拳皇
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.4 KiB

2 years ago
import { AcGameObject } from '/static/js/ac_game_object/base.js'
import { Controller } from '../controller/base.js';
class GameMap extends AcGameObject {
constructor(root) {
super();
this.root = root; // KOF对象
this.$canvas = $('<canvas width="960" height="540" tabindex=0></canvas>');
this.ctx = this.$canvas[0].getContext('2d'); // 获取上下文,canvas对象
this.root.$kof.append(this.$canvas); // 将canvas加入$kof中,this.root.$kof是class=kof的div
this.$canvas.focus(); // 聚焦
this.controller = new Controller(this.$canvas);
2 years ago
this.root.$kof.append($(`<div class="kof-head">
<div class="kof-head-hp-0">
<div><div>100</div></div>
</div>
<div class="kof-head-timer">60</div>
<div class="kof-head-hp-1">
<div><div>100</div></div>
</div>
</div>`));
2 years ago
this.root.$kof.append($(`
<audio id="player" autoplay>
<source src="./static/audios/bgm.m4a" type="audio/mpeg">
</audio>`));
2 years ago
this.time_left = 60000; // 剩余时间
this.$timer = this.root.$kof.find('.kof-head-timer');
2 years ago
this.$bgm = this.root.$kof.find('#player')[0];
this.$bgm.currentTime = 0;
this.$bgm.play();
2 years ago
}
start() {
}
2 years ago
update_timer() { // 更新时间
2 years ago
let [a, b] = this.root.players;
2 years ago
if (a.status === 6 || b.status === 6) {
2 years ago
this.$bgm.pause();
2 years ago
return;
}
2 years ago
2 years ago
this.time_left -= this.time_delta;
if (this.time_left < 0) {
this.time_left = 0;
2 years ago
this.$bgm.pause();
2 years ago
if (a.status !== 6 && b.status !== 6) {
a.status = b.status = 6;
2 years ago
a.current_frame_cnt = b.current_frame_cnt = 0;
2 years ago
a.vx = b.vx = 0;
2 years ago
}
2 years ago
}
2 years ago
this.$timer.text(parseInt(this.time_left / 1000));
2 years ago
}
2 years ago
update() {
2 years ago
this.update_timer();
2 years ago
this.render();
}
render() {
2 years ago
this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
2 years ago
// console.log(this.ctx.canvas.width,this.ctx.canvas.height); // 打印canvas的宽高
// console.log(this.$canvas.width());
// this.ctx.fillStyle = "#21252b"; // 画布的颜色
// // this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height); // 画矩形
// this.ctx.fillRect(0,0,this.$canvas.width(),this.$canvas.height());
}
}
export {
GameMap,
}