Code edit (20 edits merged)
Please save this source code
User prompt
please implement obstacleturrets shootatplayer method, so it sends turretshot in players direction
User prompt
please implement obstacleTurret's lookAtPlayer function, so it does what it says
Code edit (1 edits merged)
Please save this source code
Code edit (15 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'width')' in or related to this line: 'player.radius = orbits[currentOrbitIndex].width / 2 - 65;' Line Number: 783
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'width')' in or related to this line: 'player.radius = orbits[currentOrbitIndex].width / 2 - 65;' Line Number: 767
Code edit (1 edits merged)
Please save this source code
Code edit (22 edits merged)
Please save this source code
User prompt
in the dragon move function, please adjust the segment's radius up and down to convey a wavelike, snakelike slithering movement of the whole dragons body.
Code edit (1 edits merged)
Please save this source code
Code edit (10 edits merged)
Please save this source code
User prompt
implement the obstacleseeker function determineDirection
Code edit (10 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'update')' in or related to this line: 'particles[i].update();' Line Number: 706
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
before gameover, show a screen for five seconds, with the text: "Orbits jumped: XX\nEnergy Collected: YY\nFinal Score: (XX+YY) = ZZ"
Code edit (15 edits merged)
Please save this source code
User prompt
when a collectible is collected, show a little textlabel with the text "+1" floating up from the point instead of flashing the screen blue.
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'update')' in or related to this line: 'particles[i].update();' Line Number: 650
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of null (reading 'width')' in or related to this line: 'self.radius = self.parent.width / 2 * (1900 / self.parent.width) - self.width / 2; // * (100 / self.width);' Line Number: 59
Code edit (1 edits merged)
Please save this source code
/****
* Classes
****/
var Collectible = Container.expand(function (i) {
var self = Container.call(this);
var particleGraphics = self.attachAsset('energyPill', {
anchorX: 0.5,
anchorY: 0.5
});
self.orbitSpeed = 0; // set by the orbit that spawns it.
self.growing = Math.random() <= 0.5 ? true : false;
self._move_migrated = function () {
self.radius = self.parent.width / 2 * (1900 / self.parent.width) - self.width / 2 * (100 / self.width);
self.angle = (self.angle || 0) + self.orbitSpeed;
self.angle %= Math.PI * 2;
self.x = self.radius * Math.cos(self.angle);
self.y = self.radius * Math.sin(self.angle);
// Pulse effect
if (self.growing) {
if (self.scale.x < 1.1) {
self.scale.x += 0.025;
self.scale.y += 0.025;
} else {
self.growing = false;
}
} else {
if (self.scale.x > 0.9) {
self.scale.x -= 0.025;
self.scale.y -= 0.025;
} else {
self.growing = true;
}
}
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.orbitSpeed = 0; // This is set by the Orbit that instantiates this obstacle, so obstacles in same orbit have same speed.
self.rotatingRight = Math.random() < 0.5 ? true : false;
self.radius = self.parent.width / 2 * (1900 / self.parent.width) - self.width / 2; // * (100 / self.width);
self._move_migrated = function () {
//self.radius = self.parent.width / 2 * (1900 / self.parent.width) - self.width / 2 * (100 / self.width);
//self.radius = self.parent.width / 2 * (1900 / self.parent.width) - self.width / 2; // * (100 / self.width);
self.angle = (self.angle || 0) + self.orbitSpeed;
self.angle %= Math.PI * 2;
self.x = self.radius * Math.cos(self.angle);
self.y = self.radius * Math.sin(self.angle);
if (ENEMY_WOBBLE) {
if (self.rotatingRight) {
if (self.rotation < 0.15) {
self.rotation += 0.05;
} else {
self.rotatingRight = false;
}
} else {
if (self.rotation > -0.15) {
self.rotation -= 0.05;
} else {
self.rotatingRight = true;
}
}
}
};
});
// Orbit class
var Orbit = Container.expand(function () {
var self = Container.call(this);
var orbitGraphics = self.attachAsset('orbit1', {
anchorX: 0.5,
anchorY: 0.5,
//tint: Math.floor(Math.random() * 16777215)
tint: rainbowColors[orbitsCreated % rainbowColors.length]
});
orbitsCreated++;
orbitGraphics.alpha = 0.5; //0.5;
self.direction = Math.random() < 0.5 ? 1 : -1;
self.positionOrbit = function (i) {
self.x = 2048 / 2;
self.y = 2732 / 2;
//this.width = 1900 - i * 500;
self.width = self.height = 1900 - i * 500;
if (i !== 0) {
// Spawn normal enemies
self.numBarriers = Math.ceil(Math.random() * maxEnemiesPerOrbit);
if (self.numBarriers > maxEnemiesPerOrbit) {
self.numBarriers = maxEnemiesPerOrbit;
}
// Add powerup to some orbits
if (orbitsCreated % 17 == 0) {
self.numBarriers = 0;
self.addPowerup();
}
// We might want some static orbits. And max speed should be limited by total progression.
if (Math.random() <= 0.2) {
self.barrierSpeed = 0;
} else {
// The global var maxEnemySpeed is incremented every 10 obits or so.
self.barrierSpeed = maxEnemySpeed * Math.random() * self.direction;
}
//self.barrierSpeed = 0.01 + Math.random() * 0.015 * self.direction;
for (var j = 0; j < this.numBarriers; j++) {
self.addBarrier(self.barrierSpeed, j);
//console.log('adding barrier: ', j);
}
self.addCollectible();
}
};
/*
var orbitGraphicsMask = self.attachAsset('blackSphere', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0x000000
//tint: rainbowColors[(orbitsCreated + 1) % rainbowColors.length]
});
orbitGraphicsMask.alpha = 0;
orbitGraphicsMask.width = self.width - 200;
orbitGraphicsMask.height = self.height - 200;
*/
self.addBarrier = function (speed, index) {
var barrier = new Obstacle();
barrier.orbitSpeed = speed;
//barrier.angle = index * (Math.PI * 2 / 20);
barrier.angle = Math.random() * (Math.PI * 2);
/*
barrier.move = function () {
barrier.angle += barrier.orbitSpeed * (self.direction === 1 ? 1 : -1);
barrier.x = self.x + (self.width - barrier.width) / 2 * Math.cos(barrier.angle);
barrier.y = self.y + (self.height - barrier.height) / 2 * Math.sin(barrier.angle);
};*/
self.addChild(barrier);
obstacles.push(barrier);
};
//self.addPowerup = function (index) {
self.addPowerup = function () {
for (var i = 0; i < 5; i++) {
var powerup = new Powerup1();
powerup.angle = Math.PI * 1.5 - i * 0.08;
powerup.scale.x = 1 - (i + 1) * 0.15;
powerup.scale.y = 1 - (i + 1) * 0.15;
self.addChild(powerup);
obstacles.push(powerup);
}
};
self.addCollectible = function () {
var collectible = new Collectible();
// TODO: Maybe orbitspeed should always be 0 (or close to 0) for these collectibles, But they should pulse in place instead.
//collectible.orbitSpeed = 0.01 + Math.random() * 0.015 * self.direction;
collectible.orbitSpeed = 0.0005 * self.direction;
collectible.angle = Math.random() * (Math.PI * 2);
self.addChild(collectible);
obstacles.push(collectible);
};
});
var Particle = Container.expand(function (i) {
var self = Container.call(this);
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
self.id = i;
//self.speed = 8;
self.dead = false;
particleGraphics.blendMode = 3;
self.alpha = 0.75;
self.rotation = Math.random() * Math.PI * 2;
self.update = function () {
// TODO: Figure out how to update when we actually ARE scaling/jumping.
if (!scaling) {
//self.y += self.speed;
self.alpha -= 0.001;
self.scale.x -= 0.02;
self.scale.y -= 0.02;
//if (self.alpha <= 0 || LK.ticks % (self.id + 1 * 1) == 0) {
//if (LK.ticks % (self.id + 1 * 1) == 0) {
if (LK.ticks % (self.id + 1) == 0 || self.scale.x < 0) {
self.alpha = 0.75;
self.scale.x = 1;
self.scale.y = 1;
self.y = player.y; // + Math.random() * player.height / 4; // + player.height / 2 + (Math.random() * 50 - 25);
self.x = player.x; // + Math.random() * player.width / 4; // + (Math.random() * 50 - 25);
}
}
};
});
// Initialize player
/****
TODO:
* What if holding mouse down didn't just stall movement, but move player the other way?
* Maybe rotate enemies a little bit every frame, back and forth, so that they seem more alive and less alike. (Looks a bit silly).
* Update the instructions to explain the new hold to stall mechanic.
* Maybe only allow hold for as long as collected energy from collectibels allows? Show a draining meter live when player holds.
* I often accidently press play again on game over, so maybe make an extra screen before gameover is shown.
* Collectibles and a shop (but a shop for what?) Lives?
* Implement the seeker type enemy.
* Slower movement at start, then it increases as game progresses.
* Figure out why stuff shows up in the center on start?
* Center items better on orbits, or get better orbit graphics (by manual upload perhaps?)
* Sound & Music.
* Make sure orbits don't have too many obstacles.
* Maybe skip player and obstacle updating while scaling?
* Current min and max speeds of obstacles should be closer to each other.
* Rotate orbits with obstacles statically distributed on them instead of calculating obstacle positions (for performance).
* Would also be cool to be able to jump in AND out of orbits, but hard to implement. Or maybe just tap on the orbit to go to?
****/
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = 890;
self.angle = 0;
self.jump = function () {
currentOrbitIndex++;
var targetOrbit = orbits[currentOrbitIndex];
self.angle = Math.atan2(self.y - centerY, self.x - centerX);
if (targetOrbit) {
//self.radius = (targetOrbit.width - 100) / 2;
self.radius = targetOrbit.width / 2;
//console.log('self.radius after setting it to targetOrbits: ' + self.radius);
} else {
self.radius = 0; // Fallback radius if targetOrbit is not defined
}
self.x = centerX + self.radius * Math.cos(self.angle);
self.y = centerY + self.radius * Math.sin(self.angle);
game.setBackgroundColor(rainbowColors[(orbitsCreated + 4) % rainbowColors.length]);
//self.scale.x = 0.70;
//self.scale.y = 0.70;
self.width = 70;
self.height = self.width;
scaling = true;
LK.setScore(LK.getScore() + 1);
scoreText.setText(LK.getScore());
/*
var orbit = game.addChild(new Orbit());
orbit.positionOrbit(4);
orbits.push(orbit);
// Move player to the topmost z-index
game.setChildIndex(player, game.children.length - 1);
*/
};
self._update_migrated = function () {
//self.angleSpeed = 0.01;
//self.angle = (self.angle || 0) + self.angleSpeed;
self.angle = (self.angle || 0) + playerSpeed;
self.x = centerX + self.radius * Math.cos(self.angle);
self.y = centerY + self.radius * Math.sin(self.angle);
};
});
// Powerup class
var Powerup1 = Container.expand(function () {
var self = Container.call(this);
var powerup1Graphics = self.attachAsset('powerup2', {
anchorX: 0.5,
anchorY: 0.5
});
//self.angleSpeed = 0.01;
//self.orbitSpeed = 0.075;
self.orbitSpeed = 0.055;
self._move_migrated = function () {
//self.radius = self.parent.width / 2 * (1900 / self.parent.width) - self.width / 2 * (100 / self.width) + 10;
self.radius = self.parent.width / 2 * (1900 / self.parent.width) - self.width / 2 * (100 / self.width) + 2;
self.angle = (self.angle || 0) + self.orbitSpeed;
self.x = self.radius * Math.cos(self.angle);
self.y = self.radius * Math.sin(self.angle);
self.rotation += 0.1;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x444488 // Init game with black background
});
/****
* Game Code
****/
/****
TODO:
* What if holding mouse down didn't just stall movement, but move player the other way?
* Update the instructions to explain the new hold to stall mechanic.
* I often accidently press play again on game over, so maybe make an extra screen before gameover is shown.
* Collectibles and a shop (but a shop for what?) Lives?
* Implement the seeker type enemy.
* Slower movement at start, then it increases as game progresses.
* Figure out why stuff shows up in the center on start?
* Center items better on orbits, or get better orbit graphics (by manual upload perhaps?)
* Sound & Music.
* Make sure orbits don't have too many obstacles.
* Maybe skip player and obstacle updating while scaling?
* Current min and max speeds of obstacles should be closer to each other.
* Rotate orbits with obstacles statically distributed on them instead of calculating obstacle positions (for performance).
* Would also be cool to be able to jump in AND out of orbits, but hard to implement. Or maybe just tap on the orbit to go to?
****/
// Initialize player
var centerX = 2048 / 2;
var centerY = 2732 / 2;
var ENEMY_WOBBLE = false;
var PARTICLES_ON = true;
var INCREASE_DIFFICULTY_EVERY_X_LEVELS = 15;
var maxEnemiesPerOrbit = 2;
var fullscreenBackground = LK.getAsset('fullscreenBackground', {
anchorX: 0.507,
anchorY: 0.46,
x: 2048 / 2,
y: 2732 / 2,
alpha: 0.5
});
game.addChild(fullscreenBackground);
function hsvToHex(h, s, v) {
var r, g, b, i, f, p, q, t;
i = Math.floor(h * 6);
f = h * 6 - i;
p = v * (1 - s);
q = v * (1 - f * s);
t = v * (1 - (1 - f) * s);
switch (i % 6) {
case 0:
r = v, g = t, b = p;
break;
case 1:
r = q, g = v, b = p;
break;
case 2:
r = p, g = v, b = t;
break;
case 3:
r = p, g = q, b = v;
break;
case 4:
r = t, g = p, b = v;
break;
case 5:
r = v, g = p, b = q;
break;
}
var toHex = function toHex(x) {
var hex = Math.round(x * 255).toString(16);
return hex.length === 1 ? '0' + hex : hex;
};
return '0x' + toHex(r) + toHex(g) + toHex(b);
}
//console.log(rainbowColors);
// A for our purposes optimized hitdetection, based on orbit layer and angle.
var radIntersects = function radIntersects(p, t) {
if (t.parent == orbits[currentOrbitIndex]) {
var pa = (p.angle * (180 / Math.PI) + 180) % 360;
var ta = (t.angle * (180 / Math.PI) + 180) % 360;
if (Math.abs(pa - ta) < 6) {
return true;
} else {
return false;
}
} else {
return false;
}
};
var powerupText;
var showPowerupText = function showPowerupText() {
powerupText = new Text2('Powerup Activated!\nAll visible obstacles cleared!\nTap to continue', {
size: 100,
fill: "#bbbbbb",
align: 'center',
stroke: "#000000",
strokeThickness: 10
});
powerupText.y = 2700 / 2;
powerupText.x = 2048 / 2;
powerupText.anchor.set(0.5, 0.5);
//instructionText.x = 2048 / 2; // Center horizontally
//instructionText.y = 2732 - instructionText.height / 2; // Position at the bottom
game.addChild(powerupText);
LK.setTimeout(function () {
var fadeDuration = 4000;
var fadeStep = 30;
var fadeInterval = fadeDuration / fadeStep;
var currentStep = 0;
var fadeOutInterval = LK.setInterval(function () {
if (powerupText) {
powerupText.alpha -= 1 / fadeStep;
}
currentStep++;
if (currentStep >= fadeStep) {
LK.clearInterval(fadeOutInterval);
game.removeChild(powerupText);
powerupText = null;
}
}, fadeInterval);
}, 0);
};
// Initialize assets used in this game.
// Game variables
var player;
var playerSpeed = 0.005; //0.01;
var maxEnemySpeed = 0.01;
var collectiblesCollected = 0;
var orbits = [];
var obstacles = [];
var currentOrbitIndex = 0;
var scaling = false;
var scalingCounter = 0;
var scalingSpeed = 50;
var scalingTarget = 500;
var numColors = 18;
var orbitsCreated = Math.floor(Math.random() * numColors);
var rainbowColors = function () {
var colors = [];
for (var i = 0; i < numColors; i++) {
var hue = i * (360 / numColors) % 360;
colors.push(hsvToHex(hue / 360, 1, 1));
}
return colors;
}();
var powerup1Activated = false;
// Initialize player
var scoreText = new Text2('0', {
size: 150,
align: 'center',
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 20,
anchorX: 0.5
});
LK.gui.top.addChild(scoreText);
scoreText.x -= 40;
// Initialize orbits
function createOrbits() {
for (var i = 0; i < 5; i++) {
var orbit = game.addChild(new Orbit());
orbit.positionOrbit(i);
orbits.push(orbit);
}
}
createOrbits();
// Add instruction text at the bottom of the screen
var instructionText = new Text2('Tap to jump to the next orbit.\nDon\'t hit the red obstacles.', {
size: 50,
fill: "#bbbbbb",
align: 'center'
});
instructionText.y = 163;
instructionText.x = 50;
instructionText.anchor.set(0.5, 0);
//instructionText.x = 2048 / 2; // Center horizontally
//instructionText.y = 2732 - instructionText.height / 2; // Position at the bottom
LK.gui.top.addChild(instructionText);
//game.setBackgroundColor(rainbowColors[7] + 0xdddddd);
var playerLayer = new Container();
//player = game.addChild(new Player());
player = playerLayer.addChild(new Player());
game.addChild(playerLayer);
var particles = [];
if (PARTICLES_ON) {
var particleContainer = new Container();
//game.addChild(particleContainer);
playerLayer.addChild(particleContainer);
// Initialize particles array
//var particles = [];
// Create particles
for (var i = 0; i < 40; i++) {
var particle = new Particle(i);
particle.x = player.x;
particle.y = player.y; // + player.height * 3;
particleContainer.addChild(particle);
particles.push(particle);
}
}
//player.x = 2048 / 2;
//player.y = 2732 / 2 - 200; // Start the player 200px above the center
/*
console.log('Player radius is now: ' + player.radius);
console.log('Orbits.length is now: ' + orbits.length);
console.log('CurrentOrbitIndex is now: ' + currentOrbitIndex);
console.log('width of currentorbit is now: ' + orbits[currentOrbitIndex].width);
*/
function increaseDifficulty() {
maxEnemiesPerOrbit++;
maxEnemySpeed += 0.002;
playerSpeed += 0.002;
}
var stalling = false;
// Game logic
game.on('down', function (x, y, obj) {
if (!stalling) {
stalling = true;
}
});
game.on('up', function (x, y, obj) {
if (powerupText) {
game.removeChild(powerupText);
powerupText = null;
}
if (!scaling) {
player.jump(currentOrbitIndex);
LK.gui.top.removeChild(instructionText);
if (orbitsCreated % INCREASE_DIFFICULTY_EVERY_X_LEVELS == 0) {
//maxEnemiesPerOrbit++;
//maxEnemySpeed += 0.002;
increaseDifficulty();
}
}
if (stalling) {
stalling = false;
}
});
LK.on('tick', function () {
if (!stalling) {
player._update_migrated();
}
var t;
if (powerup1Activated) {
powerup1Activated = false;
for (var i = obstacles.length - 1; i > 0; i--) {
t = obstacles[i];
if (t instanceof Collectible == false) {
t.destroy();
t._destroyed = true;
}
}
}
if (scaling) {
scalingCounter++;
for (var i = 0; i < orbits.length; i++) {
t = orbits[i];
t.width += scalingSpeed;
t.height += scalingSpeed;
//player.radius += scalingSpeed * 0.1;
}
//player.radius = orbits[currentOrbitIndex].width / 2 - 50;
player.radius = orbits[currentOrbitIndex].width / 2 - 65;
if (player.width < 100) {
player.width += 0.3;
player.height = player.width;
}
//player.scale.x = player.scale.y =
if (scalingCounter == scalingTarget / scalingSpeed) {
scaling = false;
scalingCounter = 0;
var orbit = game.addChild(new Orbit());
orbit.positionOrbit(4);
orbits.push(orbit);
//game.setChildIndex(player, game.children.length - 1);
game.setChildIndex(playerLayer, game.children.length - 1);
player.width = 100;
player.height = 100;
//game.setBackgroundColor(rainbowColors[(10 + currentOrbitIndex) % 15] + 0xdddddd);
/*
console.log('Player radius is now: ' + player.radius);
console.log('Orbits.length is now: ' + orbits.length);
console.log('CurrentOrbitIndex is now: ' + currentOrbitIndex);
console.log('width of currentorbit is now: ' + orbits[currentOrbitIndex].width);
*/
}
}
// Update orbits
for (var i = orbits.length - 1; i > 0; i--) {
//orbits[i].positionOrbit(i);
var orb = orbits[i];
//if (orb && orb.width > 2700) {
if (orb && orb.width > 3500) {
for (var j = 0; j < orb.children.length; j++) {
t = orb.children[j];
if (t instanceof Obstacle || t instanceof Powerup1) {
// child is an instance of YourClass, do something with it
t._destroyed = true;
}
}
//orbits[i].destroy();
orb.destroy();
// Splice alters jump logic, so alter currentTargetOrbit too.
orbits.splice(i, 1);
currentOrbitIndex--;
}
}
// Update obstacles
for (var i = obstacles.length - 1; i > 0; i--) {
t = obstacles[i];
//if (obstacles[i] && !obstacles[i]._destroyed) {
if (t && !t._destroyed) {
//obstacles[i]._move_migrated();
t._move_migrated();
//if (player.intersects(obstacles[i])) {
//if (radIntersects(player, obstacles[i])) {
if (radIntersects(player, t)) {
//var t = obstacles[i];
//console.log('collision occurred: (obstacle:', t.radius, t.angle % (Math.PI * 2), ') , (player: ', player.radius, player.angle % (Math.PI * 2));
//var ta = (t.angle * (180 / Math.PI) + 180) % 360;
//var pa = (player.angle * (180 / Math.PI) + 180) % 360;
//console.log(ta, pa);
//if (radIntersects(player, obstacles[i], 100)) {
//if (obstacles[i] instanceof Powerup1) {
if (t instanceof Powerup1) {
//obstacles[i].destroy();
t.destroy();
//obstacles[i]._destroyed = true;
t._destroyed = true;
if (!powerup1Activated) {
LK.effects.flashScreen(0xffffff, 1000);
//LK.effects.flashScreen(rainbowColors[Math.floor(Math.random() * numColors)], 1000);
powerup1Activated = true;
showPowerupText();
}
} else if (t instanceof Collectible) {
t.destroy();
t._destroyed = true;
collectiblesCollected++;
LK.effects.flashScreen(0x0000ff, 300);
} else {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
} else {
obstacles.splice(i, 1);
//console.log('obstacles.length is now: ' + obstacles.length);
}
}
if (PARTICLES_ON) {
for (var i = particles.length - 1; i > 0; i++) {
particles[i].update();
}
}
});
Make the circle completely black on all pixels.
A white star. Flat vector art.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
The line-color should be white, and the circle a bit thinner.
a wonderful but not very dense starfield. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A glowing blue comic energy orb. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
I'd like a top down image of a super fine and thin white empty cicular band on a transparent background. It should be flatly white and with no other details, and of course perfectly round with blank space in the center. The band's width should be less than one percent of the width of the circle itself, as if a 1 cm band were laid out in a circle with a diameter of 100 cm. Single Game Texture. In-Game asset. 2d. Blank background.