/**** * Classes ****/ //<Assets used in the game will automatically appear here> // DuneBuggy class to represent the player's vehicle var DuneBuggy = Container.expand(function () { var self = Container.call(this); var buggyGraphics = self.attachAsset('duneBuggy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Update logic for the buggy, if needed }; }); // Obstacle class to represent obstacles in the game var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -3; self.update = function () { self.y += self.speed; }; }); // Supply class to represent supplies that can be picked up var Supply = Container.expand(function () { var self = Container.call(this); var supplyGraphics = self.attachAsset('supply', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -3; self.update = function () { self.y += self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var duneBuggy = game.addChild(new DuneBuggy()); duneBuggy.x = 2048 / 2; duneBuggy.y = 2732 - 200; var obstacles = []; var supplies = []; var score = 0; var scoreTxt = new Text2('Score: 0', { size: 100, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); game.update = function () { // Update obstacles for (var i = obstacles.length - 1; i >= 0; i--) { obstacles[i].update(); if (obstacles[i].y < -50) { obstacles[i].destroy(); obstacles.splice(i, 1); } if (duneBuggy.intersects(obstacles[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Update supplies for (var j = supplies.length - 1; j >= 0; j--) { supplies[j].update(); if (supplies[j].y < -50) { supplies[j].destroy(); supplies.splice(j, 1); } if (duneBuggy.intersects(supplies[j])) { score += 10; scoreTxt.setText('Score: ' + score); supplies[j].destroy(); supplies.splice(j, 1); } } // Spawn new obstacles and supplies if (LK.ticks % 60 == 0) { var newObstacle = new Obstacle(); newObstacle.x = Math.random() * 2048; newObstacle.y = 0; obstacles.push(newObstacle); game.addChild(newObstacle); } if (LK.ticks % 120 == 0) { var newSupply = new Supply(); newSupply.x = Math.random() * 2048; newSupply.y = 0; supplies.push(newSupply); game.addChild(newSupply); } }; game.down = function (x, y, obj) { duneBuggy.x = x; }; game.move = function (x, y, obj) { duneBuggy.x = x; }; game.up = function (x, y, obj) { // No action needed on up event };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// DuneBuggy class to represent the player's vehicle
var DuneBuggy = Container.expand(function () {
var self = Container.call(this);
var buggyGraphics = self.attachAsset('duneBuggy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Update logic for the buggy, if needed
};
});
// Obstacle class to represent obstacles in the game
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -3;
self.update = function () {
self.y += self.speed;
};
});
// Supply class to represent supplies that can be picked up
var Supply = Container.expand(function () {
var self = Container.call(this);
var supplyGraphics = self.attachAsset('supply', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -3;
self.update = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var duneBuggy = game.addChild(new DuneBuggy());
duneBuggy.x = 2048 / 2;
duneBuggy.y = 2732 - 200;
var obstacles = [];
var supplies = [];
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
game.update = function () {
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
if (obstacles[i].y < -50) {
obstacles[i].destroy();
obstacles.splice(i, 1);
}
if (duneBuggy.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update supplies
for (var j = supplies.length - 1; j >= 0; j--) {
supplies[j].update();
if (supplies[j].y < -50) {
supplies[j].destroy();
supplies.splice(j, 1);
}
if (duneBuggy.intersects(supplies[j])) {
score += 10;
scoreTxt.setText('Score: ' + score);
supplies[j].destroy();
supplies.splice(j, 1);
}
}
// Spawn new obstacles and supplies
if (LK.ticks % 60 == 0) {
var newObstacle = new Obstacle();
newObstacle.x = Math.random() * 2048;
newObstacle.y = 0;
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
if (LK.ticks % 120 == 0) {
var newSupply = new Supply();
newSupply.x = Math.random() * 2048;
newSupply.y = 0;
supplies.push(newSupply);
game.addChild(newSupply);
}
};
game.down = function (x, y, obj) {
duneBuggy.x = x;
};
game.move = function (x, y, obj) {
duneBuggy.x = x;
};
game.up = function (x, y, obj) {
// No action needed on up event
};
sheep
Sound effect
crash
Sound effect
yelp
Sound effect
rabbit
Sound effect
runner
Sound effect
runner
Sound effect
roar
Sound effect
airwrench
Sound effect
liquid
Sound effect
music
Music
crash2
Sound effect
yehaw
Sound effect
woohoo
Sound effect
bird
Sound effect
splat
Sound effect
splat
Sound effect
gascanbonus
Sound effect
tirebonus
Sound effect