/**** * Classes ****/ // Define the Backdrop class var Backdrop = Container.expand(function () { var self = Container.call(this); var backdropGraphics = self.createAsset('backdrop', 'Game backdrop', 0.5, 0.5); // Set the backdrop to cover the entire game area backdropGraphics.width = game.width; backdropGraphics.height = game.height; // Center the backdrop backdropGraphics.x = game.width / 2; backdropGraphics.y = game.height / 2; }); // Define the Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.createAsset('player', 'Player character', 0.5, 1); self.speed = 5; self.jumpPower = -22; self.gravity = 0.5; self.velocityY = 0; self.isJumping = false; self.isFlipping = false; self.flipRotation = 0; self.incrementScore = function (obstacle) { if (!obstacle.hasScored) { score++; obstacle.hasScored = true; scoreTxt.setText(score.toString()); } }; self.moveRight = function () { self.x += self.speed; }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = self.jumpPower; } }; self.update = function () { self.y += self.velocityY; self.velocityY += self.gravity; if (self.isFlipping) { playerGraphics.rotation += self.flipRotation; } // Check for ground collision if (self.y > game.height - playerGraphics.height) { self.y = game.height - playerGraphics.height; self.isJumping = false; self.isFlipping = false; playerGraphics.rotation = 0; } }; self.flip = function () { if (!self.isFlipping && self.isJumping) { self.isFlipping = true; self.flipRotation = Math.PI / 16; // 22.5 degrees per frame } }; }); // Define the Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.createAsset('obstacle', 'Obstacle', 0.5, 1); self.speed = -5; self.hasScored = false; self.move = function () { self.x += self.speed; }; self.update = function () { self.move(); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Create and add the backdrop to the game // Initialize important asset arrays and score var backdrop = game.addChild(new Backdrop()); var obstacles = []; var score = 0; var scoreTxt = new Text2(score.toString(), { size: 150, fill: "#ffaec9" // Pastel pink color }); scoreTxt.anchor.set(.5, 0); LK.gui.top.addChild(scoreTxt); var player = game.addChild(new Player()); // Set the player's starting position player.x = 2048 / 4; player.y = game.height - player.height; // Game tick event LK.on('tick', function () { // Update player player.update(); // Update obstacles for (var i = obstacles.length - 1; i >= 0; i--) { obstacles[i].update(); // Check for collision with player and if the player has jumped over an obstacle if (player.intersects(obstacles[i])) { // End game if collision occurs LK.showGameOver(); } else if (player.y < obstacles[i].y && player.x > obstacles[i].x && !obstacles[i].hasScored) { // Increment score if player jumps over the obstacle player.incrementScore(obstacles[i]); } // Remove off-screen obstacles if (obstacles[i].x + obstacles[i].width < 0) { obstacles[i].destroy(); obstacles.splice(i, 1); } // Remove off-screen obstacles if (obstacles[i].x + obstacles[i].width < 0) { obstacles[i].destroy(); obstacles.splice(i, 1); } } // Spawn obstacles with variable rate var spawnRate = 120 - Math.floor(LK.ticks / 1800); // Decrease spawn rate every 30 seconds if (spawnRate < 30) { spawnRate = 30; } // Set a minimum spawn rate if (LK.ticks % spawnRate === 0) { var obstacle = new Obstacle(); obstacle.x = game.width; obstacle.y = game.height - obstacle.height; obstacles.push(obstacle); game.addChild(obstacle); } }); // Touch event listeners game.on('down', function (obj) { var touchPos = obj.event.getLocalPosition(game); if (touchPos.x > game.width / 2) { player.moveRight(); } else { player.jump(); } }); game.on('up', function (obj) { player.flip(); });
/****
* Classes
****/
// Define the Backdrop class
var Backdrop = Container.expand(function () {
var self = Container.call(this);
var backdropGraphics = self.createAsset('backdrop', 'Game backdrop', 0.5, 0.5);
// Set the backdrop to cover the entire game area
backdropGraphics.width = game.width;
backdropGraphics.height = game.height;
// Center the backdrop
backdropGraphics.x = game.width / 2;
backdropGraphics.y = game.height / 2;
});
// Define the Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.createAsset('player', 'Player character', 0.5, 1);
self.speed = 5;
self.jumpPower = -22;
self.gravity = 0.5;
self.velocityY = 0;
self.isJumping = false;
self.isFlipping = false;
self.flipRotation = 0;
self.incrementScore = function (obstacle) {
if (!obstacle.hasScored) {
score++;
obstacle.hasScored = true;
scoreTxt.setText(score.toString());
}
};
self.moveRight = function () {
self.x += self.speed;
};
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.velocityY = self.jumpPower;
}
};
self.update = function () {
self.y += self.velocityY;
self.velocityY += self.gravity;
if (self.isFlipping) {
playerGraphics.rotation += self.flipRotation;
}
// Check for ground collision
if (self.y > game.height - playerGraphics.height) {
self.y = game.height - playerGraphics.height;
self.isJumping = false;
self.isFlipping = false;
playerGraphics.rotation = 0;
}
};
self.flip = function () {
if (!self.isFlipping && self.isJumping) {
self.isFlipping = true;
self.flipRotation = Math.PI / 16; // 22.5 degrees per frame
}
};
});
// Define the Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.createAsset('obstacle', 'Obstacle', 0.5, 1);
self.speed = -5;
self.hasScored = false;
self.move = function () {
self.x += self.speed;
};
self.update = function () {
self.move();
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Create and add the backdrop to the game
// Initialize important asset arrays and score
var backdrop = game.addChild(new Backdrop());
var obstacles = [];
var score = 0;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffaec9" // Pastel pink color
});
scoreTxt.anchor.set(.5, 0);
LK.gui.top.addChild(scoreTxt);
var player = game.addChild(new Player());
// Set the player's starting position
player.x = 2048 / 4;
player.y = game.height - player.height;
// Game tick event
LK.on('tick', function () {
// Update player
player.update();
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
// Check for collision with player and if the player has jumped over an obstacle
if (player.intersects(obstacles[i])) {
// End game if collision occurs
LK.showGameOver();
} else if (player.y < obstacles[i].y && player.x > obstacles[i].x && !obstacles[i].hasScored) {
// Increment score if player jumps over the obstacle
player.incrementScore(obstacles[i]);
}
// Remove off-screen obstacles
if (obstacles[i].x + obstacles[i].width < 0) {
obstacles[i].destroy();
obstacles.splice(i, 1);
}
// Remove off-screen obstacles
if (obstacles[i].x + obstacles[i].width < 0) {
obstacles[i].destroy();
obstacles.splice(i, 1);
}
}
// Spawn obstacles with variable rate
var spawnRate = 120 - Math.floor(LK.ticks / 1800); // Decrease spawn rate every 30 seconds
if (spawnRate < 30) {
spawnRate = 30;
} // Set a minimum spawn rate
if (LK.ticks % spawnRate === 0) {
var obstacle = new Obstacle();
obstacle.x = game.width;
obstacle.y = game.height - obstacle.height;
obstacles.push(obstacle);
game.addChild(obstacle);
}
});
// Touch event listeners
game.on('down', function (obj) {
var touchPos = obj.event.getLocalPosition(game);
if (touchPos.x > game.width / 2) {
player.moveRight();
} else {
player.jump();
}
});
game.on('up', function (obj) {
player.flip();
});
kawaii style kitten. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Kawaii style monster. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
kawaii style grass feild backdrop. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.