[WIP] Reestructurant codi abans de posar-me en el nivell 2
[NEW] Afegit music_player [NEW] Música de fons des de l'inici
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
music_info = {
|
||||
mus_life_ogg = 1.6
|
||||
}
|
||||
|
||||
music_player = {
|
||||
playlist = {song="", pos=0},
|
||||
song = "",
|
||||
playing = false,
|
||||
pos = 0,
|
||||
old_pos = 0,
|
||||
check_time = 0,
|
||||
}
|
||||
|
||||
function music_player:play(song, loop, enqueue)
|
||||
-- print("MUSIC_PLAYER:PLAY "..song)
|
||||
if enqueue then
|
||||
self.playlist.song = self.song
|
||||
self.playlist.pos = music.pos()
|
||||
end
|
||||
-- print( os.clock())
|
||||
if loop~=nil then
|
||||
music.play(song, loop)
|
||||
else
|
||||
music.play(song)
|
||||
end
|
||||
-- print( os.clock())
|
||||
self.song = song
|
||||
-- self.old_pos = music.pos()
|
||||
self.playing = true
|
||||
self.check_time = os.clock()
|
||||
end
|
||||
|
||||
|
||||
function music_player:pause()
|
||||
music.pause()
|
||||
end
|
||||
|
||||
|
||||
function music_player:resume()
|
||||
music.resume()
|
||||
end
|
||||
|
||||
|
||||
function music_player:stop()
|
||||
music.stop()
|
||||
end
|
||||
|
||||
|
||||
function music_player:pos()
|
||||
music.pos()
|
||||
end
|
||||
|
||||
|
||||
function music_player:enabled()
|
||||
music.enabled()
|
||||
end
|
||||
|
||||
function music_player:update()
|
||||
-- self.pos = music.pos()
|
||||
local curr_time = os.clock()
|
||||
local song_name = self.song:gsub("%.", "_")
|
||||
if music_info[song_name]~=nil and curr_time-self.check_time>music_info[song_name] then
|
||||
-- print("MUSIC_PLAYER:UPDATE "..self.pos.." / "..self.old_pos.." / "..music.pos())
|
||||
-- if self.pos==self.old_pos then self.playing = false end
|
||||
self.playing = false
|
||||
self.old_pos = self.pos
|
||||
self.check_time = curr_time
|
||||
end
|
||||
|
||||
if not self.playing and self.playlist.song~="" then
|
||||
self.song = self.playlist.song
|
||||
self.pos = self.playlist.pos
|
||||
-- print( os.clock())
|
||||
music.play(self.song)
|
||||
-- print( os.clock())
|
||||
-- music.pos(self.pos)
|
||||
self.playlist.song = ""
|
||||
self.playlist.pos = 0
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user