/****
* Classes
****/
// Arrow class
var Arrow = Container.expand(function (direction) {
var self = Container.call(this);
var arrowGraphics = self.createAsset('arrow_' + direction, {
anchorX: 0.5
});
arrowGraphics.height = 2732 * 2;
self.direction = direction;
self.on('down', function () {
self.isHeld = true;
});
self.on('up', function () {
self.isHeld = false;
});
self.on('out', function () {
self.isHeld = false;
});
self.update = function (player) {
if (self.isHeld) {
if (self.direction === 'left') {
player.moveLeft();
} else if (self.direction === 'right') {
player.moveRight();
}
}
// Check if player's y position is less than arrow's y position
self.alpha = 0; // Make arrow completely see-through
};
});
// BlockObstacle class
var BlockObstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('block_obstacle', {
anchorX: 0.5,
anchorY: 1
});
obstacleGraphics.scale.set(0.8); // Scale down the obstacle
self.speed = Math.random() * 3 + 2; // Random speed between 2 and 5
self.speedMultiplier = 1;
self.increaseSpeed = function () {
self.speedMultiplier += 0.001;
};
self.move = function () {
self.speedMultiplier += 0.001;
self.y += self.speed * self.speedMultiplier;
};
});
// GameStats class to keep track of game statistics
var GameStats = Container.expand(function () {
var self = Container.call(this);
self.gamesPlayed = 0;
self.incrementGamesPlayed = function () {
self.gamesPlayed++;
};
self.getGamesPlayed = function () {
return self.gamesPlayed;
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
playerGraphics.scale.set(1.5); // Scale up the player
self.speed = 10;
self.moveLeft = function () {
self.x = Math.max(self.width / 2, self.x - self.speed);
};
self.moveRight = function () {
self.x = Math.min(2048 - self.width / 2, self.x + self.speed);
};
self.update = function () {
// Player update logic
};
});
// Stopwatch class
var Stopwatch = Container.expand(function () {
var self = Container.call(this);
var timeText = new Text2('00:00', {
size: 100,
fill: '#ffffff'
});
timeText.anchor.set(0.5, 0);
LK.gui.top.addChild(timeText);
var startTime = Date.now();
self.updateTime = function () {
var elapsed = Date.now() - startTime;
var minutes = Math.floor(elapsed / 60000).toString().padStart(2, '0');
var seconds = (Math.floor(elapsed / 1000) % 60).toString().padStart(2, '0');
timeText.setText(minutes + ':' + seconds);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
var spaceBackground = game.addChild(LK.getAsset('space_background', {
x: 1024,
y: 1366,
anchorX: 0.5,
anchorY: 0.5,
width: 2048,
height: 2732
}));
// Game variables
var player = game.addChild(new Player());
player.x = 1024; // Center of the screen
player.y = 2732 - 100; // Near the bottom of the screen
var obstacles = [];
var isGameOver = false;
var gameStats = game.addChild(new GameStats());
var stopwatch = game.addChild(new Stopwatch());
// Create left and right arrow objects
var leftArrow = game.addChild(new Arrow('left'));
leftArrow.width = 1024; // Half of the screen width
leftArrow.x = leftArrow.width / 2;
leftArrow.y = player.y - player.height * 3 - leftArrow.height / 2;
var rightArrow = game.addChild(new Arrow('right'));
rightArrow.width = 1024; // Half of the screen width
rightArrow.x = 2048 - rightArrow.width / 2;
rightArrow.y = player.y - player.height * 3 - rightArrow.height / 2;
// Touch event handlers
// Add touch event listener to the game
// Game tick event
LK.on('tick', function () {
if (isGameOver) {
LK.effects.flashScreen(0x00ff00, 1000);
LK.showGameOver();
return;
}
// Update player and arrows
player.update();
leftArrow.update(player);
rightArrow.update(player);
stopwatch.updateTime();
// Generate obstacles
if (LK.ticks % 60 == 0) {
// Every 1 second
var newObstacle = new BlockObstacle();
newObstacle.x = Math.random() * (2048 - newObstacle.width) + newObstacle.width / 2;
newObstacle.y = -newObstacle.height;
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
// Move obstacles and check for collisions
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].move();
obstacles[i].increaseSpeed();
if (obstacles[i].y > 2732) {
obstacles[i].destroy();
obstacles.splice(i, 1);
} else if (player.intersects(obstacles[i])) {
isGameOver = true;
gameStats.incrementGamesPlayed();
}
}
});
Spaceship 2D Pixel.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Asteroid 2D Pixel.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Galaxy Background 2D Pixel.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.