littlejsengine 1.9.1 → 1.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/{build → dist}/littlejs.d.ts +25 -20
- package/{build → dist}/littlejs.esm.js +160 -61
- package/dist/littlejs.esm.min.js +1 -0
- package/{build → dist}/littlejs.js +160 -61
- package/dist/littlejs.min.js +1 -0
- package/{build → dist}/littlejs.release.js +154 -59
- package/examples/breakout/game.js +2 -2
- package/examples/breakout/gameObjects.js +3 -3
- package/examples/breakout/index.html +3 -3
- package/examples/breakoutTutorial/index.html +2 -2
- package/examples/electron/build.js +1 -1
- package/examples/electron/game.js +49 -38
- package/examples/electron/index.html +2 -2
- package/examples/electron/tiles.png +0 -0
- package/examples/empty/index.html +1 -1
- package/examples/js13k/build.js +1 -1
- package/examples/js13k/game.js +10 -9
- package/examples/js13k/index.html +13 -13
- package/examples/js13k/tiles.png +0 -0
- package/examples/module/game.js +45 -41
- package/examples/module/index.html +1 -1
- package/examples/module/tiles.png +0 -0
- package/examples/particles/index.html +1 -1
- package/examples/platformer/data/gameTileData.tmx +143 -0
- package/examples/platformer/data/gameTileData.tsx +4 -0
- package/examples/platformer/game.js +0 -1
- package/examples/platformer/gameCharacter.js +1 -1
- package/examples/platformer/gameEffects.js +42 -110
- package/examples/platformer/gameLevel.js +149 -183
- package/examples/platformer/gameObjects.js +61 -16
- package/examples/platformer/gamePlayer.js +3 -2
- package/examples/platformer/gameTileData.js +181 -0
- package/examples/platformer/index.html +8 -7
- package/examples/platformer/tiles.png +0 -0
- package/examples/platformer/tilesLevel.png +0 -0
- package/examples/puzzle/game.js +12 -12
- package/examples/puzzle/index.html +2 -2
- package/examples/starter/build.js +1 -1
- package/examples/starter/game.js +6 -6
- package/examples/starter/index.html +13 -13
- package/examples/starter/tiles.png +0 -0
- package/examples/stress/index.html +1 -1
- package/examples/typescript/build.bat +4 -1
- package/examples/typescript/game.js +34 -31
- package/examples/typescript/game.ts +40 -36
- package/examples/typescript/index.html +1 -1
- package/examples/typescript/tiles.png +0 -0
- package/package.json +3 -3
- package/src/engine.js +1 -1
- package/src/engineAudio.js +4 -10
- package/src/engineBuild.js +9 -2
- package/src/engineDebug.js +6 -2
- package/src/engineInput.js +4 -4
- package/src/engineMedals.js +2 -2
- package/src/engineParticles.js +5 -5
- package/src/engineTileLayer.js +1 -1
- package/src/engineUtilities.js +136 -35
- package/src/engineWebGL.js +1 -1
- package/build/littlejs.esm.min.js +0 -1
- package/build/littlejs.min.js +0 -1
- package/index.d.ts +0 -2094
|
@@ -8,214 +8,180 @@
|
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
|
-
const tileType_ladder
|
|
12
|
-
const tileType_empty
|
|
13
|
-
const tileType_solid
|
|
11
|
+
const tileType_ladder = -1;
|
|
12
|
+
const tileType_empty = 0;
|
|
13
|
+
const tileType_solid = 1;
|
|
14
|
+
const tileType_breakable = 2;
|
|
14
15
|
|
|
15
|
-
let player, playerStartPos,
|
|
16
|
-
let levelSize, levelColor,
|
|
16
|
+
let player, playerStartPos, tileData, tileLayers, foregroundLayerIndex;
|
|
17
|
+
let levelSize, levelColor, levelBackgroundColor, levelOutlineColor, warmup;
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
pos.arrayCheck(tileCollisionSize) ? tileBackground[(pos.y|0)*tileCollisionSize.x+pos.x|0] : 0;
|
|
19
|
+
const setTileData = (pos, layer, data)=>
|
|
20
|
+
pos.arrayCheck(tileCollisionSize) && (tileData[layer][(pos.y|0)*tileCollisionSize.x+pos.x|0] = data);
|
|
21
|
+
const getTileData = (pos, layer)=>
|
|
22
|
+
pos.arrayCheck(tileCollisionSize) ? tileData[layer][(pos.y|0)*tileCollisionSize.x+pos.x|0]: 0;
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
// level generation
|
|
26
|
-
|
|
27
|
-
function buildTerrain(size)
|
|
24
|
+
function buildLevel()
|
|
28
25
|
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
let groundSlope = rand(-1,1);
|
|
34
|
-
let backgroundDelta = 0, backgroundDeltaSlope = 0;
|
|
35
|
-
for (let x=0; x < size.x; x++)
|
|
36
|
-
{
|
|
37
|
-
// pull slope towards start ground level
|
|
38
|
-
groundLevel += groundSlope = rand() < .05 ? rand(-1,1) :
|
|
39
|
-
groundSlope + (startGroundLevel - groundLevel)/1e3;
|
|
40
|
-
|
|
41
|
-
// small jump
|
|
42
|
-
if (rand() < .04)
|
|
43
|
-
groundLevel += rand(9,-9);
|
|
44
|
-
|
|
45
|
-
if (rand() < .03)
|
|
46
|
-
{
|
|
47
|
-
// big jump
|
|
48
|
-
const jumpDelta = rand(19,-19);
|
|
49
|
-
startGroundLevel = clamp(startGroundLevel + jumpDelta, 20, 80);
|
|
50
|
-
groundLevel += jumpDelta;
|
|
51
|
-
groundSlope = rand(-1,1);
|
|
52
|
-
}
|
|
26
|
+
// create the level
|
|
27
|
+
levelColor = randColor(hsl(0,0,.2), hsl(0,0,.8));
|
|
28
|
+
levelBackgroundColor = levelColor.mutate().scale(.4,1);
|
|
29
|
+
levelOutlineColor = levelColor.mutate().add(hsl(0,0,.4)).clamp();
|
|
53
30
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
{
|
|
66
|
-
const pos = vec2(x,y);
|
|
67
|
-
|
|
68
|
-
let frontTile = tileType_empty;
|
|
69
|
-
if (y < groundLevel)
|
|
70
|
-
frontTile = tileType_solid;
|
|
71
|
-
|
|
72
|
-
let backTile = tileType_empty;
|
|
73
|
-
if (y < groundLevel + backgroundDelta)
|
|
74
|
-
backTile = tileType_solid;
|
|
75
|
-
|
|
76
|
-
setTileCollisionData(pos, frontTile);
|
|
77
|
-
setTileBackgroundData(pos, backTile);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
31
|
+
loadLevel();
|
|
32
|
+
initSky();
|
|
33
|
+
initParallaxLayers();
|
|
34
|
+
|
|
35
|
+
// apply decoration to all level tiles
|
|
36
|
+
const pos = vec2();
|
|
37
|
+
const layerCount = tileLayers.length;
|
|
38
|
+
for (let layer=layerCount; layer--;)
|
|
39
|
+
for (pos.x=levelSize.x; pos.x--;)
|
|
40
|
+
for (pos.y=levelSize.y; pos.y--;)
|
|
41
|
+
decorateTile(pos, layer);
|
|
80
42
|
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const offset = vec2();
|
|
87
|
-
for (offset.x = randInt(19,1); --offset.x;)
|
|
88
|
-
for (offset.y = height; --offset.y;)
|
|
89
|
-
setTileCollisionData(pos.add(offset), tileType_empty);
|
|
90
|
-
}
|
|
43
|
+
// warm up level
|
|
44
|
+
warmup = 1;
|
|
45
|
+
for (let i = 500; i--;)
|
|
46
|
+
engineObjectsUpdate();
|
|
47
|
+
warmup = 0;
|
|
91
48
|
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
49
|
+
// spawn player
|
|
50
|
+
player = new Player(cameraPos = playerStartPos);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function loadLevel()
|
|
54
|
+
{
|
|
55
|
+
// load level data from an exported Tiled js file
|
|
56
|
+
const dataName = Object.keys(TileMaps)[0];
|
|
57
|
+
const tileMapData = TileMaps[dataName];
|
|
58
|
+
levelSize = vec2(tileMapData.width, tileMapData.height);
|
|
59
|
+
initTileCollision(levelSize);
|
|
60
|
+
engineObjectsDestroy();
|
|
97
61
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
62
|
+
// set all level data tiles
|
|
63
|
+
tileData = [];
|
|
64
|
+
tileLayers = [];
|
|
65
|
+
playerStartPos = vec2(1, levelSize.y);
|
|
66
|
+
const layerCount = tileMapData.layers.length;
|
|
67
|
+
foregroundLayerIndex = layerCount-1;
|
|
68
|
+
for (let layer=layerCount; layer--;)
|
|
69
|
+
{
|
|
70
|
+
const layerData = tileMapData.layers[layer].data;
|
|
71
|
+
const tileLayer = new TileLayer(vec2(), levelSize, tile(0,16,1));
|
|
72
|
+
tileLayer.renderOrder = -1e3+layer;
|
|
73
|
+
tileLayers[layer] = tileLayer;
|
|
74
|
+
tileData[layer] = [];
|
|
75
|
+
|
|
76
|
+
for (let x=levelSize.x; x--;)
|
|
77
|
+
for (let y=levelSize.y; y--;)
|
|
101
78
|
{
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
79
|
+
const pos = vec2(x,levelSize.y-1-y);
|
|
80
|
+
const tile = layerData[y*levelSize.x+x];
|
|
81
|
+
|
|
82
|
+
if (tile >= 17 && tile <= 20)
|
|
106
83
|
{
|
|
107
|
-
|
|
108
|
-
|
|
84
|
+
// create object instead of tile
|
|
85
|
+
const objectPos = pos.add(vec2(.5));
|
|
86
|
+
if (tile == 17)
|
|
87
|
+
playerStartPos = objectPos;
|
|
88
|
+
if (tile == 18)
|
|
89
|
+
new Crate(objectPos);
|
|
90
|
+
if (tile == 19)
|
|
91
|
+
new Enemy(objectPos);
|
|
92
|
+
if (tile == 20)
|
|
93
|
+
new Coin(objectPos);
|
|
94
|
+
setTileData(pos, layer, 0);
|
|
95
|
+
continue;
|
|
109
96
|
}
|
|
110
|
-
|
|
97
|
+
|
|
98
|
+
// set the tile data
|
|
99
|
+
setTileData(pos, layer, tile);
|
|
100
|
+
|
|
101
|
+
// get tile type for special tiles
|
|
102
|
+
let tileType = tileType_empty;
|
|
103
|
+
if (tile > 0)
|
|
104
|
+
tileType = tileType_breakable;
|
|
105
|
+
if (tile == 4)
|
|
106
|
+
tileType = tileType_ladder;
|
|
107
|
+
if (tile == 5)
|
|
108
|
+
tileType = tileType_solid;
|
|
109
|
+
if (tileType)
|
|
111
110
|
{
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
setTileCollisionData(pos,
|
|
115
|
-
|
|
111
|
+
// set collision for solid tiles
|
|
112
|
+
if (layer == foregroundLayerIndex)
|
|
113
|
+
setTileCollisionData(pos, tileType);
|
|
114
|
+
|
|
115
|
+
// randomize tile appearance
|
|
116
|
+
let direction, mirror, color;
|
|
117
|
+
if (tileType == tileType_breakable)
|
|
118
|
+
{
|
|
119
|
+
direction = randInt(4);
|
|
120
|
+
mirror = randInt(2);
|
|
121
|
+
color = layer ? levelColor : levelBackgroundColor;
|
|
122
|
+
color = color.mutate(.03);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// set tile layer data
|
|
126
|
+
const data = new TileLayerData(tile-1, direction, mirror, color);
|
|
127
|
+
tileLayer.setData(pos, data);
|
|
116
128
|
}
|
|
117
129
|
}
|
|
130
|
+
tileLayer.redraw();
|
|
118
131
|
}
|
|
119
|
-
|
|
120
|
-
// spawn crates
|
|
121
|
-
for (let crateCount=100; crateCount--;)
|
|
122
|
-
new Crate(vec2((randInt(levelSize.x))+.5, randInt(levelSize.y)));
|
|
123
|
-
|
|
124
|
-
// spawn enemies
|
|
125
|
-
for (let enemyCount=10; enemyCount--;)
|
|
126
|
-
new Enemy(vec2(rand(levelSize.x), rand(levelSize.y)));
|
|
127
132
|
}
|
|
128
133
|
|
|
129
|
-
function
|
|
134
|
+
function decorateTile(pos, layer=1)
|
|
130
135
|
{
|
|
131
|
-
|
|
132
|
-
|
|
136
|
+
ASSERT((pos.x|0) == pos.x && (pos.y|0)== pos.y);
|
|
137
|
+
const tileLayer = tileLayers[layer];
|
|
133
138
|
|
|
134
|
-
|
|
135
|
-
buildTerrain(levelSize);
|
|
136
|
-
|
|
137
|
-
// find starting poing for player
|
|
138
|
-
playerStartPos = vec2(rand(levelSize.x), levelSize.y);
|
|
139
|
-
const raycastHit = tileCollisionRaycast(playerStartPos, vec2(playerStartPos.x, 0));
|
|
140
|
-
playerStartPos = raycastHit.add(vec2(0,1));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function makeTileLayers()
|
|
144
|
-
{
|
|
145
|
-
// create tile layers
|
|
146
|
-
tileLayer = new TileLayer(vec2(), levelSize, tile(0,16,1));
|
|
147
|
-
tileLayer.renderOrder = -1e3;
|
|
148
|
-
tileBackgroundLayer = new TileLayer(vec2(), levelSize, tile(0,16,1));
|
|
149
|
-
tileBackgroundLayer.renderOrder = -2e3;
|
|
150
|
-
|
|
151
|
-
const pos = vec2();
|
|
152
|
-
for (pos.x = levelSize.x; pos.x--;)
|
|
153
|
-
for (pos.y = levelSize.y; pos.y--;)
|
|
139
|
+
if (layer == foregroundLayerIndex)
|
|
154
140
|
{
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (tileType)
|
|
141
|
+
const tileType = getTileCollisionData(pos);
|
|
142
|
+
if (tileType <= 0)
|
|
158
143
|
{
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
tileIndex = 1 + rand()**3*2|0;
|
|
163
|
-
color = levelColor.mutate(.03);
|
|
164
|
-
direction = randInt(4);
|
|
165
|
-
mirror = randInt(2);
|
|
166
|
-
}
|
|
167
|
-
else if (tileType == tileType_ladder)
|
|
168
|
-
tileIndex = 3;
|
|
169
|
-
|
|
170
|
-
const data = new TileLayerData(tileIndex, direction, mirror, color);
|
|
171
|
-
tileLayer.setData(pos, data);
|
|
144
|
+
// force it to clear if it is empty
|
|
145
|
+
tileType || tileLayer.setData(pos, new TileLayerData, 1);
|
|
146
|
+
return;
|
|
172
147
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
tileType = getTileBackgroundData(pos);
|
|
176
|
-
if (tileType)
|
|
148
|
+
if (tileType == tileType_breakable)
|
|
149
|
+
for (let i=4;i--;)
|
|
177
150
|
{
|
|
178
|
-
|
|
179
|
-
|
|
151
|
+
// outline towards neighbors of differing type
|
|
152
|
+
const neighborTileType = getTileCollisionData(pos.add(vec2().setDirection(i)));
|
|
153
|
+
if (neighborTileType == tileType)
|
|
154
|
+
continue;
|
|
155
|
+
|
|
156
|
+
// make pixel perfect outlines
|
|
157
|
+
const size = i&1 ? vec2(2, 16) : vec2(16, 2);
|
|
158
|
+
tileLayer.context.fillStyle = levelOutlineColor.mutate(.1);
|
|
159
|
+
const drawPos = pos.scale(16)
|
|
160
|
+
.add(vec2(i==1?14:0,(i==0?14:0)))
|
|
161
|
+
.subtract((i&1? vec2(0,8-size.y/2) : vec2(8-size.x/2,0)));
|
|
162
|
+
tileLayer.context.fillRect(
|
|
163
|
+
drawPos.x, tileLayer.canvas.height - drawPos.y, size.x, -size.y);
|
|
180
164
|
}
|
|
181
165
|
}
|
|
182
|
-
|
|
183
|
-
tileBackgroundLayer.redraw();
|
|
184
|
-
|
|
185
|
-
if (!glEnable)
|
|
166
|
+
else
|
|
186
167
|
{
|
|
187
|
-
//
|
|
188
|
-
|
|
189
|
-
|
|
168
|
+
// make round corners
|
|
169
|
+
for (let i=4;i--;)
|
|
170
|
+
{
|
|
171
|
+
// check corner neighbors
|
|
172
|
+
const neighborTileDataA = getTileData(pos.add(vec2().setDirection(i)), layer);
|
|
173
|
+
const neighborTileDataB = getTileData(pos.add(vec2().setAngle((i+1)%4*PI/2)), layer);
|
|
174
|
+
if (neighborTileDataA > 0 || neighborTileDataB > 0)
|
|
175
|
+
continue;
|
|
176
|
+
|
|
177
|
+
const directionVector = vec2().setAngle(i*PI/2+PI/4, 10).floor();
|
|
178
|
+
const drawPos = pos.add(vec2(.5)) // center
|
|
179
|
+
.scale(16).add(directionVector).floor(); // direction offset
|
|
180
|
+
|
|
181
|
+
// clear rect without any scaling to prevent blur from filtering
|
|
182
|
+
const s = 2;
|
|
183
|
+
tileLayer.context.clearRect(
|
|
184
|
+
drawPos.x - s/2, tileLayer.canvas.height - drawPos.y - s/2, s, s);
|
|
185
|
+
}
|
|
190
186
|
}
|
|
191
187
|
}
|
|
192
|
-
|
|
193
|
-
function buildLevel()
|
|
194
|
-
{
|
|
195
|
-
levelSize = vec2(128);
|
|
196
|
-
levelColor = randColor(new Color(.2,.2,.2), new Color(.8,.8,.8));
|
|
197
|
-
levelGroundColor = levelColor.mutate().add(new Color(.4,.4,.4)).clamp();
|
|
198
|
-
|
|
199
|
-
generateLevel();
|
|
200
|
-
initSky();
|
|
201
|
-
initParallaxLayers();
|
|
202
|
-
|
|
203
|
-
// apply decoration to level tiles
|
|
204
|
-
makeTileLayers();
|
|
205
|
-
const pos = vec2();
|
|
206
|
-
for (pos.x=levelSize.x; pos.x--;)
|
|
207
|
-
for (pos.y=levelSize.y; pos.y-->1;)
|
|
208
|
-
{
|
|
209
|
-
decorateBackgroundTile(pos);
|
|
210
|
-
decorateTile(pos);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// warm up level
|
|
214
|
-
warmup = 1;
|
|
215
|
-
for (let i = 500; i--;)
|
|
216
|
-
engineObjectsUpdate();
|
|
217
|
-
warmup = 0;
|
|
218
|
-
|
|
219
|
-
// spawn player
|
|
220
|
-
player = new Player(cameraPos = playerStartPos);
|
|
221
|
-
}
|
|
@@ -26,10 +26,10 @@ class GameObject extends EngineObject
|
|
|
26
26
|
if (!this.isDead() && this.damageTimer.isSet())
|
|
27
27
|
{
|
|
28
28
|
const a = .5*percent(this.damageTimer, .15, 0);
|
|
29
|
-
this.additiveColor =
|
|
29
|
+
this.additiveColor = hsl(0,0,a,0);
|
|
30
30
|
}
|
|
31
31
|
else
|
|
32
|
-
this.additiveColor =
|
|
32
|
+
this.additiveColor = hsl(0,0,0,0);
|
|
33
33
|
|
|
34
34
|
// kill if below level
|
|
35
35
|
if (!this.isDead() && this.pos.y < -9)
|
|
@@ -68,7 +68,7 @@ class Crate extends GameObject
|
|
|
68
68
|
{
|
|
69
69
|
super(pos, vec2(1), tile(2), (randInt(4))*PI/2);
|
|
70
70
|
|
|
71
|
-
this.color = (
|
|
71
|
+
this.color = hsl(rand(),1,.8);
|
|
72
72
|
this.health = 5;
|
|
73
73
|
|
|
74
74
|
// make it a solid object for collision
|
|
@@ -88,6 +88,41 @@ class Crate extends GameObject
|
|
|
88
88
|
|
|
89
89
|
///////////////////////////////////////////////////////////////////////////////
|
|
90
90
|
|
|
91
|
+
class Coin extends EngineObject
|
|
92
|
+
{
|
|
93
|
+
constructor(pos)
|
|
94
|
+
{
|
|
95
|
+
super(pos, vec2(1), tile(6));
|
|
96
|
+
this.color = hsl(.15,1,.5);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
render()
|
|
100
|
+
{
|
|
101
|
+
// make it appear to spin
|
|
102
|
+
const t = time+this.pos.x/4+this.pos.y/4;
|
|
103
|
+
drawTile(this.pos, vec2(.1, .6), 0, this.color); // edge of coin
|
|
104
|
+
drawTile(this.pos, vec2(.5+.5*Math.sin(t*2*PI), 1), this.tileInfo, this.color);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
update(o)
|
|
108
|
+
{
|
|
109
|
+
if (!player)
|
|
110
|
+
return;
|
|
111
|
+
|
|
112
|
+
// check if player in range
|
|
113
|
+
const d = this.pos.distanceSquared(player.pos);
|
|
114
|
+
if (d > .5)
|
|
115
|
+
return;
|
|
116
|
+
|
|
117
|
+
// award points and destroy
|
|
118
|
+
++score;
|
|
119
|
+
sound_score.play(this.pos);
|
|
120
|
+
this.destroy();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
125
|
+
|
|
91
126
|
class Enemy extends GameObject
|
|
92
127
|
{
|
|
93
128
|
constructor(pos)
|
|
@@ -95,7 +130,7 @@ class Enemy extends GameObject
|
|
|
95
130
|
super(pos, vec2(.9,.9), tile(5));
|
|
96
131
|
|
|
97
132
|
this.drawSize = vec2(1);
|
|
98
|
-
this.color = (
|
|
133
|
+
this.color = hsl(rand(), 1, .7);
|
|
99
134
|
this.health = 5;
|
|
100
135
|
this.bounceTime = new Timer(rand(1e3));
|
|
101
136
|
this.setCollision(true, false);
|
|
@@ -126,7 +161,7 @@ class Enemy extends GameObject
|
|
|
126
161
|
return;
|
|
127
162
|
|
|
128
163
|
++score;
|
|
129
|
-
|
|
164
|
+
sound_score.play(this.pos);
|
|
130
165
|
makeDebris(this.pos, this.color, 300);
|
|
131
166
|
this.destroy();
|
|
132
167
|
}
|
|
@@ -180,10 +215,10 @@ class Grenade extends GameObject
|
|
|
180
215
|
{
|
|
181
216
|
drawTile(this.pos, vec2(.5), this.tileInfo, this.color, this.angle);
|
|
182
217
|
|
|
183
|
-
// draw additive flash
|
|
218
|
+
// draw additive flash exploding
|
|
184
219
|
setBlendMode(true);
|
|
185
220
|
const flash = Math.cos(this.getAliveTime()*2*PI);
|
|
186
|
-
drawTile(this.pos, vec2(2), tile(0, 16),
|
|
221
|
+
drawTile(this.pos, vec2(2), tile(0, 16), hsl(0,1,.5,.2-.2*flash));
|
|
187
222
|
setBlendMode(false);
|
|
188
223
|
}
|
|
189
224
|
}
|
|
@@ -212,8 +247,8 @@ class Weapon extends EngineObject
|
|
|
212
247
|
this.addChild(this.shellEmitter = new ParticleEmitter(
|
|
213
248
|
vec2(), 0, 0, 0, 0, .1, // pos, angle, emitSize, emitTime, emitRate, emiteCone
|
|
214
249
|
0, // tileInfo
|
|
215
|
-
|
|
216
|
-
|
|
250
|
+
rgb(1,.8,.5), rgb(.9,.7,.5), // colorStartA, colorStartB
|
|
251
|
+
rgb(1,.8,.5), rgb(.9,.7,.5), // colorEndA, colorEndB
|
|
217
252
|
3, .1, .1, .15, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
218
253
|
1, .95, 1, 0, 0, // damp, angleDamp, gravity, particleCone, fade
|
|
219
254
|
.1, 1 // randomness, collide, additive, colorLinear, renderOrder
|
|
@@ -230,7 +265,6 @@ class Weapon extends EngineObject
|
|
|
230
265
|
if (this.recoilTimer.active())
|
|
231
266
|
this.localAngle = lerp(this.recoilTimer.getPercent(), 0, this.localAngle);
|
|
232
267
|
|
|
233
|
-
|
|
234
268
|
this.mirror = this.parent.mirror;
|
|
235
269
|
this.fireTimeBuffer += timeDelta;
|
|
236
270
|
if (this.triggerIsDown)
|
|
@@ -262,7 +296,7 @@ class Bullet extends EngineObject
|
|
|
262
296
|
constructor(pos, attacker, velocity, damage)
|
|
263
297
|
{
|
|
264
298
|
super(pos, vec2());
|
|
265
|
-
this.color =
|
|
299
|
+
this.color = rgb(1,1,0);
|
|
266
300
|
this.velocity = velocity;
|
|
267
301
|
this.attacker = attacker;
|
|
268
302
|
this.damage = damage;
|
|
@@ -270,7 +304,7 @@ class Bullet extends EngineObject
|
|
|
270
304
|
this.gravityScale = 0;
|
|
271
305
|
this.renderOrder = 100;
|
|
272
306
|
this.drawSize = vec2(.2,.5);
|
|
273
|
-
this.range =
|
|
307
|
+
this.range = 5;
|
|
274
308
|
this.setCollision(1,0);
|
|
275
309
|
}
|
|
276
310
|
|
|
@@ -288,7 +322,18 @@ class Bullet extends EngineObject
|
|
|
288
322
|
this.angle = this.velocity.angle();
|
|
289
323
|
this.range -= this.velocity.length();
|
|
290
324
|
if (this.range < 0)
|
|
291
|
-
|
|
325
|
+
{
|
|
326
|
+
const emitter = new ParticleEmitter(
|
|
327
|
+
this.pos, 0, .2, .1, 50, PI, tile(0), // pos, angle, emit info, tileInfo
|
|
328
|
+
rgb(1,1,.1), rgb(1,1,1), // colorStartA, colorStartB
|
|
329
|
+
rgb(1,1,.1,0), rgb(1,1,1,0),// colorEndA, colorEndB
|
|
330
|
+
.1, .5, .1, .05, 0, // particleTime, sizeStart, sizeEnd, speed, angleSpeed
|
|
331
|
+
1, 1, .5, PI, .1, // damping, angleDamping, gravityScale, cone, fadeRate,
|
|
332
|
+
.5, 0, 1 // randomness, collide, additive, randomColorLinear
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
this.destroy();
|
|
336
|
+
}
|
|
292
337
|
}
|
|
293
338
|
|
|
294
339
|
collideWithObject(o)
|
|
@@ -322,9 +367,9 @@ class Bullet extends EngineObject
|
|
|
322
367
|
// spark effects
|
|
323
368
|
const emitter = new ParticleEmitter(
|
|
324
369
|
this.pos, 0, 0, .1, 100, .5, // pos, angle, emitSize, emitTime, emitRate, emiteCone
|
|
325
|
-
0,
|
|
326
|
-
|
|
327
|
-
|
|
370
|
+
0, // tileInfo
|
|
371
|
+
rgb(1,1,0), rgb(1,0,0), // colorStartA, colorStartB
|
|
372
|
+
rgb(1,1,0), rgb(1,0,0), // colorEndA, colorEndB
|
|
328
373
|
.2, .2, 0, .1, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
329
374
|
1, 1, .5, PI, .1, // damp, angleDamp, gravityScale, particleCone, fade,
|
|
330
375
|
.5, 1, 1 // randomness, collide, additive, colorLinear, renderOrder
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
class Player extends Character
|
|
13
13
|
{
|
|
14
|
-
update()
|
|
14
|
+
update()
|
|
15
15
|
{
|
|
16
16
|
// player controls
|
|
17
17
|
this.holdingJump = keyIsDown('ArrowUp') || gamepadIsDown(0);
|
|
@@ -21,7 +21,8 @@ class Player extends Character
|
|
|
21
21
|
|
|
22
22
|
// movement control
|
|
23
23
|
this.moveInput = isUsingGamepad ? gamepadStick(0) :
|
|
24
|
-
vec2(keyIsDown('ArrowRight') - keyIsDown('ArrowLeft'),
|
|
24
|
+
vec2(keyIsDown('ArrowRight') - keyIsDown('ArrowLeft'),
|
|
25
|
+
keyIsDown('ArrowUp') - keyIsDown('ArrowDown'));
|
|
25
26
|
|
|
26
27
|
super.update();
|
|
27
28
|
}
|