Skip to content

Instantly share code, notes, and snippets.

@plainspooky
Created August 20, 2016 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plainspooky/ca977a2de93bd995602ea9c5b0e015f9 to your computer and use it in GitHub Desktop.
Save plainspooky/ca977a2de93bd995602ea9c5b0e015f9 to your computer and use it in GitHub Desktop.
;
; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
; *
; * Rotina de movimentação do herói
; *
; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;
hero:
proc
ld hl,heroY
ld b,(hl)
inc hl
ld c,(hl)
call heroKeys
call heroLimY
call heroLimX
jp break ; não volta com 'ret'
endp
heroKeys:
proc
xor a
call GTSTCK ; lê o estado das setas de cursor
cp 0 ; algo foi lido?
jr nz,heroCheck ; trata a direção
heroJoy0:
inc a
call GTSTCK ; lê o estado do joystick 0
cp 0
jr nz,heroCheck
heroJoy1:
inc a
call GTSTCK ; lê o estado do joystick 1
heroCheck:
cp 1
jr z,heroNorth ; cima
cp 2
jr z,heroNE ; cima+direita
cp 3
jr z,heroEast ; direita
cp 4
jr z,heroSE ; baixo+direita
cp 5
jr z,heroSouth ; baixo
cp 6
jr z,heroSW ; baixo+esquerda
cp 7
jr z,heroWest ; esquerda
cp 8
jr z,heroNW ; cima+esquerda
ret ; nada, sai da rotina
heroNW:
call heroWest
heroNorth:
ld hl,heroY
dec (hl)
dec (hl)
ret
heroNE:
call heroNorth
heroEast:
ld hl,heroX
inc (hl)
inc (hl)
ret
heroSE:
call heroEast
heroSouth:
ld hl,heroY
inc (hl)
inc (hl)
ret
heroSW:
call heroSouth
heroWest:
ld hl,heroX
dec (hl)
dec (hl)
ret
endp
heroLimY:
proc
ld hl,heroMinY
ld a,(heroY) ; leio o valor de Y
cp (hl)
jr c,heroOldY ; CARRY, então Y é menor que o mínimo
ld hl,heroMaxY
cp (hl)
jr nc,heroOldY ; Sem CARRY, Y é maior que o máximo
ret
heroOldY:
ld hl,heroY ; aponto HL para HERO_Y
ld (hl),b ; reponho o valor antigo de Y
ret
endp
heroLimX:
proc
ld hl,heroMinX
ld a,(heroX) ; leio o valor de X
cp (hl)
jr c,heroOldX ; CARRY, então X é menor que o mínimo
ld hl,heroMaxX
cp (hl)
jr nc,heroOldX ; sem CARRY, X é maior que o máximo
ret
heroOldX:
ld hl,heroX ; aponto HL para HERO_X
ld (hl),c ; reponho o valor antigo de X
ret
endp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment