Bug fixes

This commit is contained in:
asraelite 2018-03-06 00:32:29 +00:00
parent 69fee5e73d
commit ce6a707526
5 changed files with 30 additions and 9 deletions

View file

@ -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;

View file

@ -48,6 +48,8 @@ function tickPlaying() {
if (pressed[mapping.inventory]) {
state.inventory = !state.inventory;
}
if (pressed['KeyR']) events.startGame();
}
function tickEditing() {

View file

@ -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) {

View file

@ -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() {

View file

@ -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;