Skip to content
Game 15 Unit 6 of 32 1 hr learning time

Placing the Player

Put the player character in the first room and display them on the grid with a unique symbol.

19% of Dungeons Of Dorin

A dungeon without an adventurer is just architecture. This unit places the player character in the first room and displays them as an @ symbol — the traditional roguelike representation of the hero. The player position is tracked with two variables, x and y, which will drive movement, viewport rendering, and collision detection in later units.

The Program

5 REM === DUNGEONS OF DORIN ===
10 BORDER 0: PAPER 0: INK 7: CLS
20 PRINT AT 3, 4; INK 7; BRIGHT 1; "DUNGEONS OF DORIN"
30 PRINT AT 6, 2; INK 6; "Descend ten floors of"
35 PRINT AT 7, 2; INK 6; "darkness. Find the Heart."
40 PRINT AT 10, 2; INK 7; "Press any key to begin"
50 PAUSE 0
60 CLS
70 REM === define stats ===
80 LET h = 20: LET z = 20: LET a = 3: LET f = 2
90 REM === generate floor ===
92 GO SUB 1000
94 REM place player in first room
96 LET x = u(1,1) + 1: LET y = u(1,2) + 1
98 REM === display grid ===
100 FOR i = 1 TO 16: FOR o = 1 TO 16
102 IF d(i,o) = 1 THEN PRINT AT i + 2, o + 6; INK 4; CHR$ 143
104 IF d(i,o) = 0 THEN PRINT AT i + 2, o + 6; INK 7; "."
106 NEXT o: NEXT i
108 REM draw player
110 PRINT AT y + 2, x + 6; INK 7; BRIGHT 1; "@"
120 PRINT AT 20, 2; INK 7; "Player at "; x; ","; y
130 STOP
1000 REM === generate floor subroutine ===
1002 DIM d(16,16)
1004 FOR i = 1 TO 16: FOR o = 1 TO 16
1006 LET d(i,o) = 1
1008 NEXT o: NEXT i
1010 LET s = INT (RND * 3) + 3
1012 DIM u(5,4)
1014 FOR i = 1 TO s
1016 LET u(i,1) = INT (RND * 10) + 2
1018 LET u(i,2) = INT (RND * 10) + 2
1020 LET u(i,3) = INT (RND * 4) + 3
1022 LET u(i,4) = INT (RND * 4) + 3
1024 FOR c = u(i,2) TO u(i,2) + u(i,4) - 1
1026 FOR o = u(i,1) TO u(i,1) + u(i,3) - 1
1028 IF c >= 1 AND c <= 16 AND o >= 1 AND o <= 16 THEN LET d(c,o) = 0
1030 NEXT o: NEXT c
1032 NEXT i
1034 FOR i = 1 TO s - 1
1036 LET t = u(i,1) + INT (u(i,3) / 2)
1038 LET t2 = u(i,2) + INT (u(i,4) / 2)
1040 LET t3 = u(i+1,1) + INT (u(i+1,3) / 2)
1042 LET t4 = u(i+1,2) + INT (u(i+1,4) / 2)
1044 IF t <= t3 THEN FOR o = t TO t3: IF t2 >= 1 AND t2 <= 16 AND o >= 1 AND o <= 16 THEN LET d(t2,o) = 0
1046 IF t <= t3 THEN NEXT o
1048 IF t > t3 THEN FOR o = t3 TO t: IF t2 >= 1 AND t2 <= 16 AND o >= 1 AND o <= 16 THEN LET d(t2,o) = 0
1050 IF t > t3 THEN NEXT o
1052 IF t2 <= t4 THEN FOR c = t2 TO t4: IF c >= 1 AND c <= 16 AND t3 >= 1 AND t3 <= 16 THEN LET d(c,t3) = 0
1054 IF t2 <= t4 THEN NEXT c
1056 IF t2 > t4 THEN FOR c = t4 TO t2: IF c >= 1 AND c <= 16 AND t3 >= 1 AND t3 <= 16 THEN LET d(c,t3) = 0
1058 IF t2 > t4 THEN NEXT c
1060 NEXT i
1062 RETURN

How It Works

Line 110 places the player inside the first room. The position is set to the room origin plus one cell in each direction, placing the player safely inside the room rather than on its edge. The room array u(1,1) and u(1,2) hold the x and y position of the first room.

The display code draws the player as a white @ character at their grid position. The @ symbol is a convention from Rogue and its descendants — it stands out clearly against the dots and blocks of the dungeon.

Position Variables

The player position uses two variables: x for column and y for row. These map directly to the dungeon array indices — d(y,x) gives the cell type at the player position. Using x and y rather than longer names keeps PRINT AT and array access compact, which matters when the same variables appear in dozens of places throughout the code.

Placement in the First Room

The player always starts in the first room generated. This is a design choice, not a technical requirement. Starting in a known room means the player always begins in open space, never stuck inside a wall. The offset of +1 from the room origin avoids placing the player on the room boundary, where wall cells might still exist depending on how adjacent corridors were carved.

Try This

Move the start position. Place the player in the last room instead of the first. Change line 110 to use u(s,1) and u(s,2). How does starting in the furthest room change the feel of exploration?

Show the player position. Add a PRINT statement that shows the x and y coordinates below the grid. This will be useful for debugging movement in the next unit.