/****
* Classes
****/
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -12;
self.update = function () {
self.x += self.speed;
};
return self;
});
var Orb = Container.expand(function () {
var self = Container.call(this);
var orbGraphics = self.attachAsset('orb', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 0;
self.gravity = 15;
self.jumpPower = -250;
self.onGround = false;
self.update = function () {
self.velocityY += self.gravity;
self.y += self.velocityY;
// Ground collision
if (self.y > 2632 - 80 - 50) {
self.y = 2632 - 80 - 50;
self.velocityY = 0;
self.onGround = true;
} else {
self.onGround = false;
}
};
self.jump = function () {
if (self.onGround) {
self.velocityY = self.jumpPower;
self.onGround = false;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x111111
});
/****
* Game Code
****/
// Create ground
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2632 - 40
}));
// Create orb
var orb = game.addChild(new Orb());
orb.x = 1024;
orb.y = 2632 - 80 - 50;
// Game input handling
game.down = function (x, y, obj) {
orb.jump();
};
// Obstacles array
var obstacles = [];
var score = 0;
// Score display
var scoreText = new Text2('Skor: 0', {
size: 45,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.topLeft.addChild(scoreText);
scoreText.x = 30;
scoreText.y = 60;
// Spawn obstacles
function spawnObstacle() {
var obs = game.addChild(new Obstacle());
obs.x = 2048 + 50;
obs.y = 2632 - 80 - 15;
obs.lastIntersecting = false;
obstacles.push(obs);
}
// Spawn timer
var spawnTimer = 0;
var spawnInterval = 90; // 1.5 seconds at 60fps
// Score timer
var scoreTimer = 0;
var scoreInterval = 60; // 1 second at 60fps
game.update = function () {
// Spawn obstacles
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnObstacle();
spawnTimer = 0;
}
// Update score
scoreTimer++;
if (scoreTimer >= scoreInterval) {
score++;
scoreText.setText('Skor: ' + score);
scoreTimer = 0;
}
// Check obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obs = obstacles[i];
// Remove off-screen obstacles
if (obs.x < -50) {
obs.destroy();
obstacles.splice(i, 1);
continue;
}
// Check collision
var currentIntersecting = orb.intersects(obs);
if (!obs.lastIntersecting && currentIntersecting) {
LK.showGameOver();
return;
}
obs.lastIntersecting = currentIntersecting;
}
}; /****
* Classes
****/
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -12;
self.update = function () {
self.x += self.speed;
};
return self;
});
var Orb = Container.expand(function () {
var self = Container.call(this);
var orbGraphics = self.attachAsset('orb', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 0;
self.gravity = 15;
self.jumpPower = -250;
self.onGround = false;
self.update = function () {
self.velocityY += self.gravity;
self.y += self.velocityY;
// Ground collision
if (self.y > 2632 - 80 - 50) {
self.y = 2632 - 80 - 50;
self.velocityY = 0;
self.onGround = true;
} else {
self.onGround = false;
}
};
self.jump = function () {
if (self.onGround) {
self.velocityY = self.jumpPower;
self.onGround = false;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x111111
});
/****
* Game Code
****/
// Create ground
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2632 - 40
}));
// Create orb
var orb = game.addChild(new Orb());
orb.x = 1024;
orb.y = 2632 - 80 - 50;
// Game input handling
game.down = function (x, y, obj) {
orb.jump();
};
// Obstacles array
var obstacles = [];
var score = 0;
// Score display
var scoreText = new Text2('Skor: 0', {
size: 45,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.topLeft.addChild(scoreText);
scoreText.x = 30;
scoreText.y = 60;
// Spawn obstacles
function spawnObstacle() {
var obs = game.addChild(new Obstacle());
obs.x = 2048 + 50;
obs.y = 2632 - 80 - 15;
obs.lastIntersecting = false;
obstacles.push(obs);
}
// Spawn timer
var spawnTimer = 0;
var spawnInterval = 90; // 1.5 seconds at 60fps
// Score timer
var scoreTimer = 0;
var scoreInterval = 60; // 1 second at 60fps
game.update = function () {
// Spawn obstacles
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnObstacle();
spawnTimer = 0;
}
// Update score
scoreTimer++;
if (scoreTimer >= scoreInterval) {
score++;
scoreText.setText('Skor: ' + score);
scoreTimer = 0;
}
// Check obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obs = obstacles[i];
// Remove off-screen obstacles
if (obs.x < -50) {
obs.destroy();
obstacles.splice(i, 1);
continue;
}
// Check collision
var currentIntersecting = orb.intersects(obs);
if (!obs.lastIntersecting && currentIntersecting) {
LK.showGameOver();
return;
}
obs.lastIntersecting = currentIntersecting;
}
};