added delta time

+ #preloadfont hack
This commit is contained in:
LuckyLaszlo
2022-10-28 01:46:11 +02:00
parent d7aa2b633b
commit 4a79083cbf
6 changed files with 45 additions and 26 deletions

View File

@@ -4,7 +4,8 @@ import {Vector, VectorInteger} from "./class/Vector.js";
import {Rectangle, MovingRectangle, Player, Ball, Line} from "./class/Rectangle.js";
import {TextElem, TextNumericValue} from "./class/Text.js";
import * as d from "./draw.js";
import {gameLoop} from "./gameLoop.js"
import {gameLoop, newRound} from "./gameLoop.js"
import {random} from "./utils.js";
/* Keys
Player 1: W/S
@@ -46,8 +47,8 @@ function startGame()
const midLineSize = Math.floor(w/150);
const wallSize = Math.floor(w/100);
const gridSize = Math.floor(w/500);
const playerSpeed = Math.floor(w/75);
const ballSpeed = Math.floor(w/75);
const playerSpeed = Math.floor(w/1.5); // pixel per second
const ballSpeed = Math.floor(w/1.5); // pixel per second
let pos = new VectorInteger;
// Component
@@ -90,7 +91,6 @@ function startGame()
h_grid_d1 = new Rectangle(pong.ctx, pos, "darkgreen", gridSize, h);
// Start
score1.update(); // first Text draw init the custom font (graphic leftover ortherwise) (a better solution ?)
d.drawInit();
window.addEventListener('keydown', function (e) {
pong.addKey(e.key);
@@ -98,7 +98,8 @@ function startGame()
window.addEventListener('keyup', function (e) {
pong.deleteKey(e.key);
});
pong.interval = window.setInterval(gameLoop, 20);
pong.interval = window.setInterval(gameLoop, 15); // min interval on Firefox seems to be 15. Chrome can go lower.
setTimeout(newRound, 1000);
}
/////////////////////////////////////////////////////////////////////////////