mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-12-26 19:29:27 +00:00
Wow, first sprite is like totally working.
This commit is contained in:
parent
9902773b35
commit
2395e8e610
@ -54,7 +54,7 @@ var player = {
|
|||||||
x : 1.5, // current x, y position
|
x : 1.5, // current x, y position
|
||||||
y : 2.5,
|
y : 2.5,
|
||||||
dir : 0, // the direction that the player is turning, either -1 for left or 1 for right.
|
dir : 0, // the direction that the player is turning, either -1 for left or 1 for right.
|
||||||
angleNum : 4, // the current angle of rotation
|
angleNum : 5, // the current angle of rotation
|
||||||
speed : 0, // is the playing moving forward (speed = 1) or backwards (speed = -1).
|
speed : 0, // is the playing moving forward (speed = 1) or backwards (speed = -1).
|
||||||
moveSpeed : 0.25, // how far (in map units) does the player move each step/update
|
moveSpeed : 0.25, // how far (in map units) does the player move each step/update
|
||||||
rotSpeed : 22.5 * Math.PI / 180, // how much does the player rotate each step/update (in radians)
|
rotSpeed : 22.5 * Math.PI / 180, // how much does the player rotate each step/update (in radians)
|
||||||
@ -470,7 +470,7 @@ function intRenderSprites()
|
|||||||
var wSpriteTop = 32 - (wSize >> 1);
|
var wSpriteTop = 32 - (wSize >> 1);
|
||||||
var wSpriteLeft = wX + wSpriteTop;
|
var wSpriteLeft = wX + wSpriteTop;
|
||||||
if (sprite.index == debugSprite)
|
if (sprite.index == debugSprite)
|
||||||
console.log(" wX=$" + wordToHex(wX) + ", wSpriteTop=$" + wordToHex(wSpriteTop) + ", wSpriteLeft=$" + wordToHex(wSpriteLeft));
|
console.log(" wX=$" + wordToHex(wX & 0xFFFF) + ", wSpriteTop=$" + wordToHex(wSpriteTop) + ", wSpriteLeft=$" + wordToHex(wSpriteLeft & 0xFFFF));
|
||||||
var bStartTx = 0;
|
var bStartTx = 0;
|
||||||
if (wSpriteLeft < 0) {
|
if (wSpriteLeft < 0) {
|
||||||
if (wSpriteLeft < -wSize) {
|
if (wSpriteLeft < -wSize) {
|
||||||
|
@ -436,9 +436,13 @@ castRay: !zone
|
|||||||
sta spriteX+1
|
sta spriteX+1
|
||||||
lda mapY
|
lda mapY
|
||||||
sta spriteY+1 ; y coord of sprite
|
sta spriteY+1 ; y coord of sprite
|
||||||
|
tya ; save Y reg to avoid losing our place on the map
|
||||||
|
pha
|
||||||
jsr spriteCalc ; do all the magic math to calculate the sprite's position
|
jsr spriteCalc ; do all the magic math to calculate the sprite's position
|
||||||
bcc .spriteDone ; if sprite is off-screen, don't draw it
|
bcc + ; if sprite is off-screen, don't draw it
|
||||||
jsr drawSprite ; put it on screen
|
jsr drawSprite ; put it on screen
|
||||||
|
+ pla
|
||||||
|
tay ; restore map position index
|
||||||
.spriteDone:
|
.spriteDone:
|
||||||
jmp .DDA_step ; trace this ray some more
|
jmp .DDA_step ; trace this ray some more
|
||||||
|
|
||||||
@ -550,6 +554,7 @@ castRay: !zone
|
|||||||
}
|
}
|
||||||
!if DEBUG {
|
!if DEBUG {
|
||||||
.debugSprite:
|
.debugSprite:
|
||||||
|
+crout
|
||||||
+prStr : !text "Hit sprite, mapX=",0
|
+prStr : !text "Hit sprite, mapX=",0
|
||||||
+prByte mapX
|
+prByte mapX
|
||||||
+prStr : !text "mapY=",0
|
+prStr : !text "mapY=",0
|
||||||
@ -562,11 +567,13 @@ castRay: !zone
|
|||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; Perform screen position calculations for a sprite.
|
; Perform screen position calculations for a sprite.
|
||||||
; Input: spriteX, spriteY, playerX, playerY
|
; Input: spriteX, spriteY, playerX, playerY, playerDir
|
||||||
; Output: clc if sprite is off screen
|
; Output: clc if sprite is off screen
|
||||||
; sec if sprite is on screen, and sets the following variables:
|
; sec if sprite is on screen, and sets the following variables:
|
||||||
; lineCt (height), wSpriteLeft, txColumn, wTxColBump, depth
|
; lineCt (height), wSpriteLeft, txColumn, wTxColBump, depth
|
||||||
spriteCalc: !zone
|
spriteCalc: !zone
|
||||||
|
!if DEBUG { jsr .debug0 }
|
||||||
|
|
||||||
lda #0 ; track sign bits
|
lda #0 ; track sign bits
|
||||||
sta bSgnSinT
|
sta bSgnSinT
|
||||||
sta bSgnCosT
|
sta bSgnCosT
|
||||||
@ -848,11 +855,16 @@ spriteCalc: !zone
|
|||||||
adc #6 ; hi byte of const
|
adc #6 ; hi byte of const
|
||||||
tax ; put it where pow2 wants it
|
tax ; put it where pow2 wants it
|
||||||
jsr pow2_w_w ; back to normal space (in: Y=lo,X=hi, out: A=lo,X=hi)
|
jsr pow2_w_w ; back to normal space (in: Y=lo,X=hi, out: A=lo,X=hi)
|
||||||
; don't need to actually store wX -- it's only needed for spriteLeft below
|
tay ; save lo byte to Y
|
||||||
|
lda bSgnRy ; check sign
|
||||||
|
and #1 ; only the lo bit counts
|
||||||
|
beq + ; clear, no invert
|
||||||
|
jsr .negYX
|
||||||
|
+ ; don't need to actually store wX -- it's only needed for spriteLeft below
|
||||||
!if DEBUG { jsr .debug5 }
|
!if DEBUG { jsr .debug5 }
|
||||||
|
|
||||||
; Calculate wSpriteLeft = wx + wSpriteTop
|
; Calculate wSpriteLeft = wx + wSpriteTop
|
||||||
|
tya
|
||||||
clc ; lo byte already in A from code above
|
clc ; lo byte already in A from code above
|
||||||
adc wSpriteTop ; add to spriteTop (which if you think about it, is a function of dist just like spriteLeft)
|
adc wSpriteTop ; add to spriteTop (which if you think about it, is a function of dist just like spriteLeft)
|
||||||
sta wSpriteLeft ; store lo byte of left coord
|
sta wSpriteLeft ; store lo byte of left coord
|
||||||
@ -860,6 +872,7 @@ spriteCalc: !zone
|
|||||||
txa ; hi byte in X from code above
|
txa ; hi byte in X from code above
|
||||||
adc wSpriteTop+1 ; hi byte of top
|
adc wSpriteTop+1 ; hi byte of top
|
||||||
sta wSpriteLeft+1 ; save hi byte of left coord
|
sta wSpriteLeft+1 ; save hi byte of left coord
|
||||||
|
!if DEBUG { jsr .debug6 }
|
||||||
bmi .ckLeft ; if negative, check against left side
|
bmi .ckLeft ; if negative, check against left side
|
||||||
|
|
||||||
; Left coord is positive, check against right side
|
; Left coord is positive, check against right side
|
||||||
@ -934,7 +947,7 @@ spriteCalc: !zone
|
|||||||
lsr
|
lsr
|
||||||
ror depth
|
ror depth
|
||||||
|
|
||||||
!if DEBUG { jsr .debug6 }
|
!if DEBUG { jsr .debug7 }
|
||||||
|
|
||||||
.draw ; Okay, I think we're all done with calculations for this sprite.
|
.draw ; Okay, I think we're all done with calculations for this sprite.
|
||||||
sec ; flag to say draw it
|
sec ; flag to say draw it
|
||||||
@ -954,6 +967,14 @@ spriteCalc: !zone
|
|||||||
|
|
||||||
; Code for debugging sprite math
|
; Code for debugging sprite math
|
||||||
!if DEBUG {
|
!if DEBUG {
|
||||||
|
.debug0 +prStr : !text "playerX=",0
|
||||||
|
+prWord playerX
|
||||||
|
+prStr : !text "playerY=",0
|
||||||
|
+prWord playerY
|
||||||
|
+prStr : !text "playerDir=",0
|
||||||
|
+prByte playerDir
|
||||||
|
+crout
|
||||||
|
rts
|
||||||
.debug1 +prStr : !text "bSgnSinT=",0
|
.debug1 +prStr : !text "bSgnSinT=",0
|
||||||
+prByte bSgnSinT
|
+prByte bSgnSinT
|
||||||
+prStr : !text "wLogSinT=",0
|
+prStr : !text "wLogSinT=",0
|
||||||
@ -1000,24 +1021,32 @@ spriteCalc: !zone
|
|||||||
+crout
|
+crout
|
||||||
rts
|
rts
|
||||||
.debug5 +prStr : !text "wX=",0
|
.debug5 +prStr : !text "wX=",0
|
||||||
+prXA
|
+prXY
|
||||||
rts
|
rts
|
||||||
.debug6 +prStr : !text "txColumn=",0
|
.debug6 +prStr : !text "wSpriteLeft=",0
|
||||||
|
+prWord wSpriteLeft
|
||||||
|
+crout
|
||||||
|
rts
|
||||||
|
.debug7 +prStr : !text "txColumn=",0
|
||||||
+prByte txColumn
|
+prByte txColumn
|
||||||
+prStr : !text "wTxColBump=",0
|
+prStr : !text "wTxColBump=",0
|
||||||
+prWord wTxColBump
|
+prWord wTxColBump
|
||||||
+prStr : !text "depth=",0
|
+prStr : !text "depth=",0
|
||||||
+prByte depth
|
+prByte depth
|
||||||
|
+crout
|
||||||
rts
|
rts
|
||||||
}
|
}
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; Draw sprite on screen. Uses all the variables output by spriteCalc.
|
; Draw sprite on screen. Uses all the variables output by spriteCalc.
|
||||||
drawSprite: !zone
|
drawSprite: !zone
|
||||||
lda screenCol
|
lda screenCol ; save screen column that main raycaster is doing
|
||||||
pha
|
pha
|
||||||
lda wSpriteLeft
|
lda wSpriteLeft ; lo byte of left coord
|
||||||
sta screenCol
|
ldx wSpriteLeft+1 ; hi byte
|
||||||
|
bpl + ; if positive, ok
|
||||||
|
lda #0 ; if negative, clamp left coord to 0
|
||||||
|
+ sta screenCol
|
||||||
lda #$80 ; fractional byte of txColumn
|
lda #$80 ; fractional byte of txColumn
|
||||||
pha
|
pha
|
||||||
.lup lda screenCol
|
.lup lda screenCol
|
||||||
@ -1038,7 +1067,7 @@ drawSprite: !zone
|
|||||||
sta txColumn ; and save it
|
sta txColumn ; and save it
|
||||||
bcc .lup ; back for more
|
bcc .lup ; back for more
|
||||||
.done pla ; discard fractional byte
|
.done pla ; discard fractional byte
|
||||||
pla ; get back to old screen column
|
pla ; get back ray caster's screen column
|
||||||
sta screenCol
|
sta screenCol
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user