12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- function setup()
- {
- this.width = 800
- this.height = 600
- this.ui = new UI(this.width, this.height);
- this.lastTime = 0;
- newGame();
- }
-
- function newGame() {
- const params = gatherMenuValues();
-
- this.game = new Game(params.TUBESNUMBERS, params.TUBESLEVELS);
- this.drawer = new Drawer(params.PADDING, this.width, this.height);
-
- this.drawer.setTubesParams(params.TUBESNUMBERS, params.TUBESLEVELS, params.TUBESIZE);
-
- this.needUpdate = true;
- }
-
- function mousePressed(e)
- {
- let tubeId = this.drawer.getTubeIdAt(mouseX, mouseY);
-
- if (tubeId != -1)
- {
- this.game.selectTube(tubeId);
- }
- this.needUpdate = true;
- }
-
- function gatherMenuValues()
- {
- let inputTubesNumbers = parseInt(document.getElementById("tbNumber").value);
- let inputTubesLevels = parseInt(document.getElementById("tbLevel").value);
- let inputTubeSize = parseInt(document.getElementById("tbSize").value);
- let inputPadding = parseInt(document.getElementById("padding").value);
-
- return {
- TUBESNUMBERS: inputTubesNumbers,
- TUBESLEVELS: inputTubesLevels,
- TUBESIZE: inputTubeSize,
- PADDING: inputPadding
- };
- }
-
- function draw()
- {
-
- const timeDelta = millis() - lastTime;
- // peut-être pas nécessaire de limiter le framerate
- if (timeDelta < 50)
- return;
- this.lastTime = millis();
-
- const steps = [
- (this.needUpdate || this.game.isCompleted) && drawGame,
- this.game.isCompleted && drawUI
- ]
-
- steps.forEach(step => step && step());
- }
-
- function drawGame()
- {
- this.drawer.draw(this.game);
- this.needUpdate = false;
- }
-
- function drawUI()
- {
- this.ui.drawWinView();
- }
|