/**** * Classes ****/ // Class for Dog var Dog = Container.expand(function () { var self = Container.call(this); var dogGraphics = self.attachAsset('dog', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Dog's update logic if needed }; }); // Class for Mouse var Mouse = Container.expand(function () { var self = Container.call(this); var mouseGraphics = self.attachAsset('mouse', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Mouse's update logic if needed }; }); // Assets will be automatically created and loaded by the LK engine based on their usage in the code. // Class for Safiye the Cat var Safiye = Container.expand(function () { var self = Container.call(this); var safiyeGraphics = self.attachAsset('safiye', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Safiye's update logic if needed }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var safiye = game.addChild(new Safiye()); safiye.x = 2048 / 2; safiye.y = 2732 - 200; var mice = []; var dogs = []; // Function to spawn a mouse function spawnMouse() { var mouse = new Mouse(); mouse.x = Math.random() * 2048; mouse.y = Math.random() * 1000; mice.push(mouse); game.addChild(mouse); } // Function to spawn a dog function spawnDog() { var dog = new Dog(); dog.x = Math.random() * 2048; dog.y = Math.random() * 1000; dogs.push(dog); game.addChild(dog); } // Handle game updates game.update = function () { // Check for collisions with mice for (var i = mice.length - 1; i >= 0; i--) { if (safiye.intersects(mice[i])) { score += 10; LK.setScore(score); scoreTxt.setText(score); mice[i].destroy(); mice.splice(i, 1); } } // Check for collisions with dogs for (var j = dogs.length - 1; j >= 0; j--) { if (safiye.intersects(dogs[j])) { score -= 10; LK.setScore(score); scoreTxt.setText(score); dogs[j].destroy(); dogs.splice(j, 1); } } // Check if score is below 1 if (score < -1) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Spawn mice and dogs periodically if (LK.ticks % 120 == 0) { spawnMouse(); } if (LK.ticks % 180 == 0) { spawnDog(); } }; // Handle touch events to move Safiye game.down = function (x, y, obj) { safiye.x = x; safiye.y = y; }; game.move = function (x, y, obj) { safiye.x = x; safiye.y = y; }; game.up = function (x, y, obj) { // No action needed on touch up };
===================================================================
--- original.js
+++ change.js
@@ -1,56 +1,56 @@
-/****
+/****
* Classes
-****/
+****/
// Class for Dog
var Dog = Container.expand(function () {
- var self = Container.call(this);
- var dogGraphics = self.attachAsset('dog', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Dog's update logic if needed
- };
+ var self = Container.call(this);
+ var dogGraphics = self.attachAsset('dog', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Dog's update logic if needed
+ };
});
// Class for Mouse
var Mouse = Container.expand(function () {
- var self = Container.call(this);
- var mouseGraphics = self.attachAsset('mouse', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Mouse's update logic if needed
- };
+ var self = Container.call(this);
+ var mouseGraphics = self.attachAsset('mouse', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Mouse's update logic if needed
+ };
});
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Class for Safiye the Cat
var Safiye = Container.expand(function () {
- var self = Container.call(this);
- var safiyeGraphics = self.attachAsset('safiye', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Safiye's update logic if needed
- };
+ var self = Container.call(this);
+ var safiyeGraphics = self.attachAsset('safiye', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Safiye's update logic if needed
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
var score = 0;
var scoreTxt = new Text2('0', {
- size: 150,
- fill: "#ffffff"
+ size: 150,
+ fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var safiye = game.addChild(new Safiye());
@@ -59,65 +59,65 @@
var mice = [];
var dogs = [];
// Function to spawn a mouse
function spawnMouse() {
- var mouse = new Mouse();
- mouse.x = Math.random() * 2048;
- mouse.y = Math.random() * 1000;
- mice.push(mouse);
- game.addChild(mouse);
+ var mouse = new Mouse();
+ mouse.x = Math.random() * 2048;
+ mouse.y = Math.random() * 1000;
+ mice.push(mouse);
+ game.addChild(mouse);
}
// Function to spawn a dog
function spawnDog() {
- var dog = new Dog();
- dog.x = Math.random() * 2048;
- dog.y = Math.random() * 1000;
- dogs.push(dog);
- game.addChild(dog);
+ var dog = new Dog();
+ dog.x = Math.random() * 2048;
+ dog.y = Math.random() * 1000;
+ dogs.push(dog);
+ game.addChild(dog);
}
// Handle game updates
game.update = function () {
- // Check for collisions with mice
- for (var i = mice.length - 1; i >= 0; i--) {
- if (safiye.intersects(mice[i])) {
- score += 10;
- LK.setScore(score);
- scoreTxt.setText(score);
- mice[i].destroy();
- mice.splice(i, 1);
- }
- }
- // Check for collisions with dogs
- for (var j = dogs.length - 1; j >= 0; j--) {
- if (safiye.intersects(dogs[j])) {
- score -= 10;
- LK.setScore(score);
- scoreTxt.setText(score);
- dogs[j].destroy();
- dogs.splice(j, 1);
- }
- }
- // Check if score is below 1
- if (score < 1) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
- // Spawn mice and dogs periodically
- if (LK.ticks % 120 == 0) {
- spawnMouse();
- }
- if (LK.ticks % 180 == 0) {
- spawnDog();
- }
+ // Check for collisions with mice
+ for (var i = mice.length - 1; i >= 0; i--) {
+ if (safiye.intersects(mice[i])) {
+ score += 10;
+ LK.setScore(score);
+ scoreTxt.setText(score);
+ mice[i].destroy();
+ mice.splice(i, 1);
+ }
+ }
+ // Check for collisions with dogs
+ for (var j = dogs.length - 1; j >= 0; j--) {
+ if (safiye.intersects(dogs[j])) {
+ score -= 10;
+ LK.setScore(score);
+ scoreTxt.setText(score);
+ dogs[j].destroy();
+ dogs.splice(j, 1);
+ }
+ }
+ // Check if score is below 1
+ if (score < -1) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ // Spawn mice and dogs periodically
+ if (LK.ticks % 120 == 0) {
+ spawnMouse();
+ }
+ if (LK.ticks % 180 == 0) {
+ spawnDog();
+ }
};
// Handle touch events to move Safiye
game.down = function (x, y, obj) {
- safiye.x = x;
- safiye.y = y;
+ safiye.x = x;
+ safiye.y = y;
};
game.move = function (x, y, obj) {
- safiye.x = x;
- safiye.y = y;
+ safiye.x = x;
+ safiye.y = y;
};
game.up = function (x, y, obj) {
- // No action needed on touch up
+ // No action needed on touch up
};
\ No newline at end of file