diff options
author | Aki <nthirtyone@gmail.com> | 2017-04-07 03:24:40 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-04-07 03:24:40 +0200 |
commit | d1a19fea50aefc9d7fb52568a5bdcfb56d75eccf (patch) | |
tree | d86118b2bae5125f6cecd28a5a7b6f46739f30a9 /not/Header.lua | |
parent | 54e85dd188af15cd5f3f5e08f5d3e69088a909b1 (diff) | |
download | roflnauts-d1a19fea50aefc9d7fb52568a5bdcfb56d75eccf.zip roflnauts-d1a19fea50aefc9d7fb52568a5bdcfb56d75eccf.tar.gz roflnauts-d1a19fea50aefc9d7fb52568a5bdcfb56d75eccf.tar.bz2 |
Moved menu elements to /not/
Diffstat (limited to 'not/Header.lua')
-rw-r--r-- | not/Header.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/not/Header.lua b/not/Header.lua new file mode 100644 index 0000000..a563ab2 --- /dev/null +++ b/not/Header.lua @@ -0,0 +1,48 @@ +--- `Header` +-- Swinging title. +Header = { + parent = --[[not.Menu]]nil, + x = 0, + y = 0, + text = "", + bounce = 2, +} + +-- `Header` is a child of `Element`. +require "not.Element" +Header.__index = Header +setmetatable(Header, Element) + +function Header:new (parent) + local o = setmetatable({}, self) + o.parent = parent + return o +end + +function Header:setText (text) + self.text = text or "" + return self +end + +function Header:getBounce (f) + local f = f or 1 + return math.sin(self.bounce*f*math.pi) +end + +-- 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 + +return Header |