/****
* Classes
****/
//<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.update = function (mouseX, mouseY) {
// Calculate the direction towards the mouse
var dx = mouseX - self.x;
var dy = mouseY - 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
self.vx += dx * 0.1;
self.vy += dy * 0.1;
// Update particle position
self.x += self.vx;
self.y += self.vy;
};
});
/****
* 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 < 1000; i++) {
var particle = new Particle();
particle.x = Math.random() * 2048; // Random initial x position
particle.y = Math.random() * 2732; // Random initial y position
particles.push(particle);
game.addChild(particle);
}
// 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.update(x, y);
});
}; ===================================================================
--- original.js
+++ change.js
@@ -1,70 +1,63 @@
-/****
+/****
* Classes
-****/
+****/
//<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.update = function (mouseX, mouseY) {
- // Calculate the direction towards the mouse
- var dx = mouseX - self.x;
- var dy = mouseY - 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
- self.vx += dx * 0.1;
- self.vy += dy * 0.1;
- // Update particle position
- self.x += self.vx;
- self.y += self.vy;
- };
+ 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.update = function (mouseX, mouseY) {
+ // Calculate the direction towards the mouse
+ var dx = mouseX - self.x;
+ var dy = mouseY - 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
+ self.vx += dx * 0.1;
+ self.vy += dy * 0.1;
+ // Update particle position
+ self.x += self.vx;
+ self.y += self.vy;
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ 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 < 1000; i++) {
- var particle = new Particle();
- particle.x = Math.random() * 2048; // Random initial x position
- particle.y = Math.random() * 2732; // Random initial y position
- particles.push(particle);
- game.addChild(particle);
+ var particle = new Particle();
+ particle.x = Math.random() * 2048; // Random initial x position
+ particle.y = Math.random() * 2732; // Random initial y position
+ particles.push(particle);
+ game.addChild(particle);
}
// 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.update(x, y);
- });
-};
-// Update function called every game tick
-game.update = function () {
- // Update each particle's position
- particles.forEach(function (particle) {
- particle.update(game.mouseX, game.mouseY);
- });
+ // Update each particle with the current mouse position
+ particles.forEach(function (particle) {
+ particle.update(x, y);
+ });
};
\ No newline at end of file