User prompt
Now make it so it saves your progress, so everytime you refresh the page it saves your wave, and gold ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Make it so everytime you survive a wave you get + 10 gold
User prompt
Now make a gold currency. Make a text under the wave text and make it say gold
User prompt
Make the text bigger
User prompt
And put a text in the rate asset saying Rate 1s
User prompt
Move it a little down and to the right
User prompt
Now move it a lot to the left
User prompt
Move it more down
User prompt
Move the rate asset down
User prompt
Make the rate asset bigger
User prompt
Add the rate asset
User prompt
Make it so every wave, the cube's speed gles up by 0.5%
User prompt
Ok make the waves go up once every 10 seconds
User prompt
When the game starts only spawn 5 cube assets
User prompt
ONLY 5!
User prompt
No only 5 on wave 1
User prompt
Make the cubes spawn
User prompt
Now they do not spawn anymore
User prompt
Ok but not all at once, make them spawn in one by one with a 1 second cooldown ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'cubestart.x')' in or related to this line: 'newCube.x = cubestart.x;' Line Number: 97
User prompt
When the game starts, spawn in 5 cube assets
User prompt
The cube assets arent spawning in wave 1
User prompt
When wave equals 1 spawn only 5 cube assets
User prompt
Now, when the game starts make the wave equal to 1
User prompt
Stop the cubes from spawning
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Create a new class for the cube asset
var Cube = Container.expand(function () {
var self = Container.call(this);
// Attach the cube asset to the Cube class
var cubeGraphics = self.attachAsset('Cube', {
anchorX: 0.5,
anchorY: 0.5
});
// Set the cube's speed
self.speed = 3;
// Set the cube's health
self.health = 1;
// Set the cube's health
self.health = 1;
// Update the cube's position every game tick
self.update = function () {
// Calculate the distance between the cube and the slime
var dx = slime.x - self.x;
var dy = slime.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Normalize the direction vector (dx and dy)
dx /= distance;
dy /= distance;
// Move the cube towards the slime at a constant speed
self.x += dx * self.speed;
self.y += dy * self.speed;
};
});
// Create a new class for the shoot asset
var Shoot = Container.expand(function () {
var self = Container.call(this);
// Attach the shoot asset to the Shoot class
var shootGraphics = self.attachAsset('Shoot', {
anchorX: 0.5,
anchorY: 0.5
});
// Set the shoot's speed
self.speed = 5;
// Set the shoot's damage
self.damage = 1;
// Set the shoot's damage
self.damage = 1;
// Update the shoot's position every game tick
self.update = function () {
// Move the shoot to the right at a constant speed
self.x += self.speed;
};
});
// Create a new class for the wave text
var WaveText = Text2.expand(function () {
var self = Text2.call(this, 'Wave: 0', {
size: 100,
fill: 0xFFFFFF
});
self.anchor.set(0, 0);
self.x = 50;
self.y = 50;
self.wave = 0;
self.update = function () {
self.setText('Wave: ' + self.wave);
};
});
/****
* Initialize Game
****/
// Spawn the cube asset from the cubestart asset every 60 game ticks
//<Assets used in the game will automatically appear here>
var game = new LK.Game({
backgroundColor: 0x008000 //Init game with green background
});
/****
* Game Code
****/
//<Assets used in the game will automatically appear here>
// Spawn 5 cube assets when the game starts
for (var i = 0; i < 5; i++) {
var newCube = new Cube();
newCube.x = cubestart.x;
newCube.y = cubestart.y;
game.addChild(newCube);
cubeCount++;
}
// Add slime asset to the game screen, make it 2x bigger and move it to the left
var slime = game.addChild(LK.getAsset('Slime', {
anchorX: 0.5,
anchorY: 0.5,
x: 200,
y: 1350,
// Adjusted y position to move the slime down a little
scaleX: 2,
scaleY: 2
}));
// Add menu asset to the game screen
var menu = game.addChild(LK.getAsset('Menu', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2766,
scaleX: 25,
scaleY: 25
}));
// Add cubestart asset to the game screen
var cubestart = game.addChild(LK.getAsset('Cubesstart', {
anchorX: 0.5,
anchorY: 0.5,
x: 1800,
// Moved to the right by a lot
y: 1366,
scaleX: 2,
scaleY: 2
}));
// Add the wave text to the game screen
var waveText = game.addChild(new WaveText());
// Set the wave to 1 when the game starts
var wave = 1;
waveText.wave = wave;
// Create a variable to keep track of the number of cubes
var cubeCount = 0;
game.update = function () {
// Spawn the cube asset from the cubestart asset every 60 game ticks
// Cubes are no longer spawned
// Make the slime asset shoot out the shoot asset to the right once every second
if (LK.ticks % 60 == 0) {
var newShoot = new Shoot();
newShoot.x = slime.x;
newShoot.y = slime.y;
newShoot.update = function () {
// Move the shoot to the right at a constant speed
this.x += this.speed;
};
game.addChild(newShoot);
}
// Check for collisions between Cube and Shoot objects
for (var i = 0; i < game.children.length; i++) {
var obj1 = game.children[i];
if (obj1 instanceof Cube) {
for (var j = 0; j < game.children.length; j++) {
var obj2 = game.children[j];
if (obj2 instanceof Shoot && obj1.intersects(obj2)) {
// Destroy both objects on collision
obj1.destroy();
obj2.destroy();
// Decrement cubeCount each time a cube is destroyed
cubeCount--;
// Check if all cubes from wave 1 have been destroyed
if (cubeCount === 0 && wave === 1) {
// Start wave 2
wave++;
waveText.wave++;
// Spawn only 5 cube assets when wave equals 1
if (wave === 1 && cubeCount === 0) {
for (var k = 0; k < 5; k++) {
var newCube = new Cube();
newCube.x = cubestart.x;
newCube.y = cubestart.y;
game.addChild(newCube);
cubeCount++;
}
}
}
break;
}
}
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -81,9 +81,16 @@
/****
* Game Code
****/
//<Assets used in the game will automatically appear here>
-// Spawn the cube asset from the cubestart asset every 60 game ticks
+// Spawn 5 cube assets when the game starts
+for (var i = 0; i < 5; i++) {
+ var newCube = new Cube();
+ newCube.x = cubestart.x;
+ newCube.y = cubestart.y;
+ game.addChild(newCube);
+ cubeCount++;
+}
// Add slime asset to the game screen, make it 2x bigger and move it to the left
var slime = game.addChild(LK.getAsset('Slime', {
anchorX: 0.5,
anchorY: 0.5,