def attemptMoveRight(a, b): global scrn blk, t = getWater(a, b) if (files.getBlockType(files.getBlock(a + 1, b)) != 2) and t == 1: l = getWaterNum(files.getBlock(a + 1, b)) if l == 8: l = 0 if (l < 4): files.setBlock(a, b, (getNumWater(blk - 1), 0)) files.setBlock(a + 1, b, (getNumWater(l + 1), 0)) if (a > scrn[0] and a < scrn[2]): if (b > scrn[1] and b < scrn[3]): gui.drawBlock(a - scrn[0], b - scrn[1], a, b) gui.drawBlock(a - scrn[0] + 1, b - scrn[1], a + 1, b)
def checkBlock(x, y, dx, dy): updateVars() b = files.getBlockType(files.getBlock(x + dx, y + dy)) if (b < 2): return False else: return True
def drawBlock(x, y, wx, wy): global gfxSurface global scale global bgcol, lastBlockDrawn, texts, block blk = files.getBlock(wx, wy) if (blk != 0): if (blk != lastBlockDrawn): block = pygame.image.load("Prime/Content/Images/Tiles_" + str(files.getTexture(blk)) + ".png") tx, ty = getVariation(wx, wy, blk) db = block.subsurface(((18 * tx), (18 * ty), 16, 16)) filledRect(gfxSurface, 16 * x, 16 * y, 16, 16, (255, 255, 255, 0)) gfxSurface.blit(db, (16 * x, 16 * y)) else: filledRect(gfxSurface, 16 * x, 16 * y, 16, 16, (255, 255, 255, 0))
def attemptReplace(x, y, rule, replace): global width, height tot = 0 target = 0 for a in range(-1, 2): for b in range(-1, 2): target = target + 1 if (x + a >= 0 and x + a <= width - 1 and y + b >= 0 and y + b <= height - 1): if (type(rule[a + 1][b + 1]) is int): if (rule[a + 1][b + 1] == -1): tot = tot + 1 elif (getBlockType(x + a, y + b) == rule[a + 1][b + 1]): tot = tot + 1 else: if (rule[a + 1][b + 1][0] == -1 and rule[a + 1][b + 1][1] == getBlock( x + a, y + b)): tot = tot + 1 elif (files.getBlock(x + a, y + b) == rule[a + 1][b + 1]): tot = tot + 1 else: tot = tot + 1 if (tot != target): return if (tot == 9): for a in range(-1, 1): for b in range(-1, 1): if (x + a >= 0 and x + a <= width - 1 and y + b >= 0 and y + b <= height - 1): if (replace[a + 1][b + 1] != -1): if (replace[a + 1][b + 1][0] == -1): files.setBlock(x + a, y + b, (files.getBlock( x + a, y + b), replace[a + 1][b + 1][1])) else: files.setBlock(x + a, y + b, replace[a + 1][b + 1])
def getVariation(wx, wy, blk): top = files.getBlock(wx, wy - 1) bottom = files.getBlock(wx, wy + 1) left = files.getBlock(wx - 1, wy) right = files.getBlock(wx + 1, wy) topleft = files.getBlock(wx - 1, wy-1) topright = files.getBlock(wx + 1, wy-1) bottomleft = files.getBlock(wx - 1, wy+1) bottomright = files.getBlock(wx + 1, wy+1) if (blk != 2): if (left == blk and right == blk): if (bottom == 2): return getCoord("A", 14) if (left == blk and right == blk): if (top == 2): return getCoord("B", 14) if (top == blk and bottom == blk): if (right == 2): return getCoord("C", 14) if (top == blk and bottom == blk): if (left == 2): return getCoord("D", 14) # base zone blending if (top == blk and bottom == blk and left == blk and right == blk and bottomright == blk and topright == blk and topleft != blk and bottomleft != blk): return getCoord("A", 11) if (top == blk and bottom == blk and left == blk and right == blk and bottomleft == blk and topleft == blk and topright != blk and bottomright != blk): return getCoord("A", 12) if (top == blk and bottom == blk and left == blk and right == blk and topright == blk and topleft == blk and bottomleft == blk and bottomright == blk): return getCoord("B", 2) if (top == blk and bottom == blk and left == blk and right == blk and bottomright == blk and bottomleft == blk and topleft != blk and topright != blk): return getCoord("B", 7) if (top != blk and bottom != blk and left != blk and right != blk and bottomright != blk and topright != blk and topleft != blk and bottomleft != blk): return getCoord("D", 10) if (top == blk and bottom == blk and left == blk and right == blk and topright == blk and topleft == blk and bottomleft != blk and bottomright != blk): return getCoord("C", 7) if (top == blk and bottom == blk and right == blk): return getCoord("A", 1) if (left == blk and bottom == blk and right == blk): return getCoord("A", 2) if (top == blk and bottom == blk and left == blk): return getCoord("A", 5) if (left == blk and top == blk and right == blk): return getCoord("C", 2) if (top == blk and bottom == blk): return getCoord("A", 6) if (bottom == blk and right == blk): return getCoord("D", 1) if (bottom == blk and left == blk): return getCoord("D", 2) if (top == blk and right == blk): return getCoord("E", 1) if (top == blk and left == blk): return getCoord("E", 2) if (left == blk and right == blk): return getCoord("E", 7) if (bottom == blk): return getCoord("A", 7) if (right == blk): return getCoord("A", 10) if (left == blk): return getCoord("A", 13) if (top == blk): return getCoord("D", 7) return getCoord("D", 10)
def renderXLineChecked(x, wx): global scrn for b in range(0, scrn[3] - scrn[1]): if (files.getBlock(wx, scrn[1] + b) == 0): drawBlock(x, b, wx, scrn[1] + b)
def getWater(a, b): blk = files.getBlock(a, b) t = files.getBlockType(blk) blk = getWaterNum(blk) return blk, t
def getBlockType(x, y): return files.getBlockType(files.getBlock(x, y))
def getBlock(x, y): return files.getBlock(x, y)
def generateWorld(): global width, height, desert, corruption, fileName filledRect(screen, 0, 0, 640, 480, (0, 0, 0)) width = files.getSetting(5) height = files.getSetting(6) fileName = "Worlds/" + randomString(8) + ".wrld" files.setDim(width, height) gnd = 50 desert = [50, 100] corruption = [100, 200] dGnd = 0 pgnd = [gnd] * width title("Generating", 0) title("Terraforming", 1) for a in range(width): progress(a / width, 1) if (a > desert[0] and a < desert[1]): for b in range(0, gnd): blk = 0 files.setBlock(a, b, blk) for b in range(gnd, height): blk = 3 files.setBlock(a, b, blk) elif (a > corruption[0] and a < corruption[1]): for b in range(0, gnd): blk = 0 files.setBlock(a, b, blk) files.setBlock(a, gnd, 5) for b in range(gnd + 1, height): blk = 2 files.setBlock(a, b, blk) else: for b in range(0, gnd): blk = 0 #if (random.randint(0, 100) < 10): #blk = random.randint(4, 7) files.setBlock(a, b, blk) files.setBlock(a, gnd, 1) for b in range(gnd + 1, height): blk = 2 files.setBlock(a, b, blk) dGnd = dGnd + random.randint(-1, 1) if (dGnd < -1): dGnd = -1 if (dGnd > 1): dGnd = 1 pgnd[a] = gnd gnd = gnd + dGnd spwnx = random.randint(files.getSetting(4) + 1, files.getSetting(4) + 51) spwny = 0 while (files.getBlockType(files.getBlock(spwnx, spwny)) != 2): spwny = spwny + 1 progress(.3, 0) title("Generating Landmarks", 1) for i in range(random.randint(15, 35)): chasmRadius = random.randint(3, 5) a = random.randint(corruption[0] + chasmRadius + 2, corruption[1] - chasmRadius - 2) curRadius = chasmRadius chasmDepth = random.randint(25, 50) for y in range(pgnd[a], chasmDepth): for x in range(a - curRadius, a + curRadius): files.setBlock(x, y, 0) files.setBlock(a - curRadius, y, 4) files.setBlock(a + curRadius, y, 4) curRadius = curRadius + random.randint(-1, 1) if (curRadius < chasmRadius - 2): curRadius = chasmRadius - 2 if (curRadius > chasmRadius + 2): curRadius = chasmRadius + 2 for i in range(random.randint(100, 200)): x = random.randint(5, width - 5) y = random.randint(5, height - 5) w = random.randint(3, 5) h = random.randint(3, 5) for a in range(-w, w + 1): for b in range(-h, h + 1): files.setBlock(x + a, y + b, 6) progress(.6, 0) progress(1, 0) files.setSpawn(spwnx, spwny) files.saveWorld(fileName) files.prepareWorld(fileName)