Moving Right Along…

Ok let’s make it all a bit more interactive. I want to add the typical WASD + QE controls for moving around in the dungeon map.

Using the Kernal

To keep things simple I will use the Kernal functions to register when a key is pressed. That should not be a problem as I am not relying on having to read and interpret multiple key presses at once.

So I simply jump to the corresponding memory address and compare the result to the key values I want to check for.

Copy to Clipboard

Making a move

After a keypress is detected I jump to the corresponding movement or rotation code. Let’s say I want to move upwards by pressing W. First I have to know how the player is oriented to make the right movement. To do that I simply shift through the bits until I reach 0 to get my orientation. When I have done that I add or substract to the y or x position based on my orientation and store both values. Now I read the data stored at the target coordinates and check if it is passable. For that I use the get_map_tile and blocked methods.

Copy to Clipboard

Spinning around

Rotation is quite a bit easier to do. I just rotate the bits left or right and check if my value gets out of bound to reset it.

Copy to Clipboard

Compiling the code

After compiling the code I can finally take my first steps in a new world 😉

The complete code listing.

Copy to Clipboard

build_mapview.asm

Copy to Clipboard

build_strips.asm

Copy to Clipboard

draw_view.asm

Copy to Clipboard