Skip to content

Commit d6b797e

Browse files
committed
refactor to use es6 modules, build with rollup -c
1 parent 832f566 commit d6b797e

29 files changed

+799
-629
lines changed

Diff for: .eslintrc.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"env": {
4+
"browser": true
5+
},
6+
"globals": {
7+
"$":false
8+
},
9+
"parserOptions": {
10+
"ecmaVersion": 5,
11+
"sourceType": "module",
12+
"ecmaFeatures": {
13+
"impliedStrict": true
14+
}
15+
}
16+
}

Diff for: assets/sprites.png

390 Bytes
Loading

Diff for: assets/tiles.png

-409 Bytes
Loading

Diff for: make-shaders

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env node
2+
"use strict";
3+
4+
var fs = require('fs');
5+
6+
// read and minify shaders.
7+
var shaders = 'var ShaderLibrary='+JSON.stringify({
8+
vertex: norm_ws(read('src/shader.vertex', 'utf8')),
9+
fragment: norm_ws(read('src/shader.fragment', 'utf8')),
10+
})+';\n';
11+
12+
// write the game-server data files.
13+
write('gen/shaders.js', 'export ' +shaders);
14+
15+
function read(from) { return fs.readFileSync(from, 'utf8'); }
16+
function write(to, text) { fs.writeFileSync(to, text, 'utf8'); }
17+
function norm_ws(text) { return text.replace(/[ \t]+/g,' ').replace(/\n\s*/g,'\n'); }

Diff for: notes.md

+26-8
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Consider:
164164
Combine 2-3 enemy motions or player motions to make timing harder.
165165
Each room is a mini puzzle you must complete, on each traverse.
166166
- Kill monk, flip switch, climb plarforms.
167-
- Lead chaser, climb ladder, dodge snake while jumping spikes.
167+
- Chaser, climb ladder, dodge snake while jumping spikes.
168168
- Climb ropes across top while avoiding climbers [instead of moving ropes]
169169
- Fixed hazards and a moving hazard to force jumps or dancing around.
170170
- Two synchro left-right enemies with horns above.
@@ -176,7 +176,7 @@ Each room is a mini puzzle you must complete, on each traverse.
176176
- Ocean: quick way jumping over causes damage; slow way to swim down and up.
177177

178178
Enemy mechanics:
179-
Horizontal and Vertical movers.
179+
Horizontal and Vertical movers [synchro, same-extents]
180180
Drop when underneath.
181181
Bats fly at the player.
182182
Chase the player on ground [unless have item, while have item]
@@ -186,13 +186,17 @@ Conveyor belt.
186186
Spikes [timed, switchable]
187187
Moving platforms [switchable]
188188
Fish swimming, jellyfish.
189+
Climbers on ropes.
189190

190191
Environment mechanics:
191192
Cooking food.
192-
Put out fire.
193+
Light or extinguish fire.
194+
Light the torches.
193195
Lower/raise water level.
194196
Burn away.
195-
Catch water in bowl.
197+
Fill bucket, catch water in bowl.
198+
Fire enemies consume water.
199+
Simon says puzzle.
196200

197201
Climbing mechanics:
198202
One-way drop.
@@ -238,18 +242,32 @@ Tile flipping (high bits)
238242
Chunks -> irregular chunks (a template group of chunks)
239243
Wang tiles -> wang chunks (for map generation)
240244

245+
Item pads (unique id)
246+
Inventory.
241247
Keys and doors.
242248
Trampoline.
243-
Sprite sheet.
244-
Dark and light tiles (or light sources?)
245-
Puzzle.
246249
Health recovery.
247250
In/out platform.
248251
Bat gfx.
249252
Snake.
250253
Axe thrower (Horiz)
251254
Up/down spikes.
252-
Spear trap (side)
255+
Spear trap (distance trigger)
253256
Dart trap.
254257
Falling brick.
258+
259+
Puzzle.
260+
Room names.
261+
Ropes sheet.
255262
Torch shader.
263+
Dark and light tiles (or light sources?)
264+
265+
Content-Type: audio/x-wav
266+
267+
rollup:
268+
* createCommonjsModule
269+
Colour conversions [xyz,lab,cie,etc]
270+
Derived conversions (breadth-first-search) is a thing.
271+
Generated bind functions are a thing.
272+
ANSI colour codes module.
273+
Call-site annotations always win e.g. @inline.

Diff for: originals/basement.json

+3-3
Large diffs are not rendered by default.

Diff for: originals/codes.bmp

0 Bytes
Binary file not shown.

Diff for: originals/halls.json

+3-3
Large diffs are not rendered by default.

Diff for: originals/make_maps.py

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
39: ('Entry', 'E', 7),
3333
# player start.
3434
48: ('Belle', 'P', 0),
35+
# doors.
36+
56: ('Green Door', '', 0),
37+
57: ('Red Door', '', 0),
38+
58: ('Blue Door', '', 0),
39+
59: ('Orange Door', '', 0),
40+
# keys.
41+
64: ('Green Key', '', 0),
42+
65: ('Red Key', '', 0),
43+
66: ('Blue Key', '', 0),
44+
67: ('Orange Key', '', 0),
3545
}
3646

3747
def findTile(img, x, y, dx, dy, marker, name):

Diff for: originals/passages.json

+2-2
Large diffs are not rendered by default.

Diff for: originals/rooftops.json

+3-3
Large diffs are not rendered by default.

Diff for: originals/upper.json

+3-3
Large diffs are not rendered by default.

Diff for: package.json

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
{
2-
"name" : "starfall-ae",
3-
"description" : "The space game",
4-
"version" : "0.0.1",
5-
"private" : true,
2+
"name": "starfall-ae",
3+
"description": "The space game",
4+
"version": "0.0.1",
5+
"private": true,
66
"dependencies": {
77
"uglify-js": "2.2.3",
88
"express": "3.0.6",
99
"cheerio": "0.10.5",
10-
"socket.io" : ">0.9.13"
10+
"socket.io": ">0.9.13"
1111
},
12-
"main": "server"
12+
"main": "server",
13+
"devDependencies": {
14+
"rollup": "^0.50.0",
15+
"rollup-plugin-buble": "^0.15.0",
16+
"rollup-plugin-closure-compiler-js": "^1.0.5",
17+
"rollup-plugin-eslint": "^4.0.0",
18+
"rollup-plugin-typescript2": "^0.5.2",
19+
"rollup-plugin-uglify": "^2.0.1"
20+
}
1321
}

Diff for: rollup.closure.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import eslint from 'rollup-plugin-eslint';
2+
import closure from 'rollup-plugin-closure-compiler-js';
3+
4+
// Doesn't match the docs (old format?)
5+
export default {
6+
entry: 'src/start.js',
7+
dest: 'gen/game.js',
8+
format: 'iife',
9+
intro: '(function($){',
10+
outro: '})',
11+
plugins: [
12+
eslint({}),
13+
closure({
14+
env: 'BROWSER',
15+
languageIn: 'ECMASCRIPT6_STRICT',
16+
languageOut: 'ECMASCRIPT5',
17+
compilationLevel: 'ADVANCED',
18+
assumeFunctionWrapper: true
19+
})
20+
]
21+
};

Diff for: rollup.config.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import eslint from 'rollup-plugin-eslint';
2+
import buble from 'rollup-plugin-buble';
3+
4+
// Doesn't match the docs (old format?)
5+
export default {
6+
entry: 'src/start.js',
7+
dest: 'gen/game.js',
8+
format: 'iife',
9+
plugins: [
10+
eslint({}),
11+
buble()
12+
]
13+
};

Diff for: rollup.uglify.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import eslint from 'rollup-plugin-eslint';
2+
import uglify from 'rollup-plugin-uglify';
3+
import buble from 'rollup-plugin-buble';
4+
import typescript from 'rollup-plugin-typescript2';
5+
6+
// Doesn't match the docs (old format?)
7+
export default {
8+
entry: 'src/start.js',
9+
dest: 'gen/game.js',
10+
format: 'iife',
11+
plugins: [
12+
typescript(),
13+
eslint({}),
14+
buble(),
15+
uglify()
16+
]
17+
};

Diff for: src/audio.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
"use strict";
2+
3+
import { log } from './defs';
14

25
// https://www.html5rocks.com/en/tutorials/webaudio/intro/
36
// https://webaudio.github.io/web-audio-api/#idl-def-AudioBufferSourceNode
47

58
// Webkit/blink browsers need prefix, Safari won't work without window.
69
var Snd_Ctx = new (window['AudioContext'] || window['webkitAudioContext'])();
710

8-
function Snd_Sample(src) {
11+
export function Sample(src) {
912
var sample = { buf:null };
1013
var req = new XMLHttpRequest();
1114
req.open('GET', src, true);
@@ -17,7 +20,7 @@ function Snd_Sample(src) {
1720
Snd_Ctx['decodeAudioData'](req['response'], function (buf) {
1821
sample.buf = buf;
1922
done();
20-
}, function (e) { log("EAudio:"+src); done(); });
23+
}, function () { log("EAudio:"+src); done(); });
2124
};
2225
req['onerror'] = function () {
2326
log("EAudio:"+src); done();
@@ -26,7 +29,7 @@ function Snd_Sample(src) {
2629
return sample;
2730
}
2831

29-
function Snd_play(sample) {
32+
export function play(sample) {
3033
if (sample.buf) {
3134
var source = Snd_Ctx.createBufferSource();
3235
source['buffer'] = sample.buf;

Diff for: src/cache.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
function CacheLoader(loader) {
1+
"use strict";
2+
3+
export function CacheLoader(loader) {
24
var cache = {};
35
var loading = 0;
46
var queue = [];

Diff for: src/controls.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*
33
4-
var mouseIsDown = false;
4+
export var mouseIsDown = false;
55
66
function onMouseDown(event) {
77
event.preventDefault();
@@ -33,7 +33,7 @@ document.addEventListener( 'mousewheel', onMouseWheel, false );
3333
3434
*/
3535

36-
var keys = [];
36+
export var keys = [];
3737

3838
function onKeyDown(event) {
3939
// event.preventDefault();

Diff for: src/defs.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
"use strict";
12

2-
var debug = true;
3+
export var debug = true;
34

4-
var log = debug && window.console && console.log && console.log.bind && console.log.bind(console) || function(){};
5-
var trace = log;
5+
var c;
66

7-
var FloatArray = window.Float32Array || window.WebGLFloatArray;
8-
var Uint16Array = window.Uint16Array;
7+
export var log = debug && (c=window['console']) && c['log'] && c['log']['bind'] && c['log']['bind'](c) || function(){};
8+
export var trace = log;
99

10-
// var hasOwn = Object.prototype.hasOwnProperty;
10+
export var FloatArray = window.Float32Array || window.WebGLFloatArray;
11+
export var Uint16Array = window.Uint16Array;

Diff for: src/dom.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
3+
export function getElem(id) { return document.getElementById(id); }
4+
export function removeElem(id,e) { (e=getElem(id)).parentNode.removeChild(e); }

Diff for: src/engine.js

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1+
"use strict";
12

2-
function setAnim(ent, anim) {
3+
import { Sample, play } from './audio';
4+
import { keys } from './controls';
5+
import { movers } from './spawn';
6+
import { white } from './glr';
7+
8+
var jumpSound = Sample('/assets/jump.wav');
9+
var painSound = Sample('/assets/ouch.wav');
10+
11+
export function setAnim(ent, anim) {
312
// start or restart an animation.
413
ent.anim = anim;
514
ent.animOfs = 0; // current animation entry.
615
ent.animTr = anim[1]; // time remaining on current frame.
716
ent.index = anim[0]; // current frame index.
817
}
918

10-
function toAnim(ent, anim) {
19+
export function toAnim(ent, anim) {
1120
// change animation without restarting.
1221
if (ent.anim !== anim) {
1322
setAnim(ent, anim);
1423
}
1524
}
1625

17-
function animateEnts(ents, delta) {
26+
export function animateEnts(ents, delta) {
1827
for (var i=0; i<ents.length; i++) {
1928
var ent = ents[i];
2029
var dt = delta;
@@ -80,8 +89,8 @@ function hitTestMap(map, L, B, R, T, falling, res) {
8089
ladder = true;
8190
if (falling) {
8291
// treat ladder tiles as solid tiles when falling.
83-
var tileT = (y * 32) + 32;
84-
if (tileT > hitB && tileT < T) hitB = tileT;
92+
var ladderT = (y * 32) + 32;
93+
if (ladderT > hitB && ladderT < T) hitB = ladderT;
8594
}
8695
}
8796
}
@@ -123,19 +132,19 @@ var jumpVelocity = 5 * (60/1000);
123132
var gravity = 0.01 * (60/1000);
124133
var walkSpeed = 3 * (60/1000);
125134
var climbSpeed = 3 * (60/1000);
126-
var maxVelX = 8 * (60/1000);
135+
// var maxVelX = 8 * (60/1000);
127136
var maxVelY = 10 * (60/1000);
128137
var res = {};
129138

130139
var hitW = 16 - 5; // subtract more than walkSpeed, for holes/ladders.
131140
var hitW2 = hitW*2-1; // added to left edge for right edge.
132141
var hitH = 16; // must go all the way to bottom of feet.
133142
var hitH2 = 32 - 2; // leave some head clearance for grabbing ledges.
134-
var ropeW = 8; // center must be within 8px of the rope.
143+
// var ropeW = 8; // center must be within 8px of the rope.
135144

136145
var RED = { r:0.47, g:0.094, b:0.075, a:0.15 };
137146

138-
function walkMove(actor, dt, map, movers) {
147+
export function walkMove(actor, dt, map) {
139148

140149
var jump = keys[32]; // Space.
141150
var left = keys[65]; // A.
@@ -206,7 +215,7 @@ function walkMove(actor, dt, map, movers) {
206215
moveY = dt * jumpVelocity;
207216
turnTo = actor.jumpAnim; // overrides everything.
208217
actor.jumpHeld = 1;
209-
Snd_play(jumpSound);
218+
play(jumpSound);
210219
}
211220
/* } else if (actor.jumpHeld > 0 && actor.jumpHeld < 10) {
212221
actor.jumpHeld += 1;
@@ -328,10 +337,10 @@ function walkMove(actor, dt, map, movers) {
328337
actor.health -= 1;
329338
actor.lastDmg -= 250;
330339
actor.color = RED;
331-
Snd_play(painSound);
340+
play(painSound);
332341
} else {
333342
if (actor.lastDmg >= 100) { // stop flashing.
334-
actor.color = GL_white;
343+
actor.color = white;
335344
}
336345
actor.lastDmg += dt;
337346
}
@@ -340,7 +349,7 @@ function walkMove(actor, dt, map, movers) {
340349
actor.lastDmg += dt;
341350
if (actor.lastDmg >= 100) { // stop flashing.
342351
actor.lastDmg = 250; // reset the timer.
343-
actor.color = GL_white;
352+
actor.color = white;
344353
}
345354
}
346355
}

0 commit comments

Comments
 (0)