Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'STAR')' in or related to this line: 'self.type = enums.STAR;' Line Number: 189
Code edit (3 edits merged)
Please save this source code
User prompt
write a collision detection check between javelin and the starpowerups where it says 'todo:colliion detection here' in the code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: starpowerups[i].move_not_really_migrated_but_still is not a function' in or related to this line: 't = starpowerups[i].move_not_really_migrated_but_still();' Line Number: 353
Code edit (1 edits merged)
Please save this source code
User prompt
at game start, add 30 starpowerups at random positions, and add them to an array for easy updating.
User prompt
create a starpowerup asset
User prompt
Migrate to the latest version of LK
Code edit (1 edits merged)
Please save this source code
Code edit (11 edits merged)
Please save this source code
User prompt
place the game logoon the screen
User prompt
make a gamelogo object
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: astronauy is not defined' in or related to this line: 'if (LK.getScore() > 300 && javelins[i].intersects(astronaut) && astronauy.y > 825) {' Line Number: 220
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
particle's update function should make them spread briefly and then disappear.
Code edit (9 edits merged)
Please save this source code
User prompt
create a function that creates a small dust particle explosion
Code edit (7 edits merged)
Please save this source code
/**** * Classes ****/ var Astronaut = Container.expand(function () { var self = Container.call(this); var surfaceGraphics = self.attachAsset('athlete', { anchorX: 0.5, anchorY: 0.5, /* x: 1024, y: 818,*/ vely: 0 }); self._move_migrated = function () { self.x += 12; self.rotation += 0.1; }; self.vely = 0; self.x = 1024; self.y = 818; }); // DustParticle class var DustParticle = Container.expand(function () { var self = Container.call(this); // Create a simple square shape for the particle var particleGraphics = self.attachAsset('particle', { anchorX: 0.5, anchorY: 0.5 }); self.width = 25 + Math.random() * 25; self.height = self.width; // Set initial speed and direction self.speedX = Math.random() * 20 - 10; self.speedY = Math.random() * 20 - 10; // Set the particle to move and fade out over time self._update_migrated = function () { self.x += self.speedX; self.y += self.speedY; self.speedX *= 0.95; // Reduce speed for spreading effect self.speedY *= 0.95; // Reduce speed for spreading effect particleGraphics.alpha *= 0.95; // Increase alpha reduction for quicker disappearance if (particleGraphics.alpha < 0.01) { self.destroy(); } }; }); // GoreParticle class var GoreParticle = Container.expand(function () { var self = Container.call(this); // Create a simple square shape for the particle var particleGraphics = self.attachAsset('particle2', { anchorX: 0.5, anchorY: 0.5 }); self.width = 25 + Math.random() * 25; self.height = self.width; // Set initial speed and direction self.speedX = Math.random() * 20; self.speedY = Math.random() * 20 - 10; // Set the particle to move and fade out over time self._update_migrated = function () { self.x += self.speedX; self.y += self.speedY; self.speedX *= 0.95; // Reduce speed for spreading effect self.speedY *= 0.95; // Reduce speed for spreading effect particleGraphics.alpha *= 0.95; // Increase alpha reduction for quicker disappearance if (particleGraphics.alpha < 0.01) { self.destroy(); } }; }); // Assets will be automatically generated based on usage in the code. // Javelin class var Javelin = Container.expand(function () { var self = Container.call(this); var javelinGraphics1 = self.attachAsset('javelin', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / 4 }); var javelinGraphics2 = self.attachAsset('javelin', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / 4, scaleY: -1, scaleX: -1, x: 100 }); self.speedX = 0; self.speedY = 0; self.scale.x = 0.8; self.scale.y = 0.8; self.rotation = -0.30; self.orbitSpeed = 0.045; self.angle = 4.6; self.radius = 570; //670 - 20 * (100 / 20); //console.log('radius ' + self.radius); self._move_migrated = function () { //self.radius = 670 - 20 * (100 / 20); //self.angle = (self.angle || 0) + self.orbitSpeed; self.angle = (self.angle || 0) + speed; self.angle %= Math.PI * 2; self.x = moonSurface.x + self.radius * Math.cos(self.angle); self.y = moonSurface.y + self.radius * Math.sin(self.angle); self.rotation = self.angle + Math.PI / 2 + 0.2; //self.radius -= 0.075; self.radius -= Math.random() * 0.02 + 0.055; if (self.radius < 512) { landed = true; self.rotation += 0.05; createDustExplosion(self.x, self.y, 20); instructionTxt.setText('Nice throw! ' + LK.getScore() + ' meters'); instructionTxt.alpha = 1; } }; self.hitUpdate = function () { self.x += 12; self.rotation += 0.1; }; }); // Moon surface class for visual effect var MoonSurface = Container.expand(function () { var self = Container.call(this); var surfaceGraphics = self.attachAsset('moonSurface', { anchorX: 0.5, anchorY: 0.5 // Anchor at the bottom }); self.x = 1024; // Center horizontally self.y = 2732 / 2; // Position at the center of the screen }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Function to create a dust particle explosion // TODOS: function createDustExplosion(x, y, count) { for (var i = 0; i < count; i++) { var particle = new DustParticle(); particle.x = x; particle.y = y; game.addChild(particle); particles.push(particle); } } function createImpactExplosion(x, y, count) { for (var i = 0; i < count; i++) { var particle = new GoreParticle(); particle.x = x; particle.y = y; game.addChild(particle); particles.push(particle); } } // Initialize important variables and arrays var javelins = []; var background = game.attachAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 974, y: 1366, alpha: 0.5 }); var moonSurface = game.addChild(new MoonSurface()); // Add the astronaut to the scene var astronaut = game.addChild(new Astronaut()); // Add the game logo to the scene var gameLogo = game.attachAsset('gameLogo', { anchorX: 0.5, anchorY: 0.5, /*x: 1024, y: 1366*/ x: 2048 - 250, y: 250, scaleX: 0.7, scaleY: 0.7 }); //TODO: Try other positions of the logo. game.addChild(gameLogo); /*var astronaut = game.attachAsset('athlete', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 818, vely: 0 }); astronaut.move = function () { self.x += speed; self.rotation += 0.1; };*/ var javelin = game.addChild(new Javelin()); javelin.x = astronaut.x - 70; javelin.y = astronaut.y; var started = false; var thrown = false; var particles = []; // Create a method to launch a javelin function launchJavelin() { /*var javelin = new Javelin(); javelin.x = 1024; // Launch from center horizontally javelin.y = 2500; // Launch from near the bottom javelin.speedX = Math.random() * 10 - 5; // Random horizontal speed javelin.speedY = -10 - Math.random() * 5; // Upward speed with a little randomness javelins.push(javelin); game.addChild(javelin);*/ javelins.push(javelin); thrown = true; } // Add a text label at the bottom of the screen: "Tap to throw the javelin" var instructionTxt = new Text2('Tap to throw the javelin', { size: 100, fill: "#ffffff" }); instructionTxt.anchor.set(0.5, 3); // Sets anchor to the center of the bottom edge of the text. LK.gui.bottom.addChild(instructionTxt); // Create a score label at the top center of the screen var scoreTxt = new Text2('0', { size: 100, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); // Sets anchor to the center of the top edge of the text. LK.gui.top.addChild(scoreTxt); // Create an action meter at the bottom of the screen var actionMeter = new Container(); var actionMeterGraphics = actionMeter.attachAsset('actionMeter', { anchorX: 0.5, anchorY: 0.5 }); actionMeter.x = 1024; // Center horizontally actionMeter.y = 2732 - 600; // Position at the bottom of the screen actionMeter.alpha = 0; game.addChild(actionMeter); var actionMeterPointer = new Container(); var actionMeterPointerGraphics = actionMeterPointer.attachAsset('actionMeterPointer', { anchorX: 0.5, anchorY: 0.5, scaleX: 4, scaleY: 4 }); actionMeterPointer.x = 1024; // Center horizontally actionMeterPointer.y = 2732 - 550; actionMeterPointer.speed = 30; actionMeterPointer.alpha = 0; game.addChild(actionMeterPointer); var midSpeed = 0.0225; var minSpeed = 0.02; var maxSpeed = 0.06; //0.045; var speed = 0; var landed = false; var playerHit = false; var landedCounter = 0; // Touch event to launch a javelin game.on('down', function (x, y, obj) { if (!started) { started = true; //gameLogo.alpha = 0; instructionTxt.alpha = 0; actionMeter.alpha = 1; actionMeterPointer.alpha = 1; } else if (!thrown) { //speed = minSpeed + (actionMeterPointer.x - 450) / 1150 * (maxSpeed - minSpeed); var min = actionMeter.x - actionMeter.width / 2; var max = actionMeter.x + actionMeter.width / 2; speed = (actionMeterPointer.x - min) / (max - min); speed *= midSpeed; speed += minSpeed; //speed = maxSpeed - speed; //console.log('speed ' + speed); launchJavelin(); //instructionTxt.setText('Tap to jump'); //instructionTxt.alpha = 1; } else { //if (astronaut.vely == 0) { if (!landed) { instructionTxt.alpha = 0; } if (astronaut.y >= 818) { astronaut.vely += 10; } } }); // Game tick event LK.on('tick', function () { if (started && !thrown) { actionMeterPointer.x += actionMeterPointer.speed; if (actionMeterPointer.x > 1600 || actionMeterPointer.x < 450) { actionMeterPointer.speed *= -1; } } if (thrown && !landed) { if (astronaut.scale.x == 1 && LK.getScore() > 200) { astronaut.scale.x = -1; instructionTxt.setText("Don't get hit! Tap to jump!"); instructionTxt.alpha = 1; instructionTxt.y = -1200; } for (var i = javelins.length - 1; i >= 0; i--) { // Update the score and scorelabel text every frame when thrown is true. LK.setScore(LK.getScore() + 100 * speed); scoreTxt.setText(LK.getScore()); javelins[i]._move_migrated(); if (LK.getScore() > 300 && javelins[i].intersects(astronaut) && astronaut.y >= 818) { landed = true; createImpactExplosion(astronaut.x, astronaut.y, 20); astronaut.removeChildAt(0); astronaut.attachAsset('athlete-hit', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / 2 }); javelins[i]._move_migrated = javelins[i].hitUpdate; playerHit = true; //instructionTxt.setText('Uh oh :(\nTry again'); instructionTxt.alpha = 1; instructionTxt.setText('Uh oh!'); } } actionMeter.alpha -= 0.01; actionMeterPointer.alpha -= 0.01; } if (astronaut.vely > 0) { astronaut.y -= astronaut.vely; astronaut.vely -= 0.2; if (astronaut.vely < 0) { astronaut.vely = 0; } } if (astronaut.y < 818) { astronaut.y += 3; } if (landed) { landedCounter++; if (landedCounter >= 120) { LK.showGameOver(); } } if (playerHit) { javelin._move_migrated(); astronaut._move_migrated(); if (javelin.x > 2500) { LK.showGameOver(); } } for (var i = particles.length - 1; i >= 0; i--) { particles[i]._update_migrated(); } });
===================================================================
--- original.js
+++ change.js
@@ -10,9 +10,9 @@
x: 1024,
y: 818,*/
vely: 0
});
- self.move = function () {
+ self._move_migrated = function () {
self.x += 12;
self.rotation += 0.1;
};
self.vely = 0;
@@ -32,9 +32,9 @@
// Set initial speed and direction
self.speedX = Math.random() * 20 - 10;
self.speedY = Math.random() * 20 - 10;
// Set the particle to move and fade out over time
- self.update = function () {
+ self._update_migrated = function () {
self.x += self.speedX;
self.y += self.speedY;
self.speedX *= 0.95; // Reduce speed for spreading effect
self.speedY *= 0.95; // Reduce speed for spreading effect
@@ -57,9 +57,9 @@
// Set initial speed and direction
self.speedX = Math.random() * 20;
self.speedY = Math.random() * 20 - 10;
// Set the particle to move and fade out over time
- self.update = function () {
+ self._update_migrated = function () {
self.x += self.speedX;
self.y += self.speedY;
self.speedX *= 0.95; // Reduce speed for spreading effect
self.speedY *= 0.95; // Reduce speed for spreading effect
@@ -94,22 +94,24 @@
self.orbitSpeed = 0.045;
self.angle = 4.6;
self.radius = 570; //670 - 20 * (100 / 20);
//console.log('radius ' + self.radius);
- self.move = function () {
+ self._move_migrated = function () {
//self.radius = 670 - 20 * (100 / 20);
//self.angle = (self.angle || 0) + self.orbitSpeed;
self.angle = (self.angle || 0) + speed;
self.angle %= Math.PI * 2;
self.x = moonSurface.x + self.radius * Math.cos(self.angle);
self.y = moonSurface.y + self.radius * Math.sin(self.angle);
self.rotation = self.angle + Math.PI / 2 + 0.2;
- self.radius -= 0.075;
+ //self.radius -= 0.075;
+ self.radius -= Math.random() * 0.02 + 0.055;
if (self.radius < 512) {
landed = true;
self.rotation += 0.05;
createDustExplosion(self.x, self.y, 20);
instructionTxt.setText('Nice throw! ' + LK.getScore() + ' meters');
+ instructionTxt.alpha = 1;
}
};
self.hitUpdate = function () {
self.x += 12;
@@ -136,18 +138,10 @@
/****
* Game Code
****/
-// TODOS:
-/*
-* Show some educational texts, maybe linked via a quesition mark button, or as a fake preloader screen:
-- The first and only astronaut to actually throw a javelin on the moon was Edgar Mitchell. This is an actual quote
-(about his experience of looking at earth from space):
- "You want to grab a politician by the scruff of the neck and drag him a quarter of a million miles out and say,
- "Look at that, you son of a bitch." " -End quote.
- - Include a small Earth in the distance.
-*/
// Function to create a dust particle explosion
+// TODOS:
function createDustExplosion(x, y, count) {
for (var i = 0; i < count; i++) {
var particle = new DustParticle();
particle.x = x;
@@ -220,9 +214,9 @@
thrown = true;
}
// Add a text label at the bottom of the screen: "Tap to throw the javelin"
var instructionTxt = new Text2('Tap to throw the javelin', {
- size: 65,
+ size: 100,
fill: "#ffffff"
});
instructionTxt.anchor.set(0.5, 3); // Sets anchor to the center of the bottom edge of the text.
LK.gui.bottom.addChild(instructionTxt);
@@ -239,9 +233,9 @@
anchorX: 0.5,
anchorY: 0.5
});
actionMeter.x = 1024; // Center horizontally
-actionMeter.y = 2732 - 500; // Position at the bottom of the screen
+actionMeter.y = 2732 - 600; // Position at the bottom of the screen
actionMeter.alpha = 0;
game.addChild(actionMeter);
var actionMeterPointer = new Container();
var actionMeterPointerGraphics = actionMeterPointer.attachAsset('actionMeterPointer', {
@@ -250,34 +244,44 @@
scaleX: 4,
scaleY: 4
});
actionMeterPointer.x = 1024; // Center horizontally
-actionMeterPointer.y = 2732 - 450;
+actionMeterPointer.y = 2732 - 550;
actionMeterPointer.speed = 30;
actionMeterPointer.alpha = 0;
game.addChild(actionMeterPointer);
+var midSpeed = 0.0225;
var minSpeed = 0.02;
-var maxSpeed = 0.045;
+var maxSpeed = 0.06; //0.045;
var speed = 0;
var landed = false;
var playerHit = false;
+var landedCounter = 0;
// Touch event to launch a javelin
-game.on('down', function (obj) {
+game.on('down', function (x, y, obj) {
if (!started) {
started = true;
- gameLogo.alpha = 0;
+ //gameLogo.alpha = 0;
instructionTxt.alpha = 0;
actionMeter.alpha = 1;
actionMeterPointer.alpha = 1;
} else if (!thrown) {
- speed = minSpeed + (actionMeterPointer.x - 450) / 1150 * (maxSpeed - minSpeed);
+ //speed = minSpeed + (actionMeterPointer.x - 450) / 1150 * (maxSpeed - minSpeed);
+ var min = actionMeter.x - actionMeter.width / 2;
+ var max = actionMeter.x + actionMeter.width / 2;
+ speed = (actionMeterPointer.x - min) / (max - min);
+ speed *= midSpeed;
+ speed += minSpeed;
//speed = maxSpeed - speed;
//console.log('speed ' + speed);
launchJavelin();
- instructionTxt.setText('Tap to jump');
- instructionTxt.alpha = 1;
+ //instructionTxt.setText('Tap to jump');
+ //instructionTxt.alpha = 1;
} else {
//if (astronaut.vely == 0) {
+ if (!landed) {
+ instructionTxt.alpha = 0;
+ }
if (astronaut.y >= 818) {
astronaut.vely += 10;
}
}
@@ -290,13 +294,19 @@
actionMeterPointer.speed *= -1;
}
}
if (thrown && !landed) {
+ if (astronaut.scale.x == 1 && LK.getScore() > 200) {
+ astronaut.scale.x = -1;
+ instructionTxt.setText("Don't get hit! Tap to jump!");
+ instructionTxt.alpha = 1;
+ instructionTxt.y = -1200;
+ }
for (var i = javelins.length - 1; i >= 0; i--) {
// Update the score and scorelabel text every frame when thrown is true.
LK.setScore(LK.getScore() + 100 * speed);
scoreTxt.setText(LK.getScore());
- javelins[i].move();
+ javelins[i]._move_migrated();
if (LK.getScore() > 300 && javelins[i].intersects(astronaut) && astronaut.y >= 818) {
landed = true;
createImpactExplosion(astronaut.x, astronaut.y, 20);
astronaut.removeChildAt(0);
@@ -304,12 +314,13 @@
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.PI / 2
});
- javelins[i].move = javelins[i].hitUpdate;
+ javelins[i]._move_migrated = javelins[i].hitUpdate;
playerHit = true;
- instructionTxt.setText('Uh oh :(\nTry again');
- //TODO: Make this happier
+ //instructionTxt.setText('Uh oh :(\nTry again');
+ instructionTxt.alpha = 1;
+ instructionTxt.setText('Uh oh!');
}
}
actionMeter.alpha -= 0.01;
actionMeterPointer.alpha -= 0.01;
@@ -323,14 +334,21 @@
}
if (astronaut.y < 818) {
astronaut.y += 3;
}
- if (landed) {}
+ if (landed) {
+ landedCounter++;
+ if (landedCounter >= 120) {
+ LK.showGameOver();
+ }
+ }
if (playerHit) {
- javelin.move();
- astronaut.move();
+ javelin._move_migrated();
+ astronaut._move_migrated();
+ if (javelin.x > 2500) {
+ LK.showGameOver();
+ }
}
for (var i = particles.length - 1; i >= 0; i--) {
- particles[i].update();
+ particles[i]._update_migrated();
}
-});
-// Note: The game automatically handles game over, score, and other UI elements.
\ No newline at end of file
+});
\ No newline at end of file
pixelart. a beautiful moon.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixelart a beautiful starry sky seen in empty outer space.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixelart. a javelin used for olympic games and athletics. Just the spear itself, horizontally laid out in the image. It should be a slim metal spear, pointy in both ends, and with a grip somewhere off center of the shaft.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixelart. a metallic triangular pointer.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixelart lettering of the word 'LUNAR' with some blank space around it.
replace inpainted area with transparency.
pixelart. asteroid with craters. subtle shading.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixelart. asteroid with craters. subtle shading.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A small light yellow star.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
delete the inpainted areas.
Pixelart. A background window for an in-game shop, with a space theme. The center part should be a large blank area with space for the items and labels for sale in the game shop. The blank space could have the form of a black computer screen inside a spaceship.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixelart. An icon of a an arm holding javelin with fire around it.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Turn in-painted area solid blue like the area around it.
Pixelart. A rectangular silvery button with the text 'CLOSE'.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.