public async void gameLoop() { DateTime oldTick = DateTime.UtcNow; DateTime newTick = DateTime.UtcNow; SimulationParams simulationParams = new SimulationParams(new TimeSpan(), new TimeSpan()); GalaxyBuilder galaxyBuilder = new GalaxyBuilder(); _collisionDetection = new QuadTreeCollision(); _pathing = new BFSearch(); IsPaused = false; while (true) { var file = ViewController.hasFile(); if (file?.Length > 0) { Map Galaxy = galaxyBuilder.buildGalaxy(loadGalaxy(file)); ModelController = new ModelController(Galaxy); simulationParams.TotalTime = TimeSpan.Zero; ContainsGalaxy = true; SimulationSpeed = 2; file = null; ViewController.resetFile(); ViewController.setSpeedText("X" + SimulationSpeed); } //simulationLoop while (ContainsGalaxy && ViewController.MainView.File == null) { newTick = DateTime.UtcNow; //TODO: check public and private everywhere (blijft hier tot dpa deadline //unit testing is 15% van het punt, voeg ze voor dpa toe //TODO: gebruik reflection factory voor behaviours inputControl(ViewController.getKeyPressed()); simulationParams.SetDelta(newTick - oldTick, SimulationSpeed); ModelController.runGameTick(simulationParams); //collision related code ModelController.CurMap.celestialBodies = _collisionDetection.Collide(ModelController.CurMap.celestialBodies); if (debugMode) //this should only be enabled for the algorithm assignment, but it is a cool showcase of the program { ViewController.bounds = _collisionDetection.GetBounds(); List <CelestialBody> sortedList = ModelController.CurMap.celestialBodies .OrderByDescending(x => x.Radius).ToList() .Where(n => n.Name != null).ToList(); ModelController.CurMap.celestialBodies = _pathing .GetPath( ModelController.CurMap.celestialBodies, sortedList[0], sortedList[1] ); } else { ViewController.bounds = null; ModelController.CurMap.celestialBodies.All(cb => { cb.IsMarked = false; return(true); }); } ViewController.drawFrame(ModelController.CurMap.celestialBodies); if (DateTime.UtcNow - newTick < MinTickTime) { await Task.Delay(MinTickTime); } oldTick = newTick; while (IsPaused && ViewController.MainView.File == null) //pause loop { await Task.Delay(MinTickTime); inputControl(ViewController.getKeyPressed()); oldTick = DateTime.UtcNow; } } await Task.Delay(MinTickTime); } }
public void detectCollision(ICollision collision) { collision.Collide(); }