walk_engine: ; hl:map addr
push hl
call fade_out
bcall _grbufclr
pop hl
ld a,(hl)
ld (mapWidth),a
inc hl
ld a,(hl)
ld (mapHeight),a
inc hl
ld (mapAddr),hl
ld hl,tiles
ld (tileAddr),hl
call gbaInitMap
call draw_map
call fade_in
walk_engine_loop:
ld a,$fe ;groupe 1
out (1),a ;-les fleches
in a,(1)
bit 0,a ;on pourrait aussi utiliser rra et v�rifier nc (rra \ call nc,walk_down)
push af
call z,walk_down
pop af
bit 1,a
push af
call z,walk_left
pop af
bit 2,a
push af
call z,walk_right
pop af
bit 3,a
call z,walk_up
ld a,$bf ;groupe 7
out (1),a ;-[2nd][Mode][Del],[Y=]->[Graph]
in a,(1)
bit 4,a ;[Y=]?
call z,menu_start
ld a,$fd ;groupe 2
out (1),a ;[Enter]->[Clear]
in a,(1)
bit 6,a ;[Clear]
jr nz,walk_engine_loop
ret
walk_down:
ld hl,player_down ;l'addresse du sprite du joueur � afficher
ld (player_direction),hl
;;
;pourquoi ne pas faire (7 octets) :
; ld bc,(player_y)
; ld a,8
; add a,c
; ld c,a
;;
ld a,(player_y)
add a,8 ;v�rifier qu'il n'y a rien dessous
ld bc,(player_y) ;c = player y, b = player x
ld c,a
;;
call gbaCollision ;a = no. de tile
call check_tile
jp nz,draw_map ;nz = un tile walkable n'a pas �t� rencontr�
walk_down_no_collision:
ld hl,no_scroll
ld (hl),0 ;0 = d�placer la carte
ld a,(player_y)
cp 24
jp p,walk_down2
ld (hl),1 ;!= 0 = il ne faut pas d�placer la carte
walk_down2:
ld hl,gbaScrollDown
ld (scroll_addr),hl ;la routine � �x�cuter
ld hl,inc_walk_y ;l'adresse d'une routine
ld (no_scroll_addr),hl
jp walk_and_scroll
walk_left:
player_left = $+1
ld hl,0
ld (player_direction),hl
ld a,(player_x)
dec a
ld bc,(player_y)
ld b,a
call gbaCollision
call check_tile
jp nz,draw_map
walk_left_no_collision:
ld hl,no_scroll
ld (hl),0
ld a,(player_x)
cp 56
jp m,walk_left2
ld (hl),1
walk_left2:
ld hl,gbaScrollLeft
ld (scroll_addr),hl
ld hl,dec_walk_x
ld (no_scroll_addr),hl
jr walk_and_scroll
walk_right:
player_right = $+1
ld hl,0
ld (player_direction),hl
ld a,(player_x)
add a,8
ld bc,(player_y)
ld b,a
call gbaCollision
call check_tile
jp nz,draw_map
walk_right_no_collision:
ld hl,no_scroll
ld (hl),0
ld a,(player_x)
cp 40
jp p,walk_right2
ld (hl),1
walk_right2:
ld hl,gbaScrollRight
ld (scroll_addr),hl
ld hl,inc_walk_x
ld (no_scroll_addr),hl
jr walk_and_scroll
walk_up:
player_up = $+1
ld hl,0
ld (player_direction),hl
ld a,(player_y)
dec a
ld bc,(player_y)
ld c,a
call gbaCollision
call check_tile
jr nz,draw_map
ld hl,no_scroll
ld (hl),0
ld a,(player_y)
cp 40
jp m,walk_up2
ld (hl),1
walk_up2:
ld hl,gbaScrollUp
ld (scroll_addr),hl
ld hl,dec_walk_y
ld (no_scroll_addr),hl
walk_and_scroll:
ld b,8
walk_and_scroll_loop:
push bc
call inc_walk_count ;il g�re l'animation du joueur ?
no_scroll = $+1
ld a,0 ;mis dans les routines de mouvement
or a ;=0 pour scroller la carte, !=0 pour ne pas scroller
jr nz,walk_and_scroll_skip
scroll_addr = $+1
ld hl,0 ;l'adresse de la routine pour scroller la carte
call jp_hl
jr nc,walk_and_scroll_loop_2 ;c = routine n'a pas pu scroller la carte
walk_and_scroll_skip:
no_scroll_addr = $+1
ld hl,0
call jp_hl
walk_and_scroll_loop_2:
call draw_map
pop bc
djnz walk_and_scroll_loop ;scroller 8 fois
xor a
ld (walk_anim),a
call draw_map
ld bc,(player_y)
call gbaCollision
jr check_event
inc_walk_y:
ld hl,player_y
inc (hl)
ret
dec_walk_x:
ld hl,player_x
dec (hl)
ret
inc_walk_x:
ld hl,player_x
inc (hl)
ret
dec_walk_y:
ld hl,player_y
dec (hl)
ret
draw_map:
call gbaRestoreMap
player_direction = $+1
ld hl,0 ;contient l'adresse du sprite selon la direction du joueur
;;
;ou (11 octets) :
; ld a,(walk_anim)
; add a,a
; add a,a
; add a,a
; add a,a
; ld e,a
; ld d,0 ;ou ld d,b, vu que b devrait �tre 0 apr�s gbaRestoreMap
; add hl,de
;;
ld de,16
ld a,(walk_anim)
or a
jr z,draw_map_3
sub 1 ;mieux serait 'dec a'
jr z,draw_map_2
add hl,de
draw_map_2:
add hl,de
draw_map_3:
;;
ld bc,(player_y)
ld de,$0108
call gbaClipSprite
call gbaDrawMaskSprite
jp ionFastCopy
inc_walk_count:
walk_count = $+1
ld a,0
inc a
ld (walk_count),a
cp walk_frequency
ret nz
xor a
ld (walk_count),a
walk_anim = $+1
ld a,0
inc a
ld (walk_anim),a
cp 4
ret nz
ld (walk_anim),a
ret
check_tile: ; z if tile is walkable
ld hl,walkable_tiles
ld b,walkable_tiles_end-walkable_tiles
check_tile_loop:
cp (hl)
ret z
inc hl
djnz check_tile_loop
check_event_block_tile:
ld hl,event_block_tiles ;pour le moment, pas n�cessaire (apr�s check_tile_loop hl pointe sur event_block_tiles)
ld b,(event_block_tiles_end-event_block_tiles)/3
jr check_event_tile_loop
check_event: ;grass/door
ld hl,event_tiles
ld b,(event_tiles_end-event_tiles)/3 ;chaque �v�nement occupe trois octets
check_event_tile_loop:
cp (hl)
jr nz,$+7 ; jr nz,$+8
inc hl
bcall _ldhlind ; ld a,(hl) \ inc hl \ ld h,(hl) \ ld l,a
jp (hl)
inc hl
inc hl
inc hl
djnz check_event_tile_loop
ret
walkable_tiles: ; walkable tiles
.db 0,2,3,4,18
walkable_tiles_end: