You are not logged in.
Pages: 1
So I was wondering if you guys could help me out. I'm not really aquainted enough with ASM to fully implement this. Basically, I want a way to query the current coordinate on the current map against a table of coordinates. So if you're coordinate was say [0,1] on the current map, it would check the table to find whether that coordinate exists in the table and then return the value in the collumn next to those coordinates. I hope this makes sense.
Thank you.
,Red
Offline
You can reuse existing code, but you won't have the (x, y, value) structure you want:
...
ld hl, .Coords
call ArePlayerCoordsInArray
jr nc, .no
ld hl, .Values
ld e, a
ld d, 0
add hl, de
ld a, [hl]
...
.no
...
.Coords:
db 1, 5
db 3, 3
...
db -1
.Values:
db 5
db 2
...
Or you can do something like this (adapted from ArePlayerCoordsInArray and IsInArray):
IsInPlayerCoordArray:
ld a, [W_YCOORD]
ld b, a
ld a, [W_XCOORD]
ld c, a
ld de, 3
IsInCoordArray:
xor a
.loop
push af
ld a, [hl]
cp -1
jr z, .no
.y
cp b
jr nz, .next
.x
inc hl
ld a, [hld]
cp c
jr z, .yes
.next
pop af
inc a
add hl, de
jr .loop
.no
pop af
and a
ret
.yes
pop af
scf
ret
Then:
...
ld hl, .Coords
call IsInPlayerCoordArray
jr nc, .no
inc hl
inc hl
ld a, [hl]
...
.no
...
.Coords:
db 1, 5, 5
db 3, 3, 2
...
db -1
Last edited by comet (2015-08-07 17:30:26)
Offline
comet provided a solution already, but I would have written mine here day before yesterday too if I had a chance to access computer then. Here is one way to do this:
Before loop: b = X coordinate, c = Y coordinate, hl = pointer to table of coordinates)
.loop ldi a, [hl]
cp a, FF
jr z, .no
cp a, b
ldi a, [hl]
jr nz, .loop // x coordinate didn't match
cp a, c
jr nz, .loop // y coordinate didn't match
scf
ret
.no and a,a
ret
Last edited by Miksy91 (2015-08-09 15:46:01)
Offline
Pages: 1