This commit is contained in:
2026-01-21 09:05:02 -06:00
parent 18ca9e14ba
commit f7be9c3344
30 changed files with 237 additions and 246 deletions

View File

@@ -14,7 +14,7 @@ var bunnies = []
// Start with some initial bunnies:
for (var i = 0; i < 100; i++) {
bunnies.push({
push(bunnies, {
x: random.random() * config.width,
y: random.random() * config.height,
vx: (random.random() * 300) - 150,
@@ -22,22 +22,12 @@ for (var i = 0; i < 100; i++) {
})
}
var fpsSamples = []
var fpsAvg = 0
this.update = function(dt) {
// Compute FPS average over the last 60 frames:
var currentFPS = 1 / dt
fpsSamples.push(currentFPS)
if (length(fpsSamples) > 60) fpsSamples.shift()
var sum = reduce(fpsSamples, function(a,b) { return a + b })
fpsAvg = sum / length(fpsSamples)
// If left mouse is down, spawn some more bunnies:
var mouse = input.mousestate()
if (mouse.left)
for (var i = 0; i < 50; i++) {
bunnies.push({
push(bunnies, {
x: mouse.x,
y: mouse.y,
vx: (random.random() * 300) - 150,
@@ -63,7 +53,4 @@ this.update = function(dt) {
this.hud = function() {
draw.images(bunnyTex, bunnies)
var msg = 'FPS: ' + fpsAvg.toFixed(2) + ' Bunnies: ' + length(bunnies)
draw.text(msg, {x:0, y:0, width:config.width, height:40}, null, 0, color.white, 0)
}