-SkyLock24- 2020-11-28 12:47
How do you create tile maps with tile collision
nousername010 2020-11-28 13:50 (Edited)
To add tiles, you can make a background with the BG/GFX editor and use BG COPY 0,0,19,19 TO 0,0 to copy it to your screen.
For simple tile collision, you can check with the CELL.C of the player position and see if the returned character matches the wall character. If it does, then undo the movement.
nousername010 2020-11-28 14:09
Though more complicated methods are required for more complex programs, here is a simple program that you can follow. Keep in mind that this method doesn't take account for sliding against walls, so you'll be stuck like glue once you collide.
-SkyLock24- 2020-11-28 15:03
@nousername010 thank you!
-SkyLock24- 2020-11-28 15:30
Would you mind explaining how to plug the information in for the program?
was8bit 2020-11-28 17:34
If you want to keep your code simple, all you have to do is restrict movement to whole cell blocks by moving 8 each time.... moving 1 each time will require checking all four corners as Timo has shown (check gamelegends posts)
I am adding a version with the 8 pixel movement, as well as fixed the edge issue and speed issue :)
was8bit 2020-11-28 17:35 (Edited)
I myself use 8 pixel movement as it makes coding simpler and easy :)
was8bit 2020-11-28 18:20 (Edited)
For smoother movements from cell to cell, i offer a sample program :)
-SkyLock24- 2020-11-28 20:47
I am confused.
I know what to do but don’t know how to do it.
I know that you need to:
But I don’t know how to do 4 and 5.
nousername010 2020-11-29 00:04 (Edited)
That's also a great and simpler option, thanks was8bit!
The CELL.C(cx,cy) command gets the cell at position cx and cy. Each cell in the background has their own respective x and y position, from 0 to 19 (there's a slight offset that allows more tiles in the background, but i'll leave that for now to make it simpler).
While cell position is based on cells in the background, sprite position is based on pixels. If the sprite would be on CELL.C(4,5), then it would be on position 32,40 since cells are 8x8 pixels in size.
Since sprites are drawn from the top left corner, so you'll have to add the sprite x or y by 7 to get the individual corners of the sprite. You will have to also do INT(P/8) for the CELL.C command since cell characters are multiples of 8, and the INT command rounds the number down. So if you want to find the cell at position 32,40, then you'll have to do CELL.C(INT(32/8),INT(40/8)).
As was8bit stated, you can also just move the player by 8 pixels so you can make your program simpler without the INT command.
Hope that helps.
was8bit 2020-11-29 05:39
And also INT(32/8) can be simplified in NX with 32\8
The backward slash is INTEGER division... in other words, it does exactly what the other version does, yields the integer result of the division ;)
was8bit 2020-11-29 06:03
Here is a demonstration that should help, i commented in the code... please ask any questions... this should help :)