/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Class for Nerdy Animal var NerdyAnimal = Container.expand(function () { var self = Container.call(this); var animalGraphics = self.attachAsset('nerdyAnimal', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for nerdy animal }; }); // Class for Slingshot var Slingshot = Container.expand(function () { var self = Container.call(this); var slingshotGraphics = self.attachAsset('slingshot', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for slingshot }; }); // Class for Target var Target = Container.expand(function () { var self = Container.call(this); var targetGraphics = self.attachAsset('target', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for target }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize game elements var nerdyAnimals = []; var slingshot = game.addChild(new Slingshot()); var targets = []; // Position slingshot slingshot.x = 300; slingshot.y = 2000; // Create nerdy animals function createNerdyAnimal(x, y) { var nerdyAnimal = new NerdyAnimal(); nerdyAnimal.x = x; nerdyAnimal.y = y; nerdyAnimals.push(nerdyAnimal); game.addChild(nerdyAnimal); } // Create targets function createTarget(x, y) { var target = new Target(); target.x = x; target.y = y; targets.push(target); game.addChild(target); } // Initialize nerdy animals and targets createNerdyAnimal(300, 1800); createNerdyAnimal(400, 1800); createNerdyAnimal(500, 1800); createTarget(1500, 500); createTarget(1600, 600); createTarget(1700, 700); // Handle dragging of nerdy animals var dragNode = null; game.down = function (x, y, obj) { for (var i = 0; i < nerdyAnimals.length; i++) { if (nerdyAnimals[i].intersects(obj)) { dragNode = nerdyAnimals[i]; break; } } }; game.move = function (x, y, obj) { if (dragNode) { dragNode.x = x; dragNode.y = y; } }; game.up = function (x, y, obj) { if (dragNode) { // Launch the nerdy animal var launchVelocity = { x: (slingshot.x - dragNode.x) * 0.1, y: (slingshot.y - dragNode.y) * 0.1 }; dragNode.update = function () { dragNode.x += launchVelocity.x; dragNode.y += launchVelocity.y; launchVelocity.y += 0.5; // Gravity effect // Check for collision with targets for (var i = 0; i < targets.length; i++) { if (dragNode.intersects(targets[i])) { targets[i].destroy(); targets.splice(i, 1); break; } } // Remove nerdy animal if it goes off-screen if (dragNode.y > 2732) { dragNode.destroy(); nerdyAnimals.splice(nerdyAnimals.indexOf(dragNode), 1); } }; dragNode = null; } }; // Update game logic game.update = function () { // Update all nerdy animals for (var i = 0; i < nerdyAnimals.length; i++) { nerdyAnimals[i].update(); } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for Nerdy Animal
var NerdyAnimal = Container.expand(function () {
var self = Container.call(this);
var animalGraphics = self.attachAsset('nerdyAnimal', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for nerdy animal
};
});
// Class for Slingshot
var Slingshot = Container.expand(function () {
var self = Container.call(this);
var slingshotGraphics = self.attachAsset('slingshot', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for slingshot
};
});
// Class for Target
var Target = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for target
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize game elements
var nerdyAnimals = [];
var slingshot = game.addChild(new Slingshot());
var targets = [];
// Position slingshot
slingshot.x = 300;
slingshot.y = 2000;
// Create nerdy animals
function createNerdyAnimal(x, y) {
var nerdyAnimal = new NerdyAnimal();
nerdyAnimal.x = x;
nerdyAnimal.y = y;
nerdyAnimals.push(nerdyAnimal);
game.addChild(nerdyAnimal);
}
// Create targets
function createTarget(x, y) {
var target = new Target();
target.x = x;
target.y = y;
targets.push(target);
game.addChild(target);
}
// Initialize nerdy animals and targets
createNerdyAnimal(300, 1800);
createNerdyAnimal(400, 1800);
createNerdyAnimal(500, 1800);
createTarget(1500, 500);
createTarget(1600, 600);
createTarget(1700, 700);
// Handle dragging of nerdy animals
var dragNode = null;
game.down = function (x, y, obj) {
for (var i = 0; i < nerdyAnimals.length; i++) {
if (nerdyAnimals[i].intersects(obj)) {
dragNode = nerdyAnimals[i];
break;
}
}
};
game.move = function (x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
};
game.up = function (x, y, obj) {
if (dragNode) {
// Launch the nerdy animal
var launchVelocity = {
x: (slingshot.x - dragNode.x) * 0.1,
y: (slingshot.y - dragNode.y) * 0.1
};
dragNode.update = function () {
dragNode.x += launchVelocity.x;
dragNode.y += launchVelocity.y;
launchVelocity.y += 0.5; // Gravity effect
// Check for collision with targets
for (var i = 0; i < targets.length; i++) {
if (dragNode.intersects(targets[i])) {
targets[i].destroy();
targets.splice(i, 1);
break;
}
}
// Remove nerdy animal if it goes off-screen
if (dragNode.y > 2732) {
dragNode.destroy();
nerdyAnimals.splice(nerdyAnimals.indexOf(dragNode), 1);
}
};
dragNode = null;
}
};
// Update game logic
game.update = function () {
// Update all nerdy animals
for (var i = 0; i < nerdyAnimals.length; i++) {
nerdyAnimals[i].update();
}
};
cartoon looking slingshot. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
nerdy cartoon animal. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
wooden house. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.