/****
* Classes
****/
// Class for 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;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 0;
self.gravity = 0.5;
self.jumpStrength = -10;
self.update = function () {
self.velocityY += self.gravity;
self.y += self.velocityY;
// Prevent player from falling below the ground
if (self.y > 2400) {
self.y = 2400;
self.velocityY = 0;
}
};
self.jump = function () {
self.velocityY = self.jumpStrength;
};
});
// Class for stars
var Star = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0
}));
// Initialize player
var player = game.addChild(new Player());
player.x = 200;
player.y = 2400;
// Arrays to keep track of obstacles and stars
var obstacles = [];
var stars = [];
// Score display
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to spawn obstacles
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = 2200;
obstacle.y = 2400;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Function to spawn stars
function spawnStar() {
var star = new Star();
star.x = 2200;
star.y = Math.random() * 2000 + 500;
stars.push(star);
game.addChild(star);
}
// Handle game updates
game.update = function () {
player.update();
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
obstacle.update();
if (player.intersects(obstacle)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update stars
for (var j = stars.length - 1; j >= 0; j--) {
var star = stars[j];
star.update();
if (player.intersects(star)) {
score += 10;
scoreTxt.setText('Score: ' + score);
star.destroy();
stars.splice(j, 1);
}
}
// Spawn new obstacles and stars
if (LK.ticks % 120 == 0) {
spawnObstacle();
}
if (LK.ticks % 180 == 0) {
spawnStar();
}
};
// Handle player jump on tap
game.down = function (x, y, obj) {
player.jump();
}; ===================================================================
--- original.js
+++ change.js
@@ -1,73 +1,79 @@
-/****
+/****
* Classes
-****/
+****/
// Class for 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;
- self.update = function () {
- self.x += self.speed;
- if (self.x < -100) {
- self.destroy();
- }
- };
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -5;
+ self.update = function () {
+ self.x += self.speed;
+ if (self.x < -100) {
+ self.destroy();
+ }
+ };
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the player character
var Player = Container.expand(function () {
- var self = Container.call(this);
- var playerGraphics = self.attachAsset('player', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.velocityY = 0;
- self.gravity = 0.5;
- self.jumpStrength = -10;
- self.update = function () {
- self.velocityY += self.gravity;
- self.y += self.velocityY;
- // Prevent player from falling below the ground
- if (self.y > 2400) {
- self.y = 2400;
- self.velocityY = 0;
- }
- };
- self.jump = function () {
- self.velocityY = self.jumpStrength;
- };
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocityY = 0;
+ self.gravity = 0.5;
+ self.jumpStrength = -10;
+ self.update = function () {
+ self.velocityY += self.gravity;
+ self.y += self.velocityY;
+ // Prevent player from falling below the ground
+ if (self.y > 2400) {
+ self.y = 2400;
+ self.velocityY = 0;
+ }
+ };
+ self.jump = function () {
+ self.velocityY = self.jumpStrength;
+ };
});
// Class for stars
var Star = Container.expand(function () {
- var self = Container.call(this);
- var starGraphics = self.attachAsset('star', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = -5;
- self.update = function () {
- self.x += self.speed;
- if (self.x < -100) {
- self.destroy();
- }
- };
+ var self = Container.call(this);
+ var starGraphics = self.attachAsset('star', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -5;
+ self.update = function () {
+ self.x += self.speed;
+ if (self.x < -100) {
+ self.destroy();
+ }
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
+var background = game.addChild(LK.getAsset('background', {
+ anchorX: 0.0,
+ anchorY: 0.0,
+ x: 0,
+ y: 0
+}));
// Initialize player
var player = game.addChild(new Player());
player.x = 200;
player.y = 2400;
@@ -76,60 +82,60 @@
var stars = [];
// Score display
var score = 0;
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);
// Function to spawn obstacles
function spawnObstacle() {
- var obstacle = new Obstacle();
- obstacle.x = 2200;
- obstacle.y = 2400;
- obstacles.push(obstacle);
- game.addChild(obstacle);
+ var obstacle = new Obstacle();
+ obstacle.x = 2200;
+ obstacle.y = 2400;
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
}
// Function to spawn stars
function spawnStar() {
- var star = new Star();
- star.x = 2200;
- star.y = Math.random() * 2000 + 500;
- stars.push(star);
- game.addChild(star);
+ var star = new Star();
+ star.x = 2200;
+ star.y = Math.random() * 2000 + 500;
+ stars.push(star);
+ game.addChild(star);
}
// Handle game updates
game.update = function () {
- player.update();
- // Update obstacles
- for (var i = obstacles.length - 1; i >= 0; i--) {
- var obstacle = obstacles[i];
- obstacle.update();
- if (player.intersects(obstacle)) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
- }
- // Update stars
- for (var j = stars.length - 1; j >= 0; j--) {
- var star = stars[j];
- star.update();
- if (player.intersects(star)) {
- score += 10;
- scoreTxt.setText('Score: ' + score);
- star.destroy();
- stars.splice(j, 1);
- }
- }
- // Spawn new obstacles and stars
- if (LK.ticks % 120 == 0) {
- spawnObstacle();
- }
- if (LK.ticks % 180 == 0) {
- spawnStar();
- }
+ player.update();
+ // Update obstacles
+ for (var i = obstacles.length - 1; i >= 0; i--) {
+ var obstacle = obstacles[i];
+ obstacle.update();
+ if (player.intersects(obstacle)) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ }
+ // Update stars
+ for (var j = stars.length - 1; j >= 0; j--) {
+ var star = stars[j];
+ star.update();
+ if (player.intersects(star)) {
+ score += 10;
+ scoreTxt.setText('Score: ' + score);
+ star.destroy();
+ stars.splice(j, 1);
+ }
+ }
+ // Spawn new obstacles and stars
+ if (LK.ticks % 120 == 0) {
+ spawnObstacle();
+ }
+ if (LK.ticks % 180 == 0) {
+ spawnStar();
+ }
};
// Handle player jump on tap
game.down = function (x, y, obj) {
- player.jump();
+ player.jump();
};
\ No newline at end of file
star red and blu. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
BouncyBall MG red and blu. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
obstacle red and blu. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
background red and blu. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows