mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-12-26 04:32:05 +00:00
Now splitting maps up into sections. Refactored game loop to make room for 2D variant.
This commit is contained in:
parent
bc73588a20
commit
4e4892381f
@ -402,8 +402,6 @@ class PackPartitions
|
||||
|
||||
def write2DMap(mapName, rows, tileSetNum, tileMap)
|
||||
{
|
||||
maps2D[name] = [num:num, buf:buf]
|
||||
|
||||
def width = rows[0].size()
|
||||
def height = rows.size()
|
||||
|
||||
@ -417,44 +415,47 @@ class PackPartitions
|
||||
def sectionNums = new int[nVertSections][nHorzSections]
|
||||
|
||||
// Allocate a buffer and assign a map number to each section.
|
||||
(0..nVertSections).each { vsect ->
|
||||
(0..nHorzSections).each { hsect ->
|
||||
buffers[vsect][hsect] = ByteBuffer.allocate(512)
|
||||
def num = maps2d.size() + 1
|
||||
(0..<nVertSections).each { vsect ->
|
||||
(0..<nHorzSections).each { hsect ->
|
||||
def buf = ByteBuffer.allocate(512)
|
||||
buffers[vsect][hsect] = buf
|
||||
def num = maps2D.size() + 1
|
||||
def sectName = "$mapName-$hsect-$vsect"
|
||||
maps2d[sectName] = [num:num, buf:buf]
|
||||
maps2D[sectName] = [num:num, buf:buf]
|
||||
}
|
||||
}
|
||||
|
||||
(0..nVertSections).each { vsect ->
|
||||
(0..nHorzSections).each { hsect ->
|
||||
(0..<nVertSections).each { vsect ->
|
||||
(0..<nHorzSections).each { hsect ->
|
||||
|
||||
// Header: first come links to other map sections - north, east, south, west
|
||||
buf.put((byte) (vsect > 0) ? sectionNums[vsect-1][hsect] : 0) // north
|
||||
buf.put((byte) (hsect > 0) ? sectionNums[vsect][hsect-1] : 0) // east
|
||||
buf.put((byte) (vsect < nVertSections-1) ? sectionNums[vsect+1][hsect] : 0) // south
|
||||
buf.put((byte) (hsect > 0) ? sectionNums[vsect-1][hsect] : 0) // west
|
||||
}
|
||||
}
|
||||
def buf = buffers[vsect][hsect]
|
||||
buf.put((byte) (vsect > 0) ? sectionNums[vsect-1][hsect] : 0xFF) // north
|
||||
buf.put((byte) (hsect > 0) ? sectionNums[vsect][hsect-1] : 0xFF) // east
|
||||
buf.put((byte) (vsect < nVertSections-1) ? sectionNums[vsect+1][hsect] : 0xFF) // south
|
||||
buf.put((byte) (hsect > 0) ? sectionNums[vsect-1][hsect] : 0xFF) // west
|
||||
|
||||
// Header: width and height
|
||||
buf.put((byte)width)
|
||||
buf.put((byte)height)
|
||||
|
||||
// Then tileSet number
|
||||
// Then links to the tile set and script library
|
||||
buf.put((byte) tileSetNum)
|
||||
buf.put((byte) 0xFF) // script library placeholder
|
||||
|
||||
// Followed by name
|
||||
writeString(buf, mapName.replaceFirst(/ ?-? ?2D/, ""))
|
||||
def hOff = hsect * TILES_PER_ROW
|
||||
def vOff = vsect * ROWS_PER_SECTION
|
||||
|
||||
// After the header comes the raw data
|
||||
rows.each { row ->
|
||||
row.each { tile ->
|
||||
(0..<ROWS_PER_SECTION).each { rowNum ->
|
||||
def y = vOff + rowNum
|
||||
def row = (y < height) ? rows[y] : null
|
||||
(0..<TILES_PER_ROW).each { colNum ->
|
||||
def x = hOff + colNum
|
||||
def tile = (row && x < width) ? row[x] : null
|
||||
def id = tile?.@id
|
||||
buf.put((byte)(id ? tileMap[tile?.@id] : 0))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump map data to Javascript code, to help in debugging the raycaster. This way,
|
||||
|
@ -55,9 +55,13 @@ const DEBUG_MEM = $1A
|
||||
const CHAIN_LOADER = $1E
|
||||
const FATAL_ERROR = $1F
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Other constants
|
||||
const callbacks = $300
|
||||
|
||||
const OVERMAP = 11
|
||||
const MAP_FLAG_3D = $4000
|
||||
const OVERMAP_NUM = 11
|
||||
const OVERMAP_IS_3D = 1
|
||||
const MAX_LOC_TRIG = 128
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Predefined functions, for circular calls
|
||||
@ -65,7 +69,6 @@ predef moveBackward, setWindow2
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Raycaster variables
|
||||
word zp = 0
|
||||
const playerDir = $5D
|
||||
const playerX = $5E
|
||||
const playerY = $60
|
||||
@ -78,21 +81,18 @@ const wndleft = $70 // left edge of the window
|
||||
const wndwdth = $71 // right edge (NOT width) of text window
|
||||
const wndtop = $72 // top of text window
|
||||
const wndbtm = $73 // bottom+1 of text window
|
||||
|
||||
const cursh = $74 // Cursor H-pos 0-39
|
||||
const cursv = $75 // Cursor V-pos 0-23
|
||||
|
||||
const MAX_LOC_TRIG = 128
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Strings.
|
||||
byte helloStr[] = "Loading Lawless Legends.\n"
|
||||
byte loopStr[] = "Entering keyboard loop.\n"
|
||||
byte tooManyTriggers[] = "Too many triggers"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Global variables
|
||||
byte mapNum = OVERMAP
|
||||
byte mapNum = OVERMAP_NUM
|
||||
byte mapIs3D = OVERMAP_IS_3D
|
||||
word pFont
|
||||
word pMap
|
||||
word pScripts
|
||||
@ -105,6 +105,7 @@ byte prevX
|
||||
byte prevY
|
||||
word prevScript
|
||||
byte prevMapNum
|
||||
byte prevMapIs3D
|
||||
byte redraw
|
||||
byte titleLoaded = FALSE
|
||||
byte cacheSky, cacheGround
|
||||
@ -519,7 +520,7 @@ def debugMem(bank, code)
|
||||
^$c050
|
||||
end
|
||||
|
||||
def initMap()
|
||||
def initMap3D()
|
||||
word scriptModule
|
||||
|
||||
// Reset memory (our module will stay since memory manager locked it upon load)
|
||||
@ -584,6 +585,7 @@ def initMap()
|
||||
prevScript = -1
|
||||
nLocTrig = 0
|
||||
prevMapNum = mapNum
|
||||
prevMapIs3D = mapIs3D
|
||||
if pScripts
|
||||
*pScripts()
|
||||
fin
|
||||
@ -637,6 +639,13 @@ end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Actions
|
||||
def resetCmds()
|
||||
byte i
|
||||
for i = 0 to 63
|
||||
cmdTbl[i] = 0
|
||||
next
|
||||
end
|
||||
|
||||
def initCmd(key, func)
|
||||
if key >= $60
|
||||
key = key - $20
|
||||
@ -674,9 +683,9 @@ def checkScript()
|
||||
next
|
||||
fin
|
||||
fin
|
||||
if mapNum <> prevMapNum
|
||||
if (mapNum <> prevMapNum) or (mapIs3D <> prevMapIs3D)
|
||||
flipToFirstPage()
|
||||
initMap()
|
||||
initMap3D()
|
||||
fin
|
||||
end
|
||||
|
||||
@ -721,9 +730,9 @@ def strafeLeft()
|
||||
adjustDir(4)
|
||||
end
|
||||
|
||||
def setMap(is3d, num)
|
||||
def setMap(is3D, num)
|
||||
// save player state if we're coming *from* the over-map
|
||||
if mapNum == OVERMAP
|
||||
if mapNum == OVERMAP_NUM and mapIs3D == OVERMAP_IS_3D
|
||||
cacheX = *playerX
|
||||
cacheY = *playerY
|
||||
cacheDir = ^playerDir
|
||||
@ -732,6 +741,7 @@ def setMap(is3d, num)
|
||||
else
|
||||
resetLocFromCache = TRUE
|
||||
fin
|
||||
mapIs3D = is3D
|
||||
mapNum = num
|
||||
end
|
||||
|
||||
@ -740,7 +750,7 @@ def nextMap()
|
||||
if mapNum > 20
|
||||
mapNum = 1
|
||||
fin
|
||||
setMap(1, mapNum)
|
||||
setMap(mapIs3D, mapNum)
|
||||
end
|
||||
|
||||
def teleport(x, y, dir)
|
||||
@ -799,12 +809,28 @@ def getYN()
|
||||
loop
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Main code.
|
||||
//
|
||||
def loadTitle()
|
||||
puts(@helloStr)
|
||||
|
||||
// Init the command table
|
||||
// Load the title screen
|
||||
loader(SET_MEM_TARGET, MAIN_MEM, $2000)
|
||||
loader(QUEUE_LOAD, MAIN_MEM, 2<<8 | RES_TYPE_SCREEN)
|
||||
loader(LOCK_MEMORY, MAIN_MEM, $2000)
|
||||
loader(FINISH_LOAD, MAIN_MEM, 1) // 1 = keep open
|
||||
titleLoaded = TRUE
|
||||
^$c050
|
||||
^$c057
|
||||
^$c054
|
||||
^$c052
|
||||
// Hack for real (not emulated) IIc: sometimes displays only lo-bit graphics
|
||||
// unless we do this. *HUGE* thanks to Brendan Robert for the fix!
|
||||
^$C07E=0 // disable double-hi-res
|
||||
^$C05F // disable double-hi-res
|
||||
end
|
||||
|
||||
def initCmds3D()
|
||||
resetCmds()
|
||||
|
||||
initCmd('W', @moveForward)
|
||||
initCmd('A', @rotateLeft)
|
||||
initCmd('D', @rotateRight)
|
||||
@ -853,28 +879,19 @@ callbacks:16 = @setGround
|
||||
// $312
|
||||
callbacks.18 = $4c
|
||||
callbacks:19 = @teleport
|
||||
end
|
||||
|
||||
// Load the title screen
|
||||
loader(SET_MEM_TARGET, MAIN_MEM, $2000)
|
||||
loader(QUEUE_LOAD, MAIN_MEM, 2<<8 | RES_TYPE_SCREEN)
|
||||
loader(LOCK_MEMORY, MAIN_MEM, $2000)
|
||||
loader(FINISH_LOAD, MAIN_MEM, 1) // 1 = keep open
|
||||
titleLoaded = TRUE
|
||||
^$c050
|
||||
^$c057
|
||||
^$c054
|
||||
^$c052
|
||||
// Hack for real (not emulated) IIc: sometimes displays only lo-bit graphics
|
||||
// unless we do this. *HUGE* thanks to Brendan Robert for the fix!
|
||||
^$C07E=0 // disable double-hi-res
|
||||
^$C05F // disable double-hi-res
|
||||
|
||||
initMap()
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Main code.
|
||||
//
|
||||
loadTitle()
|
||||
if mapIs3D
|
||||
initCmds3D()
|
||||
initMap3D()
|
||||
else
|
||||
// 2D todo
|
||||
fin
|
||||
setWindow2()
|
||||
|
||||
// Main keyboard loop
|
||||
puts(@loopStr)
|
||||
kbdLoop()
|
||||
|
||||
done
|
@ -100,8 +100,8 @@ START_MAP_LOAD
|
||||
; 1 Resource ID of next map section (east), FF = none
|
||||
; 2 Resource ID of next map section (south), FF = none
|
||||
; 3 Resource ID of next map section (west), FF = none
|
||||
; 4 Tileset resouce id
|
||||
; 5 Resource ID of script library (if any)
|
||||
; 4 Tileset resource id
|
||||
; 5 Resource ID of script library (FF = none)
|
||||
LOAD_SECTION
|
||||
CMP #$FF
|
||||
BNE .doLoad
|
||||
|
Loading…
Reference in New Issue
Block a user