/****
* Classes
****/
// Bot class to represent a bot in the game
var Bot = Container.expand(function () {
var self = Container.call(this);
// Create and attach a simple circle shape for the bot
var botGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
// Initialize bot properties
self.vx = 0; // Velocity in x direction
self.vy = 0; // Velocity in y direction
// Update function to move the bot
self.targetX = 2048 / 2;
self.targetY = 2732 / 2;
botGraphics.blendMode = 1;
self.update = function () {
// Calculate the direction towards the target
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Normalize the direction and apply a simple gravity effect
if (distance > 0) {
dx /= distance;
dy /= distance;
}
// Apply gravity towards the target
var speedModifier = 1 + distance / 300;
self.vx += dx;
self.vy += dy;
//Spped modifier
// Update bot position
self.x += self.vx;
self.y += self.vy;
var speed = Math.sqrt(self.vx * self.vx + self.vy * self.vy);
if (distance > 100) {
self.vx *= .995;
self.vy *= .995;
} else {
self.vx += (Math.random() - .5) / 1000;
self.vy += (Math.random() - .5) / 1000;
}
// Rotate the bot based on the direction
self.rotation = Math.atan2(self.vy, self.vx);
self.scaleX = Math.min(Math.max(speed / 10, 0), 1.5);
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Particle class to represent each particle in the game
var Particle = Container.expand(function () {
var self = Container.call(this);
// Create and attach a simple circle shape for the particle
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
// Initialize particle properties
self.vx = 0; // Velocity in x direction
self.vy = 0; // Velocity in y direction
// Update function to move the particle
self.targetX = 2048 / 2;
self.targetY = 2732 / 2;
particleGraphics.blendMode = 1;
self.update = function () {
// Calculate the direction towards the mouse
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Normalize the direction and apply a simple gravity effect
if (distance > 0) {
dx /= distance;
dy /= distance;
}
// Apply gravity towards the mouse
var speedModifier = 1 + distance / 300;
self.vx += dx;
self.vy += dy;
//Spped modifier
// Update particle position
self.x += self.vx;
self.y += self.vy;
var speed = Math.sqrt(self.vx * self.vx + self.vy * self.vy);
if (distance > 100) {
self.vx *= .995;
self.vy *= .995;
} else {
self.vx += (Math.random() - .5) / 1000;
self.vy += (Math.random() - .5) / 1000;
}
// Rotate the particle based on the direction
self.rotation = Math.atan2(self.vy, self.vx);
self.scaleX = Math.min(Math.max(speed / 10, 0), 1.5);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize particles array
var particles = [];
// Create 1000 particles and add them to the game
for (var i = 0; i < 2500; i++) {
var particle = new Particle();
particle.x = Math.random() * 2048; // Random initial x position
particle.y = Math.random() * 2732; // Random initial y position
particle.targetX = 2048 / 2; // Set initial target X to the center of the screen
particle.targetY = 2732 / 2; // Set initial target Y to the center of the screen
particles.push(particle);
game.addChild(particle);
}
// Create a bot and add it to the game
var bot = new Bot();
bot.x = 2048 / 2; // Initial x position
bot.y = 2732 / 2; // Initial y position
game.addChild(bot);
// Handle mouse move events to update particle gravity
game.move = function (x, y, obj) {
// Update each particle with the current mouse position
particles.forEach(function (particle) {
particle.targetX = x;
particle.targetY = y;
});
};
game.down = function (x, y, obj) {
game.move(x, y, obj);
particles.forEach(function (particle) {
var dx = x - particle.x;
var dy = y - particle.y;
var angle = Math.atan2(dy, dx);
var distance = Math.sqrt(dx * dx + dy * dy);
particle.vx += Math.cos(angle) * (distance / (50 + Math.random()) + 3);
particle.vy += Math.sin(angle) * (distance / (50 + Math.random()) + 3);
});
}; ===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,53 @@
/****
* Classes
****/
+// Bot class to represent a bot in the game
+var Bot = Container.expand(function () {
+ var self = Container.call(this);
+ // Create and attach a simple circle shape for the bot
+ var botGraphics = self.attachAsset('particle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Initialize bot properties
+ self.vx = 0; // Velocity in x direction
+ self.vy = 0; // Velocity in y direction
+ // Update function to move the bot
+ self.targetX = 2048 / 2;
+ self.targetY = 2732 / 2;
+ botGraphics.blendMode = 1;
+ self.update = function () {
+ // Calculate the direction towards the target
+ var dx = self.targetX - self.x;
+ var dy = self.targetY - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ // Normalize the direction and apply a simple gravity effect
+ if (distance > 0) {
+ dx /= distance;
+ dy /= distance;
+ }
+ // Apply gravity towards the target
+ var speedModifier = 1 + distance / 300;
+ self.vx += dx;
+ self.vy += dy;
+ //Spped modifier
+ // Update bot position
+ self.x += self.vx;
+ self.y += self.vy;
+ var speed = Math.sqrt(self.vx * self.vx + self.vy * self.vy);
+ if (distance > 100) {
+ self.vx *= .995;
+ self.vy *= .995;
+ } else {
+ self.vx += (Math.random() - .5) / 1000;
+ self.vy += (Math.random() - .5) / 1000;
+ }
+ // Rotate the bot based on the direction
+ self.rotation = Math.atan2(self.vy, self.vx);
+ self.scaleX = Math.min(Math.max(speed / 10, 0), 1.5);
+ };
+});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Particle class to represent each particle in the game
var Particle = Container.expand(function () {
@@ -71,8 +117,13 @@
particle.targetY = 2732 / 2; // Set initial target Y to the center of the screen
particles.push(particle);
game.addChild(particle);
}
+// Create a bot and add it to the game
+var bot = new Bot();
+bot.x = 2048 / 2; // Initial x position
+bot.y = 2732 / 2; // Initial y position
+game.addChild(bot);
// Handle mouse move events to update particle gravity
game.move = function (x, y, obj) {
// Update each particle with the current mouse position
particles.forEach(function (particle) {