Results 1 to 5 of 5

Thread: Lua help needed

                  
   
  1. #1
    DCEmu Regular Nicko01's Avatar
    Join Date
    Jun 2006
    Location
    www.nicko01.com
    Age
    31
    Posts
    434
    Rep Power
    71

    Default Lua help needed

    Ok, heres my code for my new game.
    It only freezes and wont work.
    I really need some help.
    (I think the collision is causing the problem...)

    grass = Image.load("grass.png")
    player = Image.load("player.png")
    spot = Image.load("spot.png")
    orange = Color.new(255, 102, 0)
    screenwidth = 480 - player:width()
    screenheight = 272 - player:width()
    hit = { }
    hit[1] = { h = false }
    score = { }
    score[1] = { s1 = 0 }
    Spot = { }
    Spot[1] = { x = math.random(5,471), y = math.random(5,263) }
    Player = { }
    Player[1] = { x = 200, y = 50 }
    while true do
    pad = Controls.read()
    screen:clear()
    for a = 0, 32 do
    for b = 0,18 do
    screen:blit(15 * a, 15 * b, grass)
    end
    end
    screen:blit(Player[1].x,Player[1].y,player)
    screen:blit(Spot[1].x,Spot[1].y,spot)
    screen:print(5, 5, "score: " .. score[1].s1,orange)
    if pad:left() and Player[1].x > 0 then
    Player[1].x = Player[1].x - 5
    end

    if pad:right() and Player[1].x < screenwidth then
    Player[1].x = Player[1].x + 5
    end

    if pad:up() and Player[1].y > 0 then
    Player[1].y = Player[1].y - 5
    end

    if pad:down() and Player[1].y < screenheight then
    Player[1].y = Player[1].y + 5
    end
    if ((Player[1].x >= Spot[1].x and Player[1].x <= (Spot[1].x+9)) and (Player[1].y >= Spot[1].y and Player[1].y <= (Spot[1].y+9))) then
    hit[1].h = true
    end

    if (((Player[1].x+16) >= Spot[1].x and (Player[1].x+16) <= (Spot[1].x+9)) and (Player[1].y >= Spot[1].y and Player[1].y <= (Spot[1].y+9))) then
    hit[1].h = true
    end

    if ((Player[1].x >= Spot[1].x and Player[1].x <= (Spot[1].x+9)) and ((Player[1].y+22) >= Spot[1].y and (Player[1].y+22) <= (Spot[1].y+9))) then
    hit[1].h = true
    end

    if (((Player[1].x+16) >= Spot[1].x and (Player[1].x+16) <= (Spot[1].x+9)) and ((Player[1].y+22) >= Spot[1].y and (Player[1].y+22) <= (Spot[1].y+9))) then
    hit[1].h = true

    if hit[1].h == true then
    score[1].s1 = score[1].s1 + 5
    Spot[1].x = math.random(9,471)
    Spot[1].y = math.random(9,263)
    hit[1].h = false
    end
    screen.waitVblankStart()
    screen.flip()
    end
    end

  2. #2
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    85

    Default

    Do you mean freeze or crash?

  3. #3
    DCEmu Regular Nicko01's Avatar
    Join Date
    Jun 2006
    Location
    www.nicko01.com
    Age
    31
    Posts
    434
    Rep Power
    71

    Default

    fixed it now, still, it needs a menu...

    menu added.

    grass = Image.load("grass.png")
    player = Image.load("player.png")
    spot = Image.load("spot.png")
    orange = Color.new(255, 102, 0)
    screenwidth = 480 - player:width()
    screenheight = 272 - player:width()
    hit = { }
    hit[1] = { a = false }
    score = { }
    score[1] = { s1 = 0 }
    Spot = { }
    Spot[1] = { x = math.random(5,471), y = math.random(5,263) }
    Player = { }
    Player[1] = { x = 200, y = 50 }
    while true do
    pad = Controls.read()
    screen:clear()
    for a = 0, 32 do
    for b = 0,18 do
    screen:blit(15 * a, 15 * b, grass)
    end
    end
    screen:blit(Player[1].x,Player[1].y,player)
    screen:blit(Spot[1].x,Spot[1].y,spot)
    screen:print(5, 5, "score: " .. score[1].s1,orange)
    if pad:left() and Player[1].x > 0 then
    Player[1].x = Player[1].x - 5
    end

    if pad:right() and Player[1].x < screenwidth then
    Player[1].x = Player[1].x + 5
    end

    if pad:up() and Player[1].y > 0 then
    Player[1].y = Player[1].y - 5
    end

    if pad:down() and Player[1].y < screenheight then
    Player[1].y = Player[1].y + 5
    end
    if ((Player[1].x >= Spot[1].x and Player[1].x <= (Spot[1].x+9)) and (Player[1].y >= Spot[1].y and Player[1].y <= (Spot[1].y+9))) then
    hit[1].a = true
    end

    if (((Player[1].x+16) >= Spot[1].x and (Player[1].x+16) <= (Spot[1].x+9)) and (Player[1].y >= Spot[1].y and Player[1].y <= (Spot[1].y+9))) then
    hit[1].a = true
    end

    if ((Player[1].x >= Spot[1].x and Player[1].x <= (Spot[1].x+9)) and ((Player[1].y+22) >= Spot[1].y and (Player[1].y+22) <= (Spot[1].y+9))) then
    hit[1].a = true
    end

    if (((Player[1].x+16) >= Spot[1].x and (Player[1].x+16) <= (Spot[1].x+9)) and ((Player[1].y+22) >= Spot[1].y and (Player[1].y+22) <= (Spot[1].y+9))) then
    hit[1].a = true
    end
    if hit[1].a == true then
    score[1].s1 = score[1].s1 + 5
    Spot[1].x = math.random(9,471)
    Spot[1].y = math.random(9,263)
    hit[1].a = false
    end
    screen.waitVblankStart()
    screen.flip()
    end

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

    Default

    Not trying to be harsh or anything but you should try and do a menu your self as it is your game.
    One thing I would say is you may want to use functions, rather than one big loop.
    LEARN, MASTER and ACHIEVE!!
    'Bruce Lee'

  5. #5
    DCEmu Regular Nicko01's Avatar
    Join Date
    Jun 2006
    Location
    www.nicko01.com
    Age
    31
    Posts
    434
    Rep Power
    71

    Default

    im done with the menu now, i just need to add a few more things
    im currently working on a timed level, next comes the one with enemies, then I'll add music.
    right now its an eboot and the game is called DOTS.

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
  •