===================================================================
--- original.js
+++ change.js
@@ -1,85 +1,85 @@
-/****
+/****
* Classes
-****/
+****/
// FlyingObject class
var FlyingObject = Container.expand(function () {
- var self = Container.call(this);
- var objectGraphics = self.attachAsset('flyingObject', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5;
- self.move = function () {
- self.x += self.speed;
- // Remove object if it moves off screen
- if (self.x > 2048) {
- self.destroy();
- }
- };
+ var self = Container.call(this);
+ var objectGraphics = self.attachAsset('flyingObject', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.move = function () {
+ self.y += self.speed;
+ // Remove object if it moves off screen
+ if (self.y > 2732) {
+ self.destroy();
+ }
+ };
});
// Assets will be automatically created based on usage in the code.
// Ninja class
var Ninja = Container.expand(function () {
- var self = Container.call(this);
- var ninjaGraphics = self.attachAsset('ninja', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Ninja update logic here
- };
+ var self = Container.call(this);
+ var ninjaGraphics = self.attachAsset('ninja', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Ninja update logic here
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
var ninja = game.addChild(new Ninja());
ninja.x = 1024; // Center horizontally
ninja.y = 2732 - 200; // Position at the bottom
var flyingObjects = [];
var score = 0;
var scoreTxt = new Text2(score.toString(), {
- size: 150,
- fill: "#ffffff"
+ size: 150,
+ fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt);
// Function to spawn flying objects
function spawnFlyingObject() {
- var flyingObject = new FlyingObject();
- flyingObject.x = 0;
- flyingObject.y = Math.random() * 2732;
- flyingObjects.push(flyingObject);
- game.addChild(flyingObject);
+ var flyingObject = new FlyingObject();
+ flyingObject.x = 0;
+ flyingObject.y = Math.random() * 2732;
+ flyingObjects.push(flyingObject);
+ game.addChild(flyingObject);
}
// Handle slicing action
game.on('down', function (obj) {
- var pos = obj.event.getLocalPosition(game);
- flyingObjects.forEach(function (object, index) {
- if (Math.abs(object.x - pos.x) < 100 && Math.abs(object.y - pos.y) < 100) {
- object.destroy(); // Destroy the object
- flyingObjects.splice(index, 1); // Remove from array
- score++; // Increase score
- scoreTxt.setText(score.toString()); // Update score display
- }
- });
+ var pos = obj.event.getLocalPosition(game);
+ flyingObjects.forEach(function (object, index) {
+ if (Math.abs(object.x - pos.x) < 100 && Math.abs(object.y - pos.y) < 100) {
+ object.destroy(); // Destroy the object
+ flyingObjects.splice(index, 1); // Remove from array
+ score++; // Increase score
+ scoreTxt.setText(score.toString()); // Update score display
+ }
+ });
});
// Game tick function
LK.on('tick', function () {
- // Move flying objects
- flyingObjects.forEach(function (object) {
- object.move();
- });
- // Spawn a new flying object every 60 frames (about 1 second)
- if (LK.ticks % 60 === 0) {
- spawnFlyingObject();
- }
+ // Move flying objects
+ flyingObjects.forEach(function (object) {
+ object.move();
+ });
+ // Spawn a new flying object every 60 frames (about 1 second)
+ if (LK.ticks % 60 === 0) {
+ spawnFlyingObject();
+ }
});
// Initialize the game with a flying object
spawnFlyingObject();
\ No newline at end of file