PDA

View Full Version : Need help with a New lua game



fatcat04912
August 16th, 2007, 19:03
Hello im in need of allot of help for my first lua game. Im trying to encode collision so a ball could jump into platforms . and i have tried about 30 different ways and i still cant figure it out :( What im trying to do is create blocks so the ball can jump on one to another to another,ect but everytime i try something goes wrong


Here is the code for the in gamegreen=Color.new(0,255,0)
white = Color.new(255,255,255) player1 =Image.load("smiley.png")

ground=Image.load("background.png")
ground:clear(black) player = {}
player.gravity = 230
player.y = 230
player.x = 50
player.jumpspeed = 10
player.jumpstate = "ground"while true do
pad = Controls.read()
screen:clear()


if pad:left() then
player.x = player.x - 2
end
if pad:right() then
player.x = player.x + 2
end
if pad:cross() and player.jumpstate == "ground" then
player.jumpstate = "jumping"
end
if player.jumpstate == "jumping" then
player.jumpspeed = player.jumpspeed - 0.5
player.gravity = player.gravity - player.jumpspeed
end
if player.gravity < 0 then
player.jumpstate = "falling"
end
if player.gravity < 230 and player.jumpstate == "falling" then
player.gravity = player.gravity + (player.jumpspeed + 3)
end
if player.gravity == 230 then
player.jumpspeed = 10
player.jumpstate = "ground"
end

if player.gravity > 230 then
player.gravity = 230 end player.y = player.gravity
screen:blit(player.x,player.y,player1)
screen:blit(0,262,ground)
screen:print(20,15, "How did you get a beta!",color[1])
if pad:start() then break
end
if pad:select() then screen:save("screenshot.png")
end
screen.waitVblankStart()
screen.flip()
end




Here is the code for the menu
System.usbDiskModeActivate()
-- Start Screen
background=Image.load( "background.png" )
while true do
screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
screen.waitVblankStart()
screen.flip()
pad = Controls.read()
if pad:start() then
break
end
end
-- menu
red = Color.new(255,0,0)
black = Color.new(0,0,0)
white = Color.new(255,255,255)
menustatus = 1
while true do
screen:clear(black)
pad = Controls.read()
if pad:up() then
menustatus = menustatus - 1
screen.waitVblankStart(4)
end
if pad:down() then
menustatus = menustatus + 1
screen.waitVblankStart(4)
end
color={white, white, white}
color[menustatus]=red
screen:print(50, 50, "Play", color[1])
screen:print(50,60, "Credits", color[2])
screen:print(50,70, "Option", color[3])
if menustatus == 1 then
if pad:cross() then
dofile("game.lua")
end
end
if menustatus == 2 then
if pad:cross() then
dofile("Credit.lua")
end
end
if menustatus == 3 then
if pad:cross() then
end
if menustatus <= 0 then
menustatus = 3
end
end
if menustatus >= 4 then
menustatus = 1
end
screen.flip()
screen.waitVblankStart()
Controls.read()
end

and here is my code for my Creditsblack = Color.new(0,0,0)
background=Image.load( "credits.png" )

function delay(seconds)
time=seconds*60
for i=1, time do
screen.waitVblankStart()

end
end
screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
screen.flip()
delay(5)

And here are the graphics you are going to need http://www.sendspace.com/file/15cvu3


Please help me if you do you will get allot of credit given to you :)

Anonymous D
August 16th, 2007, 19:53
im looking for you now...

ok so bug 1 you havent defined black

(black = Color.new(0,0,0) i think)

and..
screen:print(20,15, "How did you get a beta!",color[1])
needs to be given a real colour e.g.
screen:print(20,15, "How did you get a beta!",white)

now it works. btw nice job looks interesting
oh and remember i did that from the script in your rar file

dangee
August 16th, 2007, 20:42
player.y = math.floor(player.gravity)

fatcat04912
August 16th, 2007, 21:09
Thanks anonymous D that cleared up 2 errors but how do i do collision with blocks because its getting old trying so many methods?

fatcat04912
August 16th, 2007, 21:10
Dangee i dont really understand what your say ing :(

dangee
August 16th, 2007, 21:38
the screen coordinate args in blit() need to be
integer , not float, so use
player.y = math.floor(player.gravity)
to force player.y to integer after the gravity logic ,
or make an interesting bounce fx by changing the gravity increment from 0.5 to 1.0
edit- IGNORE that , the float thng makes nil diff.

..but wheres the collision block?

fatcat04912
August 16th, 2007, 21:52
Sorry still nothing :-P Im a real noob at coding this is only my second day . And i have an odd bug with lua devkit that when i makefile my code it makes infinity folders with all the info and i cant delete them :(

dangee
August 16th, 2007, 21:59
ok , anonD 's got the bugs sorted. player1 jumps nicely, what do you want to happen next..?

fatcat04912
August 16th, 2007, 22:02
Dangee Do you have aol add me fatcat0491 or yahoo add me [email protected]

dangee
August 16th, 2007, 23:13
nope, been trying 1/2 hr to get my netmail working , but nil transmits

fatcat04912
August 17th, 2007, 00:59
Also i made Moon pysics mode but when i try and load a background It freezes any reason why ?