|
Post by matalog on Jul 5, 2017 2:41:24 GMT -5
I now have a sprite that can jump and move between the horizontal limits of the visible screen.
I have set the background to scroll to the left, and draw the ground at various RANDOM heights as it scrolls. I am recording the height of the ground at each of the 64 horizontal background tile (x) positions in an array.
I had assumed that I would be able to use this array as collision data for my sprite, but I hadn't thought about the background coordinates being shifted as the background is scrolled. So I basically have scrolling coordinates for the background and static coordinates (all relative to screen position) for my sprite.
There is a marked difference in colour in the ground tiles and the sky tiles. Could I possibly use readtile()? I'm not sure how readtile works though, the help file just say that it returns a tile value, does it return a colour value, or a coordinate value?
Does anyone have any idea how I could use the array or readtile to detect collision between sprite and scrolling background platform levels?
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jul 5, 2017 8:56:25 GMT -5
ReadTile() isn't all that useful, but there's 2 ways you can go about this: 1.) use a tile map 2.) use an array
Using an array isn't the best option because arrays eat up a lot of memory and are slow. That's not to say you can't use them, but use them sparingly.
Let's say you wanted to use an array and your map size is 128 tiles by 128 tiles. You would set up an array like this:
Dim MyMap(127,127) as integer
This alone takes up 32kb of memory (half of what's available to you). So, while you can use it, I don't necessarily recommend it.
Instead, I would use a tile map:
MyMap: DataInt 0,0,0,1,1,1,2,3,2,1,0.... DataInt ... ....
There's several ways to draw maps from tile maps, here's a simple one:
Reload MyMap For y = 0 to 63 For x = 0 to 63 ReadInt a DrawTile a,x,y Next Next
If your character is static on screen and only the bg moves, you'll have to update a coordinate variable to match with the background movement. If you move 1 pixel at a time, you'll have to find a way to keep track of partial tile movements and update when you've walked over a new tile, then check a tile in front to see if it's walkable or not.
Once you have your X and Y coordinates figured out, you can reload the tile map with an offset:
Reload MyMap, (y*x_max+x)<<1
y = current y position, x = current x position, x_max = how wide the tile map is in the x direction
From there, use a ReadInt, and if it falls into an area that's not a passable tile, deny movement in that direction.
|
|
|
Post by matalog on Jul 6, 2017 19:52:26 GMT -5
Thanks, I managed it with a single array.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jul 7, 2017 6:21:52 GMT -5
Good deal. Like I said, you can use arrays, but it will eat up available memory. As long as you can work around that, you should be good. I know a few titles that use this method and it has worked out great, while other times people have run into issues. Keep plugging away looking forward to what you come up with
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jul 7, 2017 10:43:33 GMT -5
Devster came up with a SCREEN(X, Y) equivalent for me MANY moons ago. Not sure if it's faster or slower than readtile
' here's the SCREEN(X, Y) equivalent getchar$ = chr$(vdpramread(49152 + (checkx<<1) + (checky<<7)) [AND] 255)
Technically reading video memory is a slow process. For your average homebrewer it really doesn't matter. It seems to work.
THAT being said I've had many more unsolvable bugs regarding collision when using code that checks video memory. I'd second the technique using static arrays (i.e. DATA statements) unless you're making a sandbox style game where practically every element on-screen can be changed.
|
|