Platform Game Help Please

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

Moderators: Shine, Insert_witty_name

Post Reply
shifty_bill
Posts: 8
Joined: Sat Jan 07, 2006 12:49 pm

Platform Game Help Please

Post by shifty_bill »

Hi All,

I need some help with collision, I have it working (sort of) but when the background scrolls the image moves, but not the collision stuff(which should be moving) , its hard to explain, its like the collision background is still in the same place, yet its moving

http://www.freewebs.com/shifthouse/MegaMan.zip
AkumaATR
Posts: 11
Joined: Sun Oct 30, 2005 1:07 am

Hey

Post by AkumaATR »

I gave a theory up on this in the IRC channel you were in earlier; maybe you didn't see my response.

From playing with your demo and taking a brief look at your code, I think your collision function is checking against the background image data as it is in memory (untransformed aka unmoved). You need to perform the collision check between Mega Man and a surface that has the transformed background data (blit the background transformed ("moved") to another surface and perform collision on that extra surface, perhaps). You could also just compare directly to screen pixel data instead of using an extra surface. Also you might consider having a different means of defining your levels at a later time as I'm not sure how far the pixel checking can be taken (although I've used that method before in shooter type demos)...

good luck
soulphalanx
Posts: 35
Joined: Mon Aug 22, 2005 7:48 am

Post by soulphalanx »

I have a released something that you could look at http://soulphalanx.psplua.com/NG%200.0.2.zip

the game looks at a separate collision map to determine where the ground is
not to mention scrolling
shifty_bill
Posts: 8
Joined: Sat Jan 07, 2006 12:49 pm

Post by shifty_bill »

thanks for your help yet i still cant get it to work :(

how do i blit the (moved) background to another surface?
soulphalanx
Posts: 35
Joined: Mon Aug 22, 2005 7:48 am

Post by soulphalanx »

i cant seem to download your program

could you post some code?
shifty_bill
Posts: 8
Joined: Sat Jan 07, 2006 12:49 pm

Post by shifty_bill »

thats strange . . . ok here it is

Code: Select all

System.usbDiskModeActivate()
white = Color.new(255, 255, 255)
canjump = true
canplay = false
canmoveleft = true
canmoveright = true
grounded = false
ground = 1
playerdir = left
jump = "down"
jumptimer = 0
move = false
moveleft = false
moveright = false
playerwidth = 40
playerheight = 43
mmrunright = {}
for i=1, 14 do
mmrunright[i] = Image.load("mmsprites/runright/runright" .. i .. ".png")
end
mmrunleft = {}
for i=1, 14 do
mmrunleft[i] = Image.load("mmsprites/runleft/runleft" .. i .. ".png")
end
runpicnumber = 1

mmstandright = {}
for i=1, 6 do
mmstandright[i] = Image.load("mmsprites/standright/standright" .. i .. ".png")
end
mmstandleft = {}
for i=1, 6 do
mmstandleft[i] = Image.load("mmsprites/standleft/standleft" .. i .. ".png")
end
startanimation = {}
for i=1, 26 do
startanimation[i] = Image.load("mmsprites/start/start" .. i .. ".png")
end
mmjumpleft = {}
for i= 1, 1 do
mmjumpleft[i] = Image.load("mmsprites/jump/jumpleft" .. i .. ".png")
end
mmjumpright = {}
for i= 1, 1 do
mmjumpright[i] = Image.load("mmsprites/jump/jumpright" .. i .. ".png")
end
collisionback = Image.load("mmsprites/backgrounds/back1.png")
background = Image.load("mmsprites/backgrounds/background1.png")

collisionback2 = Image.load("mmsprites/backgrounds/back2.png")
background2 = Image.load("mmsprites/backgrounds/background2.png")
backx = 0
backx2 = 480
collisioncolor = Color.new(112,112,112)
image = Image.createEmpty(1, 1)
collisionx = playerx
collisiony = playery

startanimationpic = 1
starttimer = 0
standpicnumber = 1
picnumer = 1
stance = mmstandright
moveleft = false
moveright = false
lastdir = "right"
playerx = 100
playery = 200


timer = 0

function input()  ---------------------controls
   pad = Controls.read()
if canplay == true then 
   if pad:left() == true and canmoveleft == true then
      moveleft = true
      moveright = false
      lastdir = "left"
   else
      moveleft = false
   end
   if pad:right() == true and canmoveright == true then
      moveright = true
      moveleft = false
      lastdir = "right"
   else
      moveright = false
   end
end   

   if moveleft == true and moveright == false then
     stance = mmrunleft
      playerx = playerx - 2
   elseif moveright == true and moveleft == false then
      stance = mmrunright
      playerx = playerx + 2
   end

   if (moveleft == false and moveright == false and lastdir == "left") then
         stance = mmstandleft
      elseif (moveright == false and moveleft == false and lastdir == "right") then
         stance = mmstandright
      end

   if (pad:cross() == true and grounded == true and jump == false) then
      jump = "up"
      grounded = false 
   end
   if jump == "up" then
      jumptimer = jumptimer + 1
      if jumptimer < 24 then
         playery = playery - 4
      end
      if jumptimer > 24 then
         jump = "down"
         jumptimer = 0
      end
   end
   if grounded == false and lastdir == "left" then
      stance = mmjumpleft
   elseif grounded == false and lastdir == "right" then
      stance = mmjumpright
   end
   if stance == mmstandright then
      picnumber = standpicnumber
   elseif stance == mmstandleft then
      picnumber = standpicnumber
   elseif stance == mmrunright then
      picnumber = runpicnumber
   elseif stance == mmrunleft then
      picnumber = runpicnumber
   elseif stance == mmjumpleft then
      picnumber = 1
   elseif stance == mmjumpright then
      picnumber = 1
   end
end  
 
function gravity&#40;&#41; --------------------------------------gravity
   if grounded == false and jump == "up" then
      playery = playery - 2
   elseif grounded == false and jump == "down" then
      playery = playery + 3
   end
end

function collision&#40;&#41;  -----------------------------------collision

   if &#40;collisionback&#58;pixel&#40;playerx , playery + playerheight - 3&#41; == collisioncolor&#41; then
      jump = false
      grounded = true
      jumptimer = 0
   else
      grounded = false
      jumptimer = jumptimer + 1
      if jumptimer > 20 then
         jump = "down"
      end
   end

   if &#40;collisionback&#58;pixel&#40;playerx + playerwidth - 4, playery + 25&#41; == collisioncolor&#41; then
      canmoveright = false
      canmoveleft = true
   else
      canmoveright = true
   end
   if &#40;collisionback&#58;pixel&#40;playerx - 4, playery + 25&#41; == collisioncolor&#41; then
      canmoveright = true
      canmoveleft = false
   else
      canmoveleft = true
   end
end

function time&#40;&#41;  ---------------------------------------timers
   timer = timer + 1
   if timer >3 then
      timer = 0
      if canplay == false then
      startanimationpic = startanimationpic + 1
         if startanimationpic >= 26 then
            startanimationpic = 26
            starttimer = starttimer + 1
            if starttimer >=10 then
               canplay = true
            end
         end
      end
      runpicnumber = runpicnumber + 1
         if runpicnumber >= 14 then
            runpicnumber = 1
         end
      standpicnumber = standpicnumber + 1
      if standpicnumber >= 6 then
         standpicnumber = 1
         end
      end
   
end   

function scroll&#40;&#41;  -----------------------------scolling the backgroiund image


   if playerx >= 300 and moveright == true and canmoveright == true then
      playerx = 299
      backx = backx - 2
      backx2 = backx2 - 2
   end
   if playerx <= 120 and moveleft == true and canmoveleft == true then
      playerx = 121
      backx = backx + 2
      backx2 = backx2 + 2
   end
end
while true do

   gravity&#40;&#41;
   collision&#40;&#41;
   input&#40;&#41;
   time&#40;&#41;
   scroll&#40;&#41;
   if pad&#58;start&#40;&#41; then
         break
   end

   if grounded == true then
      ground = 1
   else
      ground = 0
   end

   
  --gravity&#40;&#41;
screen&#58;blit&#40;backx,0, collisionback, false&#41;
--screen&#58;blit&#40;backx,0, background, false&#41;
screen&#58;blit&#40;backx2,0,collisionback, false&#41;
screen&#58;print&#40;0,0, jumptimer, collisioncolor&#41;
   if canplay == false then
      screen&#58;blit&#40;playerx - 16, playery - 9, startanimation&#91;startanimationpic&#93;, true&#41;
   else
   screen&#58;blit&#40;playerx, playery, stance&#91;picnumber&#93;, true&#41;
   end
--screen&#58;fontPrint&#40;monoSpaced, 10, 214, "MEGA MAN", white&#41;
--screen&#58;fontPrint&#40;monoSpaced, 20, 234, lastdir, white&#41;
   

screen&#58;waitVblankStart&#40;&#41;
screen&#58;flip&#40;&#41;
screen&#58;clear&#40;&#41;
end

i think if u copy then paste the link into a new browser window it will download
User avatar
illfoundedmind
Posts: 22
Joined: Thu Nov 24, 2005 10:03 am
Location: N/A
Contact:

Post by illfoundedmind »

I downloaded your app and went through the code. The basic movement functions look good. I was going through the same collision problem for a RPG I'm working on with a group of people. I ended up scrapping my original way (which is much like yours setting each collusion line by hand) and moving on to doing a array that get the tileset used in that area and see if that is a passable object or not. Maybe that will help you out? good luck

BTW did you do the MegaMan sprites by hand?
illfoundedmind Production StudioImage
Post Reply