Open RobLoach opened 5 years ago
I am working on this lol...
Hey @RobLoach, Here is Lua port i did...
-- author: Rabia Alhaffar
-- desc: Benchmarking tool to see how many bunnies can fly around the screen, using Lua.
-- input: gamepad
-- script: lua
-- version: 1.0.1
screenWidth = 240
screenHeight = 136
toolbarHeight = 6
t = 0
Bunny = {}
function Bunny:new()
setmetatable(Bunny, self)
self.__index = self
self.width = 26
self.height = 32
self.x = math.random(0, screenWidth - self.width)
self.y = math.random(0, screenHeight - self.height)
self.speedX = math.random(-100, 100) / 60
self.speedY = math.random(-100, 100) / 60
self.sprite = 1
return Bunny
end
function Bunny:draw()
spr(self.sprite, self.x, self.y, 1, 1, 0, 0, 4, 4)
end
function Bunny:update()
self.x = self.x + self.speedX
self.y = self.x + self.speedY
if (self.x + self.width > screenWidth) then
self.x = screenWidth - self.width
self.speedX = self.speedX * -1
end
if (self.x < 0) then
self.x = 0
self.speedX = self.speedX * -1
end
if (self.y + self.height > screenHeight) then
self.y = screenHeight - self.height
self.speedY = self.speedY * -1
end
if (self.y < toolbarHeight) then
self.y = toolbarHeight
self.speedY = self.speedY * -1
end
end
FPS = {}
function FPS:new()
setmetatable(FPS, self)
self.__index = self
self.value = 0
self.frames = 0
self.lastTime = 0
return FPS
end
function FPS:getValue()
if (time() - self.lastTime <= 1000) then
self.frames = self.frames + 1
else
self.value = self.frames
self.frames = 0
self.lastTime = time()
end
return self.value
end
fps = FPS:new()
bunnies = {}
table.insert(bunnies, Bunny:new())
function TIC()
-- music
if t == 0 then
music(0)
end
if t == 6*64*2.375 then
music(1)
end
t = t + 1
-- Input
if btn(0) then
for i = 1, 5 do
table.insert(bunnies, Bunny:new())
end
end
if btn(1) then
for i = 1, 5 do
table.remove(bunnies, i)
end
end
-- Update
for i, item in pairs(bunnies) do
item:update()
end
-- Draw
cls(15)
for i, item in pairs(bunnies) do
item:draw()
end
rect(0, 0, screenWidth, toolbarHeight, 0)
print("Bunnies: " .. #bunnies, 1, 0, 11, false, 1, false)
print("FPS: " .. fps:getValue(), screenWidth / 2, 0, 11, false, 1, false)
end
But it's garbled sorry...
This is great, Rabios! Thanks so much! Would you like me to make the commit? If you push up a Pull Request, you'll end up getting author credits :wink:
@RobLoach Unfortunately i'm new to TIC-80 so i got stuck with injecting assets to the cartridge (Very sorry)
I know it's shame to ask for but mind if you made cartridge, Oh i should note that there is possibility where code maybe need to edit somewhere (I used this way of OOP in Lua which is metatables...)
But i included my name in code, So even if you commit at least keep my name on code and add your one if you don't mind...
Fun info: My name is Rabia lol...
About fennel, I maybe need some time to learn about it, But maybe will be in this week!
Added it... There's something wrong with integer/float types.
Hm...Isn't when downgrading bunnies count and reaches smaller than 0, Right...
http://www.lua.org/manual/5.3/