Files
prosperon/examples/bunnymark/main.ce
2026-01-21 09:05:02 -06:00

57 lines
1.4 KiB
Plaintext

var draw = use('draw2d')
var render = use('render')
var graphics = use('graphics')
var sprite = use('sprite')
var geom = use('geometry')
var config = use('config')
var color = use('color')
var random = use('random')
var bunnyTex = graphics.texture("bunny")
// We'll store our bunnies in an array of objects: { x, y, vx, vy }
var bunnies = []
// Start with some initial bunnies:
for (var i = 0; i < 100; i++) {
push(bunnies, {
x: random.random() * config.width,
y: random.random() * config.height,
vx: (random.random() * 300) - 150,
vy: (random.random() * 300) - 150
})
}
this.update = function(dt) {
// If left mouse is down, spawn some more bunnies:
var mouse = input.mousestate()
if (mouse.left)
for (var i = 0; i < 50; i++) {
push(bunnies, {
x: mouse.x,
y: mouse.y,
vx: (random.random() * 300) - 150,
vy: (random.random() * 300) - 150
})
}
// Update bunny positions and bounce them inside the screen:
for (var i = 0; i < length(bunnies); i++) {
var b = bunnies[i]
b.x += b.vx * dt
b.y += b.vy * dt
// Bounce off left/right edges
if (b.x < 0) { b.x = 0; b.vx = -b.vx }
else if (b.x > config.width) { b.x = config.width; b.vx = -b.vx }
// Bounce off bottom/top edges
if (b.y < 0) { b.y = 0; b.vy = -b.vy }
else if (b.y > config.height) { b.y = config.height; b.vy = -b.vy }
}
}
this.hud = function() {
draw.images(bunnyTex, bunnies)
}