INCLUDE "hardware.inc"
|
|
INCLUDE "input.inc"
|
|
INCLUDE "oam.inc"
|
|
|
|
Section "Player Data", WRAM0
|
|
|
|
playerWorldX: dw
|
|
playerWorldY: dw
|
|
|
|
Section "Player Code", ROM0
|
|
|
|
spriteData:
|
|
INCBIN "png/sprite/player.2bpp"
|
|
|
|
DEF SPRITE_OAM_IDX EQU 0
|
|
DEF SPRITE_IDX EQU 32 ; tile index, rename later
|
|
DEF SPRITE_WIDTH EQU 2
|
|
DEF SPRITE_HEIGHT EQU 2
|
|
|
|
Player_Init::
|
|
ld a, 8
|
|
ld hl, _OAM + 1
|
|
ld [hl], a
|
|
|
|
ld bc, _VRAM8000 + SPRITE_IDX * 16
|
|
ld hl, spriteData
|
|
ld d, 16 * (SPRITE_WIDTH * SPRITE_HEIGHT)
|
|
call memcpy
|
|
|
|
OAM_set SPRITE_OAM_IDX + 0, 8, 144-8-8, SPRITE_IDX, 0
|
|
OAM_set SPRITE_OAM_IDX + 1, 16, 144-8-8, SPRITE_IDX + 1, 0
|
|
OAM_set SPRITE_OAM_IDX + 2, 8, 144-8, SPRITE_IDX + 2, 0
|
|
OAM_set SPRITE_OAM_IDX + 3, 16, 144-8, SPRITE_IDX + 3, 0
|
|
|
|
ld bc, _OAMRAM
|
|
ld hl, _OAM
|
|
ld d, 4 * (SPRITE_WIDTH * SPRITE_HEIGHT)
|
|
call memcpy
|
|
|
|
ret
|
|
|
|
Player_Update::
|
|
; Only update every 2 frames
|
|
ld hl, frame
|
|
ld a, [hl]
|
|
and %1
|
|
cp %1
|
|
ret nz
|
|
|
|
ld hl, keys
|
|
ld b, [hl]
|
|
|
|
; check for move right
|
|
ld a, b
|
|
and BTN_RIGHT
|
|
jr z, .left
|
|
|
|
; check for right boundary
|
|
ld_OAM_x hl, SPRITE_OAM_IDX + 1
|
|
ld a, [hl]
|
|
cp SCRN_X
|
|
jr nc, .left
|
|
|
|
; TODO: check collision
|
|
call move_right
|
|
|
|
.left:
|
|
; check for left button
|
|
ld a, b
|
|
and BTN_LEFT
|
|
ret z
|
|
|
|
; check for left boundary
|
|
ld_OAM_x hl, SPRITE_OAM_IDX
|
|
ld a, [hl]
|
|
cp 9
|
|
ret c
|
|
|
|
; TODO: check collision
|
|
call move_left
|
|
|
|
ret
|
|
|
|
move_right:
|
|
ld_OAM_x hl, SPRITE_OAM_IDX
|
|
|
|
; update top left sprite
|
|
inc [hl]
|
|
inc hl
|
|
ld [hl], SPRITE_IDX
|
|
inc hl
|
|
res OAMB_XFLIP, [hl]
|
|
|
|
; update top right sprite
|
|
inc hl
|
|
inc hl
|
|
inc [hl]
|
|
inc hl
|
|
ld [hl], SPRITE_IDX + 1
|
|
inc hl
|
|
res OAMB_XFLIP, [hl]
|
|
|
|
; update bottom left sprite
|
|
inc hl
|
|
inc hl
|
|
inc [hl]
|
|
inc hl
|
|
ld [hl], SPRITE_IDX + 2
|
|
inc hl
|
|
res OAMB_XFLIP, [hl]
|
|
|
|
; update bottom right sprite
|
|
inc hl
|
|
inc hl
|
|
inc [hl]
|
|
inc hl
|
|
ld [hl], SPRITE_IDX + 3
|
|
inc hl
|
|
res OAMB_XFLIP, [hl]
|
|
|
|
ret
|
|
|
|
move_left:
|
|
ld_OAM_x hl, SPRITE_OAM_IDX
|
|
|
|
; top left
|
|
dec [hl]
|
|
inc hl
|
|
ld [hl], SPRITE_IDX + 1
|
|
inc hl
|
|
set OAMB_XFLIP, [hl]
|
|
|
|
; top right
|
|
inc hl
|
|
inc hl
|
|
dec [hl]
|
|
inc hl
|
|
ld [hl], SPRITE_IDX
|
|
inc hl
|
|
set OAMB_XFLIP, [hl]
|
|
|
|
; bottom left
|
|
inc hl
|
|
inc hl
|
|
dec [hl]
|
|
inc hl
|
|
ld [hl], SPRITE_IDX + 3
|
|
inc hl
|
|
set OAMB_XFLIP, [hl]
|
|
|
|
; bottom right
|
|
inc hl
|
|
inc hl
|
|
dec [hl]
|
|
inc hl
|
|
ld [hl], SPRITE_IDX + 2
|
|
inc hl
|
|
set OAMB_XFLIP, [hl]
|
|
|
|
ret
|