Add ship movement
This commit is contained in:
parent
09b3df649c
commit
4959519f39
15 changed files with 278 additions and 77 deletions
25
js/game/control.mjs
Normal file
25
js/game/control.mjs
Normal file
|
@ -0,0 +1,25 @@
|
|||
import * as input from '../input.mjs';
|
||||
import * as player from './player.mjs';
|
||||
|
||||
export const mapping = {
|
||||
thrust: 'KeyW',
|
||||
left: 'KeyA',
|
||||
right: 'KeyD'
|
||||
};
|
||||
|
||||
export function tick() {
|
||||
let held = input.keyCode.held;
|
||||
let pressed = input.keyCode.pressed;
|
||||
|
||||
if (held[mapping.thrust]) {
|
||||
player.ship.applyThrust({ forward: 1 });
|
||||
}
|
||||
|
||||
if (held[mapping.left]) {
|
||||
player.ship.applyThrust({ turnLeft: 1 });
|
||||
}
|
||||
|
||||
if (held[mapping.right]) {
|
||||
player.ship.applyThrust({ turnRight: 1 });
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import * as game from './index.mjs';
|
||||
import * as graphics from '../graphics/index.mjs';
|
||||
import * as world from '../world/index.mjs';
|
||||
import * as player from './player.mjs';
|
||||
|
||||
export function startGame() {
|
||||
game.changeView('game');
|
||||
|
|
|
@ -4,6 +4,8 @@ import * as assets from '../assets.mjs';
|
|||
import * as input from '../input.mjs';
|
||||
import * as world from '../world/index.mjs';
|
||||
import * as events from './events.mjs';
|
||||
import * as control from './control.mjs';
|
||||
import * as player from './player.mjs';
|
||||
|
||||
export let state;
|
||||
|
||||
|
@ -35,11 +37,16 @@ export function changeView(view) {
|
|||
|
||||
if (view == 'game') {
|
||||
world.init();
|
||||
player.init();
|
||||
}
|
||||
}
|
||||
|
||||
async function tick() {
|
||||
if (state.view == 'game') world.tick();
|
||||
if (state.view == 'game') {
|
||||
world.tick();
|
||||
control.tick();
|
||||
}
|
||||
|
||||
gui.tick();
|
||||
graphics.render();
|
||||
input.tick();
|
||||
|
|
7
js/game/player.mjs
Normal file
7
js/game/player.mjs
Normal file
|
@ -0,0 +1,7 @@
|
|||
import * as world from '../world/index.mjs';
|
||||
|
||||
export let ship;
|
||||
|
||||
export function init() {
|
||||
ship = world.playerShip;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue