/****
* Classes
****/
// Define the Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
// Define the Missile class
var Missile = Container.expand(function () {
var self = Container.call(this);
var missileGraphics = self.attachAsset('missile', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
if (self.acceleration) {
self.speed += self.acceleration; // Increase speed by acceleration each frame
}
// Update missile direction to track player if tracking is enabled and missile has acceleration
if (self.tracking && self.acceleration) {
if (!self.trackingStart) {
self.trackingStart = LK.ticks;
}
if (LK.ticks - self.trackingStart < 180) {
// 3 seconds * 60 FPS
var dx = player.x - self.x;
var dy = player.y - self.y;
var angle = Math.atan2(dy, dx);
self.x += Math.cos(angle) * self.speed;
self.y += Math.sin(angle) * self.speed;
} else {
if (self.tracking) {
LK.getSound('drop').play();
self.tracking = false;
}
}
} else {
self.y += self.speed;
}
// Add rotation effect to the missile
missileGraphics.rotation += 0.1;
if (self.y > 2732) {
self.destroy();
}
};
});
// Define the Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
// Add a dodge mechanic: if the player is clicked/touched, it will move to a random position on the screen
self.x = Math.random() * 2048;
self.y = Math.random() * (2732 - 200);
};
self.update = function () {
// Create a floating effect by slightly adjusting the y position
self.y += Math.sin(LK.ticks / 10) * 2;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Attach the background image to the game
var background = game.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
background.x = 2048 / 2;
background.y = 2732 / 2;
// Initialize player
var player = game.addChild(new Player());
// Initialize coins array
var coins = [];
// Initialize score text
var scoreTxt = new Text2('0/100', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
player.x = 2048 / 2;
player.y = 2732 - 200;
// Initialize missiles array
var missiles = [];
// Handle player movement
var lastMoveTime = 0;
var moveCooldown = 100; // 100 milliseconds cooldown
game.down = function (x, y, obj) {
var currentTime = Date.now();
if (currentTime - lastMoveTime > moveCooldown) {
player.x = x;
player.y = y;
lastMoveTime = currentTime;
}
};
// Update game state
game.update = function () {
// Add a linear vertical scrolling effect to the background
background.y += 4;
if (background.y > 2732) {
background.y = 0;
}
// Spawn coins
if (LK.ticks % 30 == 0) {
var newCoin = new Coin();
newCoin.x = Math.random() * 2048;
newCoin.y = -50;
coins.push(newCoin);
game.addChild(newCoin);
}
// Spawn missiles
if (LK.ticks % 60 == 0) {
var newMissile = new Missile();
newMissile.x = Math.random() * 2048;
newMissile.y = -50;
// Add acceleration effect to some missiles
if (Math.random() < 0.5) {
newMissile.acceleration = 0.1;
}
// Add tracking effect to some missiles
if (Math.random() < 0.5) {
newMissile.tracking = true;
newMissile.attachAsset('trackingMissile', {
anchorX: 0.5,
anchorY: 0.5
});
// Play warning sound if the missile has acceleration
if (newMissile.acceleration) {
LK.getSound('warning').play();
}
}
missiles.push(newMissile);
game.addChild(newMissile);
}
// Update coins
for (var i = coins.length - 1; i >= 0; i--) {
if (coins[i].intersects(player)) {
coins[i].destroy();
coins.splice(i, 1);
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore() + '/100');
LK.getSound('coinPickup').play();
if (LK.getScore() >= 100) {
LK.showVictory();
}
}
if (coins[i] && coins[i].y > 2732) {
coins[i].destroy();
coins.splice(i, 1);
}
}
// Update missiles
for (var i = missiles.length - 1; i >= 0; i--) {
if (missiles[i].intersects(player)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
if (missiles[i].y > 2732) {
missiles[i].destroy();
missiles.splice(i, 1);
}
}
};
一颗陨石. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
一个宇航员,卡通风格. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
一个太空星空背景,唯美,浪漫. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
一颗陨石,卡通风格. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
一个金币,卡通. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.