Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update run.js #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/world/run.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* globals btoa */
var setupScene = require("./setup-scene");
var carRun = require("../car-schema/run");
var defToCar = require("../car-schema/def-to-car");
/*Variables changed to let for the better usage of code*/

let setupScene = require("./setup-scene");
let carRun = require("../car-schema/run");
let defToCar = require("../car-schema/def-to-car");

module.exports = runDefs;
function runDefs(world_def, defs, listeners) {
Expand All @@ -10,18 +11,18 @@ function runDefs(world_def, defs, listeners) {
world_def.floorseed = btoa(Math.seedrandom());
}

var scene = setupScene(world_def);
let scene = setupScene(world_def);
scene.world.Step(1 / world_def.box2dfps, 20, 20);
console.log("about to build cars");
var cars = defs.map((def, i) => {
let cars = defs.map((def, i) => {
return {
index: i,
def: def,
car: defToCar(def, scene.world, world_def),
state: carRun.getInitialState(world_def)
};
});
var alivecars = cars;
let alivecars = cars;
return {
scene: scene,
cars: cars,
Expand All @@ -35,19 +36,19 @@ function runDefs(world_def, defs, listeners) {
car.state = carRun.updateState(
world_def, car.car, car.state
);
var status = carRun.getStatus(car.state, world_def);
let status = carRun.getStatus(car.state, world_def);
listeners.carStep(car);
if (status === 0) {
return true;
}
car.score = carRun.calculateScore(car.state, world_def);
listeners.carDeath(car);

var world = scene.world;
var worldCar = car.car;
let world = scene.world;
let worldCar = car.car;
world.DestroyBody(worldCar.chassis);

for (var w = 0; w < worldCar.wheels.length; w++) {
for (let w = 0; w < worldCar.wheels.length; w++) {
world.DestroyBody(worldCar.wheels[w]);
}

Expand Down