def canConstruct(self): for resource in self.prerequisites.keys(): if self.building.stored[resource] < self.prerequisites[resource]: ui.StatusText( 'Not enough %s in the %s to make a %s' % (resource, self.building.name, self.name), self.building.coords) return False return True
def __init__(self): my.currentEvents.append(self) self.originRiver = random.choice(my.rivers) self.originCoords = random.choice(self.originRiver.allCoords) self.radius = randint(4, 20) # radius from self.originCoords that is flooded self.floodTiles = [] coords = map.getCircleCoords(self.originCoords, self.radius) for coord in coords: if randint(0, 3) < 3: FloodTile((coord[0], coord[1])) ui.StatusText('A flood has struck!', (self.originCoords), True) sound.play('splash')
def __init__(self, coords): pygame.sprite.Sprite.__init__(self) x, y = coords if 0 > x or x > my.MAPXCELLS - 1 or 0 > y or y > my.MAPYCELLS - 1: return self.add(my.allFloodTiles) self.coords = coords self.alpha = 'static' self.surf = FloodTile.image.copy() self.rect = pygame.Rect(my.map.cellsToPixels(self.coords), (my.CELLSIZE, my.CELLSIZE)) if my.map.map[x][y] == 'tree': tree = my.map.getObj(coords, 'tree') tree.health = 1 tree.chop(100) elif my.map.map[x][y] not in ['grass', 'rock', 'water', 'iron', 'coal', 'gold']: ui.StatusText('Your %s was destroyed by the flood!' %(my.map.map[x][y]), self.coords) site = building.findBuildingAtCoord(coords) site.demolish()
def onComplete(self): my.unlockedBuildings.append('blacksmith') ui.StatusText('Blacksmith building unlocked!')
def update(self, deltaTime): my.UIhover = False my.input.get() updateCheats() if pygame.locals.K_SPACE in my.input.unpressedKeys: my.paused = not my.paused self.screenCache = my.screen.copy() self.pauseSurf = pygame.Surface((my.WINDOWWIDTH, my.WINDOWHEIGHT)) self.pauseTextSurf, self.pauseTextRect = ui.genText( 'PAUSED (press space to unpause)', (10, 10), my.WHITE, ui.MEGAFONT) self.pauseTextRect.center = (int(my.WINDOWWIDTH / 2), int(my.WINDOWHEIGHT / 2)) if pygame.locals.K_m in my.input.unpressedKeys: my.muted = not my.muted if my.muted: ui.StatusText('All sounds muted (M to unmute)', None, True) if not my.muted: ui.StatusText('All earmeltingly beautiful sounds activated', None, True) # if pygame.locals.K_p in my.input.unpressedKeys: # my.FPS = random.choice([60, 500]) # ui.StatusText('FPS: %s' %(my.FPS)) if not my.paused: self.pauseAlpha = 0 my.surf.blit(my.map.surf, my.camera.viewArea, my.camera.viewArea) my.camera.update(deltaTime) my.ticks += 1 for i in range(1, 20): if my.ticks % i == 0: my.tick[i] = True else: my.tick[i] = False my.dt = deltaTime self.sunx += my.SUNMOVESPEED if self.sunx > my.MAPWIDTH: self.sunx = -30 my.sunPos = (self.sunx, my.MAPHEIGHT + 50) try: my.mission = my.MISSIONS[my.currentMissionNum] except IndexError: if not my.DEBUGMODE and my.mission is not None: ui.StatusText( 'Congratulations, you completed all missions!') my.mission = None for key in my.resources.keys(): if my.resources[key] < 0: my.resources[key] = 0 my.map.update() my.eventHandler.update(deltaTime) building.updateBuildings(deltaTime) item.update() mob.updateMobs(deltaTime) ui.handleTooltips() my.hud.updateWorldUI() my.screen.blit(my.surf, (0, 0), my.camera.viewArea) my.hud.updateHUD(deltaTime) if my.paused: if self.pauseAlpha < 150: self.pauseAlpha += 600 * deltaTime self.pauseSurf.fill(my.DARKGREY) self.pauseSurf.set_alpha(self.pauseAlpha) self.pauseSurf.blit(self.pauseTextSurf, self.pauseTextRect) my.screen.blit(self.screenCache, (0, 0)) my.screen.blit(self.pauseSurf, (0, 0))