Added blocks for setting sky and ground colors, and teleporting the player. Added support for init scripts using Blockly.

This commit is contained in:
Martin Haye 2014-07-20 06:02:10 -07:00
parent ebe228d15f
commit 97b942036f
4 changed files with 185 additions and 35 deletions

View File

@ -49,7 +49,10 @@
<block type="logic_cointoss"></block> <block type="logic_cointoss"></block>
</category> </category>
<category name="Events"> <category name="Events">
<block type="events_setmap"></block> <block type="events_set_map"></block>
<block type="events_teleport"></block>
<block type="events_set_sky"></block>
<block type="events_set_ground"></block>
</category> </category>
<category name="Text"> <category name="Text">
<block type="text_window"></block> <block type="text_window"></block>

View File

@ -84,18 +84,66 @@ if (typeof Mythos === "undefined") {
.appendField("Coin toss"); .appendField("Coin toss");
} }
}; };
Blockly.Blocks['events_setmap'] = { Blockly.Blocks['events_set_map'] = {
init: function() { init: function() {
this.setHelpUrl(Mythos.helpUrl); this.setHelpUrl(Mythos.helpUrl);
this.setColour(54); this.setColour(54);
this.setPreviousStatement(true); this.setPreviousStatement(true);
this.setNextStatement(false); this.setNextStatement(false);
this.appendValueInput("VALUE") this.appendDummyInput()
.appendField("Set map"); .appendField("Set map to")
.appendField(new Blockly.FieldTextInput(""), "NAME");
this.setOutput(false); this.setOutput(false);
this.setTooltip('Switch to a different map (by name)'); this.setTooltip('Switch to a different map (by name)');
} }
}; };
Blockly.Blocks['events_teleport'] = {
init: function() {
this.setHelpUrl(Mythos.helpUrl);
this.setColour(54);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.appendDummyInput()
.appendField("Teleport to")
.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.setTooltip('Teleport the player to a given location and direction on this map.');
}
};
Blockly.Blocks['events_set_sky'] = {
init: function() {
this.setHelpUrl(Mythos.helpUrl);
this.setColour(54);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.appendDummyInput()
.appendField("Set sky color to")
.appendField(new Blockly.FieldTextInput("0"), "COLOR")
.appendField('(0-15)');
this.setOutput(false);
this.setTooltip('Set color of the sky');
}
};
Blockly.Blocks['events_set_ground'] = {
init: function() {
this.setHelpUrl(Mythos.helpUrl);
this.setColour(54);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.appendDummyInput()
.appendField("Set ground color to")
.appendField(new Blockly.FieldTextInput("0"), "COLOR")
.appendField('(0-15)');
this.setOutput(false);
this.setTooltip('Set color of the ground');
}
};
Blockly.Blocks['text_window'] = { Blockly.Blocks['text_window'] = {
init: function() { init: function() {
this.setHelpUrl(Mythos.helpUrl); this.setHelpUrl(Mythos.helpUrl);

View File

@ -1088,6 +1088,9 @@ class PackPartitions
def vec_displayStr = 0x303 def vec_displayStr = 0x303
def vec_getYN = 0x306 def vec_getYN = 0x306
def vec_setMap = 0x309 def vec_setMap = 0x309
def vec_setSky = 0x30C
def vec_setGround = 0x30F
def vec_teleport = 0x312
def addString(str) def addString(str)
{ {
@ -1133,6 +1136,8 @@ class PackPartitions
def packScript(scriptNum, script) def packScript(scriptNum, script)
{ {
def name = script.name[0].text() def name = script.name[0].text()
if (name == "init") // this special script gets processed later
return
println " Script '$name'" println " Script '$name'"
if (script.block.size() == 0) if (script.block.size() == 0)
@ -1170,8 +1175,14 @@ class PackPartitions
packTextPrint(blk); break packTextPrint(blk); break
case 'controls_if': case 'controls_if':
packIfStmt(blk); break packIfStmt(blk); break
case 'events_setmap': case 'events_set_map':
packSetMap(blk); break packSetMap(blk); break
case 'events_set_sky':
packSetSky(blk); break
case 'events_set_ground':
packSetGround(blk); break
case 'events_teleport':
packTeleport(blk); break
default: default:
println "Warning: don't know how to pack block of type '${blk.@type}'" println "Warning: don't know how to pack block of type '${blk.@type}'"
} }
@ -1277,16 +1288,10 @@ class PackPartitions
def packSetMap(blk) def packSetMap(blk)
{ {
assert blk.value.size() == 1 assert blk.field.size() == 1
def mapVal = blk.value[0] def fld = blk.field[0]
assert mapVal.@name == 'VALUE' assert fld.@name == 'NAME'
assert mapVal.block.size() == 1 def mapName = fld.text()
def mapValBlk = mapVal.block[0]
assert mapValBlk.@type == 'text'
assert mapValBlk.field.size() == 1
def mapValFld = mapValBlk.field[0]
assert mapValFld.@name == 'TEXT'
def mapName = mapValFld.text()
def mapNum = mapNames[mapName] def mapNum = mapNames[mapName]
assert mapNum assert mapNum
println " Set map to '$mapName' (num $mapNum)" println " Set map to '$mapName' (num $mapNum)"
@ -1301,25 +1306,94 @@ class PackPartitions
emitCodeByte(0x30) // DROP emitCodeByte(0x30) // DROP
} }
def packSetSky(blk)
{
assert blk.field.size() == 1
def fld = blk.field[0]
assert fld.@name == 'COLOR'
def color = fld.text().toInteger()
assert color >= 0 && color <= 15
println " Set sky to $color"
emitCodeByte(0x2A) // CB
emitCodeByte(color)
emitCodeByte(0x54) // CALL
emitCodeWord(vec_setSky)
emitCodeByte(0x30) // DROP
}
def packSetGround(blk)
{
assert blk.field.size() == 1
def fld = blk.field[0]
assert fld.@name == 'COLOR'
def color = fld.text().toInteger()
assert color >= 0 && color <= 15
println " Set ground to $color"
emitCodeByte(0x2A) // CB
emitCodeByte(color)
emitCodeByte(0x54) // CALL
emitCodeWord(vec_setGround)
emitCodeByte(0x30) // DROP
}
def packTeleport(blk)
{
assert blk.field.size() == 3
assert blk.field[0].@name == 'X'
assert blk.field[1].@name == 'Y'
assert blk.field[2].@name == 'FACING'
def x = blk.field[0].text().toInteger()
def y = blk.field[1].text().toInteger()
def facing = blk.field[2].text().toInteger()
assert facing >= 0 && facing <= 15
println " Teleport to ($x,$y) facing $facing"
emitCodeByte(0x2C) // CW
emitCodeWord(x)
emitCodeByte(0x2C) // CW
emitCodeWord(y)
emitCodeByte(0x2A) // CB
emitCodeByte(facing)
emitCodeByte(0x54) // CALL
emitCodeWord(vec_teleport)
emitCodeByte(0x30) // DROP
}
def makeInit(scripts) def makeInit(scripts)
{ {
println " Script: special 'init'"
startFunc(0) startFunc(0)
scripts.script.eachWithIndex { script, idx -> scripts.script.eachWithIndex { script, idx ->
script.locationTrigger.each { trig -> def name = script.name[0].text()
def x = trig.@x.toInteger() if (name == "init")
def y = trig.@y.toInteger() {
locationsWithTriggers.add([x,y]) assert script.block.size() == 1
emitCodeByte(0x2A) // CB def proc = script.block[0]
assert x >= 0 && x < 255 assert proc.@type == "procedures_defreturn"
emitCodeByte(x) assert proc.statement.size() == 1
emitCodeByte(0x2A) // CB def stmt = proc.statement[0]
assert y >= 0 && y < 255 assert stmt.@name == "STACK"
emitCodeByte(y) stmt.block.each { packBlock(it) }
emitCodeByte(0x26) // LA }
emitCodeFixup((idx+1) * 5) else {
emitCodeByte(0x54) // CALL script.locationTrigger.each { trig ->
emitCodeWord(vec_locationTrigger) def x = trig.@x.toInteger()
emitCodeByte(0x30) // DROP def y = trig.@y.toInteger()
locationsWithTriggers.add([x,y])
emitCodeByte(0x2A) // CB
assert x >= 0 && x < 255
emitCodeByte(x)
emitCodeByte(0x2A) // CB
assert y >= 0 && y < 255
emitCodeByte(y)
emitCodeByte(0x26) // LA
emitCodeFixup((idx+1) * 5)
emitCodeByte(0x54) // CALL
emitCodeWord(vec_locationTrigger)
emitCodeByte(0x30) // DROP
}
} }
} }
finishFunc() finishFunc()

View File

@ -426,7 +426,6 @@ def initMap()
pScripts = loader(QUEUE_LOAD, MAIN_MEM, (scriptModule << 8) | RES_TYPE_MODULE) pScripts = loader(QUEUE_LOAD, MAIN_MEM, (scriptModule << 8) | RES_TYPE_MODULE)
loader(FINISH_LOAD, MAIN_MEM, 1) ; 1 = keep open loader(FINISH_LOAD, MAIN_MEM, 1) ; 1 = keep open
nLocTrig = 0 nLocTrig = 0
*pScripts()
fin fin
; Start up the font engine ; Start up the font engine
@ -445,6 +444,9 @@ def initMap()
prevX = -1 prevX = -1
prevY = -1 prevY = -1
prevScript = -1 prevScript = -1
if pScripts
*pScripts()
fin
; Draw the first frame ; Draw the first frame
renderFrame() renderFrame()
@ -575,18 +577,32 @@ def nextMap()
setMap(1, mapNum) setMap(1, mapNum)
end end
def nextSky() def setSky(num)
skyNum = (skyNum + 1) & $F skyNum = num
setColor(0<<8 | skyGndTbl1[skyNum]) setColor(0<<8 | skyGndTbl1[skyNum])
setColor(1<<8 | skyGndTbl2[skyNum]) setColor(1<<8 | skyGndTbl2[skyNum])
end end
def nextGround() def nextSky()
groundNum = (groundNum + 1) & $F setSky((skyNum + 1) & $F)
end
def setGround(num)
groundNum = num
setColor(2<<8 | skyGndTbl1[groundNum]) setColor(2<<8 | skyGndTbl1[groundNum])
setColor(3<<8 | skyGndTbl2[groundNum]) setColor(3<<8 | skyGndTbl2[groundNum])
end end
def nextGround()
setGround((groundNum + 1) & $F)
end
def teleport(x, y, dir)
*playerX = ((x+1)<<8) | $80
*playerY = ((y+1)<<8) | $80
^playerDir = dir
end
def getUpperKey() def getUpperKey()
byte key byte key
while ^keyboard < 128 while ^keyboard < 128
@ -677,6 +693,15 @@ callbacks:7 = @getYN
callbacks.9 = $4c callbacks.9 = $4c
callbacks:10 = @setMap callbacks:10 = @setMap
callbacks.12 = $4c
callbacks:13 = @setSky
callbacks.15 = $4c
callbacks:16 = @setGround
callbacks.18 = $4c
callbacks:19 = @teleport
initMap() initMap()
setWindow2() setWindow2()