/****
* Classes
****/
// Bonus class for collectible bonuses
var Bonus = Container.expand(function () {
var self = Container.call(this);
var bonusGraphics = self.attachAsset('bonus', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 3; // Speed of bonus falling
if (self.y > 2732) {
self.destroy();
} // Destroy if out of bounds
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Character class for the player-controlled character
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 30; // Speed of character movement
self.moveLeft = function () {
self.x -= self.speed;
if (self.x < 0) {
self.x = 0;
} // Prevent moving out of bounds
};
self.moveRight = function () {
self.x += self.speed;
if (self.x > 2048) {
self.x = 2048;
} // Prevent moving out of bounds
};
});
// Obstacle class for incoming obstacles
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5; // Initial speed of obstacles
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
} // Destroy if out of bounds
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize variables
var character = game.addChild(new Character());
character.x = 1024; // Center character horizontally
character.y = 2500; // Position character near the bottom
var obstacles = [];
var bonuses = [];
var score = 0;
var survivalTime = 0;
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle touch events for character movement
game.down = function (x, y, obj) {
if (x < 1024) {
character.moveLeft();
} else {
character.moveRight();
}
};
// Update game state
game.update = function () {
// Update survival time
survivalTime += 1;
scoreTxt.setText('Score: ' + score);
// Increase obstacle speed over time
if (LK.ticks % 600 == 0) {
obstacles.forEach(function (obstacle) {
obstacle.speed += 1;
});
}
// Spawn obstacles
if (LK.ticks % 60 == 0) {
var newObstacle = new Obstacle();
newObstacle.x = Math.random() * 2048;
newObstacle.y = 0;
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
// Spawn bonuses
if (LK.ticks % 300 == 0) {
var newBonus = new Bonus();
newBonus.x = Math.random() * 2048;
newBonus.y = 0;
bonuses.push(newBonus);
game.addChild(newBonus);
}
// Update obstacles and check for collisions
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
if (character.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update bonuses and check for collection
for (var j = bonuses.length - 1; j >= 0; j--) {
bonuses[j].update();
if (character.intersects(bonuses[j])) {
score += 10;
bonuses[j].destroy();
bonuses.splice(j, 1);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,62 +1,70 @@
-/****
+/****
* Classes
-****/
+****/
// Bonus class for collectible bonuses
var Bonus = Container.expand(function () {
- var self = Container.call(this);
- var bonusGraphics = self.attachAsset('bonus', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- self.y += 3; // Speed of bonus falling
- if (self.y > 2732) self.destroy(); // Destroy if out of bounds
- };
+ var self = Container.call(this);
+ var bonusGraphics = self.attachAsset('bonus', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ self.y += 3; // Speed of bonus falling
+ if (self.y > 2732) {
+ self.destroy();
+ } // Destroy if out of bounds
+ };
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Character class for the player-controlled character
var Character = Container.expand(function () {
- var self = Container.call(this);
- var characterGraphics = self.attachAsset('character', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 10; // Speed of character movement
- self.moveLeft = function () {
- self.x -= self.speed;
- if (self.x < 0) self.x = 0; // Prevent moving out of bounds
- };
- self.moveRight = function () {
- self.x += self.speed;
- if (self.x > 2048) self.x = 2048; // Prevent moving out of bounds
- };
+ var self = Container.call(this);
+ var characterGraphics = self.attachAsset('character', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 30; // Speed of character movement
+ self.moveLeft = function () {
+ self.x -= self.speed;
+ if (self.x < 0) {
+ self.x = 0;
+ } // Prevent moving out of bounds
+ };
+ self.moveRight = function () {
+ self.x += self.speed;
+ if (self.x > 2048) {
+ self.x = 2048;
+ } // Prevent moving out of bounds
+ };
});
// Obstacle class for incoming obstacles
var Obstacle = Container.expand(function () {
- var self = Container.call(this);
- var obstacleGraphics = self.attachAsset('obstacle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5; // Initial speed of obstacles
- self.update = function () {
- self.y += self.speed;
- if (self.y > 2732) self.destroy(); // Destroy if out of bounds
- };
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5; // Initial speed of obstacles
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.destroy();
+ } // Destroy if out of bounds
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize variables
var character = game.addChild(new Character());
character.x = 1024; // Center character horizontally
character.y = 2500; // Position character near the bottom
@@ -65,62 +73,62 @@
var score = 0;
var survivalTime = 0;
// Score display
var scoreTxt = new Text2('Score: 0', {
- size: 100,
- fill: 0xFFFFFF
+ size: 100,
+ fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle touch events for character movement
game.down = function (x, y, obj) {
- if (x < 1024) {
- character.moveLeft();
- } else {
- character.moveRight();
- }
+ if (x < 1024) {
+ character.moveLeft();
+ } else {
+ character.moveRight();
+ }
};
// Update game state
game.update = function () {
- // Update survival time
- survivalTime += 1;
- scoreTxt.setText('Score: ' + score);
- // Increase obstacle speed over time
- if (LK.ticks % 600 == 0) {
- obstacles.forEach(function (obstacle) {
- obstacle.speed += 1;
- });
- }
- // Spawn obstacles
- if (LK.ticks % 60 == 0) {
- var newObstacle = new Obstacle();
- newObstacle.x = Math.random() * 2048;
- newObstacle.y = 0;
- obstacles.push(newObstacle);
- game.addChild(newObstacle);
- }
- // Spawn bonuses
- if (LK.ticks % 300 == 0) {
- var newBonus = new Bonus();
- newBonus.x = Math.random() * 2048;
- newBonus.y = 0;
- bonuses.push(newBonus);
- game.addChild(newBonus);
- }
- // Update obstacles and check for collisions
- for (var i = obstacles.length - 1; i >= 0; i--) {
- obstacles[i].update();
- if (character.intersects(obstacles[i])) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
- }
- // Update bonuses and check for collection
- for (var j = bonuses.length - 1; j >= 0; j--) {
- bonuses[j].update();
- if (character.intersects(bonuses[j])) {
- score += 10;
- bonuses[j].destroy();
- bonuses.splice(j, 1);
- }
- }
+ // Update survival time
+ survivalTime += 1;
+ scoreTxt.setText('Score: ' + score);
+ // Increase obstacle speed over time
+ if (LK.ticks % 600 == 0) {
+ obstacles.forEach(function (obstacle) {
+ obstacle.speed += 1;
+ });
+ }
+ // Spawn obstacles
+ if (LK.ticks % 60 == 0) {
+ var newObstacle = new Obstacle();
+ newObstacle.x = Math.random() * 2048;
+ newObstacle.y = 0;
+ obstacles.push(newObstacle);
+ game.addChild(newObstacle);
+ }
+ // Spawn bonuses
+ if (LK.ticks % 300 == 0) {
+ var newBonus = new Bonus();
+ newBonus.x = Math.random() * 2048;
+ newBonus.y = 0;
+ bonuses.push(newBonus);
+ game.addChild(newBonus);
+ }
+ // Update obstacles and check for collisions
+ for (var i = obstacles.length - 1; i >= 0; i--) {
+ obstacles[i].update();
+ if (character.intersects(obstacles[i])) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ }
+ // Update bonuses and check for collection
+ for (var j = bonuses.length - 1; j >= 0; j--) {
+ bonuses[j].update();
+ if (character.intersects(bonuses[j])) {
+ score += 10;
+ bonuses[j].destroy();
+ bonuses.splice(j, 1);
+ }
+ }
};
\ No newline at end of file