User prompt
when 'lion' is hit, play 'roar'
User prompt
when 'Scorpion' is hit, play 'runner '
User prompt
when 'Roadrunner' is hit, play 'runner '
User prompt
when 'Rabbit' is hit, play 'rabbit'
User prompt
when 'Coyote' is hit, play 'yelp'
User prompt
when 'Cactus', 'Joshua', 'Mojave', 'Tumble', and 'Yucca' are hit, play 'crash'
User prompt
when 'Bighorn' is hit, play 'sheep'
Code edit (1 edits merged)
Please save this source code
User prompt
set max fuel at 15 gallons
User prompt
add lion, behaves like bighorn
User prompt
add scorpion, behaves like roadrunner
User prompt
if roadrunner collides with dunebuggy, -3 tires
Code edit (2 edits merged)
Please save this source code
User prompt
add roadrunner, spawns randomly
User prompt
add rabbit, behaves exactly like yucca
User prompt
add coyote, behaves exactly like bighorn
Code edit (1 edits merged)
Please save this source code
User prompt
move dunebuggy back to previous y location
User prompt
spawn all drops at y = 200
Code edit (1 edits merged)
Please save this source code
User prompt
keep all spawns y = 2200 - 200
User prompt
delete turtle and snake
User prompt
delete spider
User prompt
delete roadrunner
User prompt
delete coyote
/**** * Classes ****/ // Bighorn class to represent the randomly spawned Bighorn var Bighorn = Container.expand(function () { var self = Container.call(this); var bighornGraphics = self.attachAsset('Bighorn', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { self.y += self.speed; }; }); // Cactus class to represent the randomly spawned Cactus var Cactus = Container.expand(function () { var self = Container.call(this); var cactusGraphics = self.attachAsset('Cactus', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { self.y += self.speed; }; }); //<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 }); // Initialize previous position for rotation calculation self.previousX = self.x; self.previousY = self.y; self.speed = 5; self.update = function () { // Keep the duneBuggy straight without rotation buggyGraphics.rotation = 0; // Set rotation to 0 to keep it straight // Store the current position for the next update self.previousX = self.x; self.previousY = self.y; }; }); // GasCan class to represent the randomly spawned GasCan var GasCan = Container.expand(function () { var self = Container.call(this); var gascanGraphics = self.attachAsset('gascan', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { self.y += self.speed; }; }); // Joshua class to represent the randomly spawned Joshua var Joshua = Container.expand(function () { var self = Container.call(this); var joshuaGraphics = self.attachAsset('Joshua', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { self.y += self.speed; }; }); // Mojave class to represent the randomly spawned Mojave var Mojave = Container.expand(function () { var self = Container.call(this); var mojaveGraphics = self.attachAsset('Mojave', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { self.y += self.speed; }; }); // Roadrunner class to represent the randomly spawned Roadrunner var Roadrunner = Container.expand(function () { var self = Container.call(this); var roadrunnerGraphics = self.attachAsset('Roadrunner', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { self.y += self.speed; }; }); // Snake class to represent the randomly spawned Snake var Snake = Container.expand(function () { var self = Container.call(this); var snakeGraphics = self.attachAsset('Snake', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { self.y += self.speed; }; }); // Spider class to represent the randomly spawned Spider var Spider = Container.expand(function () { var self = Container.call(this); var spiderGraphics = self.attachAsset('Spider', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { self.y += self.speed; }; }); // Tire class to represent the randomly spawned Tire var Tire = Container.expand(function () { var self = Container.call(this); var tireGraphics = self.attachAsset('tire', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { self.y += self.speed; }; }); // Tumble class to represent the randomly spawned Tumble var Tumble = Container.expand(function () { var self = Container.call(this); var tumbleGraphics = self.attachAsset('Tumble', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { self.y += self.speed; }; }); // Turtle class to represent the randomly spawned Turtle var Turtle = Container.expand(function () { var self = Container.call(this); var turtleGraphics = self.attachAsset('Turtle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { self.y += self.speed; }; }); // Yucca class to represent the randomly spawned Yucca var Yucca = Container.expand(function () { var self = Container.call(this); var yuccaGraphics = self.attachAsset('Yucca', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { self.y += self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({}); /**** * Game Code ****/ // Add Flag to the lower left of the screen var flag = LK.getAsset('Flag', { anchorX: 0.5, anchorY: 0.5, x: 180, // Adjusted to position the flag at the lower left y: 2732 - 180 // Adjusted to position the flag at the lower left }); game.addChild(flag); // Add a second Flag to the right of the first flag var secondFlag = LK.getAsset('Flag', { anchorX: 0.5, anchorY: 0.5, x: 180 + 360, // Positioned to the right of the first flag y: 2732 - 180 }); game.addChild(secondFlag); // Add a third Flag to the right of the second flag var thirdFlag = LK.getAsset('Flag', { anchorX: 0.5, anchorY: 0.5, x: 180 + 360 * 2, // Positioned to the right of the second flag y: 2732 - 180 }); game.addChild(thirdFlag); // Add a fourth Flag to the right of the third flag var fourthFlag = LK.getAsset('Flag', { anchorX: 0.5, anchorY: 0.5, x: 180 + 360 * 3, // Positioned to the right of the third flag y: 2732 - 180 }); game.addChild(fourthFlag); // Add a fifth Flag to the right of the fourth flag var fifthFlag = LK.getAsset('Flag', { anchorX: 0.5, anchorY: 0.5, x: 180 + 360 * 4, // Positioned to the right of the fourth flag y: 2732 - 180 }); game.addChild(fifthFlag); // Add a sixth Flag to the right of the fifth flag var sixthFlag = LK.getAsset('Flag', { anchorX: 0.5, anchorY: 0.5, x: 180 + 360 * 5, // Positioned to the right of the fifth flag y: 2732 - 180 }); game.addChild(sixthFlag); // Add track as the background var track = LK.getAsset('track', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(track); // Add GasCan var gascan = new GasCan(); gascan.x = 512; // Position GasCan gascan.y = 200; if (!isOverlapping(gascan)) { game.addChild(gascan); gascan.zIndex = 10; // Ensure GasCan is above the track } // Add Tire var tire = new Tire(); tire.x = 1536; // Position Tire tire.y = 200; if (!isOverlapping(tire)) { game.addChild(tire); tire.zIndex = 10; // Ensure Tire is above the track } function isOverlapping(newObject) { for (var i = 0; i < game.children.length; i++) { if (game.children[i] !== newObject && game.children[i].intersects(newObject)) { return true; } } return false; } var duneBuggy = game.addChild(new DuneBuggy()); duneBuggy.x = 2048 / 2; duneBuggy.y = 2200 - 200; var obstacles = []; var supplies = []; var score = 0; var scoreTxt = new Text2('Distance: 0', { size: 120, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); scoreTxt.x -= 0; // Move slightly to the left scoreTxt.y += 0; // Move down a little bit LK.gui.top.addChild(scoreTxt); var tiresTxt = new Text2('Tires: 100%', { size: 100, fill: "#ffffff" }); tiresTxt.anchor.set(0.5, 0); tiresTxt.x -= 400; // Move tires text to the left tiresTxt.y += 130; // Move tires text down LK.gui.top.addChild(tiresTxt); var fuelTxt = new Text2('Fuel:', { size: 100, fill: "#ffffff" }); fuelTxt.anchor.set(0.5, 0); fuelTxt.x -= -340; // Move fuel text to the left by 400 fuelTxt.y += 130; // Move fuel text down by 800 LK.gui.top.addChild(fuelTxt); var distance = 0; var fuel = 15; var tires = 100; fuelTxt.setText('Fuel: ' + fuel + ' Gallons'); game.update = function () { if (LK.ticks % 60 == 0) { distance += 0.1; scoreTxt.setText('Distance: ' + distance.toFixed(1)); if (distance % 2 < 0.1) { fuel -= 1; fuelTxt.setText('Fuel: ' + fuel + ' Gallons'); if (fuel <= 0) { LK.showGameOver(); } } // Spawn GasCan and Tire every 1 distance if (distance % 1 < 0.1) { var gascan = new GasCan(); gascan.x = Math.random() * 2048; // Random x position gascan.y = 0; if (!isOverlapping(gascan)) { game.addChild(gascan); } var tire = new Tire(); tire.x = Math.random() * 2048; // Random x position tire.y = 0; if (!isOverlapping(tire)) { game.addChild(tire); } } // Spawn Bighorn, Cactus and Coyote at different intervals if (LK.ticks % 40 == 0 && LK.ticks > 300) { var bighorn = new Bighorn(); bighorn.x = Math.random() * 2048; bighorn.y = 0; game.addChild(bighorn); } if (LK.ticks % 60 == 0 && LK.ticks > 350) { var cactus = new Cactus(); cactus.x = Math.random() * 2048; cactus.y = 0; game.addChild(cactus); } if (LK.ticks % 100 == 0 && LK.ticks > 450) { var joshua = new Joshua(); joshua.x = Math.random() * 2048; joshua.y = 0; game.addChild(joshua); } if (LK.ticks % 120 == 0 && LK.ticks > 500) { var mojave = new Mojave(); mojave.x = Math.random() * 2048; mojave.y = 0; game.addChild(mojave); } if (LK.ticks % 160 == 0 && LK.ticks > 600) { var roadrunner = new Roadrunner(); roadrunner.x = Math.random() * 2048; roadrunner.y = 0; game.addChild(roadrunner); } if (LK.ticks % 200 == 0 && LK.ticks > 700) { var snake = new Snake(); snake.x = Math.random() * 2048; snake.y = 0; game.addChild(snake); } if (LK.ticks % 220 == 0 && LK.ticks > 750) { var spider = new Spider(); spider.x = Math.random() * 2048; spider.y = 0; game.addChild(spider); } if (LK.ticks % 240 == 0 && LK.ticks > 800) { var tumble = new Tumble(); tumble.x = Math.random() * 2048; tumble.y = 0; game.addChild(tumble); } if (LK.ticks % 260 == 0 && LK.ticks > 850) { var turtle = new Turtle(); turtle.x = Math.random() * 2048; turtle.y = 0; game.addChild(turtle); } if (LK.ticks % 280 == 0 && LK.ticks > 900) { var yucca = new Yucca(); yucca.x = Math.random() * 2048; yucca.y = 0; game.addChild(yucca); } // Check for collision between duneBuggy and Bighorn, Cactus, Coyote, Joshua, Mojave, Rabbit, Roadrunner, Scorpion, Snake, Spider, Tumble, Turtle, or Yucca for (var i = game.children.length - 1; i >= 0; i--) { if (game.children[i] instanceof Bighorn || game.children[i] instanceof Cactus || game.children[i] instanceof Joshua || game.children[i] instanceof Mojave || game.children[i] instanceof Roadrunner || game.children[i] instanceof Snake || game.children[i] instanceof Spider || game.children[i] instanceof Tumble || game.children[i] instanceof Turtle || game.children[i] instanceof Yucca) { if (duneBuggy.intersects(game.children[i])) { tires -= 3; // decrease tires by 3% tiresTxt.setText('Tires: ' + tires + '%'); // update tires text if (tires <= 0) { LK.showGameOver(); // game over if tires reach 0 } game.children[i].destroy(); // destroy Bighorn, Cactus, Coyote, Joshua, Mojave, Rabbit, Roadrunner, Scorpion, Snake, or Spider on collision return; // return after destroying to prevent accessing it after destruction } } else if (game.children[i] instanceof GasCan && duneBuggy.intersects(game.children[i])) { fuel += 2; // increase fuel by 2 gallons fuelTxt.setText('Fuel: ' + fuel + ' Gallons'); // update fuel text game.children[i].destroy(); // destroy GasCan on collision return; // return after destroying to prevent accessing it after destruction } else if (game.children[i] instanceof Tire && duneBuggy.intersects(game.children[i])) { tires = Math.min(tires + 2, 100); // increase tires by 2%, max 100% tiresTxt.setText('Tires: ' + tires + '%'); // update tires text game.children[i].destroy(); // destroy Tire on collision return; // return after destroying to prevent accessing it after destruction } // Destroy any asset that leaves the screen if (game.children[i].y > 2732 || game.children[i].y < 0 || game.children[i].x > 2048 || game.children[i].x < 0) { game.children[i].destroy(); // destroy if it leaves the screen } } } }; game.down = function (x, y, obj) { duneBuggy.x = 2048 / 2; }; game.move = function (x, y, obj) { duneBuggy.x = Math.max(175, Math.min(1900, x)); }; game.up = function (x, y, obj) { // No action needed on up event };
/****
* Classes
****/
// Bighorn class to represent the randomly spawned Bighorn
var Bighorn = Container.expand(function () {
var self = Container.call(this);
var bighornGraphics = self.attachAsset('Bighorn', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
self.y += self.speed;
};
});
// Cactus class to represent the randomly spawned Cactus
var Cactus = Container.expand(function () {
var self = Container.call(this);
var cactusGraphics = self.attachAsset('Cactus', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
self.y += self.speed;
};
});
//<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
});
// Initialize previous position for rotation calculation
self.previousX = self.x;
self.previousY = self.y;
self.speed = 5;
self.update = function () {
// Keep the duneBuggy straight without rotation
buggyGraphics.rotation = 0; // Set rotation to 0 to keep it straight
// Store the current position for the next update
self.previousX = self.x;
self.previousY = self.y;
};
});
// GasCan class to represent the randomly spawned GasCan
var GasCan = Container.expand(function () {
var self = Container.call(this);
var gascanGraphics = self.attachAsset('gascan', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
self.y += self.speed;
};
});
// Joshua class to represent the randomly spawned Joshua
var Joshua = Container.expand(function () {
var self = Container.call(this);
var joshuaGraphics = self.attachAsset('Joshua', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
self.y += self.speed;
};
});
// Mojave class to represent the randomly spawned Mojave
var Mojave = Container.expand(function () {
var self = Container.call(this);
var mojaveGraphics = self.attachAsset('Mojave', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
self.y += self.speed;
};
});
// Roadrunner class to represent the randomly spawned Roadrunner
var Roadrunner = Container.expand(function () {
var self = Container.call(this);
var roadrunnerGraphics = self.attachAsset('Roadrunner', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
self.y += self.speed;
};
});
// Snake class to represent the randomly spawned Snake
var Snake = Container.expand(function () {
var self = Container.call(this);
var snakeGraphics = self.attachAsset('Snake', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
self.y += self.speed;
};
});
// Spider class to represent the randomly spawned Spider
var Spider = Container.expand(function () {
var self = Container.call(this);
var spiderGraphics = self.attachAsset('Spider', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
self.y += self.speed;
};
});
// Tire class to represent the randomly spawned Tire
var Tire = Container.expand(function () {
var self = Container.call(this);
var tireGraphics = self.attachAsset('tire', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
self.y += self.speed;
};
});
// Tumble class to represent the randomly spawned Tumble
var Tumble = Container.expand(function () {
var self = Container.call(this);
var tumbleGraphics = self.attachAsset('Tumble', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
self.y += self.speed;
};
});
// Turtle class to represent the randomly spawned Turtle
var Turtle = Container.expand(function () {
var self = Container.call(this);
var turtleGraphics = self.attachAsset('Turtle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
self.y += self.speed;
};
});
// Yucca class to represent the randomly spawned Yucca
var Yucca = Container.expand(function () {
var self = Container.call(this);
var yuccaGraphics = self.attachAsset('Yucca', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({});
/****
* Game Code
****/
// Add Flag to the lower left of the screen
var flag = LK.getAsset('Flag', {
anchorX: 0.5,
anchorY: 0.5,
x: 180,
// Adjusted to position the flag at the lower left
y: 2732 - 180 // Adjusted to position the flag at the lower left
});
game.addChild(flag);
// Add a second Flag to the right of the first flag
var secondFlag = LK.getAsset('Flag', {
anchorX: 0.5,
anchorY: 0.5,
x: 180 + 360,
// Positioned to the right of the first flag
y: 2732 - 180
});
game.addChild(secondFlag);
// Add a third Flag to the right of the second flag
var thirdFlag = LK.getAsset('Flag', {
anchorX: 0.5,
anchorY: 0.5,
x: 180 + 360 * 2,
// Positioned to the right of the second flag
y: 2732 - 180
});
game.addChild(thirdFlag);
// Add a fourth Flag to the right of the third flag
var fourthFlag = LK.getAsset('Flag', {
anchorX: 0.5,
anchorY: 0.5,
x: 180 + 360 * 3,
// Positioned to the right of the third flag
y: 2732 - 180
});
game.addChild(fourthFlag);
// Add a fifth Flag to the right of the fourth flag
var fifthFlag = LK.getAsset('Flag', {
anchorX: 0.5,
anchorY: 0.5,
x: 180 + 360 * 4,
// Positioned to the right of the fourth flag
y: 2732 - 180
});
game.addChild(fifthFlag);
// Add a sixth Flag to the right of the fifth flag
var sixthFlag = LK.getAsset('Flag', {
anchorX: 0.5,
anchorY: 0.5,
x: 180 + 360 * 5,
// Positioned to the right of the fifth flag
y: 2732 - 180
});
game.addChild(sixthFlag);
// Add track as the background
var track = LK.getAsset('track', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(track);
// Add GasCan
var gascan = new GasCan();
gascan.x = 512; // Position GasCan
gascan.y = 200;
if (!isOverlapping(gascan)) {
game.addChild(gascan);
gascan.zIndex = 10; // Ensure GasCan is above the track
}
// Add Tire
var tire = new Tire();
tire.x = 1536; // Position Tire
tire.y = 200;
if (!isOverlapping(tire)) {
game.addChild(tire);
tire.zIndex = 10; // Ensure Tire is above the track
}
function isOverlapping(newObject) {
for (var i = 0; i < game.children.length; i++) {
if (game.children[i] !== newObject && game.children[i].intersects(newObject)) {
return true;
}
}
return false;
}
var duneBuggy = game.addChild(new DuneBuggy());
duneBuggy.x = 2048 / 2;
duneBuggy.y = 2200 - 200;
var obstacles = [];
var supplies = [];
var score = 0;
var scoreTxt = new Text2('Distance: 0', {
size: 120,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.x -= 0; // Move slightly to the left
scoreTxt.y += 0; // Move down a little bit
LK.gui.top.addChild(scoreTxt);
var tiresTxt = new Text2('Tires: 100%', {
size: 100,
fill: "#ffffff"
});
tiresTxt.anchor.set(0.5, 0);
tiresTxt.x -= 400; // Move tires text to the left
tiresTxt.y += 130; // Move tires text down
LK.gui.top.addChild(tiresTxt);
var fuelTxt = new Text2('Fuel:', {
size: 100,
fill: "#ffffff"
});
fuelTxt.anchor.set(0.5, 0);
fuelTxt.x -= -340; // Move fuel text to the left by 400
fuelTxt.y += 130; // Move fuel text down by 800
LK.gui.top.addChild(fuelTxt);
var distance = 0;
var fuel = 15;
var tires = 100;
fuelTxt.setText('Fuel: ' + fuel + ' Gallons');
game.update = function () {
if (LK.ticks % 60 == 0) {
distance += 0.1;
scoreTxt.setText('Distance: ' + distance.toFixed(1));
if (distance % 2 < 0.1) {
fuel -= 1;
fuelTxt.setText('Fuel: ' + fuel + ' Gallons');
if (fuel <= 0) {
LK.showGameOver();
}
}
// Spawn GasCan and Tire every 1 distance
if (distance % 1 < 0.1) {
var gascan = new GasCan();
gascan.x = Math.random() * 2048; // Random x position
gascan.y = 0;
if (!isOverlapping(gascan)) {
game.addChild(gascan);
}
var tire = new Tire();
tire.x = Math.random() * 2048; // Random x position
tire.y = 0;
if (!isOverlapping(tire)) {
game.addChild(tire);
}
}
// Spawn Bighorn, Cactus and Coyote at different intervals
if (LK.ticks % 40 == 0 && LK.ticks > 300) {
var bighorn = new Bighorn();
bighorn.x = Math.random() * 2048;
bighorn.y = 0;
game.addChild(bighorn);
}
if (LK.ticks % 60 == 0 && LK.ticks > 350) {
var cactus = new Cactus();
cactus.x = Math.random() * 2048;
cactus.y = 0;
game.addChild(cactus);
}
if (LK.ticks % 100 == 0 && LK.ticks > 450) {
var joshua = new Joshua();
joshua.x = Math.random() * 2048;
joshua.y = 0;
game.addChild(joshua);
}
if (LK.ticks % 120 == 0 && LK.ticks > 500) {
var mojave = new Mojave();
mojave.x = Math.random() * 2048;
mojave.y = 0;
game.addChild(mojave);
}
if (LK.ticks % 160 == 0 && LK.ticks > 600) {
var roadrunner = new Roadrunner();
roadrunner.x = Math.random() * 2048;
roadrunner.y = 0;
game.addChild(roadrunner);
}
if (LK.ticks % 200 == 0 && LK.ticks > 700) {
var snake = new Snake();
snake.x = Math.random() * 2048;
snake.y = 0;
game.addChild(snake);
}
if (LK.ticks % 220 == 0 && LK.ticks > 750) {
var spider = new Spider();
spider.x = Math.random() * 2048;
spider.y = 0;
game.addChild(spider);
}
if (LK.ticks % 240 == 0 && LK.ticks > 800) {
var tumble = new Tumble();
tumble.x = Math.random() * 2048;
tumble.y = 0;
game.addChild(tumble);
}
if (LK.ticks % 260 == 0 && LK.ticks > 850) {
var turtle = new Turtle();
turtle.x = Math.random() * 2048;
turtle.y = 0;
game.addChild(turtle);
}
if (LK.ticks % 280 == 0 && LK.ticks > 900) {
var yucca = new Yucca();
yucca.x = Math.random() * 2048;
yucca.y = 0;
game.addChild(yucca);
}
// Check for collision between duneBuggy and Bighorn, Cactus, Coyote, Joshua, Mojave, Rabbit, Roadrunner, Scorpion, Snake, Spider, Tumble, Turtle, or Yucca
for (var i = game.children.length - 1; i >= 0; i--) {
if (game.children[i] instanceof Bighorn || game.children[i] instanceof Cactus || game.children[i] instanceof Joshua || game.children[i] instanceof Mojave || game.children[i] instanceof Roadrunner || game.children[i] instanceof Snake || game.children[i] instanceof Spider || game.children[i] instanceof Tumble || game.children[i] instanceof Turtle || game.children[i] instanceof Yucca) {
if (duneBuggy.intersects(game.children[i])) {
tires -= 3; // decrease tires by 3%
tiresTxt.setText('Tires: ' + tires + '%'); // update tires text
if (tires <= 0) {
LK.showGameOver(); // game over if tires reach 0
}
game.children[i].destroy(); // destroy Bighorn, Cactus, Coyote, Joshua, Mojave, Rabbit, Roadrunner, Scorpion, Snake, or Spider on collision
return; // return after destroying to prevent accessing it after destruction
}
} else if (game.children[i] instanceof GasCan && duneBuggy.intersects(game.children[i])) {
fuel += 2; // increase fuel by 2 gallons
fuelTxt.setText('Fuel: ' + fuel + ' Gallons'); // update fuel text
game.children[i].destroy(); // destroy GasCan on collision
return; // return after destroying to prevent accessing it after destruction
} else if (game.children[i] instanceof Tire && duneBuggy.intersects(game.children[i])) {
tires = Math.min(tires + 2, 100); // increase tires by 2%, max 100%
tiresTxt.setText('Tires: ' + tires + '%'); // update tires text
game.children[i].destroy(); // destroy Tire on collision
return; // return after destroying to prevent accessing it after destruction
}
// Destroy any asset that leaves the screen
if (game.children[i].y > 2732 || game.children[i].y < 0 || game.children[i].x > 2048 || game.children[i].x < 0) {
game.children[i].destroy(); // destroy if it leaves the screen
}
}
}
};
game.down = function (x, y, obj) {
duneBuggy.x = 2048 / 2;
};
game.move = function (x, y, obj) {
duneBuggy.x = Math.max(175, Math.min(1900, 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