Now able to script transitions from 2D to 3D and back.

This commit is contained in:
Martin Haye 2015-05-20 09:47:35 -07:00
parent b2b922aa7c
commit 907666c716
4 changed files with 103 additions and 33 deletions

View File

@ -92,9 +92,16 @@ if (typeof Mythos === "undefined") {
this.setNextStatement(false); this.setNextStatement(false);
this.appendDummyInput() this.appendDummyInput()
.appendField("Set map to") .appendField("Set map to")
.appendField(new Blockly.FieldTextInput(""), "NAME"); .appendField(new Blockly.FieldTextInput(""), "NAME")
.appendField('x')
.appendField(new Blockly.FieldTextInput("0"), "X")
.appendField('y')
.appendField(new Blockly.FieldTextInput("0"), "Y")
.appendField('facing')
.appendField(new Blockly.FieldTextInput("0"), "FACING")
.appendField('(0-15)');
this.setOutput(false); this.setOutput(false);
this.setTooltip('Switch to a different map (by name)'); this.setTooltip('Switch to a different map (by name) and set position on it');
} }
}; };
Blockly.Blocks['events_teleport'] = { Blockly.Blocks['events_teleport'] = {

View File

@ -1637,23 +1637,51 @@ class PackPartitions
def packSetMap(blk) def packSetMap(blk)
{ {
assert blk.field.size() == 1 def mapNum, x=0, y=0, facing=0
def fld = blk.field[0]
assert fld.@name == 'NAME' blk.field.eachWithIndex { fld, idx ->
def mapName = fld.text() switch (fld.@name)
def mapNum = mapNames[mapName] {
if (!mapNum) { case 'NAME':
printWarning "map '$mapName' not found; skipping set_map." def mapName = fld.text()
return mapNum = mapNames[mapName]
if (!mapNum) {
printWarning "map '$mapName' not found; skipping set_map."
return
}
break
case 'X':
x = fld.text().toInteger()
break
case 'Y':
y = fld.text().toInteger()
break
case 'FACING':
facing = fld.text().toInteger()
assert facing >= 0 && facing <= 15
break
default:
assert false : "Unknown field ${fld.@name}"
}
} }
//println " Set map to '$mapName' (num $mapNum)" //println " Set map to '$mapName' (num $mapNum)"
assert mapNum : "Map $mapName not found!"
emitCodeByte(0x2A) // CB emitCodeByte(0x2A) // CB
assert mapNum[0] == '2D' || mapNum[0] == '3D' assert mapNum[0] == '2D' || mapNum[0] == '3D'
emitCodeByte(mapNum[0] == '2D' ? 0 : 1) emitCodeByte(mapNum[0] == '2D' ? 0 : 1)
emitCodeByte(0x2A) // CB emitCodeByte(0x2A) // CB
emitCodeByte(mapNum[1]) emitCodeByte(mapNum[1])
emitCodeByte(0x2C) // CW
emitCodeWord(x)
emitCodeByte(0x2C) // CW
emitCodeWord(y)
emitCodeByte(0x2A) // CB
emitCodeByte(facing)
emitCodeByte(0x54) // CALL emitCodeByte(0x54) // CALL
emitCodeWord(vec_setMap) emitCodeWord(vec_setMap)
emitCodeByte(0x30) // DROP emitCodeByte(0x30) // DROP

View File

@ -96,6 +96,13 @@ byte needRender = FALSE
word skyNum = 9 word skyNum = 9
word groundNum = 10 word groundNum = 10
// Queue setMap / teleport, since otherwise script might be replaced while executing
byte q_mapIs3D
byte q_mapNum = 0
word q_x
word q_y
byte q_dir
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Definitions used by assembly code // Definitions used by assembly code
asm __defs asm __defs
@ -633,9 +640,7 @@ def initMap(x, y, dir)
// init the script module, if any, which will end up calling us back at the setScriptInfo // init the script module, if any, which will end up calling us back at the setScriptInfo
triggerTbl = NULL triggerTbl = NULL
setWindow2() setWindow2()
puts("Calling initDisplay.\n")
initDisplay(mapNum, pMap, x, y, dir) initDisplay(mapNum, pMap, x, y, dir)
puts("Back from initDisplay.\n")
needRender = FALSE needRender = FALSE
end end
@ -793,13 +798,20 @@ def moveWest()
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Switch to a new map (2D or 3D) // Switch to a new map (2D or 3D) and establish position on it
def setMap(is3D, num, x, y, dir) def setMap(is3D, num, x, y, dir)
mapIs3D = is3D if is3D == mapIs3D and num == mapNum
mapNum = num setPos(x, y)
flipToPage1() setDir(dir)
initMap(x, y, dir) needRender = TRUE
checkScripts() else
mapIs3D = is3D
mapNum = num
flipToPage1()
initMap(x, y, dir)
fin
// Don't check scripts, because we often land on an "Exit to wilderness?" script
//NO:checkScripts()
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
@ -811,8 +823,7 @@ def kbdTeleport()
^$c053 ^$c053
if ^$25 < 23; ^$25 = 23; fin if ^$25 < 23; ^$25 = 23; fin
getPos(@x, @y) getPos(@x, @y)
printf4("\nCurrent: 3D=%d Map=%d X=%d Y=%d ", mapIs3D, mapNum, x, y) printf3("\nCurrent: X=%d Y=%d Facing=%d\n", x, y, getDir())
printf1("Dir=%d\n", getDir())
puts("3D : ") puts("3D : ")
mapIs3D = parseDec(readStr()) mapIs3D = parseDec(readStr())
@ -822,7 +833,7 @@ def kbdTeleport()
x = parseDec(readStr()) x = parseDec(readStr())
puts("Y : ") puts("Y : ")
y = parseDec(readStr()) y = parseDec(readStr())
puts("Dir: ") puts("Facing: ")
dir = parseDec(readStr()) dir = parseDec(readStr())
^$c052 ^$c052
@ -831,11 +842,32 @@ def kbdTeleport()
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def teleport(x, y, dir) def showPos()
printf3("Teleport: x=%d y=%d dir=%d\n", x, y, dir) word x, y
setPos(x, y) byte dir
setDir(dir)
needRender = TRUE flipToPage1()
^$c053
if ^$25 < 23; ^$25 = 23; fin
getPos(@x, @y)
printf3("\nCurrent: X=%d Y=%d Facing=%d\n", x, y, getDir())
puts("Hit any key.\n")
getUpperKey()
^$c052
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def queue_setMap(is3D, num, x, y, dir)
q_mapIs3D = is3D
q_mapNum = num
q_x = x
q_y = y
q_dir = dir
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def queue_teleport(x, y, dir)
queue_setMap(mapIs3D, mapNum, x, y, dir)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
@ -856,6 +888,10 @@ def kbdLoop()
func = cmdTbl[key] func = cmdTbl[key]
if func; func(); fin if func; func(); fin
fin fin
if q_mapNum
setMap(q_mapIs3D, q_mapNum, q_x, q_y, q_dir)
q_mapNum = 0
fin
if needRender if needRender
render() render()
needRender = FALSE needRender = FALSE
@ -868,8 +904,6 @@ end
// is called by the init function for the scripts. // is called by the init function for the scripts.
def setScriptInfo(mapName, trigTbl) def setScriptInfo(mapName, trigTbl)
puts("In setScriptInfo\n")
// Record the trigger table pointer // Record the trigger table pointer
triggerTbl = trigTbl triggerTbl = trigTbl
@ -918,6 +952,7 @@ def initCmds()
// Commands common to both 2D and 3D // Commands common to both 2D and 3D
initCmd('T', @kbdTeleport) initCmd('T', @kbdTeleport)
initCmd('P', @showPos)
// Commands handled differently in 3D vs 2D // Commands handled differently in 3D vs 2D
if mapIs3D if mapIs3D
@ -960,13 +995,11 @@ def loadTitle()
puts("Loading Lawless Legends.\n") puts("Loading Lawless Legends.\n")
// Load the title screen // Load the title screen
puts("Loading title screen.\n")
loader(SET_MEM_TARGET, MAIN_MEM, $2000) loader(SET_MEM_TARGET, MAIN_MEM, $2000)
loader(QUEUE_LOAD, MAIN_MEM, 1<<8 | RES_TYPE_SCREEN) // title screen is fixed at #1 loader(QUEUE_LOAD, MAIN_MEM, 1<<8 | RES_TYPE_SCREEN) // title screen is fixed at #1
loader(LOCK_MEMORY, MAIN_MEM, $2000) loader(LOCK_MEMORY, MAIN_MEM, $2000)
loader(FINISH_LOAD, MAIN_MEM, 1) // 1 = keep open loader(FINISH_LOAD, MAIN_MEM, 1) // 1 = keep open
frameLoaded = 1 frameLoaded = 1
puts("Title loaded.\n")
^$c050 ^$c050
^$c057 ^$c057
^$c054 ^$c054
@ -995,7 +1028,7 @@ def setCallbacks()
// $309 // $309
callbacks.9 = $4c callbacks.9 = $4c
callbacks:10 = @setMap callbacks:10 = @queue_setMap
// $30C // $30C
callbacks.12 = $4c callbacks.12 = $4c
@ -1007,7 +1040,7 @@ def setCallbacks()
// $312 // $312
callbacks.18 = $4c callbacks.18 = $4c
callbacks:19 = @teleport callbacks:19 = @queue_teleport
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -1945,6 +1945,7 @@ pl_getPos: !zone {
; Parameters: x, y ; Parameters: x, y
; Returns: Nothing ; Returns: Nothing
pl_setPos: !zone { pl_setPos: !zone {
lda evalStkL,x ; normally handled by asmplasm, but we're also called by pl_initMap
clc clc
adc #1 ; adjust for border guards adc #1 ; adjust for border guards
sta playerY+1 sta playerY+1
@ -1973,6 +1974,7 @@ pl_getDir: !zone {
; Parameters: dir (0-15) ; Parameters: dir (0-15)
; Returns: Nothing ; Returns: Nothing
pl_setDir: !zone { pl_setDir: !zone {
lda evalStkL,x ; normally handled by asmplasm, but we're also called by pl_initMap
and #15 and #15
sta playerDir sta playerDir
rts rts