Advertising (This ad goes away for registered users. You can Login or Register)

Psp lua jump help

Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
Locked
saiyan x
Posts: 79
Joined: Mon Oct 31, 2011 1:17 pm
Contact:

Psp lua jump help

Post by saiyan x »

I am making a game and had lots of trouble with the player jumping but now jumping is fine except when u jump right or left. So here's my script and can anyone tell me why I cannot jump right or left properly.

Code: Select all

tilesize = 24
playerImage = Image.createEmpty(32, 32)
tileimg=Image.createEmpty(30, 30)
tileimg1=Image.createEmpty(30, 30)
white = Color.new(255,255,255)
red=Color.new(255,0,0)
blue=Color.new(0,255,0)
tileimg:clear(red)
tileimg1:clear(blue)
playerImage:clear(white)
tile = {tileimg, tileimg1}
player = {
 x = 40, y = 184, j=200, speedY = -2, speedX = 0, falling = 0,}
player.img = playerImage
screenwidth = 480-24
screenheight = 272-player.img:width()
world = {
 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
}
function drawTiles()
 for Y = 1, #world do 
for X = 1, #world[Y] do 
local x = (X - 1) * tilesize
 local y = (Y - 1) * tilesize
 for tileNum = 1,#tile do
 if world[Y][X] == tileNum then
screen:blit(x, y, tile[tileNum]) 
end
 end
 end
 end
end
function movePlayer() 
--Walk left--
if pad:left() and player.x>0 then
stand = 2
z=1
blit = 2
player.y=184
player.x = player.x-2
player.img = playerImage
end
--Walk right--
if pad:right() and player.x<screenwidth then
stand = 2
z=2
blit = 2
player.y=184
player.x = player.x+2
player.img = playerImage
end
end
--Jump--
function jump(object,Floor, grav)
object = player or object
Floor = Floor or 184
grav = grav or 1
jumping = false

 if pad:cross() and z==1 and object.falling == 0 then
 jumping = true
 player.img=playerImage
 stand=2
 elseif not pad:cross()and z==1 and object.y < Floor or object.falling == 1 then
 jumping = true
 player.img=playerImage
 stand=2
 end
 if pad:cross() and z==2 and object.falling == 0 then
 jumping = true
 player.img = playerImage
 stand=2
 elseif not pad:cross() and z==2 and object.y < Floor or object.falling == 1 then
 jumping = true
 player.img = playerImage
 stand=2
 end

 if jumping then
 object.speedY = object.speedY - grav
 object.y = object.y - object.speedY
 end

 if object.y >= Floor and object.falling == 0 then
 object.y = Floor
 object.speedY = 10
 jumping = false
 end
end

--Blit image--
function blitimg()
if blit == 2 then
screen:blit(player.x, player.y, player.img) 
else 
screen:blit(player.x, player.y, player.img)
end
end

while true do
 pad = Controls.read()
screen:clear()
 drawTiles()
 blitimg()
 movePlayer()
 jump()
 screen.flip()
 screen.waitVblankStart()
 end
Advertising
ultimakillz
Retired Mod
Posts: 805
Joined: Mon Sep 27, 2010 6:55 pm

Re: Psp lua jump help

Post by ultimakillz »

in the future please put all code in [ code ] [ /code ] tags. i've fixed this post for you.
Advertising
fouadtjuhmaster
Posts: 764
Joined: Sat Jan 01, 2011 12:27 am
Location: Segangan, Oriental, Morocco
Contact:

Re: Psp lua jump help

Post by fouadtjuhmaster »

Try to run the file, and if it doesn't work it gives you the line where the problem is.
Image
saiyan x
Posts: 79
Joined: Mon Oct 31, 2011 1:17 pm
Contact:

Re: Psp lua jump help

Post by saiyan x »

fouadtjuhmeastr wrote:Try to run the file, and if it doesn't work it gives you the line where the problem is.
Ignore completely wat i said before I found the problem. Thx fouadtjuhmeastr for trying to help.
Locked

Return to “Programming and Security”