Implemented blocker sprites the right way.

This commit is contained in:
Martin Haye 2014-07-06 18:22:31 -07:00
parent 61e568f38d
commit 3af48520a1
3 changed files with 51 additions and 26 deletions

View File

@ -431,18 +431,15 @@ class PackPartitions
if (name == null || name.toLowerCase() =~ /street|blank|null/)
texMap[id] = 0
else if (stripName(name) in textures) {
def flags = 0
def flags = 1
if (tile?.@obstruction == 'true')
flags |= 1
if (tile?.@sprite == 'true')
flags |= 2
if (tile?.@blocker == 'true')
flags |= 4
texList.add(textures[stripName(name)].num)
texFlags.add(flags)
texMap[id] = texList.size()
println "tex #${texList.size()}: name=$name flags=$flags"
if (tile?.@obstruction != 'true')
if (tile?.@sprite == 'true')
texMap[id] |= 0x80; // hi-bit flag to mark sprite cells
}
else if (id) {
@ -464,6 +461,10 @@ class PackPartitions
texList.each { buf.put((byte)it) }
buf.put((byte)0)
// Followed by the corresponding list of texture flags
texFlags.each { buf.put((byte)it) }
buf.put((byte)0)
// Sentinel row of $FF at start of map
(0..<width).each { buf.put((byte)0xFF) }

View File

@ -132,8 +132,8 @@ byte = $22 ; blue
byte = $28 ; orange
byte = $2A ; hi-bit white
word skyNum = 0
word groundNum = 0
word skyNum = 9
word groundNum = 10
;==================================================================================================
; Definitions used by assembly code
@ -367,9 +367,11 @@ def initCmd(key, func)
end
def moveForward()
word wasBlocked
wasBlocked = isBlocked()
*playerX = *playerX + walkDirs[^playerDir * 2]
*playerY = *playerY + walkDirs[^playerDir * 2 + 1]
if isBlocked()
if !wasBlocked and isBlocked()
moveBackward()
fin
end
@ -379,10 +381,12 @@ def adjustDir(n)
end
def moveBackward()
word wasBlocked
wasBlocked = isBlocked()
adjustDir(8)
moveForward()
adjustDir(8)
if isBlocked()
if !wasBlocked and isBlocked()
moveForward()
fin
end

View File

@ -11,7 +11,7 @@ start:
; code is at the very end. We jump to it now.
jmp initMap
jmp renderFrame
jmp getMapCell
jmp isBlocked
jmp setColor
; Conditional assembly flags
@ -19,9 +19,6 @@ DOUBLE_BUFFER = 1 ; whether to double-buffer
DEBUG = 0 ; 1=some logging, 2=lots of logging
DEBUG_COLUMN = -1
; temporary hack to try blocker sprites
BLOCKER_FOO = 0
; Shared constants, zero page, buffer locations, etc.
!source "render.i"
; Debug macros and support functions
@ -390,14 +387,19 @@ castRay: !zone
.hitSprite:
cmp #$FF ; check for special mark at edges of map
beq .hitEdge
!if BLOCKER_FOO {
cmp #$c1
beq .hitEdge
}
; We found a sprite cell on the map. We only want to process this sprite once,
; so check if we've already done it.
tax
and #$40
bne .spriteDone ; already done, don't do again
beq .notDone ; already done, don't do again
txa
and #$3F
tax
jsr getTileFlags
and #4 ; blocker sprite?
bne .hitEdge ; if yes, stop tracing here
jmp .spriteDone ; if not, keep tracing
.notDone:
; Haven't seen this one yet. Mark it, and also record the address of the flag
; so we can clear it later after tracing all rays.
lda (pMap),y ; get back the original byte
@ -434,11 +436,10 @@ castRay: !zone
jsr drawSprite ; put it on screen
+ pla
tay ; restore map position index
!if BLOCKER_FOO {
lda txNum
cmp #1
beq .hitEdge
}
ldx txNum
jsr getTileFlags
and #4 ; blocker sprite?
bne .hitEdge ; if yes, stop tracing rays
.spriteDone:
jmp .DDA_step ; trace this ray some more
@ -1553,6 +1554,12 @@ setPlayerPos: !zone
sta playerDir
rts
;-------------------------------------------------------------------------------
getTileFlags: !zone
dex ; because tile numbers start at 1 but list at 0
lda $1111,x
rts
;-------------------------------------------------------------------------------
; Load the texture expansion code, copy it to aux mem
loadTextures: !zone
@ -1607,7 +1614,15 @@ loadTextures: !zone
brk ; barf out if too many textures
+ stx txNum
jmp .lup
.done: ; end of the texture numbers is the base of the map data - record it
.done: ; end of texture numbers is the list of tile flags
lda .get+1
sta getTileFlags+2
lda .get+2
sta getTileFlags+3
- jsr .get ; skip over the flags now
tay
bne -
; end of the texture flags is the base of the map data - record it
lda .get+1
sta mapBase
lda .get+2
@ -1668,13 +1683,18 @@ calcMapOrigin: !zone
;-------------------------------------------------------------------------------
; Retrieve the map data where the player currently is
getMapCell: !zone
isBlocked: !zone
jsr calcMapOrigin
sta pMap
sty pMap+1
ldy playerX+1
lda (pMap),y
rts
beq +
and #$3F
tax
jsr getTileFlags
and #2 ; flag 2 is for obstructions
+ rts
;-------------------------------------------------------------------------------
; Cast all the rays from the current player coord