update
This commit is contained in:
0
game_endlessrun/Bundled/canvas/MyCanvas.files
Normal file
0
game_endlessrun/Bundled/canvas/MyCanvas.files
Normal file
1
game_endlessrun/Bundled/canvas/MyCanvas.json
Normal file
1
game_endlessrun/Bundled/canvas/MyCanvas.json
Normal file
@ -0,0 +1 @@
|
||||
{"name":"untitled","x":0,"y":0,"width":960,"height":540,"elements":[{"id":0,"type":0,"name":"Score","event":"","x":0,"y":0,"width":150,"height":48,"text":"0","asset":"","color":-16777216,"anchor":0,"children":[]}],"assets":[]}
|
||||
31
game_endlessrun/Sources/lnx/GemTrait.hx
Normal file
31
game_endlessrun/Sources/lnx/GemTrait.hx
Normal file
@ -0,0 +1,31 @@
|
||||
package lnx;
|
||||
|
||||
class GemTrait extends iron.Trait {
|
||||
|
||||
static var gemsCollected = 0;
|
||||
|
||||
var player:iron.object.Object = null;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
notifyOnUpdate(function() {
|
||||
object.transform.rotate(iron.math.Vec4.zAxis(), 0.05);
|
||||
|
||||
if (player == null) player = iron.Scene.active.getChild("Player");
|
||||
var w1 = object.transform.world;
|
||||
var w2 = player.transform.world;
|
||||
var d = iron.math.Vec4.distance(w1.getLoc(), w2.getLoc());
|
||||
|
||||
// Collect gem
|
||||
if (d < 0.6) {
|
||||
gemsCollected++;
|
||||
object.remove();
|
||||
|
||||
// Update UI
|
||||
var canvas = iron.Scene.active.getTrait(leenkx.trait.internal.CanvasScript);
|
||||
canvas.getElement("Score").text = gemsCollected + "";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
22
game_endlessrun/Sources/lnx/PlayerController.hx
Normal file
22
game_endlessrun/Sources/lnx/PlayerController.hx
Normal file
@ -0,0 +1,22 @@
|
||||
package lnx;
|
||||
|
||||
class PlayerController extends iron.Trait {
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
notifyOnUpdate(function() {
|
||||
var kb = iron.system.Input.getKeyboard();
|
||||
var x = object.transform.loc.x;
|
||||
|
||||
// Move player
|
||||
if ((kb.down("left") || kb.down("a")) && x > -1.8) {
|
||||
object.transform.loc.x -= 0.06;
|
||||
object.transform.dirty = true;
|
||||
}
|
||||
if ((kb.down("right") || kb.down("d")) && x < 1.8) {
|
||||
object.transform.loc.x += 0.06;
|
||||
object.transform.dirty = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
51
game_endlessrun/Sources/lnx/SceneBuilder.hx
Normal file
51
game_endlessrun/Sources/lnx/SceneBuilder.hx
Normal file
@ -0,0 +1,51 @@
|
||||
package lnx;
|
||||
|
||||
class SceneBuilder extends iron.Trait {
|
||||
|
||||
var dist = 0.0;
|
||||
var tileNum = 0;
|
||||
var tilesVisible = 14;
|
||||
var tiles:Array<iron.object.Object> = [];
|
||||
var empty:iron.object.Object;
|
||||
|
||||
function spawnTile(num:Int) {
|
||||
iron.Scene.active.spawnObject("Tile" + Std.random(2), null, function(o) {
|
||||
|
||||
// Remove old tile
|
||||
if (tiles[num % tilesVisible] != null) {
|
||||
tiles[num % tilesVisible].remove();
|
||||
}
|
||||
|
||||
// Spawn new tile
|
||||
tiles[num % tilesVisible] = o;
|
||||
o.transform.loc.x = 0;
|
||||
o.transform.loc.y = num * 4.0;
|
||||
o.transform.buildMatrix();
|
||||
|
||||
// Spawn gem
|
||||
if (Std.random(3) == 0) {
|
||||
iron.Scene.active.spawnObject("Gem", o, function(go) {
|
||||
go.transform.loc.x = (Math.random() - 0.5) * 1.8;
|
||||
go.transform.loc.z = 0.2;
|
||||
go.transform.buildMatrix();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
notifyOnUpdate(function() {
|
||||
if (empty == null) empty = iron.Scene.active.getChild("Empty");
|
||||
|
||||
// Spawn new tiles
|
||||
while (tileNum < Std.int(dist / 4 + 13)) spawnTile(tileNum++);
|
||||
|
||||
// Travel forward
|
||||
dist += 0.1;
|
||||
empty.transform.loc.y = dist;
|
||||
empty.transform.buildMatrix();
|
||||
});
|
||||
}
|
||||
}
|
||||
BIN
game_endlessrun/game_endless.blend
Normal file
BIN
game_endlessrun/game_endless.blend
Normal file
Binary file not shown.
BIN
game_endlessrun/grid.png
Normal file
BIN
game_endlessrun/grid.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
Reference in New Issue
Block a user