mirror of
https://github.com/usysrc/LICK.git
synced 2024-11-24 16:44:21 +00:00
added sequencer class, fixed mistakes
This commit is contained in:
parent
2b5f567ea3
commit
afe1fc46a8
@ -139,14 +139,14 @@ function b()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- fill the screen with translucent black
|
-- fill the screen with translucent black
|
||||||
function clear(alpha)
|
function clear_black(alpha)
|
||||||
love.graphics.setColor(0,0,0,alpha)
|
love.graphics.setColor(0,0,0,alpha)
|
||||||
love.graphics.rectangle("fill", 0,0,800,600)
|
love.graphics.rectangle("fill", 0,0,800,600)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- shorter clear
|
-- shorter clear
|
||||||
function cls(alpha)
|
function cls(alpha)
|
||||||
clear(alpha)
|
clear_black(alpha)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- one time clear
|
-- one time clear
|
||||||
@ -329,7 +329,7 @@ function sin()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- updates all objects in the _object table
|
-- updates all objects in the _object table
|
||||||
function update_objects()
|
function update_objects(dt)
|
||||||
for i,v in ipairs(_internal_object_table) do
|
for i,v in ipairs(_internal_object_table) do
|
||||||
v:update(dt)
|
v:update(dt)
|
||||||
end
|
end
|
||||||
|
@ -234,7 +234,9 @@ end
|
|||||||
Image = Class(function(self, file, x, y, color, size, orientation)
|
Image = Class(function(self, file, x, y, color, size, orientation)
|
||||||
self.image = love.graphics.newImage(file)
|
self.image = love.graphics.newImage(file)
|
||||||
-- put positions, size, orientation...
|
-- put positions, size, orientation...
|
||||||
|
self.size = size or 1
|
||||||
|
self.color = color or {255,255,255,255}
|
||||||
|
self.r = 0
|
||||||
-- call constructor of Drawable
|
-- call constructor of Drawable
|
||||||
Drawable.construct(self,x,y,color)
|
Drawable.construct(self,x,y,color)
|
||||||
end)
|
end)
|
||||||
@ -243,7 +245,7 @@ Image:inherit(Drawable)
|
|||||||
-- #draw the image
|
-- #draw the image
|
||||||
function Image:draw()
|
function Image:draw()
|
||||||
love.graphics.setColor(unpack(self.color))
|
love.graphics.setColor(unpack(self.color))
|
||||||
love.graphics.draw(self.image, self.position.x, self.position.y)
|
love.graphics.draw(self.image, self.position.x, self.position.y,self.r,self.size,self.size)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
@ -272,6 +274,53 @@ function Point:draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Sequencer
|
||||||
|
--]]
|
||||||
|
|
||||||
|
Sequencer = Class(function(self,bpm, timeSig, phraseLength)
|
||||||
|
self.timer = 0
|
||||||
|
self.frame = 0
|
||||||
|
self.beat = 1
|
||||||
|
self.bar = 1
|
||||||
|
self.phrase = 1
|
||||||
|
self.bpm = bpm or 120
|
||||||
|
|
||||||
|
self.timeSignature = timeSig or 8
|
||||||
|
self.phraseLength = phraseLength or 4
|
||||||
|
|
||||||
|
self.newBeat = function() end
|
||||||
|
self.newBar = function() end
|
||||||
|
self.newPhrase = function() end
|
||||||
|
|
||||||
|
Object.construct(self)
|
||||||
|
end)
|
||||||
|
Sequencer:inherit(Object)
|
||||||
|
|
||||||
|
function Sequencer:update(dt)
|
||||||
|
self.timer = self.timer + dt
|
||||||
|
self.frame = self.frame + 1
|
||||||
|
local _fps = 30
|
||||||
|
local fpm = 30 * _fps
|
||||||
|
--print(math.floor(fpm))
|
||||||
|
if self.frame%(math.floor(fpm)/self.bpm) == 0 then
|
||||||
|
self.beat = self.beat + 1
|
||||||
|
self.newBeat()
|
||||||
|
if self.beat%self.timeSignature == 0 then
|
||||||
|
self.bar = self.bar + 1
|
||||||
|
self.newBar()
|
||||||
|
if self.bar%self.phraseLength == 0 then
|
||||||
|
self.phrase = self.phrase + 1
|
||||||
|
self.newPhrase()
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
-- EXAMPLE:
|
-- EXAMPLE:
|
||||||
-- (put in love.load):
|
-- (put in love.load):
|
||||||
-- coco = Circle(300,300)
|
-- coco = Circle(300,300)
|
||||||
|
Loading…
Reference in New Issue
Block a user