def enter_entry(self): if not Globals.PLAYER is None: Globals.PLAYER.kill(False) Globals.PLAYER = None World.cleanupCompletely() Globals.CURRENT_LEVEL = "one" Globals.initSunTracker(True) Globals.PLAYER_MAX_HEALTH = 15 SKILL_MAX_HEALTH = 0 PLAYER_REGEN_TIME = 7 PLAYER_DAMAGE = 5 SKILL_DAMAGE = 0 PLAYER_MAX_MP = 10 PLAYER_SKILL = 0 PLAYER_JUMP = 610.0 SKILL_JUMP = 0 ARROW_VELOCITY = 700.0 ARROW_HITS = 1 ARROW_DAMAGE = 2 BOW_COOLDOWN = 0.7 MAX_SKILL = 9 MINI_SUNS = 0 LEVELS_BEAT = 0 SCORE = 0 TIME = 120 Globals.STATE = ControlScreen.ControlScreen()
def loadMap(cLevel): Globals.initSunTracker() global key global tiles global tileSize global playerPos global tileBuckets global world_width mapFile = "img/" + cLevel + "/map" keyFile = "img/" + cLevel + "/key" groups["tiles"].empty() groups["tilesObs"].empty() groups["spawners"].empty() lresources = [] for resource in ImageManager.levelRes: lresources.append(resource) for resource in lresources: if resource == "one" or resource == "two" or\ resource == "three" or resource == "four": ImageManager.unloadSet(resource) ImageManager.loadSet(cLevel) key = [] tiles = {} tileSize = 0 k = open(keyFile) y = 0 x = 0 for line in k: if y == 0: iString = "" for c in line: if c != '\n': iString = iString + c tileSize = int(iString) else: key.append(line) temp = 0 for c in line: temp += 1 if temp > x: x = temp y += 1 k.close() tileSheet = ImageManager.levelRes[cLevel]["tiles.png"] for j in range(y - 1): for i in range(x - 1): tiles[(i, j)] = tileSheet.subsurface( pygame.Rect(i * tileSize, j * tileSize, tileSize, tileSize)) f = open(mapFile) y = 0 sunID = 0 for line in f: x = 0 for c in line: if c == 'p': playerPos = (x * tileSize, y * tileSize) elif c == '*': Globals.WIN_POS = x * tileSize elif c == '-': # monster 0 makeMonsterSpawner(x * tileSize, y * tileSize, 0, cLevel) elif c == '_': # monster 1 makeMonsterSpawner(x * tileSize, y * tileSize, 1, cLevel) elif c == '=': # monster 2 makeMonsterSpawner(x * tileSize, y * tileSize, 2, cLevel) elif c == '+': # monster 3 makeMonsterSpawner(x * tileSize, y * tileSize, 3, cLevel) elif c == '~': # sun if Globals.SUN_TRACKER[Globals.CURRENT_LEVEL][sunID]: sun = Entity.Entity() sun.componentList.append(CSun.CSun()) sun.image = ImageManager.levelRes["effects"]["sun.png"] sun.rect = sun.image.get_rect() sun.rect.x = x * tileSize sun.rect.y = y * tileSize sun.posx = sun.rect.x sun.posy = sun.rect.y groups["enemies"].add(sun) Globals.sunPos()[(sun.rect.x, sun.rect.y)] = sunID sunID += 1 elif c != '\n' and c != ' ': block = Entity.Entity() block.image = tiles[findKeyPos(c)] block.rect = block.image.get_rect() block.rect.left = x * tileSize block.rect.top = y * tileSize if (c >= 'A' and c <= 'Z') or\ (c >= '0' and c <= '9'): groups["tilesObs"].add(block) else: groups["tiles"].add(block) x += 1 y += 1 Globals.BOTTOM = y * tileSize # block = Entity.Entity() # block.image = pygame.Surface((30, 600)) # block.rect = pygame.Rect((-30, 600, 30, 600)) # groups["tilesObs"].add(block) # entityBuckets = [] tileBuckets = [] xmax = (x) * tileSize + cell_size ymax = (y) * tileSize + cell_size world_width = xmax for y in range(ymax / cell_size): for x in range(xmax / cell_size): tileBuckets.append(Bucket.Bucket(x * cell_size, y * cell_size)) # entityBuckets.append(Bucket.Bucket(x * cell_size, y * cell_size)) for tE in groups["tilesObs"]: tileBuckets[hashpos(tE.rect.x, tE.rect.y)].add(tE) tileBuckets[hashpos(tE.rect.x + tE.rect.width, tE.rect.y)].add(tE) tileBuckets[hashpos(tE.rect.x, tE.rect.y + tE.rect.height)].add(tE) tileBuckets[hashpos( tE.rect.x + tE.rect.width, tE.rect.y + tE.rect.height)].add(tE)