Skip to content
Snippets Groups Projects
Verified Commit fa39a373 authored by TheJoeCoder's avatar TheJoeCoder
Browse files

Implement velocity changing

parent 54455094
Branches
No related tags found
No related merge requests found
......@@ -14,6 +14,9 @@ const DOT_FILL_COLOUR = "#666";
const DOT_OUTLINE_COLOUR = "#444";
const LINE_COLOUR = "#777";
const VELOCITY_SLOWDOWN_MULTIPLIER = 0.998;
const VELOCITY_PUSH_MULTIPLIER = 1.8;
// ----
// Sort-of constants (change with window size)
......@@ -211,6 +214,10 @@ const physics = () => {
dot.vx = clamp(dot.vx, -VELOCITY_MAX, VELOCITY_MAX);
dot.vy = clamp(dot.vy, -VELOCITY_MAX, VELOCITY_MAX);
// Slow down velocity
dot.vx *= VELOCITY_SLOWDOWN_MULTIPLIER;
dot.xy *= VELOCITY_SLOWDOWN_MULTIPLIER;
// Stop velocity from going below initial velocity
if(dot.vx < dot.initial_vx) {
dot.vx = dot.initial_vx;
......@@ -222,9 +229,11 @@ const physics = () => {
// Invert velocities if off-screen and not already inverted
if ((dot.x < 0 && dot.vx < 0) || (dot.x > canvas.width && dot.vx > 0)) {
dot.vx = -dot.vx;
dot.vx *= VELOCITY_PUSH_MULTIPLIER;
}
if ((dot.y < 0 && dot.vy < 0) || (dot.y > canvas.height && dot.vy > 0)) {
dot.vy = -dot.vy;
dot.vy *= VELOCITY_PUSH_MULTIPLIER;
}
// Make dots velocities react to mouse movement (deflected by mouse)
......@@ -241,6 +250,9 @@ const physics = () => {
dot.vx = -dot.vx;
dot.vy = -dot.vy;
dot.vx *= VELOCITY_PUSH_MULTIPLIER;
dot.vy *= VELOCITY_PUSH_MULTIPLIER;
dot.x = cx;
dot.y = cy;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment