44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
|
var asdf = require("asdf-games");
|
||
|
const { math, KeyControls, Texture, Sprite, TileSprite, TileMap } = asdf;
|
||
|
|
||
|
const texture = new Texture('./res/placeholder.png');
|
||
|
|
||
|
const levelSize = { w: 640, h: 320 };
|
||
|
var levelData = [];
|
||
|
|
||
|
for (let index = 0; index < ((levelSize.w / 32) * (levelSize.h / 32)); index++) {
|
||
|
levelData.push({ x: 0, y: 0 });
|
||
|
}
|
||
|
|
||
|
class Level extends TileMap {
|
||
|
constructor (window, keys, player) {
|
||
|
super(levelData, levelSize.w / 32, levelSize.h / 32, 32, 32, texture);
|
||
|
this.pos.x = (window.w / 2) - (levelSize.w / 2);
|
||
|
this.pos.y = (window.h / 2) - (levelSize.h / 2);
|
||
|
|
||
|
this.keys = keys;
|
||
|
this.player = player
|
||
|
}
|
||
|
|
||
|
update(dt, t) {
|
||
|
// Change walking direction
|
||
|
if (this.keys.x == -1) {
|
||
|
// Left
|
||
|
this.pos.x = this.pos.x + dt * (1 / this.player.rate) * 10;
|
||
|
}
|
||
|
if (this.keys.x == 1) {
|
||
|
// Right
|
||
|
this.pos.x = this.pos.x - dt * (1 / this.player.rate) * 10;
|
||
|
}
|
||
|
if (this.keys.y == -1) {
|
||
|
// Down
|
||
|
this.pos.y = this.pos.y + dt * (1 / this.player.rate) * 10;
|
||
|
}
|
||
|
if (this.keys.y == 1) {
|
||
|
// Up
|
||
|
this.pos.y = this.pos.y - dt * (1 / this.player.rate) * 10;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = Level;
|