Sidescroller Help

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
c5cha7
Posts: 14
Joined: Wed Oct 05, 2005 9:36 pm

Sidescroller Help

Post by c5cha7 »

Hi
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&#91;2&#93;
   elseif animTimer>=5 and animTimer<=8 then Spriteimg=sprite&#91;3&#93;
   end
   if animTimer>=9 then animTimer=0 end
end

function walkLeft&#40;&#41;
LastDirection=sprite&#91;6&#93;
animTimer=animTimer+1
   if animTimer>=1 and animTimer<=4 then Spriteimg=sprite&#91;4&#93;
   elseif animTimer>=5 and animTimer<=8 then Spriteimg=sprite&#91;5&#93;
   end
   if animTimer>=9 then animTimer=0 end
end

while true do
	screen&#58;blit&#40;0, 0, background, 0, 0, background&#58;width&#40;&#41;, background&#58;height&#40;&#41;, false&#41;
	screen&#58;blit&#40;415, 190, Kart&#41;

   pad = Controls.read&#40;&#41;
   if pad&#58;right&#40;&#41; then walkRight&#40;&#41; x=x+2 Spriteimg=Spriteimg
   elseif pad&#58;left&#40;&#41; then walkLeft&#40;&#41; x=x-2 Spriteimg=Spriteimg
   else Spriteimg=LastDirection

	if pad&#58;cross&#40;&#41; 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&#58;blit&#40;x, y, Spriteimg&#41;
  screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;
end
yeah it's the worst code EVER but i did it withing a few min's lol.
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.
Currently Working On
PSP Chao Garden - Lua
Next Project might be
Dragon Ball P
or Metroid Prime
Post Reply