Skip to content

Instantly share code, notes, and snippets.

@johngirvin
Created September 21, 2016 22:51
Show Gist options
  • Save johngirvin/8b4eb5db3662ec07fbbc1eecc62c1ef3 to your computer and use it in GitHub Desktop.
Save johngirvin/8b4eb5db3662ec07fbbc1eecc62c1ef3 to your computer and use it in GitHub Desktop.
Gideros Mobile Bunnymark
local bunnies = 0
local frames = 0
local frameTime = 0
local min_x = 13
local min_y = 19
local max_x = application:getLogicalWidth()-13
local max_y = application:getLogicalHeight()-19
local info = TextField.new(nil, "-WAIT-")
info:setScale(4)
info:setPosition(0,application:getLogicalHeight())
info:setTextColor(0xffffff)
-- --------------------------------------------------------------------------------
BunnyTex = Texture.new("wabbit_alpha.png")
Bunny = Core.class(Sprite)
function Bunny:init()
self:addChild(Bitmap.new(BunnyTex))
self.xv = math.random(-100, 100)
self.yv = math.random(-100, 100)
self.rv = math.random(-90 , 90)
self:setPosition(math.random(max_x), math.random(max_y))
self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
end
function Bunny:onEnterFrame(event)
-- get the current position
local x,y = self:getPosition()
-- change the position according to the speed
x = x + event.deltaTime * self.xv
y = y + event.deltaTime * self.yv
if (x < min_x or x > max_x) then
self.xv = -self.xv
end
if (y < min_y or y > max_y) then
self.yv = -self.yv
end
self:setPosition(x, y)
self:setRotation( (self.rv * event.deltaTime + self:getRotation()) % 360 )
end
function addBunnies(n)
for i = 1,n do
stage:addChild(Bunny.new())
end
bunnies = bunnies + n
end
function onEnterFrame(event)
frames = frames + 1
frameTime = frameTime + event.deltaTime
if (frameTime >= 5) then
info:setText(bunnies .. " @ " .. string.format("%.2f",frames / frameTime))
frames = 0
frameTime = 0;
end
end
function onTouchEnd(event)
addBunnies(100)
end
application:setBackgroundColor(0x000044)
stage:addChild(info)
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
stage:addEventListener(Event.TOUCHES_END, onTouchEnd)
addBunnies(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment