Akalabeth Main Game File

31 thoughts
last posted April 5, 2014, 6 a.m.

29 earlier thoughts

0

Because it's hard to understand what is being initialized in lines 51–62 without seeing how it's later used, let's take a look into the routines starting at line 200.

We enter hires graphics mode, set DIS (distance?) to zero and set the plot colour to white:

200  HGR :DIS = 0: HCOLOR= 3

Next we calculate CENT, LEFT and RIGH (RIGHT). Recall that PX and PY are the player's location and DX and DY give the direction they are looking.

202 CENT = DNG%(PX + DX * DIS,PY + DY * DIS):LEFT = DNG%(PX + DX * DIS + DY,PY + DY * DIS - DX):RIGH = DNG%(PX + DX * DIS - DY,PY + DY * DIS + DX)

We'll come back to line 204 .

Now CENT, LEFT and RIGHT contain what is in front and to the left and right. The tens column is each case is used for the monster (if any) and the ones column for the tile. We put into MC the monster in front and change CENT to just be the tile. Similarly we change LEFT and RIGHT to just contain the tile (with no monster info):

205 CENT =  INT (CENT):LEFT =  INT (LEFT):RIGHT =  INT (RIGHT)
206 MC =  INT (CENT / 10):CENT = CENT - MC * 10:LEFT =  INT ((LEFT / 10 -  INT (LEF / 10)) * 10 + .1):RIGH =  INT ((RIGH / 10 -  INT (RIG / 10)) * 10 + .1)

If DIS is zero then we skip to 216...

208  IF DIS = 0 THEN 216

Otherwise...

We're still not sure what 3 or 4 correspond to (doors?) but if we have a WALL (1) or a 3 or 4 we draw a line from (L1,T1) to (R1,T1) to (R1,B1) to (L1,B1) to (L1,T1).

210  IF CENT = 1 OR CENT = 3 OR CENT = 4 THEN  HPLOT L1,T1 TO R1,T1 TO R1,B1 TO L1,B1 TO L1,T1

And if it's a WALL or 3, that's it, we go on to line 260.

212  IF CENT = 1 OR CENT = 3 THEN EN = 1: GOTO 260

If it is a 4 we additionally draw 4 more lines.

214  IF CENT = 4 THEN  HPLOT CD%(DIS,0),CD%(DIS,3) TO CD%(DIS,0),CD%(DIS,2) TO CD%(DIS,1),CD%(DIS,2) TO CD%(DIS,1),CD%(DIS,3):EN = 1: GOTO 260

So does this tell us anything about these variables?

L, T, R and B almost certainly stand for left, top, right and bottom. L1, T1, R1 and B1 must be coordinates of the rectangle for a wall straight in front of the player.

They were initialized as:

204 L1 = PER%(DIS,0):R1 = PER%(DIS,1):T1 = PER%(DIS,2):B1 = PER%(DIS,3):L2 = PER%(DIS + 1,0):R2 = PER%(DIS + 1,1):T2 = PER%(DIS + 1,2):B2 = PER%(DIS + 1,3)

So we seem to have unlocked what PER%(10,3) is for. PER%(d, n) tells us the n-th coordinate used to draw a wall a distance d away. I suspect PER may be short for "perspective".

Let's take a look at the initialization:

Into XX%(0) and YY%(0) we put our vanishing point (roughly center of the screen):

51 XX%(0) = 139:YY%(0) = 79

Next we step 2, 4, 6, ... 20 and calculate XX%(X/2) and YY%(X/2) (i.e. 1, 2, ... 10):

52  FOR X = 2 TO 20 STEP 2:XX%(X / 2) =  INT ( ATN (1 / X) /  ATN (1) * 140 + .5):YY%(X / 2) =  INT (XX%(X / 2) * 4 / 7)

I'll explain the trigonometry in a little bit but note here that the 4 / 7 is just because that's the ratio of the viewport height to the viewport width and so once we've worked out the XX for a given distance, we can just get the YY by multiplying by this.

This enables us to calculate our perspective. 0 is left, 1 is right, 2 is top, 3 is bottom.

53 PER%(X / 2,0) = 139 - XX%(X / 2):PER%(X / 2,1) = 139 + XX%(X / 2):PER%(X / 2,2) = 79 - YY%(X / 2):PER%(X / 2,3) = 79 + YY%(X / 2): NEXT

And finally we set our zero-distance coordinates to be the edge of the screen:

54 PER%(0,0) = 0:PER%(0,1) = 279:PER%(0,2) = 0:PE%(0,3) = 159

And what about CD%(10,3) seen in line 214?

It is initialized on line 55:

55  FOR X = 1 TO 10:CD%(X,0) = 139 - XX%(X) / 3:CD%(X,1) = 139 + XX%(X) / 3:CD%(X,2) = 79 - YY%(X) * .7:CD%(X,3) = 79 + YY%(X): NEXT : PRINT ".";

This is very similar to PER but (X,0) and (X,1) are scaled by 1/3, and (X,2) by 0.7.

The only thing CD%() is used for is line 214 (drawing tile 4).

1 later thought