|
Post by tiberiyltim on Sept 5, 2016 6:53:21 GMT -5
How detect collision Sprite on Tile?
my code:
|
|
|
Post by nitrofurano1 on Sept 5, 2016 16:09:27 GMT -5
in theory, i think it depends on how you have your tiles organized (a group of tiles that is not related to collision and a group that is) on the video ram, or keep checking the sprite position on a map from rom - i guess this was how games for colecovision, master system and msx were made related to this
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Sept 6, 2016 6:38:41 GMT -5
|
|
|
Post by nitrofurano1 on Sept 6, 2016 8:16:37 GMT -5
|
|
|
Post by tiberiyltim on Sept 6, 2016 12:27:55 GMT -5
Collision map not displaced through scroll? use the readtile function... dim positionx(50) as integer dim positiony(50) as integer
positionx=130 positiony=60
'Tiles line for y=24 to 24 for x=0 to 39 drawtile &h39,x,y next next
'Player data Player1=AddSprite(4,3) PropSprite Player1,128,0 MoveSprite Player1,positionx,positiony
while 1
'down Sprite if Stop=0 then ShiftSprite Player1,0,+2
a=readtile(positionx(0),positiony(0))
'stop Sprite??? if a=&h39 then Stop=1 endif
Sleep 1
wend not work
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Sept 7, 2016 15:56:31 GMT -5
There's a lot of methods for doing this, but it really all depends on what your engine needs as well.
The first thing you'll need to do is convert your sprite coordinates to tile coordinates. Let's assume it's an 8x8 pixel sprite: sprx = (spriteposx(MySprite) - 128) / 8 spry = (spriteposy(MySprite) - 128) / 8
(you can substitute >> 3 in place of /8)
Then, what you can do is reload your tile map and use the coordinates as your offset
MapOffset = ((spry + y_move) * MapX) + sprx + x_move
Reload MyMap, MapOffset ReadInt z
The y_move would be -1 if you're going up, +1 if you're going down, and 0 if you're not moving in the Y direction The x_move would be -1 if going left, +1 if going right, and 0 if not moving on the X axis
Now, why the ReadInt z?
What I do is assign a number range for my tiles (to keep it simple) to note which ones are walkable/passable and which ones aren't passable. For example, tiles 1 to 50 are walkable tiles (grass, regular ground, etc), and everything else is impassable.
Next, I do something along the lines of:
If z > 0 And z < 51 Then ' move my sprite routine End If
|
|
|
Post by tiberiyltim on Sept 8, 2016 14:47:01 GMT -5
elusive, you have easy to use example "scroll Map"?
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Sept 8, 2016 17:53:02 GMT -5
I don't, but moon posted an example some time back that showed collision for tiles, and later in the thread has an example with scrolling added. Here's the thread devster.proboards.com/thread/760/castlevaniaHope this helps!
|
|
|
Post by tiberiyltim on Sept 9, 2016 5:41:41 GMT -5
There there is no scrolling map. Sorry, Thanks!
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Sept 9, 2016 9:56:48 GMT -5
It's the 2nd example near the bottom of the page.
|
|
|
Post by nemezes on Dec 19, 2017 16:02:24 GMT -5
There's a lot of methods for doing this, but it really all depends on what your engine needs as well. The first thing you'll need to do is convert your sprite coordinates to tile coordinates. Let's assume it's an 8x8 pixel sprite: sprx = (spriteposx(MySprite) - 128) / 8 spry = (spriteposy(MySprite) - 128) / 8 (you can substitute >> 3 in place of /8) Then, what you can do is reload your tile map and use the coordinates as your offset MapOffset = ((spry + y_move) * MapX) + sprx + x_move Reload MyMap, MapOffset ReadInt z The y_move would be -1 if you're going up, +1 if you're going down, and 0 if you're not moving in the Y direction The x_move would be -1 if going left, +1 if going right, and 0 if not moving on the X axis Now, why the ReadInt z? What I do is assign a number range for my tiles (to keep it simple) to note which ones are walkable/passable and which ones aren't passable. For example, tiles 1 to 50 are walkable tiles (grass, regular ground, etc), and everything else is impassable. Next, I do something along the lines of: If z > 0 And z < 51 Then ' move my sprite routine End If I was trying to understand what was that shift left right in binary.. Now I figure out what it is.. so simple x<<n is the same as x*(2^n). thanks a lot yes, I am still learning how to code.
|
|