User prompt
Game over when car hits a bug
User prompt
Bugs scroll from top to bottom
User prompt
Car moves for as long as the screen remains touched
User prompt
Itās not required to touch inside the car for it to move
User prompt
Car moves towards the direction that I touch the screen
Initial prompt
Safari Bugs
/**** * Classes ****/ // Bug class to represent the giant bugs var Bug = Container.expand(function () { var self = Container.call(this); var bugGraphics = self.attachAsset('bug', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Bug movement logic can be added here }; }); //<Assets used in the game will automatically appear here> // Jeep class to represent the player's vehicle var Jeep = Container.expand(function () { var self = Container.call(this); var jeepGraphics = self.attachAsset('jeep', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Jeep movement logic can be added here }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize game variables var jeep; var bugs = []; var score = 0; var scoreTxt; // Function to initialize game elements function initGame() { // Create and position the Jeep jeep = game.addChild(new Jeep()); jeep.x = 2048 / 2; jeep.y = 2732 - 200; // Create initial bugs for (var i = 0; i < 5; i++) { createBug(); } // Initialize score display scoreTxt = new Text2('Score: 0', { size: 100, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); } // Function to create a new bug function createBug() { var bug = new Bug(); bug.x = Math.random() * 2048; bug.y = Math.random() * 1000; bugs.push(bug); game.addChild(bug); } // Function to update the score function updateScore() { scoreTxt.setText('Score: ' + score); } // Event handler for moving the Jeep game.move = function (x, y, obj) { var dx = x - jeep.x; var dy = y - jeep.y; var angle = Math.atan2(dy, dx); jeep.x += jeep.speed * Math.cos(angle); jeep.y += jeep.speed * Math.sin(angle); }; // Event handler for snapping a bug game.down = function (x, y, obj) { for (var i = bugs.length - 1; i >= 0; i--) { if (bugs[i].intersects(jeep)) { score += 10; updateScore(); bugs[i].destroy(); bugs.splice(i, 1); createBug(); } } }; // Game update loop game.update = function () { jeep.update(); for (var i = 0; i < bugs.length; i++) { bugs[i].update(); } }; // Initialize the game initGame();
===================================================================
--- original.js
+++ change.js
@@ -1,99 +1,102 @@
-/****
+/****
* Classes
-****/
+****/
// Bug class to represent the giant bugs
var Bug = Container.expand(function () {
- var self = Container.call(this);
- var bugGraphics = self.attachAsset('bug', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Bug movement logic can be added here
- };
+ var self = Container.call(this);
+ var bugGraphics = self.attachAsset('bug', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Bug movement logic can be added here
+ };
});
//<Assets used in the game will automatically appear here>
// Jeep class to represent the player's vehicle
var Jeep = Container.expand(function () {
- var self = Container.call(this);
- var jeepGraphics = self.attachAsset('jeep', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 10;
- self.update = function () {
- // Jeep movement logic can be added here
- };
+ var self = Container.call(this);
+ var jeepGraphics = self.attachAsset('jeep', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 10;
+ self.update = function () {
+ // Jeep movement logic can be added here
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize game variables
var jeep;
var bugs = [];
var score = 0;
var scoreTxt;
// Function to initialize game elements
function initGame() {
- // Create and position the Jeep
- jeep = game.addChild(new Jeep());
- jeep.x = 2048 / 2;
- jeep.y = 2732 - 200;
- // Create initial bugs
- for (var i = 0; i < 5; i++) {
- createBug();
- }
- // Initialize score display
- scoreTxt = new Text2('Score: 0', {
- size: 100,
- fill: "#ffffff"
- });
- scoreTxt.anchor.set(0.5, 0);
- LK.gui.top.addChild(scoreTxt);
+ // Create and position the Jeep
+ jeep = game.addChild(new Jeep());
+ jeep.x = 2048 / 2;
+ jeep.y = 2732 - 200;
+ // Create initial bugs
+ for (var i = 0; i < 5; i++) {
+ createBug();
+ }
+ // Initialize score display
+ scoreTxt = new Text2('Score: 0', {
+ size: 100,
+ fill: "#ffffff"
+ });
+ scoreTxt.anchor.set(0.5, 0);
+ LK.gui.top.addChild(scoreTxt);
}
// Function to create a new bug
function createBug() {
- var bug = new Bug();
- bug.x = Math.random() * 2048;
- bug.y = Math.random() * 1000;
- bugs.push(bug);
- game.addChild(bug);
+ var bug = new Bug();
+ bug.x = Math.random() * 2048;
+ bug.y = Math.random() * 1000;
+ bugs.push(bug);
+ game.addChild(bug);
}
// Function to update the score
function updateScore() {
- scoreTxt.setText('Score: ' + score);
+ scoreTxt.setText('Score: ' + score);
}
// Event handler for moving the Jeep
game.move = function (x, y, obj) {
- jeep.x = x;
- jeep.y = y;
+ var dx = x - jeep.x;
+ var dy = y - jeep.y;
+ var angle = Math.atan2(dy, dx);
+ jeep.x += jeep.speed * Math.cos(angle);
+ jeep.y += jeep.speed * Math.sin(angle);
};
// Event handler for snapping a bug
game.down = function (x, y, obj) {
- for (var i = bugs.length - 1; i >= 0; i--) {
- if (bugs[i].intersects(jeep)) {
- score += 10;
- updateScore();
- bugs[i].destroy();
- bugs.splice(i, 1);
- createBug();
- }
- }
+ for (var i = bugs.length - 1; i >= 0; i--) {
+ if (bugs[i].intersects(jeep)) {
+ score += 10;
+ updateScore();
+ bugs[i].destroy();
+ bugs.splice(i, 1);
+ createBug();
+ }
+ }
};
// Game update loop
game.update = function () {
- jeep.update();
- for (var i = 0; i < bugs.length; i++) {
- bugs[i].update();
- }
+ jeep.update();
+ for (var i = 0; i < bugs.length; i++) {
+ bugs[i].update();
+ }
};
// Initialize the game
initGame();
\ No newline at end of file
Giant insect, facing down, open wings, cartoony. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Jeep car cartoony, top down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cartoony heart for game hud. In-Game asset. 2d. High contrast. No shadows