keskiviikko 23. tammikuuta 2013

The Techy Bits of an Adventure Game

Introduction

In today's blog, you'll get to read about sprite positioning in a 256 pixel wide screen, how the adventurer stores objects in two pockets and some other technical bits.

Sprites, keyboard reader and music

The IRQ is certainly a very handy feature in the 6502 processor. It is quite well known that the IRQ should be used to play music and sound FX, but the IRQ can be used for other things as well. So, you should make good use of it. Make it do things that have to be done constantly.

First, about the sprite thingy. Since I am using the Spectrum screen size in my game (256 x 192), I decided to use a nifty little technique in the IRQ that will make moving the sprites around the screen a lot easier.
Instead of using the built-in sprite X,Y addresses of the VIC2 directly, I created a little routine into the IRQ that places the sprites according to values in the zero page. For example, the X,Y location of the protagonist is defined in $10 - $11. The IRQ takes the value from $10 and uses it to define the X positions of the player sprites (The player consists of 4 sprites.). The IRQ will set the MSB's of the sprites when needed, so we don't need to do that at all outside the IRQ. This applies to the enemy sprites as well. :) The Y position for the player is taken from $11, respectively. Thanks to the IRQ, we only need to change two zero page addresses when moving the player around.
I saw this technique being used in an another game, and I thought it was pretty clever. In Shiver Me Timbers, it is certainly quite useful.

I am also making use of the IRQ to read the keyboard keys. The key that is being held down is stored in an address. I have to use my own key reader, because the Kernal is completely disabled to take full advantage of the 64 Kb and therefore the built-in key reader routines are unavailable. My routine is a bit more advanced anyway as it reports any of the 64 keys, including the CBM key and both Shift keys. If the user chooses keyboard control at the start menu, he can re-define the keys with the RE-DEFINE KEYS option, otherwise the default keys U, H, K are used for moving the guy around.

The IRQ is also used to play music & sound FX, of course. ;)

Items and a bit of realism

It has been a tradition in arcade-adventures to only allow the protagonist to carry two objects at a time. Makes sense. After all, you only have two hands in real life, too.

Typically the system works like this. You walk past an object. Object 2 is dropped and object 1 moves to object 2. Object 1 then holds the object that you picked up.

Some objects can only be exchanged with an another object, however. For example, in order to get THE PENNY in Pyjamarama, you need to have THE POUND COIN.


Wally decides to change his pound coin to a penny.

Then there are objects that might be in a certain "state" when you first pick them up, such as: a water bucket that is empty, a gun that is not loaded, a torch that is broken, and so on.


Wally filled his water bucket with water.
The items could be represented by byte values. For example, $00 for a book, $01 for a piece of paper, $02 for a crowbar, etc. The two items that you are carrying could be stored in two zero page locations, such as $02 and $03 for example. When you pick up an object, you move $02 to $03 and $02 changes to the value of the picked object, such as $00 if you picked up a book.

It might be necessary to execute some extra code in some rooms, for example to check if the player walked past a water pump while carrying a bucket, or some such.



Well, that's it for today. I hope you enjoyed reading this part of the blog. I still have lots to do for Shiver Me Timbers before all the code is in place, but I have progressed pretty nicely in a rather short time. :) As soon as everything except for the room data is ready, suggestions for puzzles and locations of the game are warmly welcome.

Thanks for reading, see you in the next part!

Ei kommentteja:

Lähetä kommentti