diff --git a/js/canvas.js b/js/canvas.js index d9c815d..100f1a0 100644 --- a/js/canvas.js +++ b/js/canvas.js @@ -57,8 +57,8 @@ function animatePacket(packets, allEntities) { //console.log(sliderVal); //console.log(iterations); for (let packet of packets) { - var dxCompute = (packet.x - packet.nextEntity.x) / iterations; - packet.dx = dxCompute; + packet.dxX = (packet.x - packet.nextEntity.x) / iterations; + packet.dxY = (packet.y - packet.nextEntity.y) / iterations; } runSim(packets, allEntities); @@ -161,8 +161,11 @@ async function startSimulation() { ddd.garbage = garbage; router.nextEntity = ddd; } + let server = new Server(1200, y, router, packetsPerTimeUnit); + client.nextEntity = server; + garbage.nextEntity = server; garbage.packetsPerTimeUnit = 1; diff --git a/js/packet.js b/js/packet.js index 97457f9..4bbae9f 100644 --- a/js/packet.js +++ b/js/packet.js @@ -3,7 +3,8 @@ export class Packet{ // Animation instance variables this.x = x; this.y = y; - this.dx; + this.dxY; + this.dxX; this.radius = radius; this.nextEntity; this.ctx = ctx; @@ -34,12 +35,8 @@ export class Packet{ this.done = true; return; } - if (this.dropped == true) { - this.x -= this.dx; - this.y -= this.dx; - } else { - this.x -= this.dx; - } + this.x -= this.dxX; + this.y -= this.dxY; this.draw(); }