Melkhior’s Mansion – Project Update #10

Welcome to project update #10 for the conversion of Melkhior’s Mansion Spectrum Next!

It’s been a crazy week! The game is starting to take shape, the main character can now run around and explore the game world!

In the last update, I mentioned the collision data and adding the player sprite as well as the 3D isometric engine. I decided that it would be a good idea to turn my attention to the main character and press ahead with navigation of the rooms and game world now that I had collision data. I rescheduled the 3D isometric engine development to the following Monday.

The first half of the week was spent coding various routines to act on the collision data. I created several resources to gather data allowing the code to interact with the game world. The methods involved would require ‘code talk’ technical explanations so I have spared you the pain by not providing those this week!

I started development of the main character movement on Thursday. This involved adding the walk animation, inertia and the slide around obstacles bringing Sir Stamperlot to life!

I spent some time studying the original PC version. I spoke with the developer to discuss the physics and logic to make sure I was implementing their game mechanics correctly.

There were math problems to solve as the 8 bit Z80 cannot use the floating point calculations that the C# Monogame based PC version implements. The subject of normalizing a vector was brought up which requires a square root calculation. This was not ideal for the Spectrum Next’s 8 bit Z80 CPU so time was spent finding an alternate solution. The movement algorithms took a couple of days to develop and I still feel that some refinement is necessary.

Saturday was a game changer lol This was a great moment for me as I implemented the room linking system to allow Sir Stamperlot to walk through a door into a new location. At last!! I could run around the game world.

There are several coloured doors which require a key to pass through them. I have not added the object system so I have limited access to the Mansion which I found rather amusing although I can press a shortcut key to room skip.

There were various problems to solve with the room linking as the location of a door in each room is specified in a high level format. This is expected as the original version is programmed in C#. I had to resolve each door position by looking up the room’s floor size and calculating the position from a set of compass codes.

For example, the largest room is made up from a 3×3 grid of 24×24 pixel floor tiles – row and columns are used, numbered 0,1,2. A door in the centre of the north east wall has a code of NE1_0 as it relates to row 1.0 of the floor tiles. I have to calculate the position of the door in 2D space by multiplying the floor tile size of 24 by the row and column, thus it would be 72,24 pixels from the origin of 0,0 (bottom right).

Each door has a destination room number so I have to lookup the wall of the door in the new room location that points to the current room. So room 006, door NE1_0 may point to room 007 so I lookup the door in room 007 that links to room 006, find the wall which would be opposite of north east, south west in most cases, resolve the 2D location in pixels and place the player in the centre of the doorway. Lots of fun!

There are a maximum of six exits and one trapdoor in each room. Here are the Z80/x86 room data structures described above:

room_006

db LEVEL_GROUND
db FLOOR3X3HEX

db DOOR_SE1_0,0
dw 005

db DOOR_NE1_0,0
dw 007

db DOOR_SW1_0,GATE_CYAN
dw 010

db DOOR_NONE,0
dw 000

db DOOR_NONE,0
dw 000

db DOOR_NONE,0
dw 000

db TRAPDOOR_1
dw 073

; ————

room_007

db LEVEL_GROUND
db FLOOR2X3

db DOOR_NE0_5,0
dw 008

db DOOR_SW0_5,0
dw 006

db DOOR_NW1_0,0
dw 017

db DOOR_NONE,0
dw 000

db DOOR_NONE,0
dw 000

db DOOR_NONE,0
dw 000

db 0
dw 000

Here is the original XML data:

<Room ID=”006″ Size=”72 72″ RenderOffset=”0 0″ Style=”CastleHex” Theme=”Cyan” Description=”Ground Floor”>
<Template Type=”FLOOR3X3HEX” Position=”0 0 -4″ />
<Door Position=”SE1″ Destination=”005″ />
<Door Position=”NE1″ Destination=”007″ />
<Door Position=”SW1″ Destination=”010″ GateType=”Cyan” />
<Entity Type=”TrapDoor” Position=”31 13 0″>
<UserData Key=”Destination” Value=”073″ />
</Entity>
</Room>
<Room ID=”007″ Size=”48 72″ RenderOffset=”0 0″ Style=”Castle” Theme=”Green” Description=”Ground Floor”>
<Template Type=”FLOOR2X3″ Position=”0 0 -4″ />
<Door Position=”NE0.5″ Destination=”008″ />
<Door Position=”SW0.5″ Destination=”006″ />
<Door Position=”NW1″ Destination=”017″ />
</Room>

The main character is automatically pushed through the door once he is under the archway. I added a system to allow the game engine to take control of the sprite for a split second. This fakes input from the user causing the character to keep moving in the current direction, the system walks the player into the new room as soon as the screen flip completes. Control is given back to the user after 5 video frames which is sufficient to build enough momentum to slide the player away from the door. It’s subtle and many of you wont notice during gameplay especially if you keep running as you will already be travelling at maximum velocity.

I feel it’s essential to duplicate the logic from the original PC version as close as possible so I may need to tweak some of my parameters and algorithms after feedback from the original developers.

Now that the doors were active, I moved on to the trapdoors found on the floor and wired those up allowing the player to access more of the game world. The final linking logic is the secret passage short cuts which I will implement after I write this post!

I have spent most of the weekend tidying up and polishing what I have so far. An example is animating the main character during the trapdoor shaft falling sequence. This burns development time but is rather important as loose ends can create bugs and I also feel that they leave the software looking half finished and untidy.

There are many nice touches in the original PC version which I am implementing one by one. The game engine has evolved to a point where it is easy to add each new coding task as the resources and code base grow.

Sadly, that’s it for this week. I will be back next Sunday night UK time (GMT) with update #11.

KevB aka 9bitcolor.

https://twitter.com/9bitcolor
https://twitter.com/EricRetro
https://twitter.com/hot_piping
https://twitter.com/alberto_mcalby

One Comment

Leave a Reply to Matt Davies Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.