-
+
+ ; vectors for each direction
+ ; SOUTH, NORTH, WEST, EAST
+ ; S: Sign bit
+ ; y: y position
+ ; x: x position
+ ; bits:
+ ; SYYYSXXX
+act_dir_vector:
+.db 0x90 ; SOUTH
+.db 0x10 ; NORTH
+.db 0x09 ; WEST
+.db 0x01 ; EAST
+
+
+
; updates and draws an actor
; calls different routines fro combat and map state
; inputs:
#define UI_TILE_HEIGHT 4
; player position offset to get center of tile
-#define MAP_W 20
-#define MAP_H 14
+#define MAP_W 6
+#define MAP_H 6
#define MAP_TILES (MAP_W * MAP_H)
; actor type enum
.de ACT_T_BAT, 1
; actor struct
+ ; stats are defined by looking up the type in a table
+ ; player stats are variable
; act_def
.se 0
.de act_type, 1
.de act_flags, 1
.de act_pos_y, 1 ; y/x position
.de act_pos_x, 1
+ ; actor direction information
+ ; D: facing direction bits (0-3)
+ ; 000000DD
+.de act_dir, 1
; custom parameter
.de act_p0, 1
; state parameter
; tile flags
.se 1
-.de TF_WALL, 1
+ ; SOUTH EXIT
+.de TF_SE, 1
+ ; NORTH EXIT
+.de TF_NE, 2
+ ; WEST EXIT
+.de TF_WE, 4
+ ; EAST EXIT
+.de TF_EE, 8
; tile struct
.se 0
; 0 = player, 1-N = map actors
.de t_actor, 1
.de t_p0, 1
- ; graphical tile
-.de t_tile, 1
.de t_size, 0
; exit table entry
.def int DIRLEFT = BTNLEFT
.def int DIRRIGHT = BTNRIGHT
+ ; player direction
+.def int SOUTH = 0
+.def int NORTH = 1
+.def int WEST = 2
+.def int EAST = 3
+
; gameplay control flags
.se 1
- ; default tile id table
- ; 00: empty
- ; 01: wall up left
- ; 02: wall up right
- ; 03: wall down left
- ; 04: wall down right
; level definitions
; levels always have a header
l1:
mapdef MAP_F_DO_FULL_REDRAW, map_r_nop, 0, tile_banks_default, tile_id_table
+ .db 0, 0, 0, 0, 0, 0
+ .db 0, 0, 0, 0, 0, 0
+ .db 0, 0, 0, 0, 0, 0
+ .db 0, 0, 0, 0, 0, 0
+ .db 0, 0, 0, 0, 0, 0
+ .db 0, 0, 0, 0, 0, 0
+ .db 0, 0, 0, 0, 0, 0
+
#include "spawn.inc"
tile_banks_default:
; $1: type
; $2: flags
; $3: p0
- ; $4: tile gfx
#macro tiledef
.db $1, $2
; t_actor
.db 0
.db $3
- .db $4
#endmacro
; defines a new actor
; $6: mp
#macro actdef
.db $1, $2, $3, $4
- ; p0 and state
- .db 0, 0
+ ; dir, p0 and state
+ .db 0, 0, 0
.db $5, $6
#endmacro
ld hl, tile_null
ret
- ; prepares tile draw
- ; by writing the expected tiles
- ; to tile_to_draw[0] to [3]
- ; inputs:
- ; b/c: y/x position
- ; returns:
- ; update_tile_to_draw: 1 bytes of new tile data
- ; upte_tile_vram: ptr to vram
-map_draw_tile_prep:
- ; find tile to draw
- push bc
- call map_get_tile
- ld a, h
- ld [update_tile_ptr], a
- ld a, l
- ld [update_tile_ptr+1], a
-
- ld bc, t_tile
- add hl, bc ; hl = tile gfx
- pop bc
-
- ; load tile into a
- ld a, [hl] ; a = tile
- push af ; save tile gfx
-
- ; TODO: this needs to wrap around
- ; if hl goes oob in y-loop
- ld a, [map_vram_tl]
- ld h, a
- ld a, [map_vram_tl+1]
- ld l, a
- ld de, ((MAP_W) + 12) ; one row
-
- ; skip y loop if b is 0
- ld a, b
- cp a, 0
- jr z, @skip_y REL
-
-@y_loop:
- add hl, de
- dec b
- jr nz, @y_loop REL
-@skip_y:
-
- ld d, 0
- ld a, c
- ld e, a
- add hl, de ; hl = SCRN location
-
- ; save hl to vram ptr
-
- ld a, h
- ld [update_tile_vram], a
- ld a, l
- ld [update_tile_vram+1], a
-
- ; hl = tile data buffer
- ld hl, update_tile_to_draw
-
- ; a = start tile
- pop af
-
- ; draw 1 tile
- ld [hl], a
-
- ret
-
-#macro map_draw_row_inc_c
- push bc
- call map_draw_tile_prep
- pop bc
- push bc
- call map_draw_tile
- pop bc
- inc c
-#endmacro
-
- ; draws a row of tiles
- ; inputs:
- ; b: y position
-map_draw_row:
- ld c, 0
- map_draw_row_inc_c
- map_draw_row_inc_c
- map_draw_row_inc_c
- map_draw_row_inc_c
-
- map_draw_row_inc_c
- map_draw_row_inc_c
- map_draw_row_inc_c
- map_draw_row_inc_c
-
- map_draw_row_inc_c
- map_draw_row_inc_c
- map_draw_row_inc_c
- map_draw_row_inc_c
-
- map_draw_row_inc_c
- map_draw_row_inc_c
- map_draw_row_inc_c
- map_draw_row_inc_c
-
- map_draw_row_inc_c
- map_draw_row_inc_c
- map_draw_row_inc_c
- map_draw_row_inc_c
-
- ret
-
-#macro map_full_draw_inc_b
- call map_draw_row
- inc b
-#endmacro
; draws a full page of the currently selected map
+ ; into the map render buffer
+ ; the map render buffer is then written to the screen
; inputs:
; [map]
map_full_draw:
- ld b, 0
- map_full_draw_inc_b
- map_full_draw_inc_b
- map_full_draw_inc_b
- map_full_draw_inc_b
-
- map_full_draw_inc_b
- map_full_draw_inc_b
- map_full_draw_inc_b
- map_full_draw_inc_b
-
- map_full_draw_inc_b
- map_full_draw_inc_b
- map_full_draw_inc_b
- map_full_draw_inc_b
-
- map_full_draw_inc_b
- map_full_draw_inc_b
-
ret
; nop map rotuine
; sets up the player actor
player_init:
- ld a, 0x5A
+ xor a, a
ld [player+act_pos_y], a
ld a, 0x47
ld [player+act_pos_x], a
ret
+ ; draws the players current facing direction
+ ; as a compass
+compass_draw:
+ ret
+
; moves the player
; does not move out of bounds
; based on the last queued input
player_handle_move:
ret
-
- ; draws player at current location
-player_draw:
- ; flicker the cursor
- ; for transparency effect
- ld a, [frame_count]
- and a, 1
- ret z
-
- ld a, 2
- call oamalloc
-
- ; write left cursor
-
- ; calculate y pos
- ld a, [scroll_y]
- ld b, a ; b = scroll y
-
- ld a, [player+act_pos_y]
- add a, OBJ_OFF_Y
- sub a, b ; - scroll y
- ; store y for second obj
- ld [tmp_y], a
-
- ; write y
- ld [hl+], a
-
- ; calculate x pos
- ld a, [scroll_x]
- ld b, a
-
- ld a, [player+act_pos_x]
- add a, OBJ_OFF_X
- sub a, b ; - scroll x
- ; store x for second obj
- ld [tmp_x], a
-
- ; write x
- ld [hl+], a
-
- ; write tile
- ld a, PLAYER_CURSOR_L
- ld [hl+], a
-
- ; write flags
- xor a, a
- ld [hl+], a
-
- ; write right cursor
-
-
- ; write y
- ld a, [tmp_y]
- ld [hl+], a
-
- ; write x
- ld a, [tmp_x]
- add a, 8
- ld [hl+], a
-
- ; write tile
- ld a, PLAYER_CURSOR_R
- ld [hl+], a
-
- ; write flags
- xor a, a
- ld [hl+], a
-
- ret
; tile definitions
-#define GFX_GRASS 0x20
-#define GFX_WALL 0x40
-
; maps from tile ids
; to tile presets (tile index)
tile_id_table:
- ; 0
- dw tile_grass
-
- ; 1
- dw tile_wall_tl
- dw tile_wall_tr
- dw tile_wall_bl
- dw tile_wall_br
+ ; 0 all exit flags set
+ dw tile_all_exit
- ; 4
- dw tile_wall_single
; fallback tile
tile_null:
tiledef 0, 0, 0, 0
-tile_grass:
- tiledef TT_EMPTY, 0, 0, GFX_GRASS
-
-
-tile_wall_tr:
- tiledef TT_WALL, TF_WALL, 0, GFX_WALL+1
-
-tile_wall_tl:
- tiledef TT_WALL, TF_WALL, 0, GFX_WALL
-
-tile_wall_bl:
- tiledef TT_WALL, TF_WALL, 0, GFX_WALL+16
-tile_wall_br:
- tiledef TT_WALL, TF_WALL, 0, GFX_WALL+17
+tile_all_exit:
+ tiledef TT_WALL, TF_SE | TF_NE | TF_EE | TF_WE, 0
-tile_wall_single:
- tiledef TT_WALL, TF_WALL, 0, 0x42
; player should update even in debug mode
call player_update
- call player_draw
+ call compass_draw
; tick rng every frame
call rand