42 lines
875 B
JavaScript
42 lines
875 B
JavaScript
|
import * as ujs from './engine.js';
|
||
|
|
||
|
let app = new ujs.App(400, 400);
|
||
|
|
||
|
let player = {
|
||
|
x: 200 - 25,
|
||
|
y: 200 - 25,
|
||
|
obj: null,
|
||
|
};
|
||
|
|
||
|
player.obj = new ujs.Rect(player.x, player.y, 50, 50, 'red');
|
||
|
player.obj.ticker = () => {
|
||
|
player.obj.y = player.y;
|
||
|
player.obj.x = player.x;
|
||
|
};
|
||
|
|
||
|
let firstScene = new ujs.Scene(app.canvas, app.context, 400, 400);
|
||
|
let layerInstances = new ujs.SceneLayer('Instances', [player.obj]);
|
||
|
firstScene.addLayer(layerInstances);
|
||
|
app.scene = firstScene;
|
||
|
|
||
|
window.addEventListener('DOMContentLoaded', () => {
|
||
|
document.body.appendChild(app.view);
|
||
|
});
|
||
|
|
||
|
document.addEventListener('keydown', (e) => {
|
||
|
switch (e.code) {
|
||
|
case 'ArrowUp':
|
||
|
player.y -= 10;
|
||
|
break;
|
||
|
case 'ArrowDown':
|
||
|
player.y += 10;
|
||
|
break;
|
||
|
case 'ArrowLeft':
|
||
|
player.x -= 10;
|
||
|
break;
|
||
|
case 'ArrowRight':
|
||
|
player.x += 10;
|
||
|
break;
|
||
|
}
|
||
|
});
|