def placeEquipment(self): """Drops some equipment where the actor is.""" tile = self.hero.parent tile.addContent(EntityManager.construct("leggings", self)) tile.addContent(EntityManager.construct("ceramic sword", self)) tile.addContent(EntityManager.construct("ceramic mace", self)) tile.addContent(EntityManager.construct("flight cap", self))
def placePebbles(self): for _ in range(15): while(True): x = Rand.r.randint(0, self.WORLD_WIDTH -1) y = Rand.r.randint(0, self.WORLD_HEIGHT -1) tile = self.getTile(x, y) if(tile.canPass()): break rock = EntityManager.construct("pebble", self) rock.parent = tile tile.contents[rock] = True rock = EntityManager.construct("pebble", self) rock.parent = tile tile.contents[rock] = True
def placeActor(self): """Finds a passable place to put the character at.""" while(True): x = Rand.r.randint(0, self.WORLD_WIDTH -1) y = Rand.r.randint(0, self.WORLD_HEIGHT -1) tile = self.getTile(x, y) if(tile.canPass()): break actor = EntityManager.construct("nausicaa", self) actor.parent = tile tile.contents[actor] = True self.hero = actor
def generateCropZone(self, w, h, x, y): """Creates a crop growing zone with the given size at the given location. Returns whether it succeeded or not.""" for i in [posX + x for posX in range(w+2)]: for j in [posy + y for posy in range(h+2)]: if not self.getTile(i, j).canPass(): return False # All terrain is passable! for i in [posX + x + 1 for posX in range(w)]: for j in [posy + y + 1 for posy in range(h)]: crop = EntityManager.construct("cereal", self) self.getTile(i, j).addContent(crop, True) # Create fences xts = [(posX + x, y) for posX in range(w+2)] xbs = [(posX + x, y+h+1) for posX in range(w+2)] yls = [(x, posY + y + 1) for posY in range(h)] yrs = [(x+w+1, posY + y + 1) for posY in range(h)] toFence = [xts, xbs, yls, yrs] for row in toFence: for (fx, fy) in row: self.getTile(fx, fy).addContent(EntityManager.construct("fence", self)) # To choose gate positions, remove corners. xts = xts[1:-1] xbs = xbs[1:-1] forGate = [] forGate.extend(xts) forGate.extend(xbs) forGate.extend(yls) forGate.extend(yrs) (gateX, gateY) = forGate[Rand.r.randint(0, len(forGate)-1)] tile = self.getTile(gateX, gateY) tile.removeContent(tile.getEntity("fence")) tile.addContent(EntityManager.construct("fence gate", self))
def placeWindmill(self): for _ in range(10): while(True): x = Rand.r.randint(0, self.WORLD_WIDTH -2) y = Rand.r.randint(0, self.WORLD_HEIGHT -2) tile1 = self.getTile(x, y) tile2 = self.getTile(x+1, y) tile3 = self.getTile(x, y+1) tile4 = self.getTile(x+1, y+1) if(tile1.canPass() and tile2.canPass() and tile3.canPass() and tile4.canPass()): break rock = EntityManager.construct("windmill", self) tile1.addContent(rock)