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
Platform Game Help Please
Moderators: Shine, Insert_witty_name
Hey
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
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
-
- Posts: 35
- Joined: Mon Aug 22, 2005 7:48 am
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
the game looks at a separate collision map to determine where the ground is
not to mention scrolling
-
- Posts: 8
- Joined: Sat Jan 07, 2006 12:49 pm
-
- Posts: 35
- Joined: Mon Aug 22, 2005 7:48 am
-
- Posts: 8
- Joined: Sat Jan 07, 2006 12:49 pm
thats strange . . . ok here it is
i think if u copy then paste the link into a new browser window it will download
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() --------------------------------------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() -----------------------------------collision
if (collisionback:pixel(playerx , playery + playerheight - 3) == collisioncolor) then
jump = false
grounded = true
jumptimer = 0
else
grounded = false
jumptimer = jumptimer + 1
if jumptimer > 20 then
jump = "down"
end
end
if (collisionback:pixel(playerx + playerwidth - 4, playery + 25) == collisioncolor) then
canmoveright = false
canmoveleft = true
else
canmoveright = true
end
if (collisionback:pixel(playerx - 4, playery + 25) == collisioncolor) then
canmoveright = true
canmoveleft = false
else
canmoveleft = true
end
end
function time() ---------------------------------------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() -----------------------------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()
collision()
input()
time()
scroll()
if pad:start() then
break
end
if grounded == true then
ground = 1
else
ground = 0
end
--gravity()
screen:blit(backx,0, collisionback, false)
--screen:blit(backx,0, background, false)
screen:blit(backx2,0,collisionback, false)
screen:print(0,0, jumptimer, collisioncolor)
if canplay == false then
screen:blit(playerx - 16, playery - 9, startanimation[startanimationpic], true)
else
screen:blit(playerx, playery, stance[picnumber], true)
end
--screen:fontPrint(monoSpaced, 10, 214, "MEGA MAN", white)
--screen:fontPrint(monoSpaced, 20, 234, lastdir, white)
screen:waitVblankStart()
screen:flip()
screen:clear()
end
i think if u copy then paste the link into a new browser window it will download
- illfoundedmind
- Posts: 22
- Joined: Thu Nov 24, 2005 10:03 am
- Location: N/A
- Contact:
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?
BTW did you do the MegaMan sprites by hand?
illfoundedmind Production Studio
- A TEAM making games for PSP.
- Email admin@illfoundedmind.com if your interested in joining.