Add start of ship editing
This commit is contained in:
parent
d85338d9f2
commit
b88c0eb358
18 changed files with 288 additions and 100 deletions
|
@ -1,16 +1,36 @@
|
|||
import * as input from '../input.mjs';
|
||||
import * as events from './events.mjs';
|
||||
import * as player from './player.mjs';
|
||||
import * as graphics from '../graphics/index.mjs';
|
||||
import {state} from './index.mjs';
|
||||
|
||||
export const mapping = {
|
||||
thrust: 'KeyW',
|
||||
left: 'KeyA',
|
||||
right: 'KeyD'
|
||||
right: 'KeyD',
|
||||
exitEdit: 'Escape'
|
||||
};
|
||||
|
||||
export function tick() {
|
||||
let held = input.keyCode.held;
|
||||
let pressed = input.keyCode.pressed;
|
||||
let held, pressed;
|
||||
|
||||
export function tick() {
|
||||
held = input.keyCode.held;
|
||||
pressed = input.keyCode.pressed;
|
||||
|
||||
if (state.editing) {
|
||||
tickEditing();
|
||||
} else if (state.playing) {
|
||||
tickPlaying();
|
||||
}
|
||||
|
||||
if (!state.editing) {
|
||||
if (input.mouse.scroll !== 0) {
|
||||
graphics.changeZoom(-input.mouse.scroll);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function tickPlaying() {
|
||||
if (held[mapping.thrust]) {
|
||||
player.ship.applyThrust({ forward: 1 });
|
||||
}
|
||||
|
@ -23,3 +43,9 @@ export function tick() {
|
|||
player.ship.applyThrust({ turnRight: 1 });
|
||||
}
|
||||
}
|
||||
|
||||
function tickEditing() {
|
||||
if (held[mapping.exitEdit]) {
|
||||
events.endEditing();
|
||||
}
|
||||
}
|
||||
|
|
10
js/game/edit.mjs
Normal file
10
js/game/edit.mjs
Normal file
|
@ -0,0 +1,10 @@
|
|||
import * as game from './index.mjs';
|
||||
import * as graphics from '../graphics/index.mjs';
|
||||
|
||||
export function init() {
|
||||
graphics.setZoom(20);
|
||||
}
|
||||
|
||||
export function end() {
|
||||
|
||||
}
|
|
@ -2,8 +2,34 @@ 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';
|
||||
import * as edit from './edit.mjs';
|
||||
|
||||
export let shipLanded = false;
|
||||
|
||||
export function startGame() {
|
||||
game.changeView('game');
|
||||
graphics.perspective.focusPlayer();
|
||||
}
|
||||
|
||||
export function landShip() {
|
||||
shipLanded = true;
|
||||
game.state.landed = true;
|
||||
}
|
||||
|
||||
export function launchShip() {
|
||||
shipLanded = false;
|
||||
game.state.landed = false;
|
||||
}
|
||||
|
||||
export function editShip() {
|
||||
console.log('a');
|
||||
graphics.changePerspective('parent', -5, 0);
|
||||
game.state.editing = true;
|
||||
edit.init();
|
||||
}
|
||||
|
||||
export function endEditing() {
|
||||
graphics.changePerspective('universe');
|
||||
game.state.editing = false;
|
||||
edit.end();
|
||||
}
|
||||
|
|
|
@ -6,12 +6,15 @@ 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';
|
||||
import * as edit from './edit.mjs';
|
||||
|
||||
export let state;
|
||||
|
||||
export async function init() {
|
||||
state = {
|
||||
view: 'menu',
|
||||
playing: false,
|
||||
editing: false,
|
||||
paused: false
|
||||
};
|
||||
|
||||
|
@ -36,6 +39,9 @@ export function changeView(view) {
|
|||
gui.changeView(view);
|
||||
|
||||
if (view == 'game') {
|
||||
state.playing = true;
|
||||
state.editing = false;
|
||||
state.paused = false;
|
||||
world.init();
|
||||
player.init();
|
||||
}
|
||||
|
|
0
js/game/inventory.mjs
Normal file
0
js/game/inventory.mjs
Normal file
|
@ -1,4 +1,5 @@
|
|||
import * as world from '../world/index.mjs';
|
||||
import * as inventory from './inventory.mjs';
|
||||
|
||||
export let ship;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue