summaryrefslogtreecommitdiffhomepage
path: root/header.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-12-20 06:05:56 +0100
committerGitHub <noreply@github.com>2016-12-20 06:05:56 +0100
commit493a89fb354ee6ce667d29a7b96bb4fdd0f6697f (patch)
treed862856d4b62a6c996ea16211ebd321206e236b4 /header.lua
parented6ad6687aeb5359af48bc97c1dbf5dd66842c9c (diff)
parent73bcd524906c51d43b22b3ea68c64b38f130bea6 (diff)
downloadroflnauts-493a89fb354ee6ce667d29a7b96bb4fdd0f6697f.zip
roflnauts-493a89fb354ee6ce667d29a7b96bb4fdd0f6697f.tar.gz
roflnauts-493a89fb354ee6ce667d29a7b96bb4fdd0f6697f.tar.bz2
Merge pull request #16 from nthirtyone/menuv1.0-pre.4
Menu
Diffstat (limited to 'header.lua')
-rw-r--r--header.lua57
1 files changed, 57 insertions, 0 deletions
diff --git a/header.lua b/header.lua
new file mode 100644
index 0000000..d67e582
--- /dev/null
+++ b/header.lua
@@ -0,0 +1,57 @@
+-- `Header`
+-- It dances!
+
+Header = {
+ x = 0,
+ y = 0,
+ text = "",
+ parent,
+ bounce = 2,
+}
+function Header:new(parent)
+ local o = {}
+ setmetatable(o, self)
+ self.__index = self
+ o.parent = parent
+ return o
+end
+function Header:setText(text)
+ self.text = text or ""
+ return self
+end
+function Header:setPosition(x, y)
+ self.x = x or 0
+ self.y = y or 0
+ return self
+end
+function Header:getBounce(f)
+ local f = f or 1
+ return math.sin(self.bounce*f*math.pi)
+end
+function Header:getPosition() return self.x,self.y end -- gives x,y of Element
+function Header:focus()
+ return false
+end
+function Header:blur() end -- Called when Element loses focus
+
+-- LÖVE2D callbacks
+function Header:draw(scale)
+ local angle = self:getBounce(2)
+ local dy = self:getBounce()*4
+ local x,y = self:getPosition()
+ love.graphics.setColor(255,255,255,255)
+ love.graphics.setFont(Bold)
+ love.graphics.printf(string.upper(self.text),x*scale,(y+dy)*scale,400,"center",(angle*5)*math.pi/180,scale,scale,200,12)
+end
+function Header:update(dt)
+ self.bounce = self.bounce + dt*0.7
+ if self.bounce > Header.bounce then -- Header.bounce is initial
+ self.bounce = self.bounce - Header.bounce
+ end
+end
+
+-- Controller callbacks
+function Header:controlpressed(set, action, key) end
+function Header:controlreleased(set, action, key) end
+
+return Header \ No newline at end of file