mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-09-29 11:55:21 +00:00
Now scripts have a flag of their own on the map, for speedy detection.
This commit is contained in:
parent
d6815eab05
commit
f4342b12c1
@ -396,7 +396,7 @@ class PackPartitions
|
|||||||
javascriptOut.println("];\n")
|
javascriptOut.println("];\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
def write3DMap(buf, mapName, rows, scriptModule) // [ref BigBlue1_50]
|
def write3DMap(buf, mapName, rows, scriptModule, locationsWithTriggers) // [ref BigBlue1_50]
|
||||||
{
|
{
|
||||||
def width = rows[0].size() + 2 // Sentinel $FF at start and end of each row
|
def width = rows[0].size() + 2 // Sentinel $FF at start and end of each row
|
||||||
def height = rows.size() + 2 // Sentinel rows of $FF's at start and end
|
def height = rows.size() + 2 // Sentinel rows of $FF's at start and end
|
||||||
@ -431,6 +431,10 @@ class PackPartitions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make a map of all the locations with triggers
|
||||||
|
def locMap = [:]
|
||||||
|
locationsWithTriggers.each { x,y -> locMap[[x,y]] = true }
|
||||||
|
|
||||||
// Header: width and height
|
// Header: width and height
|
||||||
buf.put((byte)width)
|
buf.put((byte)width)
|
||||||
@ -454,10 +458,12 @@ class PackPartitions
|
|||||||
(0..<width).each { buf.put((byte)0xFF) }
|
(0..<width).each { buf.put((byte)0xFF) }
|
||||||
|
|
||||||
// After the header comes the raw data
|
// After the header comes the raw data
|
||||||
rows.each { row ->
|
rows.eachWithIndex { row,y ->
|
||||||
buf.put((byte)0xFF) // sentinel at start of row
|
buf.put((byte)0xFF) // sentinel at start of row
|
||||||
row.each { tile ->
|
row.eachWithIndex { tile,x ->
|
||||||
buf.put((byte)texMap[tile?.@id])
|
// Mark scripted locations with a flag
|
||||||
|
def flags = locMap.containsKey([x,y]) ? 0x20 : 0
|
||||||
|
buf.put((byte)texMap[tile?.@id] | flags)
|
||||||
}
|
}
|
||||||
buf.put((byte)0xFF) // sentinel at end of row
|
buf.put((byte)0xFF) // sentinel at end of row
|
||||||
}
|
}
|
||||||
@ -572,10 +578,10 @@ class PackPartitions
|
|||||||
def num = maps3D.size() + 1
|
def num = maps3D.size() + 1
|
||||||
def name = mapEl.@name ?: "map$num"
|
def name = mapEl.@name ?: "map$num"
|
||||||
println "Packing 3D map #$num named '$name'."
|
println "Packing 3D map #$num named '$name'."
|
||||||
def scriptModule = packScripts(mapEl, name)
|
def (scriptModule, locationsWithTriggers) = packScripts(mapEl, name)
|
||||||
def rows = parseMap(mapEl, tileEls)
|
def rows = parseMap(mapEl, tileEls)
|
||||||
def buf = ByteBuffer.allocate(50000)
|
def buf = ByteBuffer.allocate(50000)
|
||||||
write3DMap(buf, name, rows, scriptModule)
|
write3DMap(buf, name, rows, scriptModule, locationsWithTriggers)
|
||||||
maps3D[name] = [num:num, buf:buf]
|
maps3D[name] = [num:num, buf:buf]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -591,7 +597,7 @@ class PackPartitions
|
|||||||
modules[name] = [num:num, buf:wrapByteList(module.data)]
|
modules[name] = [num:num, buf:wrapByteList(module.data)]
|
||||||
bytecodes[name] = [num:num, buf:wrapByteList(module.bytecode)]
|
bytecodes[name] = [num:num, buf:wrapByteList(module.bytecode)]
|
||||||
fixups[name] = [num:num, buf:wrapByteList(module.fixups)]
|
fixups[name] = [num:num, buf:wrapByteList(module.fixups)]
|
||||||
return num
|
return [num, module.locationsWithTriggers]
|
||||||
}
|
}
|
||||||
|
|
||||||
def readBinary(path)
|
def readBinary(path)
|
||||||
@ -1058,6 +1064,8 @@ class ScriptModule
|
|||||||
|
|
||||||
def nScripts = 0
|
def nScripts = 0
|
||||||
|
|
||||||
|
def locationsWithTriggers = []
|
||||||
|
|
||||||
def vec_locationTrigger = 0x300
|
def vec_locationTrigger = 0x300
|
||||||
def vec_displayStr = 0x303
|
def vec_displayStr = 0x303
|
||||||
|
|
||||||
@ -1217,6 +1225,7 @@ class ScriptModule
|
|||||||
script.locationTrigger.each { trig ->
|
script.locationTrigger.each { trig ->
|
||||||
def x = trig.@x.toInteger()
|
def x = trig.@x.toInteger()
|
||||||
def y = trig.@y.toInteger()
|
def y = trig.@y.toInteger()
|
||||||
|
locationsWithTriggers.add([x,y])
|
||||||
emitCodeByte(0x2A) // CB
|
emitCodeByte(0x2A) // CB
|
||||||
assert x >= 0 && x < 255
|
assert x >= 0 && x < 255
|
||||||
emitCodeByte(x)
|
emitCodeByte(x)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
; Handy constants.
|
; Handy constants.
|
||||||
const FALSE = 0
|
const FALSE = 0
|
||||||
const TRUE = !FALSE
|
const TRUE = !FALSE
|
||||||
|
const NULL = 0
|
||||||
|
|
||||||
;==================================================================================================
|
;==================================================================================================
|
||||||
; Fixed memory locations
|
; Fixed memory locations
|
||||||
@ -98,6 +99,7 @@ word locTrig_y[MAX_LOC_TRIG]
|
|||||||
word locTrig_func[MAX_LOC_TRIG]
|
word locTrig_func[MAX_LOC_TRIG]
|
||||||
word prevX
|
word prevX
|
||||||
word prevY
|
word prevY
|
||||||
|
word prevScript
|
||||||
|
|
||||||
; Movement amounts when walking at each angle
|
; Movement amounts when walking at each angle
|
||||||
; Each entry consists of an X bump and a Y bump, in 8.8 fixed point
|
; Each entry consists of an X bump and a Y bump, in 8.8 fixed point
|
||||||
@ -307,13 +309,30 @@ asm isBlocked
|
|||||||
rts
|
rts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
asm isScripted
|
||||||
|
txa
|
||||||
|
pha
|
||||||
|
bit setROM
|
||||||
|
jsr $6009
|
||||||
|
tay
|
||||||
|
pla
|
||||||
|
tax
|
||||||
|
dex
|
||||||
|
tya
|
||||||
|
sta evalStkL,x
|
||||||
|
lda #0
|
||||||
|
sta evalStkH,x
|
||||||
|
bit setLcRW+lcBank2
|
||||||
|
rts
|
||||||
|
end
|
||||||
|
|
||||||
asm setColor
|
asm setColor
|
||||||
txa
|
txa
|
||||||
pha
|
pha
|
||||||
bit setROM
|
bit setROM
|
||||||
lda evalStkL,x
|
lda evalStkL,x
|
||||||
ldy evalStkH,x
|
ldy evalStkH,x
|
||||||
jsr $6009
|
jsr $600C
|
||||||
bit setLcRW+lcBank2
|
bit setLcRW+lcBank2
|
||||||
pla
|
pla
|
||||||
tax
|
tax
|
||||||
@ -426,6 +445,7 @@ def initMap()
|
|||||||
setWindow2()
|
setWindow2()
|
||||||
prevX = -1
|
prevX = -1
|
||||||
prevY = -1
|
prevY = -1
|
||||||
|
prevScript = -1
|
||||||
|
|
||||||
; Draw the first frame
|
; Draw the first frame
|
||||||
renderFrame()
|
renderFrame()
|
||||||
@ -480,13 +500,18 @@ def checkScript()
|
|||||||
if x <> prevX or y <> prevY
|
if x <> prevX or y <> prevY
|
||||||
prevX = x
|
prevX = x
|
||||||
prevY = y
|
prevY = y
|
||||||
clearWindow()
|
if prevScript
|
||||||
for i = 0 to nLocTrig-1
|
clearWindow()
|
||||||
if x == locTrig_x[i] and y == locTrig_y[i]
|
fin
|
||||||
func = locTrig_func[i]
|
prevScript = NULL
|
||||||
*func()
|
if isScripted()
|
||||||
fin
|
for i = 0 to nLocTrig-1
|
||||||
next
|
if x == locTrig_x[i] and y == locTrig_y[i]
|
||||||
|
prevScript = locTrig_func[i]
|
||||||
|
*prevScript()
|
||||||
|
fin
|
||||||
|
next
|
||||||
|
fin
|
||||||
fin
|
fin
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ start:
|
|||||||
jmp initMap
|
jmp initMap
|
||||||
jmp renderFrame
|
jmp renderFrame
|
||||||
jmp isBlocked
|
jmp isBlocked
|
||||||
|
jmp isScripted
|
||||||
jmp setColor
|
jmp setColor
|
||||||
|
|
||||||
; Conditional assembly flags
|
; Conditional assembly flags
|
||||||
@ -297,6 +298,7 @@ castRay: !zone
|
|||||||
lda deltaDistX ; re-init X distance
|
lda deltaDistX ; re-init X distance
|
||||||
sta sideDistX
|
sta sideDistX
|
||||||
lda (pMap),y ; check map at current X/Y position
|
lda (pMap),y ; check map at current X/Y position
|
||||||
|
and #$DF ; mask off script flag
|
||||||
beq .DDA_step ; nothing there? do another step.
|
beq .DDA_step ; nothing there? do another step.
|
||||||
bpl .hitX
|
bpl .hitX
|
||||||
jmp .hitSprite
|
jmp .hitSprite
|
||||||
@ -353,6 +355,7 @@ castRay: !zone
|
|||||||
lda deltaDistY ; re-init Y distance
|
lda deltaDistY ; re-init Y distance
|
||||||
sta sideDistY
|
sta sideDistY
|
||||||
lda (pMap),y ; check map at current X/Y position
|
lda (pMap),y ; check map at current X/Y position
|
||||||
|
and #$DF ; mask off script flag
|
||||||
bmi .hitSprite
|
bmi .hitSprite
|
||||||
bne .hitY ; nothing there? do another step.
|
bne .hitY ; nothing there? do another step.
|
||||||
jmp .DDA_step
|
jmp .DDA_step
|
||||||
@ -393,7 +396,7 @@ castRay: !zone
|
|||||||
and #$40
|
and #$40
|
||||||
beq .notDone ; already done, don't do again
|
beq .notDone ; already done, don't do again
|
||||||
txa
|
txa
|
||||||
and #$3F
|
and #$1F
|
||||||
tax
|
tax
|
||||||
jsr getTileFlags
|
jsr getTileFlags
|
||||||
and #4 ; blocker sprite?
|
and #4 ; blocker sprite?
|
||||||
@ -405,7 +408,7 @@ castRay: !zone
|
|||||||
lda (pMap),y ; get back the original byte
|
lda (pMap),y ; get back the original byte
|
||||||
ora #$40 ; add special flag
|
ora #$40 ; add special flag
|
||||||
sta (pMap),y ; and store it back
|
sta (pMap),y ; and store it back
|
||||||
and #$3F ; get just the texture number
|
and #$1F ; get just the texture number
|
||||||
sta txNum ; and save it
|
sta txNum ; and save it
|
||||||
ldx nMapSprites ; get ready to store the address so we can fix the flag later
|
ldx nMapSprites ; get ready to store the address so we can fix the flag later
|
||||||
cpx #MAX_SPRITES ; check for table overflow
|
cpx #MAX_SPRITES ; check for table overflow
|
||||||
@ -1683,20 +1686,31 @@ calcMapOrigin: !zone
|
|||||||
rts
|
rts
|
||||||
|
|
||||||
;-------------------------------------------------------------------------------
|
;-------------------------------------------------------------------------------
|
||||||
; Retrieve the map data where the player currently is
|
; Check if the player's current location is an obstruction block
|
||||||
isBlocked: !zone
|
isBlocked: !zone
|
||||||
jsr calcMapOrigin
|
jsr calcMapOrigin
|
||||||
sta pMap
|
sta pMap
|
||||||
sty pMap+1
|
sty pMap+1
|
||||||
ldy playerX+1
|
ldy playerX+1
|
||||||
lda (pMap),y
|
lda (pMap),y
|
||||||
|
and #$1F
|
||||||
beq +
|
beq +
|
||||||
and #$3F
|
|
||||||
tax
|
tax
|
||||||
jsr getTileFlags
|
jsr getTileFlags
|
||||||
and #2 ; flag 2 is for obstructions
|
and #2 ; flag 2 is for obstructions
|
||||||
+ rts
|
+ rts
|
||||||
|
|
||||||
|
;-------------------------------------------------------------------------------
|
||||||
|
; Check if the player's current location has a script flag on it
|
||||||
|
isScripted: !zone
|
||||||
|
jsr calcMapOrigin
|
||||||
|
sta pMap
|
||||||
|
sty pMap+1
|
||||||
|
ldy playerX+1
|
||||||
|
lda (pMap),y
|
||||||
|
and #$20
|
||||||
|
rts
|
||||||
|
|
||||||
;-------------------------------------------------------------------------------
|
;-------------------------------------------------------------------------------
|
||||||
; Cast all the rays from the current player coord
|
; Cast all the rays from the current player coord
|
||||||
castAllRays: !zone
|
castAllRays: !zone
|
||||||
|
Loading…
Reference in New Issue
Block a user