Results 1 to 9 of 9

Thread: Music In Lua

                  
   
  1. #1
    DCEmu Coder splodger15's Avatar
    Join Date
    Jun 2006
    Location
    London
    Age
    34
    Posts
    4,123
    Rep Power
    95

    Default Music In Lua

    I am going to add music into my lua script but i was wondering if i can have multiple tracks so for example:

    Music.playFile("Song 1.mp3", true)
    Music.playFile("Song 2.mp3", true)
    Music.playFile("Song 3.mp3", true)

    If these were my songs how could i have these songs playone after another so if song 1 finishes i want it to start song 2

    I have had a try at adding it to my script



    ------------------------------------------------------------------
    -- Created by splodger15


    ----------detect other cars collision--------------
    function detectCollision(player, opponent)
    if (player.x + character:width() > opponent.x) and (player.x < opponent.x + opponent.pic:width()) and (player.y + character:height() > opponent.y) and (player.y < opponent.y + opponent.pic:height()) then
    screen.waitVblankStart(60)
    end
    end

    Music.playFile("Song 1.mp3", true)
    Music.playFile("Song 2.mp3", true)
    Music.playFile("Song 3.mp3", true)
    Room_width = 480
    Room_height = 272
    player1x = 15
    player1y = 136
    road=Image.load("images/road.PNG")
    background=road
    car1=Image.load("images/car1.PNG")
    player1=car1
    car2=Image.load("images/car2.PNG")
    car3=Image.load("images/car3.PNG")
    car4=Image.load("images/car4.PNG")

    ----------walls------------

    wall1 = Image.createEmpty(480,2)
    wall2 = Image.createEmpty(2,272)
    wall3 = Image.createEmpty(2,272)
    wall4 = Image.createEmpty(480,2)

    wall1 = {x = 0, y = 0, height = wall1:height(), width = wall1:width() }
    wall2 = {x = 450, y = 0, height = wall2:height(), width = wall2:width() }
    wall3 = {x = 0, y = 0, height = wall3:height(), width = wall3:width() }
    wall4 = {x = 0, y = 299, height = wall4:height(), width = wall4:width() }



    player = {}
    player.x = 250
    player.y = 100
    playerHeight = 63
    playerWidth = 33

    car2 = {}
    car2.x = 128
    car2.y = 90
    car2Height = 63
    car2Width = 33
    car2.pic = Image.load("images/car2.PNG")

    car3 = {}
    car3.x = 228
    car3.y = 90
    car3Height = 63
    car3Width = 33
    car3.pic = Image.load("images/car3.PNG")

    car4 = {}
    car4.x = 28
    car4.y = 20
    car4Height = 63
    car4Width = 33
    car4.pic = Image.load("images/car4.PNG")

    character = car1

    ------------------player sprite loading--------------

    function rands1()
    rand2 = math.random(1,3)
    end

    function rands2()
    rand3 = math.random(1,3)
    end

    function rands3()
    rand4 = math.random(1,3)
    end

    XScrollPosition = 480

    numberOfScrolls = 0

    while true do
    math.randomseed(os.time() )
    rand=math.random(1,3)
    random1 =math.random(20,99)
    random2 =math.random(90,185)
    random3 =math.random(192,220)

    pad = Controls.read()
    screen:clear()

    oldx = player.x
    oldy = player.y
    screen:clear()

    if pad:left() then
    character = car1
    player.x = player.x - 2
    end

    if pad:right() then
    character = car1
    XScrollPosition = XScrollPosition - 10
    if XScrollPosition < 0 then
    XScrollPosition = XScrollPosition + 480
    numberOfScrolls = numberOfScrolls + 1
    end
    end

    if pad:up() then
    character = car1
    player.y = player.y - 2
    end

    if pad:down() then
    character = car1
    player.y = player.y + 2
    end

    if pad:triangle() then
    dofile("index1.lua")
    end

    if pad:square() then
    Image:save("screenshot.png")
    end

    if pad:start() then
    break
    end


    if rand ==1 then
    car2.x = car2.x -10
    car3.x = car3.x-10
    car4.x = car3.x-10
    end

    if rand ==2 then
    car2.x = car2.x -10
    car3.x = car3.x-10
    car4.x = car3.x-10
    end

    if rand ==3 then
    car2.x = car2.x -10
    car3.x = car3.x-10
    car4.x = car3.x-10
    end

    if car2.x <=0 then
    car2.x =510
    car2.y = random1
    rands1()
    end

    if car3.x <=0 then
    car3.x = 520
    car3.y = random2
    rands2()
    end

    if car4.x <=0 then
    car4.x = 500
    car4.y = random3
    rands3()
    end

    screen:clear()

    screen:blit(XScrollPosition, 0, road)

    if XScrollPosition > 0 then
    screen:blit(XScrollPosition - 480, 0, road)
    else
    screen:blit(XScrollPosition + 480, 0, road)
    end

    if numberOfScrolls > 30 then
    dofile("eol.lua")
    end

    if player.x > 448 then
    Player.x = 448
    end
    if player.x < 0 then
    player.x = 0
    end

    if player.y > 240 then
    player.y = 240
    end
    if player.y < 0 then
    player.y = 0
    end


    detectCollision(player, car2)
    detectCollision(player, car3)
    detectCollision(player, car4)

    -----------blit background and player------------

    screen:blit(player.x, player.y, character)
    screen:blit(car2.x, car2.y, car2.pic)
    screen:blit(car3.x, car3.y, car3.pic)
    screen:blit(car4.x, car4.y, car4.pic)
    screen.flip()
    screen.waitVblankStart()
    end

    PSN ID: splodger15

  2. #2
    DCEmu Coder PSPKOR's Avatar
    Join Date
    Apr 2006
    Location
    England
    Age
    36
    Posts
    184
    Rep Power
    70

    Default

    Well the statement 'Music.playFile("Song 1.mp3", true)' means play that file and the true part means for it to loop, so to start with you want that false.

    Also you want them to be split up, so to say if song 1 is not playing, play song 2.

    But the main thing wrong with what you are doing is having the songs in .mp3 format bacause Lua player doesn't play .mp3 files.

    Go here to find out more info on music and sounds in Lua-
    http://evilmana.com/tutorials/lua_tutorial_10.php
    LEARN, MASTER and ACHIEVE!!
    'Bruce Lee'

  3. #3
    Registered User NoQuarter's Avatar
    Join Date
    Dec 2005
    Posts
    2,106
    Rep Power
    0

    Default

    There is a recent lua player mod that is capable of playing mp3 and ogg
    That may be what he is using.

  4. #4
    DCEmu Coder PSPKOR's Avatar
    Join Date
    Apr 2006
    Location
    England
    Age
    36
    Posts
    184
    Rep Power
    70

    Default

    Didn't know about that, do you know where I could find it?
    Someone should try to improve the music in the Lua player as its fairly poor at doing music stuff.
    LEARN, MASTER and ACHIEVE!!
    'Bruce Lee'

  5. #5
    Registered User NoQuarter's Avatar
    Join Date
    Dec 2005
    Posts
    2,106
    Rep Power
    0

    Default

    Yeah it's here at dcemu,I don't remember where but just look around.
    Ok so I'm lazy and already downloaded it and don't feel like looking again.
    But it is here,make somethin cool with it for all of us

  6. #6
    DCEmu Art Pro
    Join Date
    Apr 2006
    Posts
    1,950
    Rep Power
    98

    Default

    You got music then.

  7. #7
    DCEmu Coder splodger15's Avatar
    Join Date
    Jun 2006
    Location
    London
    Age
    34
    Posts
    4,123
    Rep Power
    95

    Default

    Quote Originally Posted by S34MU5 View Post
    You got music then.
    Yeh alot has been added in this next release

    Also is there any mp3 to xm converter

    Cause i tried to convert the songs to wav and the were a massive size of 44mb

    i dont understand the music in lua

    PSN ID: splodger15

  8. #8
    DCEmu Coder PSPKOR's Avatar
    Join Date
    Apr 2006
    Location
    England
    Age
    36
    Posts
    184
    Rep Power
    70

    Default

    Quote Originally Posted by splodger15 View Post
    i dont understand the music in lua
    I dont blame you for not understanding it, the music in Lua its rather bad to work with.

    Quote Originally Posted by splodger15 View Post
    Also is there any mp3 to xm converter

    Cause i tried to convert the songs to wav and the were a massive size of 44mb
    If you look at my first post and follow the link then read that tutorial, it gives you a good converter to get it to the correct formats.
    In case you want to know I use .it format, not sure if its the best but it seems to be the easyest to convert to.

    PS- .WAV file should only be used for sound effects not music.
    LEARN, MASTER and ACHIEVE!!
    'Bruce Lee'

  9. #9
    DCEmu Coder splodger15's Avatar
    Join Date
    Jun 2006
    Location
    London
    Age
    34
    Posts
    4,123
    Rep Power
    95

    Default

    Thanks PSPKOR i have got all my songs to it format

    But still figuring out this to put music into the script

    PSN ID: splodger15

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •