PDA

View Full Version : Lua help needed



Nicko01
October 27th, 2006, 23:25
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

yaustar
October 28th, 2006, 01:29
Do you mean freeze or crash?

Nicko01
October 28th, 2006, 02:18
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

PSPKOR
October 28th, 2006, 16:27
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.

Nicko01
October 28th, 2006, 16:41
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.