merge from devel
This commit is contained in:
commit
8946b240dd
11
demo.py
11
demo.py
|
@ -2,11 +2,14 @@
|
|||
|
||||
import map
|
||||
import render
|
||||
import water
|
||||
import utils
|
||||
|
||||
def main():
|
||||
textures = []
|
||||
textures.append(map.Texture("char", "#", "hash"))
|
||||
textures.append(map.Texture("mchar", "simple", "simple"))
|
||||
textures.append(map.Texture("char", "o", "water"))
|
||||
|
||||
for i in textures:
|
||||
i.load()
|
||||
|
@ -23,10 +26,18 @@ def main():
|
|||
t.addTexture(textures[1])
|
||||
tiles.append(t)
|
||||
|
||||
t = water.WaterTile([30, 2], source=True)
|
||||
t.addTexture(textures[2])
|
||||
tiles.append(t)
|
||||
renderer = render.Renderer()
|
||||
[renderer.addTile(i) for i in tiles]
|
||||
|
||||
while True:
|
||||
renderer.massUpdate()
|
||||
|
||||
renderer.finalRender()
|
||||
|
||||
input()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
3
map.py
3
map.py
|
@ -42,11 +42,12 @@ class TileError(BaseException):
|
|||
pass
|
||||
|
||||
class Tile:
|
||||
def __init__(self, pos, ttype):
|
||||
def __init__(self, pos, ttype, name="none"):
|
||||
self.x = pos[0]
|
||||
self.y = pos[1]
|
||||
self.ttype = ttype
|
||||
self.textures = {}
|
||||
self.name = name
|
||||
self.dims = None
|
||||
self.animation = 0
|
||||
def getCoords(self):
|
||||
|
|
|
@ -18,7 +18,7 @@ class Renderer:
|
|||
|
||||
def massUpdate(self):
|
||||
for i in self.tiles:
|
||||
if i.ttype == "standard":
|
||||
if i.ttype == "standard" or i.ttype == "liquid":
|
||||
i.update(self.tiles)
|
||||
|
||||
def inViewport(self, pos):
|
||||
|
@ -37,6 +37,8 @@ class Renderer:
|
|||
|
||||
for i in self.tiles:
|
||||
dims = i.dims
|
||||
if not dims:
|
||||
dims = [1, 1]
|
||||
pos = i.getCoords()
|
||||
|
||||
try:
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
class BoardUtils:
|
||||
def findOccupied(board):
|
||||
occupied = []
|
||||
for i in board:
|
||||
pos = i.getCoords()
|
||||
dims = i.dims
|
||||
for j in range(dims[0]):
|
||||
for k in range(dims[1]):
|
||||
occupied.append([pos[0] + j, pos[1] + k])
|
||||
return occupied
|
||||
def surround(pos, radius=1):
|
||||
surrounding = []
|
||||
for i in range(-1 * radius, radius + 1, 1):
|
||||
for j in range(-1 * radius, radius + 1, 1):
|
||||
surrounding.append([pos[0] + i, pos[1] + j])
|
||||
|
||||
return surrounding
|
||||
def tileAtPosition(board, pos):
|
||||
for i in board:
|
||||
lpos = i.getCoords()
|
||||
dims = i.dims
|
||||
if not dims:
|
||||
dims = [1, 1]
|
||||
for j in range(dims[0]):
|
||||
for k in range(dims[1]):
|
||||
if [lpos[0] + j, lpos[1] + k] == pos:
|
||||
return i
|
||||
return None
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import map
|
||||
import utils
|
||||
|
||||
class WaterTile(map.Tile):
|
||||
def __init__(self, pos, source=False, noupdate=False):
|
||||
self.source = source
|
||||
self.noupdate = noupdate
|
||||
if source:
|
||||
self.waterlevel = 10 # ten is maximum
|
||||
else:
|
||||
self.waterlevel = 0
|
||||
super(WaterTile, self).__init__(pos, "liquid", "water")
|
||||
def update(self, tiles):
|
||||
if self.noupdate:
|
||||
self.noupdate = False
|
||||
return
|
||||
if self.waterlevel == 0 or self.waterlevel == 1:
|
||||
# we can't spread water, so don't update
|
||||
return
|
||||
# get a list of all tiles around current tile
|
||||
surround = utils.BoardUtils.surround(self.getCoords())
|
||||
dist = False
|
||||
for i in surround:
|
||||
tile = utils.BoardUtils.tileAtPosition(tiles, i)
|
||||
if not tile:
|
||||
# there's no tile here, so create one
|
||||
t = WaterTile(i, noupdate=True)
|
||||
t.waterlevel = 1
|
||||
tiles.append(t)
|
||||
dist = True
|
||||
elif tile.name == "water":
|
||||
# we can populate into this tile
|
||||
tile.waterlevel += 1
|
||||
dist = True
|
||||
if dist and not self.source:
|
||||
self.waterlevel -= 1
|
||||
|
||||
|
||||
def render(self):
|
||||
return "s"
|
||||
|
Loading…
Reference in New Issue