/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Alien = Container.expand(function () {
var self = Container.call(this);
var alienGraphics = self.attachAsset('alien', {
anchorX: 0.5,
anchorY: 0.5
});
// Movement properties
self.velocityX = (Math.random() - 0.5) * 4;
self.velocityY = 0;
self.gravity = 0.3;
self.jumpCooldown = 0;
self.isDragging = false;
self.groundY = 2500;
// Walking animation
self.walkTimer = 0;
self.originalScaleX = 1;
self.update = function () {
if (self.isDragging) return;
// Apply gravity
self.velocityY += self.gravity;
// Update position
self.x += self.velocityX;
self.y += self.velocityY;
// Ground collision
if (self.y > self.groundY) {
self.y = self.groundY;
self.velocityY = 0;
// Random jump
if (self.jumpCooldown <= 0 && Math.random() < 0.02) {
self.velocityY = -8 - Math.random() * 4;
self.jumpCooldown = 60;
}
}
if (self.jumpCooldown > 0) {
self.jumpCooldown--;
}
// Bounce off screen edges
if (self.x < 60) {
self.x = 60;
self.velocityX = Math.abs(self.velocityX);
}
if (self.x > 1988) {
self.x = 1988;
self.velocityX = -Math.abs(self.velocityX);
}
// Walking animation
self.walkTimer += 0.2;
alienGraphics.scaleX = self.originalScaleX + Math.sin(self.walkTimer) * 0.1;
alienGraphics.scaleY = 1 + Math.cos(self.walkTimer * 1.5) * 0.05;
// Change direction occasionally
if (Math.random() < 0.005) {
self.velocityX = (Math.random() - 0.5) * 4;
}
};
return self;
});
var Basket = Container.expand(function () {
var self = Container.call(this);
var basketGraphics = self.attachAsset('basket', {
anchorX: 0.5,
anchorY: 1.0
});
var rimGraphics = self.attachAsset('basketRim', {
anchorX: 0.5,
anchorY: 0.5
});
rimGraphics.y = -basketGraphics.height + 15;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game variables
var aliens = [];
var draggedAlien = null;
var basket;
var scoreTxt;
var spawnTimer = 0;
var maxAliens = 3;
var aliensOnScreen = 0;
// Create basket
basket = game.addChild(new Basket());
basket.x = 1024;
basket.y = 2600;
// Create score display
scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 150;
// Function to spawn new alien
function spawnAlien() {
if (aliensOnScreen >= maxAliens) return;
var alien = new Alien();
alien.x = 200 + Math.random() * 1600;
alien.y = 1000 + Math.random() * 800;
alien.groundY = 2000 + Math.random() * 500;
aliens.push(alien);
game.addChild(alien);
aliensOnScreen++;
LK.getSound('spawn').play();
}
// Initial aliens
spawnAlien();
spawnAlien();
// Touch handlers
game.down = function (x, y, obj) {
// Check if touching an alien
for (var i = 0; i < aliens.length; i++) {
var alien = aliens[i];
var bounds = alien.getBounds();
if (x >= bounds.x && x <= bounds.x + bounds.width && y >= bounds.y && y <= bounds.y + bounds.height) {
draggedAlien = alien;
alien.isDragging = true;
break;
}
}
};
game.move = function (x, y, obj) {
if (draggedAlien) {
draggedAlien.x = x;
draggedAlien.y = y;
}
};
game.up = function (x, y, obj) {
if (draggedAlien) {
// Check if alien is dropped in basket
var basketBounds = basket.getBounds();
if (draggedAlien.x >= basketBounds.x && draggedAlien.x <= basketBounds.x + basketBounds.width && draggedAlien.y >= basketBounds.y && draggedAlien.y <= basketBounds.y + basketBounds.height) {
// Alien collected!
LK.setScore(LK.getScore() + 10);
scoreTxt.setText('Score: ' + LK.getScore());
// Flash effect
LK.effects.flashObject(draggedAlien, 0xffff00, 300);
// Remove alien
var alienIndex = aliens.indexOf(draggedAlien);
if (alienIndex > -1) {
aliens.splice(alienIndex, 1);
}
draggedAlien.destroy();
aliensOnScreen--;
LK.getSound('collect').play();
} else {
// Alien not in basket, resume normal movement
draggedAlien.isDragging = false;
}
draggedAlien = null;
}
};
// Main game loop
game.update = function () {
// Spawn new aliens periodically
spawnTimer++;
if (spawnTimer >= 180) {
// Every 3 seconds
spawnAlien();
spawnTimer = 0;
// Increase difficulty over time
if (LK.getScore() > 0 && LK.getScore() % 100 === 0) {
maxAliens = Math.min(maxAliens + 1, 8);
}
}
// Check for game over condition
if (aliensOnScreen >= 15) {
LK.showGameOver();
}
// Update aliens
for (var i = 0; i < aliens.length; i++) {
aliens[i].update();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,189 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Alien = Container.expand(function () {
+ var self = Container.call(this);
+ var alienGraphics = self.attachAsset('alien', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Movement properties
+ self.velocityX = (Math.random() - 0.5) * 4;
+ self.velocityY = 0;
+ self.gravity = 0.3;
+ self.jumpCooldown = 0;
+ self.isDragging = false;
+ self.groundY = 2500;
+ // Walking animation
+ self.walkTimer = 0;
+ self.originalScaleX = 1;
+ self.update = function () {
+ if (self.isDragging) return;
+ // Apply gravity
+ self.velocityY += self.gravity;
+ // Update position
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ // Ground collision
+ if (self.y > self.groundY) {
+ self.y = self.groundY;
+ self.velocityY = 0;
+ // Random jump
+ if (self.jumpCooldown <= 0 && Math.random() < 0.02) {
+ self.velocityY = -8 - Math.random() * 4;
+ self.jumpCooldown = 60;
+ }
+ }
+ if (self.jumpCooldown > 0) {
+ self.jumpCooldown--;
+ }
+ // Bounce off screen edges
+ if (self.x < 60) {
+ self.x = 60;
+ self.velocityX = Math.abs(self.velocityX);
+ }
+ if (self.x > 1988) {
+ self.x = 1988;
+ self.velocityX = -Math.abs(self.velocityX);
+ }
+ // Walking animation
+ self.walkTimer += 0.2;
+ alienGraphics.scaleX = self.originalScaleX + Math.sin(self.walkTimer) * 0.1;
+ alienGraphics.scaleY = 1 + Math.cos(self.walkTimer * 1.5) * 0.05;
+ // Change direction occasionally
+ if (Math.random() < 0.005) {
+ self.velocityX = (Math.random() - 0.5) * 4;
+ }
+ };
+ return self;
+});
+var Basket = Container.expand(function () {
+ var self = Container.call(this);
+ var basketGraphics = self.attachAsset('basket', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ var rimGraphics = self.attachAsset('basketRim', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ rimGraphics.y = -basketGraphics.height + 15;
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87ceeb
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var aliens = [];
+var draggedAlien = null;
+var basket;
+var scoreTxt;
+var spawnTimer = 0;
+var maxAliens = 3;
+var aliensOnScreen = 0;
+// Create basket
+basket = game.addChild(new Basket());
+basket.x = 1024;
+basket.y = 2600;
+// Create score display
+scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+scoreTxt.y = 150;
+// Function to spawn new alien
+function spawnAlien() {
+ if (aliensOnScreen >= maxAliens) return;
+ var alien = new Alien();
+ alien.x = 200 + Math.random() * 1600;
+ alien.y = 1000 + Math.random() * 800;
+ alien.groundY = 2000 + Math.random() * 500;
+ aliens.push(alien);
+ game.addChild(alien);
+ aliensOnScreen++;
+ LK.getSound('spawn').play();
+}
+// Initial aliens
+spawnAlien();
+spawnAlien();
+// Touch handlers
+game.down = function (x, y, obj) {
+ // Check if touching an alien
+ for (var i = 0; i < aliens.length; i++) {
+ var alien = aliens[i];
+ var bounds = alien.getBounds();
+ if (x >= bounds.x && x <= bounds.x + bounds.width && y >= bounds.y && y <= bounds.y + bounds.height) {
+ draggedAlien = alien;
+ alien.isDragging = true;
+ break;
+ }
+ }
+};
+game.move = function (x, y, obj) {
+ if (draggedAlien) {
+ draggedAlien.x = x;
+ draggedAlien.y = y;
+ }
+};
+game.up = function (x, y, obj) {
+ if (draggedAlien) {
+ // Check if alien is dropped in basket
+ var basketBounds = basket.getBounds();
+ if (draggedAlien.x >= basketBounds.x && draggedAlien.x <= basketBounds.x + basketBounds.width && draggedAlien.y >= basketBounds.y && draggedAlien.y <= basketBounds.y + basketBounds.height) {
+ // Alien collected!
+ LK.setScore(LK.getScore() + 10);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ // Flash effect
+ LK.effects.flashObject(draggedAlien, 0xffff00, 300);
+ // Remove alien
+ var alienIndex = aliens.indexOf(draggedAlien);
+ if (alienIndex > -1) {
+ aliens.splice(alienIndex, 1);
+ }
+ draggedAlien.destroy();
+ aliensOnScreen--;
+ LK.getSound('collect').play();
+ } else {
+ // Alien not in basket, resume normal movement
+ draggedAlien.isDragging = false;
+ }
+ draggedAlien = null;
+ }
+};
+// Main game loop
+game.update = function () {
+ // Spawn new aliens periodically
+ spawnTimer++;
+ if (spawnTimer >= 180) {
+ // Every 3 seconds
+ spawnAlien();
+ spawnTimer = 0;
+ // Increase difficulty over time
+ if (LK.getScore() > 0 && LK.getScore() % 100 === 0) {
+ maxAliens = Math.min(maxAliens + 1, 8);
+ }
+ }
+ // Check for game over condition
+ if (aliensOnScreen >= 15) {
+ LK.showGameOver();
+ }
+ // Update aliens
+ for (var i = 0; i < aliens.length; i++) {
+ aliens[i].update();
+ }
+};
\ No newline at end of file