Never got it to work -> sprites and walls

Página 1/2
| 2

Por dracul

Master (171)

imagem de dracul

05-04-2019, 13:31

Okay, here's the thing...
I was playing around in BASIC and got a sprite to move. There's another sprite and when they collide it ends.

That's something that I could program as a teenager back in the years...

but I never got it to work with walls.
If I draw (for instance) a maze, how do I detect the wall, and make sure the sprite doesn't go over the wall, but stays within the walls?

Could someone explain that to me? Quite frustrating ... 30 years later, I still don't know how to ;-)

Entrar ou registrar-se para comentar

Por meits

Scribe (6573)

imagem de meits

05-04-2019, 14:04

Never tried but I'm thinking of color detection. You could use POINT for that.
If your wall has color 5 and your sprite is 8 pixels wide and you go one pixel left or up, check the color of the destination coordinate. If you go one pixel right or down, check the destination coordinate + 8.

Por Rogerup

Resident (39)

imagem de Rogerup

05-04-2019, 14:32

If you are using characters for walls you can check the video memory directly with:


It will return the number of the character you have at position X,Y

Por Mafcase

Champion (258)

imagem de Mafcase

05-04-2019, 15:14

Maybe you could use an array?

For example: 1 for walls and 0 for where the character can walk.
After reading the cursorkeys or joystick check if there is a 1 or a 0 in the array in the direction given by the player to decide if your character can move or not.

However maybe this way is too slow in basic.

Por MsxKun

Paragon (1134)

imagem de MsxKun

05-04-2019, 15:15

You can just have a copy of your map on RAM. Then check bytes (mostly like Rogerup said, but using RAM instead of VRAM, just PEEK). Using RAM is way faster. But... you need space on RAM Big smile Wich in Basic is also a treasure...

So think what do you need more. RAM Space or Game Speed?

Por dracul

Master (171)

imagem de dracul

05-04-2019, 17:04

MsxKun ... well... to be honest, I have to get it to work first ;-)

Anyway, I'm going to try some of the stuff you guys mentioned in this thread! Thanks so much!

Por jacco_bot

Rookie (18)

imagem de jacco_bot

05-04-2019, 18:13

What I have done for MSX2 is a simple tile based representation of your maze, divide your screen up in blocks of 8x8 or 16x16, whatever your tile-size is and use a 1 for something inpenetrable, and a 0 for something that you can walk through, a 2 for a ladder, 3 for a trap etc.
Then you translate your x,y coordinate from your sprite to your map-coordinates (divide by 8 or 16, depending on tile-size). This then gives you the spot in your map to look for a 1 or 0. If you want to account for a moving sprite, then you check the position x+8 for moves to the right, x-8 for moves to the left etc. before you move your sprite to see if you can.
For MSX1 it is similar: If you are using screen 1, then you already are using a character based map in VRAM, you then just need the character code for whatever is a wall or trap or stairs or ladder or lava-wall to take action upon.

Por dracul

Master (171)

imagem de dracul

05-04-2019, 18:52

As I'm completely new to programming, I wanted to start with a line drawn in basic (line (x,y)) ... and then checking whether the sprite touches the line or not...
I've been playing with Point (x,x) ... but I think that I take it too hard... I'm used to excell where you can nest all those IF statements together... Think that's not possible in Basic?

So,... how would one progress on, to do this? I'm just a beginner! :-)

Por Grauw

Ascended (10821)

imagem de Grauw

05-04-2019, 19:57

A tile map based representation of the world is the most standard approach, using a 2-dimensional array (or 1-dimensional with y * width + x) with bytes representing 8x8 or 16x16 tiles.

Then to do collision detection, if the character sprite moves right, calculate the tile(s) that corresponds to the top right and bottom right pixel of the sprite, and check if the tile is solid or not. The simplest way is to say tiles with index 0-127 are pass-through, and tiles 128-255 are solid. A more complex set-up is to have a separate table which specifies for each tile index whether it is solid or not.

If you search Google or Youtube for something like “tile map” or “tile map basics” you should be able to find a number of deeper explanations of the concept, maybe that will be useful. They will not likely be specific to MSX, but still give you useful background information. Many games from the 80s were based on this concept (e.g. super mario), and many are even today.

In the MSX pattern screen modes (screen 1, 2 and 4), they are already tile based modes using 8x8 tiles, so there you could even check the tile number by reading from VRAM, rather than to do your lookups in a separate tile map in RAM. To use the pattern modes as a tile map, you would typically not use commands like line, pset, etc., rather you would draw a tile map in a graphics editor, load it as pattern and colour table data, and then vpoke the tile numbers into the name table.

Por Latok

msx guru (3960)

imagem de Latok

05-04-2019, 20:15

dracul, I had the same feeling as you and programmed my first maze just last month! I decided to work with 16x16 blocks and that means that in screen 5 with a resolution of 256x192 the map in RAM is only 192 bytes. In my maze every 16x16 block has its own number. So you program the sprite runs through this map in RAM and you let the sprite on screen do whatever sequence you programmed for a specific numbered 16x16 block. For example 'move 16 pixels left' or 'move 16 pixels down' or 'clear level'.

I'm now at the point of programming an enemy that walks the same maze and has some AI. Can't figure that out just yet how to do this. For this, I would love to get some input.

Por Manuel

Ascended (19683)

imagem de Manuel

05-04-2019, 23:44

What is the problem exactly, Latok? Can you make a more precise question? That alone usually already helps you Smile

Página 1/2
| 2