/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Define a class for Earth planet
var Earth = Container.expand(function () {
var self = Container.call(this);
var earthGraphics = self.attachAsset('saturn', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.startY = 2400; // Store initial Y position at bottom area
self.zigzagAmount = 200; // Amount of vertical movement - increased for more pronounced zigzag
self.zigzagSpeed = 0.02; // Speed of vertical oscillation
self.zigzagOffset = Math.random() * Math.PI * 2; // Random starting position in the cycle
self.update = function () {
self.x += self.speed;
// Add zigzag movement using sine wave for smooth oscillation
self.y = self.startY + Math.sin(LK.ticks * self.zigzagSpeed + self.zigzagOffset) * self.zigzagAmount;
if (self.x > 2048 + 125) {
self.x = -125;
}
};
return self;
});
// Define a class for enemies
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
self.x -= self.speed;
if (self.x < -50) {
self.destroy();
}
};
});
// Define a class for Moon object
var Moon = Container.expand(function () {
var self = Container.call(this);
var moonGraphics = self.attachAsset('moon', {
anchorX: 0.5,
anchorY: 0.5
});
// Initial position and movement parameters
self.speedX = 1.5; // Slower horizontal speed
self.speedY = -1.5; // Slower vertical speed (negative to move upward)
self.startX = -100; // Starting X position
self.startY = 2732 - 100; // Starting Y position (bottom left)
self.update = function () {
// Move diagonally (bottom-left to top-right) slowly
self.x += self.speedX;
self.y += self.speedY;
// Reset position when it goes off-screen at the top-right
if (self.x > 2048 + 100 || self.y < -100) {
self.x = self.startX;
self.y = self.startY;
}
};
return self;
});
// Define a class for the Music Toggle Button
var MusicButton = Container.expand(function () {
var self = Container.call(this);
var musicPlaying = true;
// Initialize with music on icon
var buttonGraphics = self.attachAsset('musicOn', {
anchorX: 0.5,
anchorY: 0.5
});
// Event handler for button press
self.down = function () {
if (musicPlaying) {
// Change to music off icon
self.removeChild(buttonGraphics);
buttonGraphics = self.attachAsset('musicOff', {
anchorX: 0.5,
anchorY: 0.5
});
// Stop music
LK.stopMusic();
musicPlaying = false;
} else {
// Change to music on icon
self.removeChild(buttonGraphics);
buttonGraphics = self.attachAsset('musicOn', {
anchorX: 0.5,
anchorY: 0.5
});
// Play music
LK.playMusic('spaceMusic', {
loop: true
});
musicPlaying = true;
}
};
return self;
});
//<Assets used in the game will automatically appear here>
// Define a 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.speed = 5;
self.jumpHeight = 40; // Further increased jump power
self.isJumping = false;
self.velocityY = 0;
self.update = function () {
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.7; // Decreased gravity effect by 30%
if (self.y >= 2732 / 2) {
// Ground level
self.y = 2732 / 2;
self.isJumping = false;
self.velocityY = 0;
}
}
};
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.velocityY = -self.jumpHeight;
// Play jump sound when player jumps
LK.getSound('jump').play();
}
};
});
// Define a class for Uranus planet
var Uranus = Container.expand(function () {
var self = Container.call(this);
var uranusGraphics = self.attachAsset('uranus', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.startY = 250; // Store initial Y position
self.zigzagAmount = 200; // Amount of vertical movement - increased for more pronounced zigzag
self.zigzagSpeed = 0.02; // Speed of vertical oscillation
self.zigzagOffset = Math.random() * Math.PI * 2; // Random starting position in the cycle
self.update = function () {
self.x += self.speed;
// Add zigzag movement using sine wave for smooth oscillation
self.y = self.startY + Math.sin(LK.ticks * self.zigzagSpeed + self.zigzagOffset) * self.zigzagAmount;
if (self.x > 2048 + 125) {
self.x = -125;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Import tween library for animations
// Play space-themed background music with looping
LK.playMusic('spaceMusic', {
loop: true
});
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
}));
background.x = 0;
background.y = 0;
// Initialize Uranus
var uranus = game.addChild(new Uranus());
uranus.x = -125;
uranus.y = 250; // Position at the top of the screen
uranus.startY = 250; // Store initial Y position for zigzag movement
// Initialize Earth
var earth = game.addChild(new Earth());
earth.x = -125;
earth.y = 2400; // Position at the bottom of the screen
earth.startY = 2400; // Store initial Y position for zigzag movement
// Initialize Moon
var moon = game.addChild(new Moon());
moon.x = 0; // Start at bottom left
moon.y = 2732 - 100; // Bottom of screen
// Initialize player
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
// Initialize enemies
var enemies = [];
var enemySpawnInterval = 100;
var enemySpawnCounter = 0;
// Create variables to track different score types
var jumpScore = 0;
// Create a new Text2 object to display the regular score
var scoreText = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
// Add the score text to the game GUI at the top center of the screen
LK.gui.top.addChild(scoreText);
scoreText.x = 2048 / 2;
scoreText.y = 0;
// Create a new Text2 object to display jump score in the top-right corner
var jumpScoreText = new Text2('Jump Score: 0', {
size: 75,
fill: 0xFFFFFF
});
// Add the jump score text to the top right
LK.gui.topRight.addChild(jumpScoreText);
jumpScoreText.anchor.set(1, 0); // Align right
jumpScoreText.x = -20; // Padding from right edge
jumpScoreText.y = 20; // Padding from top
// Create and position music toggle button further down below the jump score in top-right
var musicButton = game.addChild(new MusicButton());
musicButton.x = 2048 - 80; // Position near the jump score (right side)
musicButton.y = jumpScoreText.y + jumpScoreText.height + 150; // Position even further below jump score with more padding
// Add the jump score text to the top right
LK.gui.topRight.addChild(jumpScoreText);
jumpScoreText.anchor.set(1, 0); // Align right
jumpScoreText.x = -20; // Padding from right edge
jumpScoreText.y = 20; // Padding from top
// Handle game updates
game.update = function () {
player.update();
// Update Uranus
uranus.update();
// Update Earth
earth.update();
// Update Moon
moon.update();
// Spawn enemies
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
var enemy = new Enemy();
enemy.x = 2048;
enemy.y = 2732 / 2;
enemies.push(enemy);
game.addChild(enemy);
// Randomize the spawn interval for the next enemy
enemySpawnInterval = Math.floor(Math.random() * 150) + 50;
enemySpawnCounter = 0;
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
if (player.intersects(enemies[j])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
} else if (player.x > enemies[j].x && !enemies[j].passed && player.isJumping) {
// Player jumped over an enemy
enemies[j].passed = true;
LK.setScore(LK.getScore() + 1);
scoreText.setText(LK.getScore());
// Increment and update jump score
jumpScore++;
jumpScoreText.setText('Jump Score: ' + jumpScore);
}
}
};
// Handle player jump
game.down = function (x, y, obj) {
player.jump();
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Define a class for Earth planet
var Earth = Container.expand(function () {
var self = Container.call(this);
var earthGraphics = self.attachAsset('saturn', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.startY = 2400; // Store initial Y position at bottom area
self.zigzagAmount = 200; // Amount of vertical movement - increased for more pronounced zigzag
self.zigzagSpeed = 0.02; // Speed of vertical oscillation
self.zigzagOffset = Math.random() * Math.PI * 2; // Random starting position in the cycle
self.update = function () {
self.x += self.speed;
// Add zigzag movement using sine wave for smooth oscillation
self.y = self.startY + Math.sin(LK.ticks * self.zigzagSpeed + self.zigzagOffset) * self.zigzagAmount;
if (self.x > 2048 + 125) {
self.x = -125;
}
};
return self;
});
// Define a class for enemies
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
self.x -= self.speed;
if (self.x < -50) {
self.destroy();
}
};
});
// Define a class for Moon object
var Moon = Container.expand(function () {
var self = Container.call(this);
var moonGraphics = self.attachAsset('moon', {
anchorX: 0.5,
anchorY: 0.5
});
// Initial position and movement parameters
self.speedX = 1.5; // Slower horizontal speed
self.speedY = -1.5; // Slower vertical speed (negative to move upward)
self.startX = -100; // Starting X position
self.startY = 2732 - 100; // Starting Y position (bottom left)
self.update = function () {
// Move diagonally (bottom-left to top-right) slowly
self.x += self.speedX;
self.y += self.speedY;
// Reset position when it goes off-screen at the top-right
if (self.x > 2048 + 100 || self.y < -100) {
self.x = self.startX;
self.y = self.startY;
}
};
return self;
});
// Define a class for the Music Toggle Button
var MusicButton = Container.expand(function () {
var self = Container.call(this);
var musicPlaying = true;
// Initialize with music on icon
var buttonGraphics = self.attachAsset('musicOn', {
anchorX: 0.5,
anchorY: 0.5
});
// Event handler for button press
self.down = function () {
if (musicPlaying) {
// Change to music off icon
self.removeChild(buttonGraphics);
buttonGraphics = self.attachAsset('musicOff', {
anchorX: 0.5,
anchorY: 0.5
});
// Stop music
LK.stopMusic();
musicPlaying = false;
} else {
// Change to music on icon
self.removeChild(buttonGraphics);
buttonGraphics = self.attachAsset('musicOn', {
anchorX: 0.5,
anchorY: 0.5
});
// Play music
LK.playMusic('spaceMusic', {
loop: true
});
musicPlaying = true;
}
};
return self;
});
//<Assets used in the game will automatically appear here>
// Define a 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.speed = 5;
self.jumpHeight = 40; // Further increased jump power
self.isJumping = false;
self.velocityY = 0;
self.update = function () {
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.7; // Decreased gravity effect by 30%
if (self.y >= 2732 / 2) {
// Ground level
self.y = 2732 / 2;
self.isJumping = false;
self.velocityY = 0;
}
}
};
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.velocityY = -self.jumpHeight;
// Play jump sound when player jumps
LK.getSound('jump').play();
}
};
});
// Define a class for Uranus planet
var Uranus = Container.expand(function () {
var self = Container.call(this);
var uranusGraphics = self.attachAsset('uranus', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.startY = 250; // Store initial Y position
self.zigzagAmount = 200; // Amount of vertical movement - increased for more pronounced zigzag
self.zigzagSpeed = 0.02; // Speed of vertical oscillation
self.zigzagOffset = Math.random() * Math.PI * 2; // Random starting position in the cycle
self.update = function () {
self.x += self.speed;
// Add zigzag movement using sine wave for smooth oscillation
self.y = self.startY + Math.sin(LK.ticks * self.zigzagSpeed + self.zigzagOffset) * self.zigzagAmount;
if (self.x > 2048 + 125) {
self.x = -125;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Import tween library for animations
// Play space-themed background music with looping
LK.playMusic('spaceMusic', {
loop: true
});
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
}));
background.x = 0;
background.y = 0;
// Initialize Uranus
var uranus = game.addChild(new Uranus());
uranus.x = -125;
uranus.y = 250; // Position at the top of the screen
uranus.startY = 250; // Store initial Y position for zigzag movement
// Initialize Earth
var earth = game.addChild(new Earth());
earth.x = -125;
earth.y = 2400; // Position at the bottom of the screen
earth.startY = 2400; // Store initial Y position for zigzag movement
// Initialize Moon
var moon = game.addChild(new Moon());
moon.x = 0; // Start at bottom left
moon.y = 2732 - 100; // Bottom of screen
// Initialize player
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
// Initialize enemies
var enemies = [];
var enemySpawnInterval = 100;
var enemySpawnCounter = 0;
// Create variables to track different score types
var jumpScore = 0;
// Create a new Text2 object to display the regular score
var scoreText = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
// Add the score text to the game GUI at the top center of the screen
LK.gui.top.addChild(scoreText);
scoreText.x = 2048 / 2;
scoreText.y = 0;
// Create a new Text2 object to display jump score in the top-right corner
var jumpScoreText = new Text2('Jump Score: 0', {
size: 75,
fill: 0xFFFFFF
});
// Add the jump score text to the top right
LK.gui.topRight.addChild(jumpScoreText);
jumpScoreText.anchor.set(1, 0); // Align right
jumpScoreText.x = -20; // Padding from right edge
jumpScoreText.y = 20; // Padding from top
// Create and position music toggle button further down below the jump score in top-right
var musicButton = game.addChild(new MusicButton());
musicButton.x = 2048 - 80; // Position near the jump score (right side)
musicButton.y = jumpScoreText.y + jumpScoreText.height + 150; // Position even further below jump score with more padding
// Add the jump score text to the top right
LK.gui.topRight.addChild(jumpScoreText);
jumpScoreText.anchor.set(1, 0); // Align right
jumpScoreText.x = -20; // Padding from right edge
jumpScoreText.y = 20; // Padding from top
// Handle game updates
game.update = function () {
player.update();
// Update Uranus
uranus.update();
// Update Earth
earth.update();
// Update Moon
moon.update();
// Spawn enemies
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
var enemy = new Enemy();
enemy.x = 2048;
enemy.y = 2732 / 2;
enemies.push(enemy);
game.addChild(enemy);
// Randomize the spawn interval for the next enemy
enemySpawnInterval = Math.floor(Math.random() * 150) + 50;
enemySpawnCounter = 0;
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
if (player.intersects(enemies[j])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
} else if (player.x > enemies[j].x && !enemies[j].passed && player.isJumping) {
// Player jumped over an enemy
enemies[j].passed = true;
LK.setScore(LK.getScore() + 1);
scoreText.setText(LK.getScore());
// Increment and update jump score
jumpScore++;
jumpScoreText.setText('Jump Score: ' + jumpScore);
}
}
};
// Handle player jump
game.down = function (x, y, obj) {
player.jump();
};
y pozisyonunda yatay bir uzay mekiği. In-Game asset. 2d. High contrast. No shadows
uzayda yürüyen astronot. In-Game asset. 2d. High contrast. No shadows
uranus planet. In-Game asset. 2d. High contrast. No shadows
earth. In-Game asset. 2d. High contrast. No shadows
büyük yıldızlardan birkaçını çıkar ve genel yıldız sayısını azalt
music sound off. In-Game asset. 2d. High contrast. No shadows
music nota orange. In-Game asset. 2d. High contrast. No shadows