/**** * 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.velocity = { x: 0, y: 0 }; self.update = function () { self.x += self.velocity.x; self.y += self.velocity.y; }; }); // 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 }; // Event handler called when a press happens on element. This is automatically called on press if slingshot is attached. self.down = function (x, y, obj) { console.log("Down was triggered on Slingshot with local cord of ", { x: x, y: y }); var game_position = game.toLocal(obj.global); console.log("Down was triggered on Slingshot with game scoped cord of ", game_position); }; // Event handler called when a release happens on element. This is automatically called on press if slingshot is attached. self.up = function (x, y, obj) { console.log("Up was triggered on Slingshot with local cord of ", { x: x, y: y }); var game_position = game.toLocal(obj.global); console.log("Up was triggered on Slingshot with game scoped cord of ", game_position); }; // Event handler called on every mouse move.This is automatically called on press if slingshot is attached. self.move = function (x, y, obj) { //Generally do not define .move events on anything except for game. }; }); // 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; } } if (dragNode && slingshot.intersects(obj)) { dragNode.velocity.x = (slingshot.x - dragNode.x) * 0.1; dragNode.velocity.y = (slingshot.y - dragNode.y) * 0.1; } }; 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(); } };
===================================================================
--- original.js
+++ change.js
@@ -1,53 +1,80 @@
-/****
+/****
* 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
- };
+ var self = Container.call(this);
+ var animalGraphics = self.attachAsset('nerdyAnimal', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocity = {
+ x: 0,
+ y: 0
+ };
+ self.update = function () {
+ self.x += self.velocity.x;
+ self.y += self.velocity.y;
+ };
});
// 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
- };
+ var self = Container.call(this);
+ var slingshotGraphics = self.attachAsset('slingshot', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Update logic for slingshot
+ };
+ // Event handler called when a press happens on element. This is automatically called on press if slingshot is attached.
+ self.down = function (x, y, obj) {
+ console.log("Down was triggered on Slingshot with local cord of ", {
+ x: x,
+ y: y
+ });
+ var game_position = game.toLocal(obj.global);
+ console.log("Down was triggered on Slingshot with game scoped cord of ", game_position);
+ };
+ // Event handler called when a release happens on element. This is automatically called on press if slingshot is attached.
+ self.up = function (x, y, obj) {
+ console.log("Up was triggered on Slingshot with local cord of ", {
+ x: x,
+ y: y
+ });
+ var game_position = game.toLocal(obj.global);
+ console.log("Up was triggered on Slingshot with game scoped cord of ", game_position);
+ };
+ // Event handler called on every mouse move.This is automatically called on press if slingshot is attached.
+ self.move = function (x, y, obj) {
+ //Generally do not define .move events on anything except for game.
+ };
});
// 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
- };
+ 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
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize game elements
var nerdyAnimals = [];
var slingshot = game.addChild(new Slingshot());
var targets = [];
@@ -55,21 +82,21 @@
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);
+ 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);
+ 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);
@@ -79,52 +106,56 @@
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;
- }
- }
+ for (var i = 0; i < nerdyAnimals.length; i++) {
+ if (nerdyAnimals[i].intersects(obj)) {
+ dragNode = nerdyAnimals[i];
+ break;
+ }
+ }
+ if (dragNode && slingshot.intersects(obj)) {
+ dragNode.velocity.x = (slingshot.x - dragNode.x) * 0.1;
+ dragNode.velocity.y = (slingshot.y - dragNode.y) * 0.1;
+ }
};
game.move = function (x, y, obj) {
- if (dragNode) {
- dragNode.x = x;
- dragNode.y = y;
- }
+ 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;
- }
+ 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();
- }
+ // Update all nerdy animals
+ for (var i = 0; i < nerdyAnimals.length; i++) {
+ nerdyAnimals[i].update();
+ }
};
\ No newline at end of file
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.