Code edit (1 edits merged)
Please save this source code
User prompt
Sky Pilot Adventures
Initial prompt
Toca planes (2016). Tap on any plane to get started, tap on ginger 🐱, Harvey 🐶, twitter 🐦, jacky 🐰, or buzzy 🐹 to choose, tap on the plane to watch it begin flying, before it lands into space, to reach to the pictures taking.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var PhotoOpportunity = Container.expand(function () { var self = Container.call(this); self.captured = false; var photoGraphics = self.attachAsset('photo_opportunity', { anchorX: 0.5, anchorY: 0.5 }); // Add pulsing animation var pulseUp = function pulseUp() { tween(photoGraphics, { scaleX: 1.3, scaleY: 1.3 }, { duration: 800, easing: tween.easeInOut, onFinish: pulseDown }); }; var pulseDown = function pulseDown() { tween(photoGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 800, easing: tween.easeInOut, onFinish: pulseUp }); }; pulseUp(); self.capture = function () { if (!self.captured) { self.captured = true; LK.getSound('photo_capture').play(); LK.setScore(LK.getScore() + 50); scoreText.setText('Score: ' + LK.getScore()); // Flash effect tween(photoGraphics, { alpha: 0, scaleX: 2, scaleY: 2 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); } }; self.down = function (x, y, obj) { if (gameState === 'flying') { self.capture(); } }; return self; }); var Pilot = Container.expand(function (pilotType) { var self = Container.call(this); self.pilotType = pilotType; self.isSelected = false; var pilotGraphics = self.attachAsset('pilot_' + pilotType, { anchorX: 0.5, anchorY: 0.5 }); // Create pilot name text var nameText = new Text2(pilotType.charAt(0).toUpperCase() + pilotType.slice(1), { size: 36, fill: 0xFFFFFF }); nameText.anchor.set(0.5, 0.5); nameText.y = 120; self.addChild(nameText); self.select = function () { self.isSelected = true; pilotGraphics.alpha = 1.0; tween(pilotGraphics, { scaleX: 1.2, scaleY: 1.2 }, { duration: 300, easing: tween.easeOut }); }; self.deselect = function () { self.isSelected = false; pilotGraphics.alpha = 0.7; tween(pilotGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 300, easing: tween.easeOut }); }; self.down = function (x, y, obj) { if (gameState === 'selection') { selectPilot(self.pilotType); } }; // Initialize as deselected self.deselect(); return self; }); var Plane = Container.expand(function (planeType) { var self = Container.call(this); self.planeType = planeType; self.speed = 0; self.altitude = 0; self.isFlying = false; var planeGraphics = self.attachAsset('plane_' + planeType, { anchorX: 0.5, anchorY: 0.5 }); self.launch = function () { self.isFlying = true; self.speed = 8; LK.getSound('takeoff').play(); tween(self, { rotation: -0.3 }, { duration: 1000, easing: tween.easeOut }); }; self.update = function () { if (self.isFlying) { self.y -= self.speed; self.altitude = Math.max(0, startY - self.y); // Update altitude display altitudeText.setText('Altitude: ' + Math.floor(self.altitude) + 'm'); // Check for space achievement if (self.altitude >= 3000 && !spaceAchieved) { spaceAchieved = true; LK.setScore(LK.getScore() + 1000); scoreText.setText('Score: ' + LK.getScore()); LK.getSound('milestone').play(); // Show you win when reaching space LK.setTimeout(function () { LK.showYouWin(); }, 1000); } // Check altitude milestones var currentMilestone = Math.floor(self.altitude / 500); if (currentMilestone > lastMilestone) { lastMilestone = currentMilestone; LK.setScore(LK.getScore() + 100); scoreText.setText('Score: ' + LK.getScore()); LK.getSound('milestone').play(); } } }; self.down = function (x, y, obj) { if (gameState === 'ready' && !self.isFlying) { self.launch(); gameState = 'flying'; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Sound assets // Photo opportunity assets // Plane assets // Pilot character assets // Game state variables var gameState = 'selection'; // 'selection', 'ready', 'flying' var selectedPilot = null; var currentPlane = null; var pilots = []; var photoOpportunities = []; var startY = 0; var spaceAchieved = false; var lastMilestone = 0; // UI Elements var titleText = new Text2('Sky Pilot Adventures', { size: 80, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0.5); titleText.x = 1024; titleText.y = 200; game.addChild(titleText); var instructionText = new Text2('Choose Your Pilot!', { size: 48, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 0.5); instructionText.x = 1024; instructionText.y = 300; game.addChild(instructionText); var scoreText = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); var altitudeText = new Text2('Altitude: 0m', { size: 48, fill: 0xFFFFFF }); altitudeText.anchor.set(0.5, 0); altitudeText.y = 80; LK.gui.top.addChild(altitudeText); // Create pilots var pilotTypes = ['ginger', 'harvey', 'twitter', 'jacky', 'buzzy']; var pilotPositions = [{ x: 300, y: 600 }, { x: 650, y: 600 }, { x: 1000, y: 600 }, { x: 1350, y: 600 }, { x: 1700, y: 600 }]; for (var i = 0; i < pilotTypes.length; i++) { var pilot = new Pilot(pilotTypes[i]); pilot.x = pilotPositions[i].x; pilot.y = pilotPositions[i].y; pilots.push(pilot); game.addChild(pilot); } function selectPilot(pilotType) { // Deselect all pilots for (var i = 0; i < pilots.length; i++) { pilots[i].deselect(); } // Select chosen pilot selectedPilot = pilotType; for (var i = 0; i < pilots.length; i++) { if (pilots[i].pilotType === pilotType) { pilots[i].select(); break; } } // Hide pilots and show plane for (var i = 0; i < pilots.length; i++) { pilots[i].visible = false; } // Create and show plane currentPlane = new Plane(pilotType); currentPlane.x = 1024; currentPlane.y = 2500; startY = currentPlane.y; game.addChild(currentPlane); // Update instruction instructionText.setText('Tap Your Plane to Launch!'); gameState = 'ready'; // Generate photo opportunities generatePhotoOpportunities(); } function generatePhotoOpportunities() { // Clear existing photo opportunities for (var i = photoOpportunities.length - 1; i >= 0; i--) { photoOpportunities[i].destroy(); } photoOpportunities = []; // Create photo opportunities at different altitudes for (var altitude = 500; altitude <= 3000; altitude += 400) { var photo = new PhotoOpportunity(); photo.x = 200 + Math.random() * 1648; // Random x position photo.y = startY - altitude; photoOpportunities.push(photo); game.addChild(photo); } } // Game update loop game.update = function () { // Clean up destroyed photo opportunities for (var i = photoOpportunities.length - 1; i >= 0; i--) { if (photoOpportunities[i].destroyed) { photoOpportunities.splice(i, 1); } } // Update camera position to follow plane if (currentPlane && currentPlane.isFlying) { var targetY = Math.max(0, currentPlane.y - 1366); game.y = targetY; // Hide instruction text when flying if (gameState === 'flying') { instructionText.visible = false; titleText.visible = false; } } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,309 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var PhotoOpportunity = Container.expand(function () {
+ var self = Container.call(this);
+ self.captured = false;
+ var photoGraphics = self.attachAsset('photo_opportunity', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Add pulsing animation
+ var pulseUp = function pulseUp() {
+ tween(photoGraphics, {
+ scaleX: 1.3,
+ scaleY: 1.3
+ }, {
+ duration: 800,
+ easing: tween.easeInOut,
+ onFinish: pulseDown
+ });
+ };
+ var pulseDown = function pulseDown() {
+ tween(photoGraphics, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 800,
+ easing: tween.easeInOut,
+ onFinish: pulseUp
+ });
+ };
+ pulseUp();
+ self.capture = function () {
+ if (!self.captured) {
+ self.captured = true;
+ LK.getSound('photo_capture').play();
+ LK.setScore(LK.getScore() + 50);
+ scoreText.setText('Score: ' + LK.getScore());
+ // Flash effect
+ tween(photoGraphics, {
+ alpha: 0,
+ scaleX: 2,
+ scaleY: 2
+ }, {
+ duration: 500,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ self.destroy();
+ }
+ });
+ }
+ };
+ self.down = function (x, y, obj) {
+ if (gameState === 'flying') {
+ self.capture();
+ }
+ };
+ return self;
+});
+var Pilot = Container.expand(function (pilotType) {
+ var self = Container.call(this);
+ self.pilotType = pilotType;
+ self.isSelected = false;
+ var pilotGraphics = self.attachAsset('pilot_' + pilotType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Create pilot name text
+ var nameText = new Text2(pilotType.charAt(0).toUpperCase() + pilotType.slice(1), {
+ size: 36,
+ fill: 0xFFFFFF
+ });
+ nameText.anchor.set(0.5, 0.5);
+ nameText.y = 120;
+ self.addChild(nameText);
+ self.select = function () {
+ self.isSelected = true;
+ pilotGraphics.alpha = 1.0;
+ tween(pilotGraphics, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ };
+ self.deselect = function () {
+ self.isSelected = false;
+ pilotGraphics.alpha = 0.7;
+ tween(pilotGraphics, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ };
+ self.down = function (x, y, obj) {
+ if (gameState === 'selection') {
+ selectPilot(self.pilotType);
+ }
+ };
+ // Initialize as deselected
+ self.deselect();
+ return self;
+});
+var Plane = Container.expand(function (planeType) {
+ var self = Container.call(this);
+ self.planeType = planeType;
+ self.speed = 0;
+ self.altitude = 0;
+ self.isFlying = false;
+ var planeGraphics = self.attachAsset('plane_' + planeType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.launch = function () {
+ self.isFlying = true;
+ self.speed = 8;
+ LK.getSound('takeoff').play();
+ tween(self, {
+ rotation: -0.3
+ }, {
+ duration: 1000,
+ easing: tween.easeOut
+ });
+ };
+ self.update = function () {
+ if (self.isFlying) {
+ self.y -= self.speed;
+ self.altitude = Math.max(0, startY - self.y);
+ // Update altitude display
+ altitudeText.setText('Altitude: ' + Math.floor(self.altitude) + 'm');
+ // Check for space achievement
+ if (self.altitude >= 3000 && !spaceAchieved) {
+ spaceAchieved = true;
+ LK.setScore(LK.getScore() + 1000);
+ scoreText.setText('Score: ' + LK.getScore());
+ LK.getSound('milestone').play();
+ // Show you win when reaching space
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 1000);
+ }
+ // Check altitude milestones
+ var currentMilestone = Math.floor(self.altitude / 500);
+ if (currentMilestone > lastMilestone) {
+ lastMilestone = currentMilestone;
+ LK.setScore(LK.getScore() + 100);
+ scoreText.setText('Score: ' + LK.getScore());
+ LK.getSound('milestone').play();
+ }
+ }
+ };
+ self.down = function (x, y, obj) {
+ if (gameState === 'ready' && !self.isFlying) {
+ self.launch();
+ gameState = 'flying';
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+// Sound assets
+// Photo opportunity assets
+// Plane assets
+// Pilot character assets
+// Game state variables
+var gameState = 'selection'; // 'selection', 'ready', 'flying'
+var selectedPilot = null;
+var currentPlane = null;
+var pilots = [];
+var photoOpportunities = [];
+var startY = 0;
+var spaceAchieved = false;
+var lastMilestone = 0;
+// UI Elements
+var titleText = new Text2('Sky Pilot Adventures', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+titleText.anchor.set(0.5, 0.5);
+titleText.x = 1024;
+titleText.y = 200;
+game.addChild(titleText);
+var instructionText = new Text2('Choose Your Pilot!', {
+ size: 48,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 0.5);
+instructionText.x = 1024;
+instructionText.y = 300;
+game.addChild(instructionText);
+var scoreText = new Text2('Score: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+var altitudeText = new Text2('Altitude: 0m', {
+ size: 48,
+ fill: 0xFFFFFF
+});
+altitudeText.anchor.set(0.5, 0);
+altitudeText.y = 80;
+LK.gui.top.addChild(altitudeText);
+// Create pilots
+var pilotTypes = ['ginger', 'harvey', 'twitter', 'jacky', 'buzzy'];
+var pilotPositions = [{
+ x: 300,
+ y: 600
+}, {
+ x: 650,
+ y: 600
+}, {
+ x: 1000,
+ y: 600
+}, {
+ x: 1350,
+ y: 600
+}, {
+ x: 1700,
+ y: 600
+}];
+for (var i = 0; i < pilotTypes.length; i++) {
+ var pilot = new Pilot(pilotTypes[i]);
+ pilot.x = pilotPositions[i].x;
+ pilot.y = pilotPositions[i].y;
+ pilots.push(pilot);
+ game.addChild(pilot);
+}
+function selectPilot(pilotType) {
+ // Deselect all pilots
+ for (var i = 0; i < pilots.length; i++) {
+ pilots[i].deselect();
+ }
+ // Select chosen pilot
+ selectedPilot = pilotType;
+ for (var i = 0; i < pilots.length; i++) {
+ if (pilots[i].pilotType === pilotType) {
+ pilots[i].select();
+ break;
+ }
+ }
+ // Hide pilots and show plane
+ for (var i = 0; i < pilots.length; i++) {
+ pilots[i].visible = false;
+ }
+ // Create and show plane
+ currentPlane = new Plane(pilotType);
+ currentPlane.x = 1024;
+ currentPlane.y = 2500;
+ startY = currentPlane.y;
+ game.addChild(currentPlane);
+ // Update instruction
+ instructionText.setText('Tap Your Plane to Launch!');
+ gameState = 'ready';
+ // Generate photo opportunities
+ generatePhotoOpportunities();
+}
+function generatePhotoOpportunities() {
+ // Clear existing photo opportunities
+ for (var i = photoOpportunities.length - 1; i >= 0; i--) {
+ photoOpportunities[i].destroy();
+ }
+ photoOpportunities = [];
+ // Create photo opportunities at different altitudes
+ for (var altitude = 500; altitude <= 3000; altitude += 400) {
+ var photo = new PhotoOpportunity();
+ photo.x = 200 + Math.random() * 1648; // Random x position
+ photo.y = startY - altitude;
+ photoOpportunities.push(photo);
+ game.addChild(photo);
+ }
+}
+// Game update loop
+game.update = function () {
+ // Clean up destroyed photo opportunities
+ for (var i = photoOpportunities.length - 1; i >= 0; i--) {
+ if (photoOpportunities[i].destroyed) {
+ photoOpportunities.splice(i, 1);
+ }
+ }
+ // Update camera position to follow plane
+ if (currentPlane && currentPlane.isFlying) {
+ var targetY = Math.max(0, currentPlane.y - 1366);
+ game.y = targetY;
+ // Hide instruction text when flying
+ if (gameState === 'flying') {
+ instructionText.visible = false;
+ titleText.visible = false;
+ }
+ }
+};
\ No newline at end of file