rng class..
This commit is contained in:
parent
3ff375dbb4
commit
cbc2b88f47
12 changed files with 4762 additions and 25 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import Util from './../common/Util.js'
|
||||
import { Rng } from '../common/Rng.js'
|
||||
import Util from '../common/Util.js'
|
||||
|
||||
let minVx = -10
|
||||
let deltaVx = 20
|
||||
|
|
@ -17,22 +18,22 @@ const explosionDividerFactor = 10
|
|||
const nBombs = 1
|
||||
const percentChanceNewBomb = 5
|
||||
|
||||
function color() {
|
||||
const r = Util.randomInt(0, 255)
|
||||
const g = Util.randomInt(0, 255)
|
||||
const b = Util.randomInt(0, 255)
|
||||
function color(/** @type Rng */ rng) {
|
||||
const r = Util.randomInt(rng, 0, 255)
|
||||
const g = Util.randomInt(rng, 0, 255)
|
||||
const b = Util.randomInt(rng, 0, 255)
|
||||
return 'rgba(' + r + ',' + g + ',' + b + ', 0.8)'
|
||||
}
|
||||
|
||||
// A Bomb. Or firework.
|
||||
class Bomb {
|
||||
constructor() {
|
||||
constructor(/** @type Rng */ rng) {
|
||||
this.radius = bombRadius
|
||||
this.previousRadius = bombRadius
|
||||
this.explodingDuration = explodingDuration
|
||||
this.hasExploded = false
|
||||
this.alive = true
|
||||
this.color = color()
|
||||
this.color = color(rng)
|
||||
|
||||
this.px = (window.innerWidth / 4) + (Math.random() * window.innerWidth / 2)
|
||||
this.py = window.innerHeight
|
||||
|
|
@ -124,8 +125,9 @@ class Particle {
|
|||
}
|
||||
|
||||
class Controller {
|
||||
constructor(canvas) {
|
||||
constructor(canvas, /** @type Rng */ rng) {
|
||||
this.canvas = canvas
|
||||
this.rng = rng
|
||||
this.ctx = this.canvas.getContext('2d')
|
||||
this.resize()
|
||||
|
||||
|
|
@ -161,13 +163,13 @@ class Controller {
|
|||
this.particles = []
|
||||
|
||||
for (let i = 0; i < nBombs; i++) {
|
||||
this.readyBombs.push(new Bomb())
|
||||
this.readyBombs.push(new Bomb(this.rng))
|
||||
}
|
||||
}
|
||||
|
||||
update() {
|
||||
if (Math.random() * 100 < percentChanceNewBomb) {
|
||||
this.readyBombs.push(new Bomb())
|
||||
this.readyBombs.push(new Bomb(this.rng))
|
||||
}
|
||||
|
||||
const aliveBombs = []
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import Util from './../common/Util.js'
|
|||
import PuzzleGraphics from './PuzzleGraphics.js'
|
||||
import Game from './Game.js'
|
||||
import fireworksController from './Fireworks.js'
|
||||
import { Rng } from '../common/Rng.js'
|
||||
|
||||
if (typeof GAME_ID === 'undefined') throw '[ GAME_ID not set ]'
|
||||
if (typeof WS_ADDRESS === 'undefined') throw '[ WS_ADDRESS not set ]'
|
||||
|
|
@ -324,6 +325,7 @@ async function main() {
|
|||
}
|
||||
|
||||
const game = await Communication.connect(gameId, CLIENT_ID)
|
||||
game.rng.obj = Rng.unserialize(game.rng.obj)
|
||||
Game.newGame(game)
|
||||
|
||||
const bitmaps = await PuzzleGraphics.loadPuzzleBitmaps(game.puzzle)
|
||||
|
|
@ -338,7 +340,7 @@ async function main() {
|
|||
let finished = longFinished ? true : false
|
||||
const justFinished = () => !!(finished && !longFinished)
|
||||
|
||||
const fireworks = new fireworksController(canvas)
|
||||
const fireworks = new fireworksController(canvas, game.rng.obj)
|
||||
fireworks.init(canvas)
|
||||
|
||||
const ctx = canvas.getContext('2d')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue