Code edit (1 edits merged)
Please save this source code
User prompt
move down particle 1 by 50px
User prompt
Move particle #1 20px to the left
User prompt
Move particle #1 20px to the left
User prompt
Move particle #1 20px to the left and 30px down
User prompt
Have 4 fixed offsets for particles
User prompt
Spawn 4 particles per tick
User prompt
decrease random spacing of particles to 20
Code edit (2 edits merged)
Please save this source code
User prompt
in projectMovement reverse the angle of projection
User prompt
project movement with projectMovement before applying to car x,y
Code edit (5 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self')' in this line: 'self.projectMovement = function (vector) {' Line Number: 11
User prompt
Add a method on car that takes a movement vector and projects it 45 degrees counter clockwise
User prompt
when applying momentum to x and y on car, rotate the movement vector 45 degrees counter clockwise
User prompt
when applying momentum x and y to car, rotate the momentum 45 degrees counter clockwise first
User prompt
Update momentum such that it slows down faster in the direction the car is not traveling
User prompt
Car should move right or up rather than diagonally
User prompt
Car should have different momentum depending on the direction it's traveling in, such that it slows down in the direction it's not traveling in
Code edit (1 edits merged)
Please save this source code
User prompt
Momentum modifier should be different for X and Y, such that you loose speed faster in the direction the car is not traveling
User prompt
decrease offset x y divider to 5
User prompt
Update car logic such that it has momentum. With speed being a modifier to momentum
User prompt
add 20px randomly to x and y of particle when spawning them
User prompt
Spawn particles below the car with a random 50px offset on both x and y
===================================================================
--- original.js
+++ change.js
@@ -17,20 +17,22 @@
y: 0
};
self.move = function () {
var momentumModifier = 0.1;
- var radians = -Math.PI / 4;
- var cos = Math.cos(radians);
- var sin = Math.sin(radians);
- var rotatedMomentumX = cos * self.momentum.x - sin * self.momentum.y;
- var rotatedMomentumY = sin * self.momentum.x + cos * self.momentum.y;
+ var angle = -Math.PI / 4;
+ var cos = Math.cos(angle);
+ var sin = Math.sin(angle);
+ var deltaX = self.speed * momentumModifier;
+ var deltaY = -self.speed * momentumModifier;
if (self.direction === 0) {
- rotatedMomentumX += self.speed * momentumModifier;
+ self.momentum.x += cos * deltaX - sin * deltaY;
+ self.momentum.y += sin * deltaX + cos * deltaY;
} else {
- rotatedMomentumY -= self.speed * momentumModifier;
+ self.momentum.x += cos * deltaY - sin * deltaX;
+ self.momentum.y += sin * deltaY + cos * deltaX;
}
- self.x += rotatedMomentumX;
- self.y += rotatedMomentumY;
+ self.x += self.momentum.x;
+ self.y += self.momentum.y;
if (self.direction === 0) {
self.momentum.x *= 0.98;
self.momentum.y *= 0.95;
} else {