Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- nanamiTest:
- ;1
- ; jp $
- ;Moves the bullet in the directoin given via an angle
- ; the angle is gotten from a lut and the lower bits of the counter are used for the lut table loc
- ; t = Ftttttt
- ; charweapondat holds the ttl for the angle
- ;E=Y D=X
- ;inc e \ inc d ;modify for collision routine
- ;ld ix,PBMoveANGcont ;return address for collision routine
- ;jp SmallBulletCollision ;IN: DE=XY,
- ;PBMoveANGcont:
- ; dec e \ dec d ;unmodify from collision routine
- ; jp $
- push de ;move the stack back because xy is poped into de before teh jump
- ld a,d
- and %11111100
- ld h,a
- ld a,e
- and %11111100
- ld l,a
- ld de,(chary) ; de = your pos
- ; srl e \ srl d
- ; srl e \ srl d ; pos is stored same as enimies no need to muck with them
- ex de,hl
- ld b,0 ;initializing...
- ld a,e ;
- rrca \ rrca \ and %00111111
- sub L ;y1-y2
- jr nc,_ ;result is negative. Set B for flags (bit 0) and adjust Y for pos.
- set 0,b
- neg
- _:
- ld e,a ;D=Y for later
- rlca \ rlca ;shifting so that %00yyyynn is %yyyynn00 for later. n matters not
- ld L,a ;half-result in L now
- ld a,d
- rrca \ rrca \ and %00111111
- sub H ;x1-x2
- jr nc,_ ;result is negative. Set B for flags (bit 1) and adjust X for pos.
- set 1,b
- neg
- _:
- ld c,a ;C=X for results later
- rrca \ rrca ;shifting so that %00xxxxnn is %nn00xxxx. n still matters not.
- xor L ;combine with Y
- and $0F ;mask out to keep old X low bits
- xor L ;and we have %yyyyxxxx
- ld L,b ;saving flags into L for now.
- ld h,e ;restore H for... stuffs
- ld ix,ArcTanTable
- ld e,a
- ld d,0
- add ix,de ;We have our offset now.
- ;So at this point, C=X, H=Y, L=flags.
- ;Let's go ahead and do X-interpolation first.
- ld a,c
- and %00000011 ;value-ranking
- ld c,(ix+0) ;storing non-adjusted "output" value into C
- jr z,r.arctan.skipxx
- ld e,a ;Loop for second half of X interpolate
- cpl ;ranking first value on inverse of distance to next number
- add a,5 ;So 1=3,2=2,3=1
- ld b,a
- xor a
- _:
- add a,c
- djnz -_
- ld c,(ix+1)
- ld b,e
- _:
- add a,c
- djnz -_
- rra \ rra
- and %00111111
- ld c,a ;out by the time we're done with everything.
- r.arctan.skipxx:
- ld a,h
- ld H,c ;H=InterpolatedX
- and %00000011 ;value-ranking
- ld c,(ix+0) ;storing non-adjusted "output" value into C
- jr z,r.arctan.skipyy
- ld e,a ;Loop for second half of Y interpolate
- cpl ;ranking first value on inverse of distance to next number
- add a,5 ;So 1=3,2=2,3=1
- ld b,a
- xor a
- _:
- add a,c
- djnz -_
- ld c,(ix+16)
- ld b,e
- _:
- add a,c
- djnz -_
- rra \ rra ;Also trying to get any leftovers from too many values of 64
- cp 64
- jr z,_
- and %00111111
- _:
- ld c,a ;added. Since 64*4 is a 9 bit number, getting that back.
- r.arctan.skipyy:
- ld a,c
- add a,H
- rra
- cp 64
- jr z,_
- and %00111111 ;and NOW we have our final angle. (if it wasn't 64...)
- _:
- ld b,0 ;Set to 128 if X is negative. For additions later on.
- bit 1,L
- jr z,_
- ld b,128
- neg ;negate angle
- _:
- bit 0,L
- jr z,_
- neg ;negate angle again if (-,-) else first neg. Still correct :)
- _:
- add a,b ;completing the angle
- ld a,c ; put angle in a
- pop hl
- push hl ; restore xy
- jp moveang
Advertisement
Add Comment
Please, Sign In to add comment