diff --git a/javascript/newsim.js b/javascript/newsim.js index 4458761..cbe641d 100644 --- a/javascript/newsim.js +++ b/javascript/newsim.js @@ -2,7 +2,6 @@ let images = {}; let simulator = []; let maxSpeed = 1; let backgroundImage; -let worldScale; let LEFT = [-1,0]; const entityTypes = Object.freeze({ @@ -69,18 +68,18 @@ function createEntity(x, y, vx, vy, ax, ay, rot, rotv, type, id=0, iframes=Math. } }else{ simulator.push({ - x: x, - y: y, - ax: ax, - ay: ay, - vx: vx, - vy: vy, - rot: rot, - rotv: rotv, - mass: getMass(type), - forcex: 0.0, - forcey: 0.0, - type: type, + x: x, + y: y, + ax: ax, + ay: ay, + vx: vx, + vy: vy, + rot: rot, + rotv: rotv, + mass: getMass(type), + forcex: 0.0, + forcey: 0.0, + type: type, show: true, ueid: id, iframes: iframes @@ -103,11 +102,11 @@ function getRandomType(){ function physicsUpdate(entity){ if (entity.show){ - entity.vx += entity.ax; - entity.vy += entity.ay; - entity.x += entity.vx; - entity.y += entity.vy; - entity.rot += entity.rotv; + entity.vx += entity.ax; + entity.vy += entity.ay; + entity.x += entity.vx; + entity.y += entity.vy; + entity.rot += entity.rotv; if (entity.iframes > 0) entity.iframes -= 1; if (entity.iframes == 0) simulator.forEach((other_entity) =>{ checkCollision(entity, other_entity); @@ -117,7 +116,7 @@ function physicsUpdate(entity){ function checkCollision(entity1, entity2){ if (entity1.type == entityTypes.COMET && entity2.type == entityTypes.COMET){ - + }else if (entity1.ueid != entity2.ueid && entity1.show && entity2.show){ @@ -129,11 +128,11 @@ function checkCollision(entity1, entity2){ line(entity1.x,entity1.y, entity2.x, entity2.y); console.log("Collision at", entity1.x, entity1.y, entity1.iframes, entity2.x, entity2.y, dist); } - Explode(entity1); + Explode(entity1); Explode(entity2); } } - } +} function Explode(entity){ if(entity.type == entityTypes.METERORITE_SMALL){ @@ -143,12 +142,12 @@ function Explode(entity){ entity.type = entityTypes.METERORITE_SMALL entity.iframes = 1000; createEntity(entity.x, entity.y, entity.vx + Math.random(), entity.vy + Math.random(), 0.0,0.0,0.0,0.0, entityTypes.METERORITE_SMALL, id=entity.ueid, iframes=1000); - } - + } + } function BlackHole(x,y,m,entity){ - + } function drawBackground(refImage){ @@ -163,16 +162,16 @@ function drawBackground(refImage){ function drawEntity(entity){ if (entity.show){ - push(); - imageMode(CENTER); + push(); + imageMode(CENTER); translate(entity.x, entity.y, 0); - if (entity.type == entityTypes.COMET){ - rotate((Math.atan2(entity.vx, entity.vy) - Math.atan2(-1,0)) * 180/Math.PI); - }else{ - rotate(entity.rot); - } - image(images[entity.type], 0,0); - pop(); + if (entity.type == entityTypes.COMET){ + rotate((Math.atan2(entity.vx, entity.vy) - Math.atan2(-1,0)) * 180/Math.PI); + }else{ + rotate(entity.rot); + } + image(images[entity.type], 0,0); + pop(); } } @@ -190,7 +189,7 @@ function setup(){ describe("A space physics simulator"); canvas.position(0,0); - worldScale = createSlider(); + //Load Entities for(var i = 0; i <= Settings.entityCount; i+=1){ @@ -214,7 +213,6 @@ function mouseClicked(){ simulator.forEach((entity) =>{ }) - console.log(worldScale.value()); } function draw(){