/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Cookie class representing the cookies to be eaten var Cookie = Container.expand(function () { var self = Container.call(this); var cookieGraphics = self.attachAsset('cookie', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += 5; // Move cookies downwards }; }); // CookieVariant class representing the variant cookies to be eaten var CookieVariant = Container.expand(function () { var self = Container.call(this); var cookieVariantGraphics = self.attachAsset('cookieVariant', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += 5; // Move variant cookies downwards }; }); // NewCookieVariant class representing a new variant of cookies to be eaten var NewCookieVariant = Container.expand(function () { var self = Container.call(this); var newCookieVariantGraphics = self.attachAsset('newCookieVariant', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += 5; // Move new variant cookies downwards }; }); // Obstacle class representing obstacles to dodge var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += 7; // Move obstacles downwards faster }; }); // ObstacleVariant1 class representing the first variant of obstacles to dodge var ObstacleVariant1 = Container.expand(function () { var self = Container.call(this); var obstacleVariant1Graphics = self.attachAsset('obstacleVariant1', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += 10; // Increase the speed of the first variant obstacles }; }); // ObstacleVariant2 class representing the second variant of obstacles to dodge var ObstacleVariant2 = Container.expand(function () { var self = Container.call(this); var obstacleVariant2Graphics = self.attachAsset('obstacleVariant2', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += 4; // Make second variant obstacles move even slower }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var background = game.addChild(LK.getAsset('background', { anchorX: 0.0, anchorY: 0.0 })); // Initialize arrays to keep track of cookies and obstacles var cookies = []; var cookieVariants = []; var obstacles = []; var obstacleVariants1 = []; var obstacleVariants2 = []; var score = 0; // Create a character to eat cookies var character = game.addChild(new Container()); var characterGraphics = character.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); character.x = 2048 / 2; character.y = 2732 - 200; // Score display var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Handle touch events to move the character game.down = function (x, y, obj) { character.x = x; character.y = y; }; // Update game logic game.update = function () { // Spawn cookies and obstacles if (LK.ticks % 60 == 0) { var newCookie = new Cookie(); newCookie.x = Math.random() * 2048; newCookie.y = -50; cookies.push(newCookie); game.addChild(newCookie); var newObstacle = new Obstacle(); newObstacle.x = Math.random() * 2048; newObstacle.y = -50; obstacles.push(newObstacle); game.addChild(newObstacle); } // Spawn obstacle variant1 even less frequently if (LK.ticks % 240 == 0) { var newObstacleVariant1 = new ObstacleVariant1(); newObstacleVariant1.x = Math.random() * 2048; newObstacleVariant1.y = -50; obstacleVariants1.push(newObstacleVariant1); game.addChild(newObstacleVariant1); } // Spawn obstacle variant2 even less frequently if (LK.ticks % 480 == 0) { var newObstacleVariant2 = new ObstacleVariant2(); newObstacleVariant2.x = Math.random() * 2048; newObstacleVariant2.y = -50; obstacleVariants2.push(newObstacleVariant2); game.addChild(newObstacleVariant2); } // Spawn cookie variant less frequently if (LK.ticks % 120 == 0) { var newCookieVariant = new CookieVariant(); newCookieVariant.x = Math.random() * 2048; newCookieVariant.y = -50; cookieVariants.push(newCookieVariant); game.addChild(newCookieVariant); } // Update cookies and check for collisions for (var i = cookies.length - 1; i >= 0; i--) { var cookie = cookies[i]; cookie.update(); if (cookie.y > 2732) { cookie.destroy(); cookies.splice(i, 1); } else if (character.intersects(cookie)) { score++; scoreTxt.setText(score); cookie.destroy(); cookies.splice(i, 1); } } // Spawn new cookie variant less frequently if (LK.ticks % 180 == 0) { var newCookieVariant = new NewCookieVariant(); newCookieVariant.x = Math.random() * 2048; newCookieVariant.y = -50; cookieVariants.push(newCookieVariant); game.addChild(newCookieVariant); } // Update new cookie variants and check for collisions for (var p = cookieVariants.length - 1; p >= 0; p--) { var newCookieVariant = cookieVariants[p]; newCookieVariant.update(); if (newCookieVariant.y > 2732) { newCookieVariant.destroy(); cookieVariants.splice(p, 1); } else if (character.intersects(newCookieVariant)) { score += 5; // Higher score for new cookie variants scoreTxt.setText(score); newCookieVariant.destroy(); cookieVariants.splice(p, 1); } } // Update obstacles and check for collisions for (var j = obstacles.length - 1; j >= 0; j--) { var obstacle = obstacles[j]; obstacle.update(); if (obstacle.y > 2732) { obstacle.destroy(); obstacles.splice(j, 1); } else if (character.intersects(obstacle)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Update first obstacle variants and check for collisions for (var m = obstacleVariants1.length - 1; m >= 0; m--) { var obstacleVariant1 = obstacleVariants1[m]; obstacleVariant1.update(); if (obstacleVariant1.y > 2732) { obstacleVariant1.destroy(); obstacleVariants1.splice(m, 1); } else if (character.intersects(obstacleVariant1)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Update second obstacle variants and check for collisions for (var n = obstacleVariants2.length - 1; n >= 0; n--) { var obstacleVariant2 = obstacleVariants2[n]; obstacleVariant2.update(); if (obstacleVariant2.y > 2732) { obstacleVariant2.destroy(); obstacleVariants2.splice(n, 1); } else if (character.intersects(obstacleVariant2)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Update cookie variants and check for collisions for (var k = cookieVariants.length - 1; k >= 0; k--) { var cookieVariant = cookieVariants[k]; cookieVariant.update(); if (cookieVariant.y > 2732) { cookieVariant.destroy(); cookieVariants.splice(k, 1); } else if (character.intersects(cookieVariant)) { score += 3; // Triple score for cookie variants scoreTxt.setText(score); cookieVariant.destroy(); cookieVariants.splice(k, 1); } } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Cookie class representing the cookies to be eaten
var Cookie = Container.expand(function () {
var self = Container.call(this);
var cookieGraphics = self.attachAsset('cookie', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 5; // Move cookies downwards
};
});
// CookieVariant class representing the variant cookies to be eaten
var CookieVariant = Container.expand(function () {
var self = Container.call(this);
var cookieVariantGraphics = self.attachAsset('cookieVariant', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 5; // Move variant cookies downwards
};
});
// NewCookieVariant class representing a new variant of cookies to be eaten
var NewCookieVariant = Container.expand(function () {
var self = Container.call(this);
var newCookieVariantGraphics = self.attachAsset('newCookieVariant', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 5; // Move new variant cookies downwards
};
});
// Obstacle class representing obstacles to dodge
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 7; // Move obstacles downwards faster
};
});
// ObstacleVariant1 class representing the first variant of obstacles to dodge
var ObstacleVariant1 = Container.expand(function () {
var self = Container.call(this);
var obstacleVariant1Graphics = self.attachAsset('obstacleVariant1', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 10; // Increase the speed of the first variant obstacles
};
});
// ObstacleVariant2 class representing the second variant of obstacles to dodge
var ObstacleVariant2 = Container.expand(function () {
var self = Container.call(this);
var obstacleVariant2Graphics = self.attachAsset('obstacleVariant2', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 4; // Make second variant obstacles move even slower
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0
}));
// Initialize arrays to keep track of cookies and obstacles
var cookies = [];
var cookieVariants = [];
var obstacles = [];
var obstacleVariants1 = [];
var obstacleVariants2 = [];
var score = 0;
// Create a character to eat cookies
var character = game.addChild(new Container());
var characterGraphics = character.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
character.x = 2048 / 2;
character.y = 2732 - 200;
// Score display
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle touch events to move the character
game.down = function (x, y, obj) {
character.x = x;
character.y = y;
};
// Update game logic
game.update = function () {
// Spawn cookies and obstacles
if (LK.ticks % 60 == 0) {
var newCookie = new Cookie();
newCookie.x = Math.random() * 2048;
newCookie.y = -50;
cookies.push(newCookie);
game.addChild(newCookie);
var newObstacle = new Obstacle();
newObstacle.x = Math.random() * 2048;
newObstacle.y = -50;
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
// Spawn obstacle variant1 even less frequently
if (LK.ticks % 240 == 0) {
var newObstacleVariant1 = new ObstacleVariant1();
newObstacleVariant1.x = Math.random() * 2048;
newObstacleVariant1.y = -50;
obstacleVariants1.push(newObstacleVariant1);
game.addChild(newObstacleVariant1);
}
// Spawn obstacle variant2 even less frequently
if (LK.ticks % 480 == 0) {
var newObstacleVariant2 = new ObstacleVariant2();
newObstacleVariant2.x = Math.random() * 2048;
newObstacleVariant2.y = -50;
obstacleVariants2.push(newObstacleVariant2);
game.addChild(newObstacleVariant2);
}
// Spawn cookie variant less frequently
if (LK.ticks % 120 == 0) {
var newCookieVariant = new CookieVariant();
newCookieVariant.x = Math.random() * 2048;
newCookieVariant.y = -50;
cookieVariants.push(newCookieVariant);
game.addChild(newCookieVariant);
}
// Update cookies and check for collisions
for (var i = cookies.length - 1; i >= 0; i--) {
var cookie = cookies[i];
cookie.update();
if (cookie.y > 2732) {
cookie.destroy();
cookies.splice(i, 1);
} else if (character.intersects(cookie)) {
score++;
scoreTxt.setText(score);
cookie.destroy();
cookies.splice(i, 1);
}
}
// Spawn new cookie variant less frequently
if (LK.ticks % 180 == 0) {
var newCookieVariant = new NewCookieVariant();
newCookieVariant.x = Math.random() * 2048;
newCookieVariant.y = -50;
cookieVariants.push(newCookieVariant);
game.addChild(newCookieVariant);
}
// Update new cookie variants and check for collisions
for (var p = cookieVariants.length - 1; p >= 0; p--) {
var newCookieVariant = cookieVariants[p];
newCookieVariant.update();
if (newCookieVariant.y > 2732) {
newCookieVariant.destroy();
cookieVariants.splice(p, 1);
} else if (character.intersects(newCookieVariant)) {
score += 5; // Higher score for new cookie variants
scoreTxt.setText(score);
newCookieVariant.destroy();
cookieVariants.splice(p, 1);
}
}
// Update obstacles and check for collisions
for (var j = obstacles.length - 1; j >= 0; j--) {
var obstacle = obstacles[j];
obstacle.update();
if (obstacle.y > 2732) {
obstacle.destroy();
obstacles.splice(j, 1);
} else if (character.intersects(obstacle)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update first obstacle variants and check for collisions
for (var m = obstacleVariants1.length - 1; m >= 0; m--) {
var obstacleVariant1 = obstacleVariants1[m];
obstacleVariant1.update();
if (obstacleVariant1.y > 2732) {
obstacleVariant1.destroy();
obstacleVariants1.splice(m, 1);
} else if (character.intersects(obstacleVariant1)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update second obstacle variants and check for collisions
for (var n = obstacleVariants2.length - 1; n >= 0; n--) {
var obstacleVariant2 = obstacleVariants2[n];
obstacleVariant2.update();
if (obstacleVariant2.y > 2732) {
obstacleVariant2.destroy();
obstacleVariants2.splice(n, 1);
} else if (character.intersects(obstacleVariant2)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update cookie variants and check for collisions
for (var k = cookieVariants.length - 1; k >= 0; k--) {
var cookieVariant = cookieVariants[k];
cookieVariant.update();
if (cookieVariant.y > 2732) {
cookieVariant.destroy();
cookieVariants.splice(k, 1);
} else if (character.intersects(cookieVariant)) {
score += 3; // Triple score for cookie variants
scoreTxt.setText(score);
cookieVariant.destroy();
cookieVariants.splice(k, 1);
}
}
};
Rock. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Chocolate chip cookie. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Person man running. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Golden cookie. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
360-degree missile. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Mountain. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Rainbow cookie. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows