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>
</category>
<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 name="Text">
<block type="text_window"></block>

View File

@ -84,18 +84,66 @@ if (typeof Mythos === "undefined") {
.appendField("Coin toss");
}
};
Blockly.Blocks['events_setmap'] = {
Blockly.Blocks['events_set_map'] = {
init: function() {
this.setHelpUrl(Mythos.helpUrl);
this.setColour(54);
this.setPreviousStatement(true);
this.setNextStatement(false);
this.appendValueInput("VALUE")
.appendField("Set map");
this.appendDummyInput()
.appendField("Set map to")
.appendField(new Blockly.FieldTextInput(""), "NAME");
this.setOutput(false);
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'] = {
init: function() {
this.setHelpUrl(Mythos.helpUrl);

View File

@ -1088,6 +1088,9 @@ class PackPartitions
def vec_displayStr = 0x303
def vec_getYN = 0x306
def vec_setMap = 0x309
def vec_setSky = 0x30C
def vec_setGround = 0x30F
def vec_teleport = 0x312
def addString(str)
{
@ -1133,6 +1136,8 @@ class PackPartitions
def packScript(scriptNum, script)
{
def name = script.name[0].text()
if (name == "init") // this special script gets processed later
return
println " Script '$name'"
if (script.block.size() == 0)
@ -1170,8 +1175,14 @@ class PackPartitions
packTextPrint(blk); break
case 'controls_if':
packIfStmt(blk); break
case 'events_setmap':
case 'events_set_map':
packSetMap(blk); break
case 'events_set_sky':
packSetSky(blk); break
case 'events_set_ground':
packSetGround(blk); break
case 'events_teleport':
packTeleport(blk); break
default:
println "Warning: don't know how to pack block of type '${blk.@type}'"
}
@ -1277,16 +1288,10 @@ class PackPartitions
def packSetMap(blk)
{
assert blk.value.size() == 1
def mapVal = blk.value[0]
assert mapVal.@name == 'VALUE'
assert mapVal.block.size() == 1
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()
assert blk.field.size() == 1
def fld = blk.field[0]
assert fld.@name == 'NAME'
def mapName = fld.text()
def mapNum = mapNames[mapName]
assert mapNum
println " Set map to '$mapName' (num $mapNum)"
@ -1300,26 +1305,95 @@ class PackPartitions
emitCodeWord(vec_setMap)
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)
{
println " Script: special 'init'"
startFunc(0)
scripts.script.eachWithIndex { script, idx ->
script.locationTrigger.each { trig ->
def x = trig.@x.toInteger()
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
def name = script.name[0].text()
if (name == "init")
{
assert script.block.size() == 1
def proc = script.block[0]
assert proc.@type == "procedures_defreturn"
assert proc.statement.size() == 1
def stmt = proc.statement[0]
assert stmt.@name == "STACK"
stmt.block.each { packBlock(it) }
}
else {
script.locationTrigger.each { trig ->
def x = trig.@x.toInteger()
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()

View File

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