Added tile swap for 3D mode.

This commit is contained in:
Martin Haye 2016-11-01 09:25:36 -07:00
parent 831c0cd822
commit 2aa9e342e7
7 changed files with 121 additions and 8 deletions

View File

@ -137,6 +137,7 @@
<block type="graphics_set_fullscreen"></block>
<block type="graphics_clr_fullscreen"></block>
<block type="graphics_set_avatar"></block>
<block type="graphics_swap_tile"></block>
</category>
<category name="Sound">
</category>

View File

@ -807,6 +807,23 @@ if (typeof Mythos === "undefined") {
this.setTooltip('Use the given tile as the avatar image (by name)');
}
};
Blockly.Blocks['graphics_swap_tile'] = {
init: function () {
this.setHelpUrl(Mythos.helpUrl);
this.setColour(54);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.appendDummyInput()
.appendField("Swap tile from X/Y")
.appendField(new Blockly.FieldTextInput(""), "FROM_X")
.appendField(new Blockly.FieldTextInput(""), "FROM_Y")
.appendField("to X/Y")
.appendField(new Blockly.FieldTextInput(""), "TO_X")
.appendField(new Blockly.FieldTextInput(""), "TO_Y");
this.setOutput(false);
this.setTooltip('Swap the map tile between two locations');
}
};
Blockly.Blocks['graphics_clr_portrait'] = {
init: function () {
this.setHelpUrl(Mythos.helpUrl);

View File

@ -2983,6 +2983,8 @@ end
packSetFullscreen(blk); break
case 'graphics_set_avatar':
packSetAvatar(blk); break
case 'graphics_swap_tile':
packSwapTile(blk); break
case 'variables_set':
packVarSet(blk); break
case 'interaction_give_item':
@ -3333,6 +3335,20 @@ end
outIndented("scriptSetAvatar(${avatars[tileName.toLowerCase()]})\n")
}
def packSwapTile(blk)
{
assert blk.field.size() == 4
assert blk.field[0].@name == 'FROM_X'
assert blk.field[1].@name == 'FROM_Y'
assert blk.field[2].@name == 'TO_X'
assert blk.field[3].@name == 'TO_Y'
def fromX = blk.field[0].text().toInteger()
def fromY = blk.field[1].text().toInteger()
def toX = blk.field[2].text().toInteger()
def toY = blk.field[3].text().toInteger()
outIndented("scriptSwapTile($fromX, $fromY, $toX, $toY)\n")
}
def packSetSky(blk)
{
def color = getSingle(blk.field, 'COLOR').text().toInteger()

View File

@ -28,6 +28,7 @@ import gamelib
predef giveItemToPlayer, takeItemFromPlayer, playerHasItem, getStat, setStat
predef setGameFlag, getGameFlag, scriptSetAvatar, parseDecWithDefault, readStr
predef addPlayerToParty, removePlayerFromParty, partyHasPlayer, loadFrameImg
predef scriptSwapTile
/////////// Shared string constants //////////////

View File

@ -215,6 +215,10 @@ export asm setAvatar // params: tile number (in the global tileset)
+asmPlasm 1
jmp $6021
end
asm swapTile // params: fromX, fromY, toX, toY
+asmPlasm 4
jmp $6024
end
///////////////////////////////////////////////////////////////////////////////////////////////////
asm readAuxByte // params: ptr; ret: char
@ -1688,6 +1692,14 @@ export def scriptDisplayStrNL(str)
displayStr("\n")
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Called by scripts to swap a map tile. We set a flag noting we need to re-render, then use an
// assembly routine to do the work.
export def scriptSwapTile(fromX, fromY, toX, toY)
needRender = TRUE
swapTile(fromX, fromY, toX, toY)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Get a key, and don't return until it's Y or N (or lower-case of those). Returns 1 for Y.
export def getYN()

View File

@ -19,6 +19,11 @@ start:
; then routines that call those to build complexity. The main
; code is at the very end.
; Documentation of flags used on the map tiles:
; $20 = script hint
; $40 = sprite already done flag
; $80 = sprite flag
; Here are the entry points for PLASMA code. Identical API for 2D and 3D.
jmp pl_initMap ; params: mapNum, pMapData, x, y, dir
jmp pl_flipToPage1 ; params: none; return: nothing
@ -32,6 +37,7 @@ start:
jmp pl_texControl ; params: 0=unload textures, 1=load textures
jmp pl_getScripts ; params: none
jmp pl_setAvatar ; params: A=tile number
jmp pl_swapTile ; params: fromX, fromY, toX, toY
; Conditional assembly flags
DEBUG = 0 ; 1=some logging, 2=lots of logging
@ -1709,12 +1715,13 @@ graphInit: !zone
;-------------------------------------------------------------------------------
; Using the current coordinates, calculate pointer on the map to the current row
; and put it in mapRayOrigin (and also A=lo, Y=hi)
; and put it in mapRayOrigin and pMap (and also return A=lo, Y=hi)
calcMapOrigin: !zone
ldx playerY+1 ; integer part of player's Y coord
calcMapOriginX:
lda mapBase ; start at row 0, col 0 of the map
ldy mapBase+1
ldx playerY+1 ; integer part of player's Y coord
beq .gotMapRow
clc
.mapLup: ; advance forward one row
@ -1722,11 +1729,13 @@ calcMapOrigin: !zone
bcc +
iny
clc
+ dex ; until we reach players Y coord
+ dex ; until we reach player's Y coord
bne .mapLup
.gotMapRow:
sta mapRayOrigin
sta pMap
sty mapRayOrigin+1
sty pMap+1
rts
;-------------------------------------------------------------------------------
@ -1766,8 +1775,6 @@ pl_advance: !zone
; Check if the new position is blocked
jsr calcMapOrigin
sta pMap
sty pMap+1
ldy playerX+1
lda (pMap),y
and #$1F
@ -1778,7 +1785,6 @@ pl_advance: !zone
and #2 ; tile flag 2 is for obstructions
beq .ok
; Blocked! Restore old position.
+prStr : !text "Blocked.", 0
pla
sta playerY+1
pla
@ -1814,6 +1820,57 @@ pl_advance: !zone
ldy #0 ; hi byte of ret is always 0
rts ; all done
;-------------------------------------------------------------------------------
; Swap tiles at two positions.
; Params: fromX, fromY, toX, toY
; 3 2 1 0
; Return: none
pl_swapTile: !zone
; Grab stuff from the PLASMA eval stack
lda evalStkL+3,x ; fromX
sta tmp
lda evalStkL+1,x ; toX
pha
lda evalStkL+2,x ; fromY
pha
lda evalStkL,x ; toY
tax
inx ; because we add a phantom row at the top
jsr calcMapOriginX ; result in A=lo,Y=hi
sta pTmp ; toRow now in pTmp
sty pTmp+1
pla ; retrieve fromY
tax
inx ; because we add a phantom row at the top
jsr calcMapOriginX ; result in A=lo,Y=hi
sec ; sec to add 1, because we add a phantom column at the left
adc tmp ; add fromX
sta pMap
bcc +
iny
+ sty pMap+1 ; pMap now holds fromRow+fromX
pla ; retrieve toX
tay ; index in Y. Now (pTmp),y is toRow+toX
iny ; +1 because we add a phantom column at the left
ldx #0
lda (pMap,x) ; grab fromTile
sta tmp+1
lda (pTmp),y ; grab toTile
sta tmp
eor tmp+1 ; grab all bits from fromTile
and #$20 ; except script hint
eor tmp+1
sta (pTmp),y ; save toTile
lda tmp+1
eor tmp ; grab all bits from toTile
and #$20 ; except script hint
eor tmp
sta (pMap,x) ; save fromTile
rts ; all done
;-------------------------------------------------------------------------------
; Render at the current position and direction.
; Params: none
@ -1869,8 +1926,8 @@ castAllRays: !zone
asl ; as screen column * 4
asl
tay
lda mapRayOrigin ; set initial map pointer for the ray
sta pMap
lda mapRayOrigin ; reset initial map pointer for the ray (have to do for each column
sta pMap ; even though calcMapOrigin did first one)
lda mapRayOrigin+1
sta pMap+1

View File

@ -117,6 +117,7 @@ next_zp = $AC
JMP pl_texControl ; params: 1=load, 0=unload
JMP pl_getScripts ; params: none
JMP pl_setAvatarTile ; params: A=tile number
JMP pl_swapTile ; params: fromX, fromY, toX, toY
;----------------------------------------------------------------------
; >> START LOADING MAP SECTIONS
@ -1189,6 +1190,14 @@ pl_flipToPage1:
pl_setColor:
rts
;----------------------------------------------------------------------
; >> pl_swapTile
; Not yet implemented for 2D mode, because very complex due to map
; segmenting.
pl_swapTile:
+prChr 'T'
brk
;----------------------------------------------------------------------
; >> pl_getPos
; Params: @X, @Y