/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Pest (Enemy) class var Pest = Container.expand(function () { var self = Container.call(this); // Lane index (0-4) self.lane = 0; // Speed in px per tick self.speed = 2 + Math.random() * 1.5; // Slight speed variation // Attach pest asset (ellipse, brown) var pestAsset = self.attachAsset('pest', { anchorX: 0.5, anchorY: 0.5 }); // Health self.hp = 3; // Called every tick self.update = function () { self.x -= self.speed; }; // Take damage self.hit = function (dmg) { self.hp -= dmg; if (self.hp <= 0) { self.destroyed = true; // Flash on death LK.effects.flashObject(self, 0xffff00, 300); } else { // Flash on hit LK.effects.flashObject(self, 0xff0000, 150); } }; return self; }); // Plant (Shooter) class var Plant = Container.expand(function () { var self = Container.call(this); // Lane index (0-4) self.lane = 0; // Attach plant asset (box, green) var plantAsset = self.attachAsset('plant', { anchorX: 0.5, anchorY: 0.5 }); // Fire cooldown (ticks) self.cooldown = 0; // Called every tick self.update = function () { if (self.cooldown > 0) { self.cooldown--; } }; // Try to fire self.tryFire = function () { if (self.cooldown <= 0) { self.cooldown = 40; // About 0.66s at 60fps return true; } return false; }; return self; }); // Projectile (Seed) class var Seed = Container.expand(function () { var self = Container.call(this); // Attach seed asset (small yellow ellipse) var seedAsset = self.attachAsset('seed', { anchorX: 0.5, anchorY: 0.5 }); // Speed in px per tick self.speed = 12; // Called every tick self.update = function () { self.x += self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x7ec850 // Light green garden }); /**** * Game Code ****/ // --- Constants --- var GAME_WIDTH = 2048; var GAME_HEIGHT = 2732; var LANE_COUNT = 5; var LANE_HEIGHT = Math.floor(GAME_HEIGHT / LANE_COUNT); var LANE_Y = []; for (var i = 0; i < LANE_COUNT; i++) { LANE_Y[i] = Math.floor((i + 0.5) * LANE_HEIGHT); } var PLANT_COST = 10; var START_RESOURCES = 20; var MAX_BREACHES = 5; var TOTAL_WAVES = 10; // --- Asset Initialization --- // --- Game State --- var plants = []; // All plant objects var pests = []; // All pest objects var seeds = []; // All seed objects var resources = START_RESOURCES; var breaches = 0; var wave = 1; var waveInProgress = false; var waveTimer = 0; var nextPestTick = 0; var selectedLane = null; // Lane index for planting var plantPreview = null; // Preview asset for planting // --- UI Elements --- var resourceTxt = new Text2(resources + '', { size: 90, fill: 0xFFF700 }); resourceTxt.anchor.set(0.5, 0); LK.gui.top.addChild(resourceTxt); var waveTxt = new Text2('Wave 1/' + TOTAL_WAVES, { size: 70, fill: 0xFFFFFF }); waveTxt.anchor.set(0.5, 0); LK.gui.top.addChild(waveTxt); var breachTxt = new Text2('Breaches: 0/' + MAX_BREACHES, { size: 70, fill: 0xFF4444 }); breachTxt.anchor.set(0.5, 0); LK.gui.top.addChild(breachTxt); // Position UI resourceTxt.x = 400; resourceTxt.y = 20; waveTxt.x = GAME_WIDTH / 2; waveTxt.y = 20; breachTxt.x = GAME_WIDTH - 400; breachTxt.y = 20; // --- Lane Markers (for touch feedback) --- var laneMarkers = []; for (var i = 0; i < LANE_COUNT; i++) { var marker = LK.getAsset('plant', { anchorX: 0.5, anchorY: 0.5, x: 200, y: LANE_Y[i], alpha: 0.12, width: 180, height: LANE_HEIGHT - 10 }); game.addChild(marker); laneMarkers.push(marker); } // --- Plant Preview (shows where plant will be placed) --- function showPlantPreview(lane) { if (plantPreview) { plantPreview.visible = false; } if (lane === null) return; if (!plantPreview) { plantPreview = LK.getAsset('plant', { anchorX: 0.5, anchorY: 0.5, alpha: 0.5, width: 120, height: 120 }); game.addChild(plantPreview); } plantPreview.x = 200; plantPreview.y = LANE_Y[lane]; plantPreview.visible = true; } // --- Plant Placement Handler --- function canPlacePlant(lane) { // Only one plant per lane for (var i = 0; i < plants.length; i++) { if (plants[i].lane === lane) return false; } return resources >= PLANT_COST; } function placePlant(lane) { if (!canPlacePlant(lane)) return false; var plant = new Plant(); plant.lane = lane; plant.x = 200; plant.y = LANE_Y[lane]; plants.push(plant); game.addChild(plant); resources -= PLANT_COST; resourceTxt.setText(resources + ''); return true; } // --- Touch Handler for Planting --- game.down = function (x, y, obj) { // Ignore top 100px (menu area) if (y < 100) return; // Find lane var lane = Math.floor(y / LANE_HEIGHT); if (lane < 0 || lane >= LANE_COUNT) return; selectedLane = lane; showPlantPreview(lane); }; game.move = function (x, y, obj) { if (y < 100) { showPlantPreview(null); selectedLane = null; return; } var lane = Math.floor(y / LANE_HEIGHT); if (lane < 0 || lane >= LANE_COUNT) { showPlantPreview(null); selectedLane = null; return; } selectedLane = lane; showPlantPreview(lane); }; game.up = function (x, y, obj) { if (selectedLane !== null) { if (canPlacePlant(selectedLane)) { placePlant(selectedLane); } } showPlantPreview(null); selectedLane = null; }; // --- Resource Generation --- var resourceTimer = LK.setInterval(function () { resources += 1; resourceTxt.setText(resources + ''); }, 1000); // --- Wave System --- function startWave() { waveInProgress = true; waveTimer = 0; nextPestTick = 0; waveTxt.setText('Wave ' + wave + '/' + TOTAL_WAVES); } function endWave() { waveInProgress = false; wave++; if (wave > TOTAL_WAVES) { LK.showYouWin(); } else { // Short pause before next wave LK.setTimeout(function () { startWave(); }, 1800); } } // --- Pest Spawning --- function spawnPest() { var lane = Math.floor(Math.random() * LANE_COUNT); var pest = new Pest(); pest.lane = lane; pest.x = GAME_WIDTH - 100; pest.y = LANE_Y[lane]; pests.push(pest); game.addChild(pest); } // --- Main Game Update --- game.update = function () { // --- Wave logic --- if (!waveInProgress) { startWave(); return; } waveTimer++; // Pest spawn logic: spawn a pest every 60-90 ticks, up to 6+wave pests per wave if (nextPestTick <= 0) { if (waveTimer < (6 + wave) * 80) { spawnPest(); nextPestTick = 60 + Math.floor(Math.random() * 30); } } else { nextPestTick--; } // End wave if all pests spawned and none left if (waveTimer > (6 + wave) * 80 && pests.length === 0) { endWave(); return; } // --- Plants fire seeds --- for (var i = 0; i < plants.length; i++) { var plant = plants[i]; plant.update(); // Fire if pest in lane and cooldown ready var pestInLane = false; for (var j = 0; j < pests.length; j++) { if (pests[j].lane === plant.lane && pests[j].x > plant.x) { pestInLane = true; break; } } if (pestInLane && plant.tryFire()) { var seed = new Seed(); seed.x = plant.x + 60; seed.y = plant.y; seed.lane = plant.lane; seeds.push(seed); game.addChild(seed); } } // --- Seeds move and hit pests --- for (var s = seeds.length - 1; s >= 0; s--) { var seed = seeds[s]; seed.update(); var hit = false; for (var p = 0; p < pests.length; p++) { var pest = pests[p]; if (pest.lane === seed.lane && !pest.destroyed && Math.abs(seed.x - pest.x) < 60) { pest.hit(1); hit = true; break; } } if (hit || seed.x > GAME_WIDTH + 50) { seed.destroy(); seeds.splice(s, 1); } } // --- Pests move and check for breach or death --- for (var p = pests.length - 1; p >= 0; p--) { var pest = pests[p]; if (pest.destroyed) { pest.destroy(); pests.splice(p, 1); continue; } pest.update(); if (pest.x < 80) { // Breach! breaches++; breachTxt.setText('Breaches: ' + breaches + '/' + MAX_BREACHES); LK.effects.flashScreen(0xff0000, 400); pest.destroy(); pests.splice(p, 1); if (breaches >= MAX_BREACHES) { LK.showGameOver(); return; } } } }; // --- Clean up on game over/win --- game.on('destroy', function () { LK.clearInterval(resourceTimer); plants = []; pests = []; seeds = []; breaches = 0; resources = START_RESOURCES; wave = 1; waveInProgress = false; if (plantPreview) { plantPreview.destroy(); plantPreview = null; } }); // --- Initial UI update --- resourceTxt.setText(resources + ''); waveTxt.setText('Wave 1/' + TOTAL_WAVES); breachTxt.setText('Breaches: 0/' + MAX_BREACHES);
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,373 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+// Pest (Enemy) class
+var Pest = Container.expand(function () {
+ var self = Container.call(this);
+ // Lane index (0-4)
+ self.lane = 0;
+ // Speed in px per tick
+ self.speed = 2 + Math.random() * 1.5; // Slight speed variation
+ // Attach pest asset (ellipse, brown)
+ var pestAsset = self.attachAsset('pest', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Health
+ self.hp = 3;
+ // Called every tick
+ self.update = function () {
+ self.x -= self.speed;
+ };
+ // Take damage
+ self.hit = function (dmg) {
+ self.hp -= dmg;
+ if (self.hp <= 0) {
+ self.destroyed = true;
+ // Flash on death
+ LK.effects.flashObject(self, 0xffff00, 300);
+ } else {
+ // Flash on hit
+ LK.effects.flashObject(self, 0xff0000, 150);
+ }
+ };
+ return self;
+});
+// Plant (Shooter) class
+var Plant = Container.expand(function () {
+ var self = Container.call(this);
+ // Lane index (0-4)
+ self.lane = 0;
+ // Attach plant asset (box, green)
+ var plantAsset = self.attachAsset('plant', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Fire cooldown (ticks)
+ self.cooldown = 0;
+ // Called every tick
+ self.update = function () {
+ if (self.cooldown > 0) {
+ self.cooldown--;
+ }
+ };
+ // Try to fire
+ self.tryFire = function () {
+ if (self.cooldown <= 0) {
+ self.cooldown = 40; // About 0.66s at 60fps
+ return true;
+ }
+ return false;
+ };
+ return self;
+});
+// Projectile (Seed) class
+var Seed = Container.expand(function () {
+ var self = Container.call(this);
+ // Attach seed asset (small yellow ellipse)
+ var seedAsset = self.attachAsset('seed', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Speed in px per tick
+ self.speed = 12;
+ // Called every tick
+ self.update = function () {
+ self.x += self.speed;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x7ec850 // Light green garden
+});
+
+/****
+* Game Code
+****/
+// --- Constants ---
+var GAME_WIDTH = 2048;
+var GAME_HEIGHT = 2732;
+var LANE_COUNT = 5;
+var LANE_HEIGHT = Math.floor(GAME_HEIGHT / LANE_COUNT);
+var LANE_Y = [];
+for (var i = 0; i < LANE_COUNT; i++) {
+ LANE_Y[i] = Math.floor((i + 0.5) * LANE_HEIGHT);
+}
+var PLANT_COST = 10;
+var START_RESOURCES = 20;
+var MAX_BREACHES = 5;
+var TOTAL_WAVES = 10;
+// --- Asset Initialization ---
+// --- Game State ---
+var plants = []; // All plant objects
+var pests = []; // All pest objects
+var seeds = []; // All seed objects
+var resources = START_RESOURCES;
+var breaches = 0;
+var wave = 1;
+var waveInProgress = false;
+var waveTimer = 0;
+var nextPestTick = 0;
+var selectedLane = null; // Lane index for planting
+var plantPreview = null; // Preview asset for planting
+// --- UI Elements ---
+var resourceTxt = new Text2(resources + '', {
+ size: 90,
+ fill: 0xFFF700
+});
+resourceTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(resourceTxt);
+var waveTxt = new Text2('Wave 1/' + TOTAL_WAVES, {
+ size: 70,
+ fill: 0xFFFFFF
+});
+waveTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(waveTxt);
+var breachTxt = new Text2('Breaches: 0/' + MAX_BREACHES, {
+ size: 70,
+ fill: 0xFF4444
+});
+breachTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(breachTxt);
+// Position UI
+resourceTxt.x = 400;
+resourceTxt.y = 20;
+waveTxt.x = GAME_WIDTH / 2;
+waveTxt.y = 20;
+breachTxt.x = GAME_WIDTH - 400;
+breachTxt.y = 20;
+// --- Lane Markers (for touch feedback) ---
+var laneMarkers = [];
+for (var i = 0; i < LANE_COUNT; i++) {
+ var marker = LK.getAsset('plant', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 200,
+ y: LANE_Y[i],
+ alpha: 0.12,
+ width: 180,
+ height: LANE_HEIGHT - 10
+ });
+ game.addChild(marker);
+ laneMarkers.push(marker);
+}
+// --- Plant Preview (shows where plant will be placed) ---
+function showPlantPreview(lane) {
+ if (plantPreview) {
+ plantPreview.visible = false;
+ }
+ if (lane === null) return;
+ if (!plantPreview) {
+ plantPreview = LK.getAsset('plant', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.5,
+ width: 120,
+ height: 120
+ });
+ game.addChild(plantPreview);
+ }
+ plantPreview.x = 200;
+ plantPreview.y = LANE_Y[lane];
+ plantPreview.visible = true;
+}
+// --- Plant Placement Handler ---
+function canPlacePlant(lane) {
+ // Only one plant per lane
+ for (var i = 0; i < plants.length; i++) {
+ if (plants[i].lane === lane) return false;
+ }
+ return resources >= PLANT_COST;
+}
+function placePlant(lane) {
+ if (!canPlacePlant(lane)) return false;
+ var plant = new Plant();
+ plant.lane = lane;
+ plant.x = 200;
+ plant.y = LANE_Y[lane];
+ plants.push(plant);
+ game.addChild(plant);
+ resources -= PLANT_COST;
+ resourceTxt.setText(resources + '');
+ return true;
+}
+// --- Touch Handler for Planting ---
+game.down = function (x, y, obj) {
+ // Ignore top 100px (menu area)
+ if (y < 100) return;
+ // Find lane
+ var lane = Math.floor(y / LANE_HEIGHT);
+ if (lane < 0 || lane >= LANE_COUNT) return;
+ selectedLane = lane;
+ showPlantPreview(lane);
+};
+game.move = function (x, y, obj) {
+ if (y < 100) {
+ showPlantPreview(null);
+ selectedLane = null;
+ return;
+ }
+ var lane = Math.floor(y / LANE_HEIGHT);
+ if (lane < 0 || lane >= LANE_COUNT) {
+ showPlantPreview(null);
+ selectedLane = null;
+ return;
+ }
+ selectedLane = lane;
+ showPlantPreview(lane);
+};
+game.up = function (x, y, obj) {
+ if (selectedLane !== null) {
+ if (canPlacePlant(selectedLane)) {
+ placePlant(selectedLane);
+ }
+ }
+ showPlantPreview(null);
+ selectedLane = null;
+};
+// --- Resource Generation ---
+var resourceTimer = LK.setInterval(function () {
+ resources += 1;
+ resourceTxt.setText(resources + '');
+}, 1000);
+// --- Wave System ---
+function startWave() {
+ waveInProgress = true;
+ waveTimer = 0;
+ nextPestTick = 0;
+ waveTxt.setText('Wave ' + wave + '/' + TOTAL_WAVES);
+}
+function endWave() {
+ waveInProgress = false;
+ wave++;
+ if (wave > TOTAL_WAVES) {
+ LK.showYouWin();
+ } else {
+ // Short pause before next wave
+ LK.setTimeout(function () {
+ startWave();
+ }, 1800);
+ }
+}
+// --- Pest Spawning ---
+function spawnPest() {
+ var lane = Math.floor(Math.random() * LANE_COUNT);
+ var pest = new Pest();
+ pest.lane = lane;
+ pest.x = GAME_WIDTH - 100;
+ pest.y = LANE_Y[lane];
+ pests.push(pest);
+ game.addChild(pest);
+}
+// --- Main Game Update ---
+game.update = function () {
+ // --- Wave logic ---
+ if (!waveInProgress) {
+ startWave();
+ return;
+ }
+ waveTimer++;
+ // Pest spawn logic: spawn a pest every 60-90 ticks, up to 6+wave pests per wave
+ if (nextPestTick <= 0) {
+ if (waveTimer < (6 + wave) * 80) {
+ spawnPest();
+ nextPestTick = 60 + Math.floor(Math.random() * 30);
+ }
+ } else {
+ nextPestTick--;
+ }
+ // End wave if all pests spawned and none left
+ if (waveTimer > (6 + wave) * 80 && pests.length === 0) {
+ endWave();
+ return;
+ }
+ // --- Plants fire seeds ---
+ for (var i = 0; i < plants.length; i++) {
+ var plant = plants[i];
+ plant.update();
+ // Fire if pest in lane and cooldown ready
+ var pestInLane = false;
+ for (var j = 0; j < pests.length; j++) {
+ if (pests[j].lane === plant.lane && pests[j].x > plant.x) {
+ pestInLane = true;
+ break;
+ }
+ }
+ if (pestInLane && plant.tryFire()) {
+ var seed = new Seed();
+ seed.x = plant.x + 60;
+ seed.y = plant.y;
+ seed.lane = plant.lane;
+ seeds.push(seed);
+ game.addChild(seed);
+ }
+ }
+ // --- Seeds move and hit pests ---
+ for (var s = seeds.length - 1; s >= 0; s--) {
+ var seed = seeds[s];
+ seed.update();
+ var hit = false;
+ for (var p = 0; p < pests.length; p++) {
+ var pest = pests[p];
+ if (pest.lane === seed.lane && !pest.destroyed && Math.abs(seed.x - pest.x) < 60) {
+ pest.hit(1);
+ hit = true;
+ break;
+ }
+ }
+ if (hit || seed.x > GAME_WIDTH + 50) {
+ seed.destroy();
+ seeds.splice(s, 1);
+ }
+ }
+ // --- Pests move and check for breach or death ---
+ for (var p = pests.length - 1; p >= 0; p--) {
+ var pest = pests[p];
+ if (pest.destroyed) {
+ pest.destroy();
+ pests.splice(p, 1);
+ continue;
+ }
+ pest.update();
+ if (pest.x < 80) {
+ // Breach!
+ breaches++;
+ breachTxt.setText('Breaches: ' + breaches + '/' + MAX_BREACHES);
+ LK.effects.flashScreen(0xff0000, 400);
+ pest.destroy();
+ pests.splice(p, 1);
+ if (breaches >= MAX_BREACHES) {
+ LK.showGameOver();
+ return;
+ }
+ }
+ }
+};
+// --- Clean up on game over/win ---
+game.on('destroy', function () {
+ LK.clearInterval(resourceTimer);
+ plants = [];
+ pests = [];
+ seeds = [];
+ breaches = 0;
+ resources = START_RESOURCES;
+ wave = 1;
+ waveInProgress = false;
+ if (plantPreview) {
+ plantPreview.destroy();
+ plantPreview = null;
+ }
+});
+// --- Initial UI update ---
+resourceTxt.setText(resources + '');
+waveTxt.setText('Wave 1/' + TOTAL_WAVES);
+breachTxt.setText('Breaches: 0/' + MAX_BREACHES);
\ No newline at end of file
Pixelated sun . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Flip it around
Make the background white
Make it angry
Make a dirty patch of dirt. In-Game asset. 2d. High contrast. No shadows
Make the background red
Make the background green
Make it shiny
Looks like a gargantuar from plants vs zombies but a rat. In-Game asset. 2d. High contrast. No shadows
Make the background blue