[A83] I'm trying collision based on pixel states, using ionGetPixel
[Prev][Next][Index][Thread]
[A83] I'm trying collision based on pixel states, using ionGetPixel
Well, I wrote a demo for myself that uses ionGetPixel for collision. If you
press left, it checks the pixel 1 to the left of the x coordinate, and if it
is on, then don't move. If you press right, it checks the pixel 8 to the
right of the x coordinate, and if it's on, then don't move. Same method for
the up and down keypresses, except using the y coordinate. Since this is me
writing this, it doesn't work. I know the entire prog can be optimized right
now, don't tell me what is faster and smaller, I just need an explanation of
what's wrong with it, and what the code should be for it to work.
; Ion Header...
; Variable Equates...
runtime:
ld de,tilemap
call drawmap
ld a,8
ld (xcoord),a
ld (ycoord),a
sprite_loop:
call put_dude
call ionFastCopy
key_check_loop:
ld a,kReset
out (1),A
ld a,Group1
out (1),A
in a,(1)
cp kLeft
jp z,move_left
cp kRight
jp z,move_right
cp kUp
jp z,move_up
cp kDown
jp z,move_down
ld a,kReset
out (1),A
ld a,Group2
out (1),A
in a,(1)
cp kClear
ret z
jp key_check_loop
move_left:
ld a,(xcoord)
dec a
ld (xcoord),a
call pixel_state
jp nz,key_check_loop
ld a,(xcoord)
inc a
ld (xcoord),a
call put_dude
ld a,(xcoord)
dec a
ld (xcoord),a
jp sprite_loop
move_right:
ld a,(xcoord)
add a,8
ld (xcoord),a
call pixel_state
jp nz,key_check_loop
ld a,(xcoord)
ld e,8
sub e
ld (xcoord),a
call put_dude
ld a,(xcoord)
inc a
ld (xcoord),a
jp sprite_loop
move_up:
ld a,(ycoord)
dec a
ld (ycoord),a
call pixel_state
jp nz,key_check_loop
ld a,(ycoord)
inc a
ld (ycoord),a
call put_dude
ld a,(ycoord)
dec a
ld (ycoord),a
jp sprite_loop
move_down:
ld a,(ycoord)
add a,8
ld (ycoord),a
call pixel_state
jp nz,key_check_loop
ld a,(ycoord)
ld e,8
sub e
ld (ycoord),a
call put_dude
ld a,(ycoord)
inc a
ld (ycoord),a
jp sprite_loop
pixel_state:
ld a,(ycoord)
ld e,a
ld a,(xcoord)
call ionGetPixel
and (hl)
ret
put_dude:
ld b,8
ld a,(ycoord)
ld l,a
ld a,(xcoord)
ld ix,dude
call ionPutSprite
ret
;This draws a 8x12 screen tile map pointed to by de,
; with offsets from tiles. The routine is 58 bytes.
Drawmap:
ld hl, plotsscreen
ld bc, 8*256+0
DrawmapLoop:
ld a, (de)
push de
push hl
ld l, a
ld h, 0
add hl, hl
add hl, hl
add hl, hl
ld de, tiles
add hl, de
ex de, hl
pop hl
push bc
ld b, 8
push hl
DrawmapLoop2:
ld a, (de)
ld (hl),a
inc de
push bc
ld bc, 12
add hl, bc
pop bc
djnz DrawmapLoop2
pop hl
pop bc
pop de
inc de
inc hl
inc c
ld a, c
cp 12
jr nz, Drawmaploop
ld c,0
push de
ld de, 7*12
add hl, de
pop de
djnz Drawmaploop
ret
tilemap:
.db 1,1,1,1,1,1,1,1,1,1,1,1
.db 1,0,0,0,0,0,0,0,0,0,0,1
.db 1,0,0,0,0,0,0,0,0,0,0,1
.db 1,0,0,0,0,0,0,0,0,0,0,1
.db 1,0,0,0,0,2,3,0,0,0,0,1
.db 1,0,0,0,0,0,0,0,0,0,0,1
.db 1,0,0,0,0,0,0,0,0,0,0,1
.db 1,1,1,1,1,1,1,1,1,1,1,1
dude:
.db %00111100
.db %00100100
.db %00011000
.db %00100100
.db %01100110
.db %10111101
.db %00100100
.db %01100110
tiles:
space:
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %00000000
block:
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
chest:
.db %01111111
.db %10000000
.db %10000011
.db %11111110
.db %10000011
.db %10000000
.db %10000000
.db %11111111
chest2:
.db %11111110
.db %00000001
.db %11000001
.db %01111111
.db %11000001
.db %00000001
.db %00000001
.db %11111111
#include "keys.inc"
.end
END
----------------------------
Thanks,
Colin Hart
Xempest@aol.com
Follow-Ups: