Jump to content

  •  

* * * * *
Photo

Creating a diagonal guardian


I thought I'd copy this across from a PM as it could be useful to a wider audience. :)

 

Try this. Call it every tick whilst Willy is in the room in question (either via the Patch Vector regime, or else insert a ‘special case’ check of the room number into the Main Loop, similar to the way the Flying Pig playing sprite is handled in the original ‘Draw Willy’ routine).

 

The code below is based on the guardian being the first in the list for the room, but can be adjusted to suit. (e.g. if the guardian is second on the guardian list, then replace the LD A, #8100 with LD A, #8108 and the LD HL, #8103 with LD HL, #810B).

 

The angle of trajectory should be 45 degrees for this configuration. Remove the CPL command to reverse the direction of slope.

 

It should be quite an elegant solution which deals with the guardian moving in both directions. However, I haven’t tried it out so it might fail spectacularly! Good luck!!

 

LD A, #8100 3A 00 81
LD HL, #8103 21 03 81
CPL 2F
RRA 0F
RRA 0F
RRA 0F
RRA 0F
AND #08 E6 08
SUB A, #04 D6 04
ADD A, (HL) 86
LD (HL), A 77
RET C9

 

****************************

 

I just tried out the above. I am pleased to report that it does work. B)

 

However, you have to make sure that the starting y-coordinate is set appropriately for the guardian, dependent on its initial x-coordinate, to avoid it crashing through the floor or ceiling before it reaches the extremities of its range. You should be able to get something sensible working if you play around with it though. :)

 

I managed to get one of the Monks in First Landing to walk up and down the ramp, in both directions (reversing the ramp and its pixel pattern where necessary). ;) Although on both occasions it was 'hovering' slightly above the ramp as it descended, only stepping 'on' the ramp when it went up it. :o :lol:

 

This meant that the guardian had an 'elongated diagonal rectangle' trajectory. i.e. as it reaches each end of its trajectory, the reversal in left-right motion is one time-frame out of sync with the reversal in up-down motion.

 

That happens because the Patch Vector is usually called from a point in the Main Loop which is reached after the guardian has been both moved (via the normal routine at #90C0) and drawn to the screen buffer (via the routine at #91BE).

 

In order to make the guardian move truly diagonally, without deviating from a straight (diagonal) line, you could insert the call to the subroutine which I provided earlier, into the routine at #9534 ('deal with special rooms'), with a check of the room number so that it is only implemented in the room under consideration.

 

The routine at #9534 is CALLED from the Main Loop after the guardians have been subjected to the usual 'Move the guardians' routine, but before the 'Draw the guardians' routine is enacted, and so all the elements of the guardian's movement are completed before it is drawn, thus avoiding the problem described above.




2 Comments

Excellent. :) Thank you for posting this, its appreciated.

This might be slightly more byte-efficient:

 

LD A, #8100                        3A 00 81
LD HL, #8103                      21 03 81
RLA                                       17
LD A, #08                             3E 08

JR NC, #01 or JR C, #01     30 01 or 38 01 (dependent on 'direction' of diagonal guardian: NW-SE or NE-SW)

XOR A                                  AF

SUB A, #04                          D6 04
ADD A, (HL)                         86
LD (HL), A                            77
RET                                       C9