From ce6a707526d6b8c2bbe12d3c1d9a4fa808246e76 Mon Sep 17 00:00:00 2001 From: asraelite Date: Tue, 6 Mar 2018 00:32:29 +0000 Subject: [PATCH] Bug fixes --- js/consts.mjs | 4 ++-- js/game/control.mjs | 2 ++ js/game/inventory.mjs | 17 ++++++++++++++++- js/gui/inventory.mjs | 1 + js/world/ship.mjs | 15 +++++++++------ 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/js/consts.mjs b/js/consts.mjs index 03e9d48..845f5a0 100644 --- a/js/consts.mjs +++ b/js/consts.mjs @@ -18,8 +18,8 @@ export const MAX_ZOOM = 100; export const DEFAULT_ZOOM = 10; export const ZOOM_SPEED = 0.01; // Ship landing. Angle in radians. -export const TIP_ANGLE = 0.3; -export const TIP_SPEED = 0.015; +export const TIP_ANGLE = 0.25; +export const TIP_SPEED = 0.03; // Ship flight mechanics. Speed measured in units per tick. export const FUEL_BURN_RATE = 0.01; export const THRUST_POWER = 0.007; diff --git a/js/game/control.mjs b/js/game/control.mjs index b787ee3..9f0cdd4 100644 --- a/js/game/control.mjs +++ b/js/game/control.mjs @@ -48,6 +48,8 @@ function tickPlaying() { if (pressed[mapping.inventory]) { state.inventory = !state.inventory; } + + if (pressed['KeyR']) events.startGame(); } function tickEditing() { diff --git a/js/game/inventory.mjs b/js/game/inventory.mjs index ad563e4..4565f50 100644 --- a/js/game/inventory.mjs +++ b/js/game/inventory.mjs @@ -1,3 +1,4 @@ +import {state} from './index.mjs'; import {modules} from '../data.mjs'; import {images as assets} from '../assets.mjs'; import * as events from './events.mjs'; @@ -5,6 +6,8 @@ import * as events from './events.mjs'; export const items = new Map(); export let currentItem = null; +let onupdate = () => {}; + export function init() { items.clear(); } @@ -20,6 +23,7 @@ export function addItem(type, id) { if (!items.has(mapId)) items.set(mapId, new Tile(type, id)); let tile = items.get(mapId); tile.increase(); + update(); } export function removeItem(type, id) { @@ -31,11 +35,22 @@ export function removeItem(type, id) { items.delete(mapId); currentItem = null; } - events.tossItem(); + if (!state.editing) + events.tossItem(); + update(); } export function selectItem(type, id) { currentItem = items.get(toId(type, id)); + update(); +} + +export function setOnupdate(func) { + onupdate = func; +} + +function update() { + onupdate(); } function toId(type, id) { diff --git a/js/gui/inventory.mjs b/js/gui/inventory.mjs index 815b391..ba3cd7c 100644 --- a/js/gui/inventory.mjs +++ b/js/gui/inventory.mjs @@ -11,6 +11,7 @@ export default class GuiInventory extends GuiElement { this.tileWidth = 4; this.tileHeight = 5; this.currentPage = 0; + inventory.setOnupdate(this.updateTiles.bind(this)); } updateTiles() { diff --git a/js/world/ship.mjs b/js/world/ship.mjs index 831257f..72697b1 100644 --- a/js/world/ship.mjs +++ b/js/world/ship.mjs @@ -111,16 +111,19 @@ export default class Ship extends Body { } resolveCelestialCollision(pos, cel) { - //debugger; + // I don't even know why this works, don't touch it. let theta = this.angleTo(...this.com, ...cel.com); let angleToCom = this.angleTo(...this.com, ...pos); - let angle = angleToCom - theta; - let [force] = this.rotateVector(0, 1, angle); - if (Math.abs(angle) < consts.TIP_ANGLE) { + let turnAngle = angleToCom - theta; + let checkAngle = theta - this.r - Math.PI / 2; + let [force] = this.rotateVector(0, 1, turnAngle); + if (Math.abs(checkAngle) < consts.TIP_ANGLE) { force *= -1; } - if (Math.abs(angle) < 0.003 - && Math.abs(this.rvel) < 0.001) { + let canLand = Math.abs(checkAngle) < 0.03 + && Math.abs(this.rvel) < 0.001; + + if (canLand) { this.landed = true; this.rvel = 0; this.r = theta - Math.PI / 2;