/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var BabyCreature = Container.expand(function (creatureType) { var self = Container.call(this); var graphics = self.attachAsset(creatureType || 'babyShark', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.lifespan = 300; // 5 seconds at 60fps self.age = 0; self.update = function () { self.y += self.speed; self.age++; // Fade out as it ages graphics.alpha = Math.max(0, 1 - self.age / self.lifespan); }; return self; }); var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { self.y += self.speed; }; return self; }); var Orca = Container.expand(function () { var self = Container.call(this); var orcaGraphics = self.attachAsset('orca', { anchorX: 0.5, anchorY: 0.5 }); self.health = 3; self.birthTimer = 0; self.birthInterval = 120; // Birth every 2 seconds at 60fps self.update = function () { self.birthTimer++; if (self.birthTimer >= self.birthInterval) { self.birthTimer = 0; giveBirth(); } // Keep orca within bounds if (self.x < 100) self.x = 100; if (self.x > 1948) self.x = 1948; if (self.y < 100) self.y = 100; if (self.y > 2632) self.y = 2632; }; return self; }); var PowerUp = Container.expand(function () { var self = Container.call(this); var powerupGraphics = self.attachAsset('powerup', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.bobTimer = 0; self.update = function () { self.y += self.speed; self.bobTimer += 0.1; powerupGraphics.y = Math.sin(self.bobTimer) * 10; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x006994 }); /**** * Game Code ****/ var orca = new Orca(); var babyCreatures = []; var obstacles = []; var powerups = []; var dragNode = null; var gameSpeed = 1; var obstacleTimer = 0; var powerupTimer = 0; // Initialize orca position orca.x = 1024; orca.y = 1366; game.addChild(orca); // Score display var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Health display var healthTxt = new Text2('Health: 3', { size: 60, fill: 0xFF6B6B }); healthTxt.anchor.set(1, 0); LK.gui.topRight.addChild(healthTxt); function giveBirth() { var creatureType = Math.random() < 0.6 ? 'babyShark' : 'hammerhead'; var baby = new BabyCreature(creatureType); baby.x = orca.x + (Math.random() - 0.5) * 100; baby.y = orca.y + 80; babyCreatures.push(baby); game.addChild(baby); LK.setScore(LK.getScore() + 10); scoreTxt.setText('Score: ' + LK.getScore()); LK.getSound('birth').play(); // Flash effect on birth LK.effects.flashObject(orca, 0x3498db, 500); } function spawnObstacle() { var obstacle = new Obstacle(); obstacle.x = Math.random() * 1848 + 100; obstacle.y = -100; obstacles.push(obstacle); game.addChild(obstacle); } function spawnPowerUp() { var powerup = new PowerUp(); powerup.x = Math.random() * 1848 + 100; powerup.y = -50; powerups.push(powerup); game.addChild(powerup); } function handleMove(x, y, obj) { if (dragNode) { dragNode.x = x; dragNode.y = y; } } game.move = handleMove; game.down = function (x, y, obj) { dragNode = orca; handleMove(x, y, obj); }; game.up = function (x, y, obj) { dragNode = null; }; game.update = function () { // Increase game speed over time if (LK.ticks % 600 == 0) { // Every 10 seconds gameSpeed += 0.1; } // Spawn obstacles obstacleTimer++; if (obstacleTimer >= Math.max(60, 180 - LK.getScore() / 10)) { obstacleTimer = 0; spawnObstacle(); } // Spawn powerups occasionally powerupTimer++; if (powerupTimer >= 480) { // Every 8 seconds powerupTimer = 0; if (Math.random() < 0.3) { spawnPowerUp(); } } // Update baby creatures for (var i = babyCreatures.length - 1; i >= 0; i--) { var baby = babyCreatures[i]; if (baby.age >= baby.lifespan || baby.y > 2800) { baby.destroy(); babyCreatures.splice(i, 1); } } // Update obstacles for (var j = obstacles.length - 1; j >= 0; j--) { var obstacle = obstacles[j]; // Check collision with orca if (orca.intersects(obstacle)) { orca.health--; healthTxt.setText('Health: ' + orca.health); LK.effects.flashObject(orca, 0xe74c3c, 800); LK.getSound('hit').play(); obstacle.destroy(); obstacles.splice(j, 1); if (orca.health <= 0) { LK.showGameOver(); return; } continue; } // Remove off-screen obstacles if (obstacle.y > 2800) { obstacle.destroy(); obstacles.splice(j, 1); } } // Update powerups for (var k = powerups.length - 1; k >= 0; k--) { var powerup = powerups[k]; // Check collision with orca if (orca.intersects(powerup)) { LK.setScore(LK.getScore() + 50); scoreTxt.setText('Score: ' + LK.getScore()); LK.effects.flashObject(orca, 0x2ecc71, 600); LK.getSound('collect').play(); powerup.destroy(); powerups.splice(k, 1); continue; } // Remove off-screen powerups if (powerup.y > 2800) { powerup.destroy(); powerups.splice(k, 1); } } // Check win condition if (LK.getScore() >= 1000) { LK.showYouWin(); } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,229 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var BabyCreature = Container.expand(function (creatureType) {
+ var self = Container.call(this);
+ var graphics = self.attachAsset(creatureType || 'babyShark', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 2;
+ self.lifespan = 300; // 5 seconds at 60fps
+ self.age = 0;
+ self.update = function () {
+ self.y += self.speed;
+ self.age++;
+ // Fade out as it ages
+ graphics.alpha = Math.max(0, 1 - self.age / self.lifespan);
+ };
+ return self;
+});
+var Obstacle = Container.expand(function () {
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 3;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+var Orca = Container.expand(function () {
+ var self = Container.call(this);
+ var orcaGraphics = self.attachAsset('orca', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.health = 3;
+ self.birthTimer = 0;
+ self.birthInterval = 120; // Birth every 2 seconds at 60fps
+ self.update = function () {
+ self.birthTimer++;
+ if (self.birthTimer >= self.birthInterval) {
+ self.birthTimer = 0;
+ giveBirth();
+ }
+ // Keep orca within bounds
+ if (self.x < 100) self.x = 100;
+ if (self.x > 1948) self.x = 1948;
+ if (self.y < 100) self.y = 100;
+ if (self.y > 2632) self.y = 2632;
+ };
+ return self;
+});
+var PowerUp = Container.expand(function () {
+ var self = Container.call(this);
+ var powerupGraphics = self.attachAsset('powerup', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 2;
+ self.bobTimer = 0;
+ self.update = function () {
+ self.y += self.speed;
+ self.bobTimer += 0.1;
+ powerupGraphics.y = Math.sin(self.bobTimer) * 10;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x006994
+});
+
+/****
+* Game Code
+****/
+var orca = new Orca();
+var babyCreatures = [];
+var obstacles = [];
+var powerups = [];
+var dragNode = null;
+var gameSpeed = 1;
+var obstacleTimer = 0;
+var powerupTimer = 0;
+// Initialize orca position
+orca.x = 1024;
+orca.y = 1366;
+game.addChild(orca);
+// Score display
+var scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Health display
+var healthTxt = new Text2('Health: 3', {
+ size: 60,
+ fill: 0xFF6B6B
+});
+healthTxt.anchor.set(1, 0);
+LK.gui.topRight.addChild(healthTxt);
+function giveBirth() {
+ var creatureType = Math.random() < 0.6 ? 'babyShark' : 'hammerhead';
+ var baby = new BabyCreature(creatureType);
+ baby.x = orca.x + (Math.random() - 0.5) * 100;
+ baby.y = orca.y + 80;
+ babyCreatures.push(baby);
+ game.addChild(baby);
+ LK.setScore(LK.getScore() + 10);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ LK.getSound('birth').play();
+ // Flash effect on birth
+ LK.effects.flashObject(orca, 0x3498db, 500);
+}
+function spawnObstacle() {
+ var obstacle = new Obstacle();
+ obstacle.x = Math.random() * 1848 + 100;
+ obstacle.y = -100;
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
+}
+function spawnPowerUp() {
+ var powerup = new PowerUp();
+ powerup.x = Math.random() * 1848 + 100;
+ powerup.y = -50;
+ powerups.push(powerup);
+ game.addChild(powerup);
+}
+function handleMove(x, y, obj) {
+ if (dragNode) {
+ dragNode.x = x;
+ dragNode.y = y;
+ }
+}
+game.move = handleMove;
+game.down = function (x, y, obj) {
+ dragNode = orca;
+ handleMove(x, y, obj);
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+};
+game.update = function () {
+ // Increase game speed over time
+ if (LK.ticks % 600 == 0) {
+ // Every 10 seconds
+ gameSpeed += 0.1;
+ }
+ // Spawn obstacles
+ obstacleTimer++;
+ if (obstacleTimer >= Math.max(60, 180 - LK.getScore() / 10)) {
+ obstacleTimer = 0;
+ spawnObstacle();
+ }
+ // Spawn powerups occasionally
+ powerupTimer++;
+ if (powerupTimer >= 480) {
+ // Every 8 seconds
+ powerupTimer = 0;
+ if (Math.random() < 0.3) {
+ spawnPowerUp();
+ }
+ }
+ // Update baby creatures
+ for (var i = babyCreatures.length - 1; i >= 0; i--) {
+ var baby = babyCreatures[i];
+ if (baby.age >= baby.lifespan || baby.y > 2800) {
+ baby.destroy();
+ babyCreatures.splice(i, 1);
+ }
+ }
+ // Update obstacles
+ for (var j = obstacles.length - 1; j >= 0; j--) {
+ var obstacle = obstacles[j];
+ // Check collision with orca
+ if (orca.intersects(obstacle)) {
+ orca.health--;
+ healthTxt.setText('Health: ' + orca.health);
+ LK.effects.flashObject(orca, 0xe74c3c, 800);
+ LK.getSound('hit').play();
+ obstacle.destroy();
+ obstacles.splice(j, 1);
+ if (orca.health <= 0) {
+ LK.showGameOver();
+ return;
+ }
+ continue;
+ }
+ // Remove off-screen obstacles
+ if (obstacle.y > 2800) {
+ obstacle.destroy();
+ obstacles.splice(j, 1);
+ }
+ }
+ // Update powerups
+ for (var k = powerups.length - 1; k >= 0; k--) {
+ var powerup = powerups[k];
+ // Check collision with orca
+ if (orca.intersects(powerup)) {
+ LK.setScore(LK.getScore() + 50);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ LK.effects.flashObject(orca, 0x2ecc71, 600);
+ LK.getSound('collect').play();
+ powerup.destroy();
+ powerups.splice(k, 1);
+ continue;
+ }
+ // Remove off-screen powerups
+ if (powerup.y > 2800) {
+ powerup.destroy();
+ powerups.splice(k, 1);
+ }
+ }
+ // Check win condition
+ if (LK.getScore() >= 1000) {
+ LK.showYouWin();
+ }
+};
\ No newline at end of file