Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pixel collision...
#1
In my game, I want it so that when the player's spear/sword/whatever hits an npc, the npc disappears. unfortunately my pixel collision is a bit buggy... this is what i have.


Code:
function pixelcol (tileseg1, tileoff1, tile1x, tile1y, tileseg2, tileoff2, tile2x, tile2y)

for y = 0 to tile.height
for x = 0 to tile.wid

if pointclone (tileseg1, tileoff1, x,y) <> 0 then

x2 = tile1x + x - tile2x
y2 = tile1y + y - tile2y

if pointclone(tileseg2, tileoff2, x2,y2) <> 0 then
pixelcol= 1
exit sub
endif
endif
next x,y

end function


FUNCTION pointclone (segment, offset, x, y)

DEF SEG = segment
pointclone = PEEK(x + y * tile.wid + offset)


END FUNCTION

would this be returning false collisions? Because i'm sure that sometimes i'm not hitting the sprite yet he dies.
Jumping Jahoolipers!
Reply
#2
PEEK(x + y * tile.wid + offset)

shouldn't that be

PEEK(y + x * tile.wid + offset)

?


I reformat for my own sake ------------
[syntax="qbasic"]
function pixelcol (tileseg1, tileoff1, tile1x, tile1y, tileseg2, tileoff2, tile2x, tile2y)

for y = 0 to tile.height : for x = 0 to tile.wid
if pointclone (tileseg1, tileoff1, x,y) <> 0 then
x2 = tile1x + x - tile2x
y2 = tile1y + y - tile2y

if pointclone(tileseg2, tileoff2, x2,y2) <> 0 then
pixelcol = 1
exit sub
end if
end if
next x,y

end function

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

FUNCTION pointclone (segment, offset, x, y)
DEF SEG = segment
getpcolor = PEEK(x + y * tile.wid + offset)
END FUNCTION
[/syntax]

or maybe change getpcolor to pointclone, alors:

[syntax="qbasic"]
FUNCTION pointclone (segment, offset, x, y)
DEF SEG = segment
pointclone = PEEK(x + y * tile.wid + offset)
END FUNCTION
[/syntax]
ammit potato!
Reply
#3
no, it's x + y * tile.wid + offset.

remember that memory is handled single dimensionally. (or something like that.) You need to times the y by the width of your sprite/tile/whatever, then add the x and the offset.


btw, did some more testing, there is definately some false collisions.

::EDIT::

I noticed that too, and i fixed it. (this is pseudo code: i don't have the source on hand, so i had to go with what i knew, which is pretty much the whole source.) I fixed that up. But that's not what's wrong with it... Thanks anyways potato.
Jumping Jahoolipers!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)