Add item markers
This commit is contained in:
parent
b27bd7bba2
commit
3eb74e44aa
8 changed files with 41 additions and 12 deletions
|
@ -37,7 +37,8 @@ export const images = {
|
||||||
export const audio = {
|
export const audio = {
|
||||||
itemPickup: 'up1.mp3',
|
itemPickup: 'up1.mp3',
|
||||||
fuelPickup: 'blip2.mp3',
|
fuelPickup: 'blip2.mp3',
|
||||||
endEdit: 'release1.mp3'
|
endEdit: 'release1.mp3',
|
||||||
|
newPlanet: 'up2.mp3'
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function init() {
|
export async function init() {
|
||||||
|
|
|
@ -33,7 +33,7 @@ export const EDIT_MARGIN = 2;
|
||||||
// Floating items.
|
// Floating items.
|
||||||
export const ENTITY_ROTATION_RATE = 0.01;
|
export const ENTITY_ROTATION_RATE = 0.01;
|
||||||
// World generation.
|
// World generation.
|
||||||
export const PLANET_SPAWN_RATE = 3;
|
export const PLANET_SPAWN_RATE = 50;
|
||||||
export const ENTITY_SPAWN_RATE = 8;
|
export const ENTITY_SPAWN_RATE = 8;
|
||||||
export const MIN_CELESTIAL_SPACING = 15;
|
export const MIN_CELESTIAL_SPACING = 15;
|
||||||
export const FUEL_CAN_AMOUNT = 4;
|
export const FUEL_CAN_AMOUNT = 4;
|
||||||
|
|
|
@ -12,7 +12,8 @@ export const mapping = {
|
||||||
exitEdit: 'Escape',
|
exitEdit: 'Escape',
|
||||||
inventory: 'KeyE',
|
inventory: 'KeyE',
|
||||||
cycleRotation: 'KeyC',
|
cycleRotation: 'KeyC',
|
||||||
toggleTrace: 'KeyT'
|
toggleTrace: 'KeyT',
|
||||||
|
toggleMarkers: 'KeyR'
|
||||||
};
|
};
|
||||||
|
|
||||||
let held, pressed;
|
let held, pressed;
|
||||||
|
@ -59,14 +60,16 @@ function tickPlaying() {
|
||||||
events.toggleTrace();
|
events.toggleTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pressed[mapping.toggleMarkers]) {
|
||||||
|
events.toggleMarkers();
|
||||||
|
}
|
||||||
|
|
||||||
// For debugging.
|
// For debugging.
|
||||||
if (pressed['KeyR']) events.startGame();
|
if (pressed['KeyZ']) events.startGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
function tickEditing() {
|
function tickEditing() {
|
||||||
if (pressed[mapping.exitEdit]) {
|
if (pressed[mapping.exitEdit]) {
|
||||||
events.endEditing();
|
events.endEditing();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pressed['KeyX']) throw new Error();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,10 @@ let notLife = 0;
|
||||||
|
|
||||||
let landedPlanets = new Set();
|
let landedPlanets = new Set();
|
||||||
|
|
||||||
function notify(message) {
|
function notify(message, time = 80) {
|
||||||
if (notification === null) return;
|
if (notification === null) return;
|
||||||
notification.text = message;
|
notification.text = message;
|
||||||
notLife = 80;
|
notLife = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tick() {
|
export function tick() {
|
||||||
|
@ -47,6 +47,7 @@ export function landShip(planet) {
|
||||||
function newPlanet(planet) {
|
function newPlanet(planet) {
|
||||||
let value = (planet.radius + 30) | 0;
|
let value = (planet.radius + 30) | 0;
|
||||||
landedPlanets.add(planet);
|
landedPlanets.add(planet);
|
||||||
|
audio.play('newPlanet');
|
||||||
score += value;
|
score += value;
|
||||||
notify('Landed on new planet: +' + value);
|
notify('Landed on new planet: +' + value);
|
||||||
}
|
}
|
||||||
|
@ -71,6 +72,11 @@ export function toggleTrace() {
|
||||||
notify('Path prediction: ' + (trace ? 'on' : 'off'));
|
notify('Path prediction: ' + (trace ? 'on' : 'off'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toggleMarkers() {
|
||||||
|
let markers = graphics.toggleMarkers();
|
||||||
|
notify('Item markers: ' + (markers ? 'on' : 'off'));
|
||||||
|
}
|
||||||
|
|
||||||
export function cycleRotationMode() {
|
export function cycleRotationMode() {
|
||||||
let message = {
|
let message = {
|
||||||
parent: 'planet',
|
parent: 'planet',
|
||||||
|
@ -105,7 +111,7 @@ export function tossItem() {
|
||||||
particle.createItemToss(world.playerShip);
|
particle.createItemToss(world.playerShip);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function collectItem(type, id) {
|
export function collectItem(type, id, name) {
|
||||||
if (type === 'fuelcan') {
|
if (type === 'fuelcan') {
|
||||||
world.playerShip.addFuel(consts.FUEL_CAN_AMOUNT);
|
world.playerShip.addFuel(consts.FUEL_CAN_AMOUNT);
|
||||||
audio.play('fuelPickup');
|
audio.play('fuelPickup');
|
||||||
|
@ -116,7 +122,7 @@ export function collectItem(type, id) {
|
||||||
inventory.addItem(type, id);
|
inventory.addItem(type, id);
|
||||||
audio.play('itemPickup');
|
audio.play('itemPickup');
|
||||||
score += 20;
|
score += 20;
|
||||||
notify('Collected module: +20');
|
notify(`Collected "${name}" module: +20`, 150);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ export async function init() {
|
||||||
gui.init();
|
gui.init();
|
||||||
input.init();
|
input.init();
|
||||||
|
|
||||||
//events.startGame();
|
events.startGame();
|
||||||
|
|
||||||
//tick(); return;
|
//tick(); return;
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ const TAU = consts.TAU;
|
||||||
export let canvas, context, tempCanvas, tempContext;
|
export let canvas, context, tempCanvas, tempContext;
|
||||||
export let perspective;
|
export let perspective;
|
||||||
export let trace = false;
|
export let trace = false;
|
||||||
|
export let markers = false;
|
||||||
|
|
||||||
export function init() {
|
export function init() {
|
||||||
canvas = document.querySelector('#main');
|
canvas = document.querySelector('#main');
|
||||||
|
@ -74,6 +75,11 @@ export function toggleTrace() {
|
||||||
return trace;
|
return trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toggleMarkers() {
|
||||||
|
markers = !markers;
|
||||||
|
return markers;
|
||||||
|
}
|
||||||
|
|
||||||
export function changeZoom(delta) {
|
export function changeZoom(delta) {
|
||||||
perspective.zoomDelta(delta);
|
perspective.zoomDelta(delta);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,17 @@ function renderParticle(particle) {
|
||||||
function renderEntity(entity) {
|
function renderEntity(entity) {
|
||||||
context.save();
|
context.save();
|
||||||
context.translate(...entity.com);
|
context.translate(...entity.com);
|
||||||
|
if (graphics.perspective.zoom < 2 && graphics.markers) {
|
||||||
|
context.globalAlpha = 0.7 / graphics.perspective.zoom;
|
||||||
|
context.beginPath();
|
||||||
|
context.arc(0, 0, 4, 0, 2 * Math.PI);
|
||||||
|
context.lineWidth = 1;
|
||||||
|
context.strokeStyle = '#31911b';
|
||||||
|
if (entity.type === 'fuelcan')
|
||||||
|
context.strokeStyle = '#af4021';
|
||||||
|
context.stroke();
|
||||||
|
context.globalAlpha = 1;
|
||||||
|
}
|
||||||
context.rotate(entity.r);
|
context.rotate(entity.r);
|
||||||
context.drawImage(entity.image, -0.5, -0.5, 1, 1);
|
context.drawImage(entity.image, -0.5, -0.5, 1, 1);
|
||||||
context.restore();
|
context.restore();
|
||||||
|
|
|
@ -23,8 +23,10 @@ export default class Entity extends Body {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
if (this.type === 'fuelcan') {
|
if (this.type === 'fuelcan') {
|
||||||
this.image = assets.modules.fuelcan;
|
this.image = assets.modules.fuelcan;
|
||||||
|
this.name = 'Fuel Can';
|
||||||
} else {
|
} else {
|
||||||
this.image = assets.modules[type][id];
|
this.image = assets.modules[type][id];
|
||||||
|
this.name = modules[type][id].name;
|
||||||
if (this.type === 'thruster')
|
if (this.type === 'thruster')
|
||||||
this.image = this.image.off;
|
this.image = this.image.off;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +57,7 @@ export default class Entity extends Body {
|
||||||
if (playerShip.colliding(this.com, this.radius)) {
|
if (playerShip.colliding(this.com, this.radius)) {
|
||||||
if (this.touched) return;
|
if (this.touched) return;
|
||||||
this.touched = true;
|
this.touched = true;
|
||||||
let success = events.collectItem(this.type, this.id);
|
let success = events.collectItem(this.type, this.id, this.name);
|
||||||
if (!success) return;
|
if (!success) return;
|
||||||
particle.createPickupBurst(playerShip, this.com);
|
particle.createPickupBurst(playerShip, this.com);
|
||||||
this.remove();
|
this.remove();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue