I Am making my first (Well kinda second) Lua game.
It is my first Sidescroller though and i needed to know
how would i get him to hit barrier's and jump on them including
image's ect?
Sorry but this is my code
Code: Select all
x = 2
y = 195
leftlimit = 0
rightlimit = 450
uplimit = 65
downlimit = 244
jumping2 = false
sprite = {}
sprite[1] = Image.load("Mario/sprite.png")
sprite[2] = Image.load("Mario/sprite2.png")
sprite[3] = Image.load("Mario/sprite3.png")
sprite[4] = Image.load("Mario/sprite2-2.png")
sprite[5] = Image.load("Mario/sprite3-3.png")
sprite[6] = Image.load("Mario/sprite-1.png")
sprite[7] = Image.load("Mario/sprite4.png")
sprite[8] = Image.load("Mario/sprite4-4.png")
sprite[9] = Image.load("Mario/sprite6-6.png")
Spriteimg=sprite[1]
anim = 1
animTimer = 0
LastDirection = sprite[9]
function walkRight()
LastDirection=sprite[1]
animTimer=animTimer+1
if animTimer>=1 and animTimer<=4 then Spriteimg=sprite[2]
elseif animTimer>=5 and animTimer<=8 then Spriteimg=sprite[3]
end
if animTimer>=9 then animTimer=0 end
end
function walkLeft()
LastDirection=sprite[6]
animTimer=animTimer+1
if animTimer>=1 and animTimer<=4 then Spriteimg=sprite[4]
elseif animTimer>=5 and animTimer<=8 then Spriteimg=sprite[5]
end
if animTimer>=9 then animTimer=0 end
end
while true do
screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
screen:blit(415, 190, Kart)
pad = Controls.read()
if pad:right() then walkRight() x=x+2 Spriteimg=Spriteimg
elseif pad:left() then walkLeft() x=x-2 Spriteimg=Spriteimg
else Spriteimg=LastDirection
if pad:cross() then
if jumping2 == false then
jumping = true
end
end
if jumping == true then
if jumping2 == true then
jumping = false
end
y = y - 4
if y < 130 then
jumping2 = true
jumping = false
end
end
if jumping2 == true then
y = y + 4
if y > 197 then
y = 197
jumping2 = false
end
end
end
if x<=leftlimit then x=leftlimit
elseif x>=rightlimit then x=rightlimit end
screen:blit(x, y, Spriteimg)
screen.waitVblankStart()
screen.flip()
end
Also when my player trie's to jump he can run in the sky?
lol Well it is my first try and it was pretty fast....
I Guess i could start from scratch but i dont have the time yet.
EDIT:
I Didnt include all my code sorry about that but it does'nt matter.