new fps counter
This commit is contained in:
@@ -8,7 +8,7 @@ function DebugUI()
|
||||
love.graphics.print(light.pos.x,light.pos.x,light.pos.y+40)
|
||||
end
|
||||
|
||||
love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..math.floor(current_dt* 1000).."ms", 10*textScale, 0*textScale, 0, textScale)
|
||||
love.graphics.print("fps: "..fps_current, 10*textScale, 0*textScale, 0, textScale)
|
||||
love.graphics.print(--[["CPUtime: "..checkCPUTime("total")..", CPU: "..(math.floor(checkCPUTime("get")*10000)/100).."%,]] "memoryUsage: "..memoryUsage.."kB", 10*textScale, 20*textScale, 0, textScale)
|
||||
|
||||
love.graphics.setColor(1,1,1)
|
||||
|
||||
@@ -220,7 +220,8 @@ function Player:DoPhysics()
|
||||
if self.isHooked then
|
||||
self.move_x = 0
|
||||
local hook = Vector(self.pos.x, self.pos.y, self.hookAnchor.x, self.hookAnchor.y)
|
||||
if GetVectorValue(hook) > self.hookDistance then
|
||||
local dist = math.min(GetVectorValue(hook), self.hookDistance)
|
||||
|
||||
local hook_angle = GetAngleFromVector(hook[1],hook[2])-math.rad(180)
|
||||
|
||||
if Keybind:CheckDown(Keybind.move.right) then
|
||||
@@ -229,6 +230,7 @@ function Player:DoPhysics()
|
||||
|
||||
if Keybind:CheckDown(Keybind.move.left) then
|
||||
hook_angle = hook_angle + self.hookSwingSpeed
|
||||
|
||||
end
|
||||
|
||||
local particle_data = {
|
||||
@@ -242,13 +244,12 @@ function Player:DoPhysics()
|
||||
}
|
||||
Particle:New(self.pos.x,self.pos.y,particle_data)
|
||||
|
||||
local pos_x = self.hookAnchor.x + self.hookDistance * math.cos(hook_angle)
|
||||
local pos_y = self.hookAnchor.y + self.hookDistance * math.sin(hook_angle)
|
||||
local pos_x = self.hookAnchor.x + dist * math.cos(hook_angle)
|
||||
local pos_y = self.hookAnchor.y + dist * math.sin(hook_angle)
|
||||
self.vel.x = self.vel.x + pos_x - self.pos.x
|
||||
self.vel.y = self.vel.y + pos_y - self.pos.y
|
||||
self.pos.x = pos_x
|
||||
self.pos.y = pos_y
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
74
code/queue.lua
Normal file
74
code/queue.lua
Normal file
@@ -0,0 +1,74 @@
|
||||
Queue = {}
|
||||
|
||||
function Queue:New()
|
||||
local o = {head = nil, tail = nil}
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
|
||||
function Queue:Enqueue(item)
|
||||
local elem = {item = item}
|
||||
if self.head == nil then
|
||||
self.head = elem
|
||||
self.tail = elem
|
||||
return
|
||||
end
|
||||
|
||||
elem.next = self.head
|
||||
elem.next.prev = elem
|
||||
self.head = elem
|
||||
return
|
||||
end
|
||||
|
||||
function Queue:Empty()
|
||||
return self.tail == nil
|
||||
end
|
||||
|
||||
function Queue:Dequeue()
|
||||
if self:Empty() then
|
||||
return nil
|
||||
end
|
||||
|
||||
local newtail = self.tail.prev
|
||||
local item = self.tail.item
|
||||
if newtail then
|
||||
newtail.next = nil
|
||||
end
|
||||
self.tail = newtail
|
||||
return item
|
||||
end
|
||||
|
||||
local tq1 = Queue:New()
|
||||
tq1:Enqueue(5)
|
||||
assert(tq1.head.item == 5)
|
||||
assert(tq1:Dequeue() == 5)
|
||||
|
||||
-- queue that keeps a rolling tally of its arguments
|
||||
AvgQueue = {}
|
||||
|
||||
function AvgQueue:New(n, initial)
|
||||
local o = {}
|
||||
|
||||
o.n = n
|
||||
o.queue = Queue:New()
|
||||
o.avg = initial
|
||||
|
||||
|
||||
local x = initial / n
|
||||
for _ = 1,n do
|
||||
o.queue:Enqueue(x)
|
||||
end
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
|
||||
function AvgQueue:Push(item)
|
||||
local x = item/self.n
|
||||
self.avg = self.avg + x - self.queue:Dequeue()
|
||||
self.queue:Enqueue(x)
|
||||
return self.avg
|
||||
end
|
||||
@@ -18,6 +18,7 @@ require "code/level"
|
||||
require "code/camera"
|
||||
require "code/animation"
|
||||
require "code/audio"
|
||||
require "code/queue"
|
||||
|
||||
-- objects
|
||||
require "code/entity"
|
||||
|
||||
Reference in New Issue
Block a user