public Enemy(int x, int y, int type, Level l, bool forceSandToSpawn = false) : base(new Vector2(Level.TEX_SIZE * l.xPos + (x * Level.TILE_SIZE) + Level.TILE_SIZE / 2, Level.TEX_SIZE * l.yPos + (y * Level.TILE_SIZE) + Level.TILE_SIZE / 2), new Hitbox(32, 32)) { level = l; tileX = x; tileY = y; this.forceSandToSpawn = forceSandToSpawn; this.type = type; this.setTexture("enemy" + (type + 1)); id = idCounter++; health = STARTING_HEALTH; scale = 0.5f; deathEmitter = Emitter.getPrebuiltEmitter(PrebuiltEmitter.EnemyDeathExplosion); idleAI = new TurnInPlaceAI((float)RetroGame.rand.NextDouble() * 2, RetroGame.rand.Next(5)); targetedAI = new HeroChaseAI(true); }
public void putPremadeLevelAt(Level premadeLevel, int xPos, int yPos) { premadeLevel.levelManager = this; premadeLevel.xPos = xPos; premadeLevel.yPos = yPos; levels[xPos, yPos] = premadeLevel; currentLevels = null; // make the CurrentLevels list be recalculated }
public PowerupIcon newRegeneratingPowerup(Type powerupType, int tileX, int tileY, Level l) { return new PowerupIconRegenerating(l.xPos * Level.TEX_SIZE + tileX * Level.TILE_SIZE + Level.TILE_SIZE / 2, l.yPos * Level.TEX_SIZE + tileY * Level.TILE_SIZE + Level.TILE_SIZE / 2, l.xPos, l.yPos, tileX, tileY, powerupType); }
public Prisoner newPrisoner(int tileX, int tileY, Color c, Level l) { return new Prisoner(c, Names.getRandomName(), l.xPos * Level.TEX_SIZE + tileX * Level.TILE_SIZE + Level.TILE_SIZE / 2, l.yPos * Level.TEX_SIZE + tileY * Level.TILE_SIZE + Level.TILE_SIZE / 2, l.xPos, l.yPos, tileX, tileY); }
public PowerupIcon newPowerup(int tileX, int tileY, Level l) { return new PowerupIcon(l.xPos * Level.TEX_SIZE + tileX * Level.TILE_SIZE + Level.TILE_SIZE / 2, l.yPos * Level.TEX_SIZE + tileY * Level.TILE_SIZE + Level.TILE_SIZE / 2, l.xPos, l.yPos, tileX, tileY, Powerups.RandomWildPowerupType()); }
public void createSpecificLevelAt(LevelFragment fullLevelFragment, int xPos, int yPos) { if (fullLevelFragment.type != LevelContent.Type.Full) throw new ArgumentException("Creating a specific level requires a full level fragment", "fullLevelFragment"); levels[xPos, yPos] = new Level(this, fullLevelFragment, xPos, yPos); currentLevels = null; // make the CurrentLevels list be recalculated }
public void createRandomLevelAt(int xPos, int yPos, int levelLayout) { levels[xPos, yPos] = new Level(this, xPos, yPos, levelLayout); currentLevels = null; // make the CurrentLevels list be recalculated }
public void addEnemy(int x, int y, int type, Level l, bool forceSandToSpawn = false) { l.addEnemy(x, y, type, forceSandToSpawn); }
public LevelMemento(Level target) { //save necessary information from target here Target = target; drilledWalls = new List<Point>(target.drilledWalls); enemyGrid = (Enemy[,])target.enemyGrid.Clone(); enemyMementos = new IMemento[target.enemies.Count]; for (int i = 0; i < enemyMementos.Length; i++) { enemyMementos[i] = target.enemies[i].GenerateMementoFromCurrentFrame(); } }
public override void Update(GameTime gameTime) { //reset per-frame powerup modification fields BEFORE updating controls globalMoveSpeedMultiplier = 1; powerupCooldownModifier = 1; teleportedThisFrame = false; if (!Alive) { Powerups = (from pair in Powerups orderby pair.Value ascending select pair).ToDictionary(pair => pair.Key, pair => pair.Value); foreach (Powerup p in Powerups.Values) p.Update(gameTime); return; } UpdateControls(bindings, gameTime); #if DEBUG if (this == RetroGame.getHeroes()[0]) UpdateDebugKeys(); #endif //remove expendable powerups for (int i = 0; i < Powerups.Count; i++) { Powerup p = Powerups.Values.ElementAt(i); if (p.toRemove) { RemovePowerup(p.GenericName, false); i--; } } Powerups = (from pair in Powerups orderby pair.Value ascending select pair).ToDictionary(pair => pair.Key, pair => pair.Value); foreach (Powerup p in Powerups.Values) p.Update(gameTime); float seconds = gameTime.getSeconds(HERO_TIMESCALE); movement = dirVector * MOVE_SPEED * globalMoveSpeedMultiplier * seconds; updateCurrentLevelAndTile(); Level level = RetroGame.getLevels()[levelX, levelY]; float nextX = position.X + movement.X; float nextY = position.Y + movement.Y; moved = true; int n; if (HERO_TIMESCALE > 0f) { switch (controllerDirection) { case Direction.Up: case Direction.Down: moved = canMove(movement); if (!moved) { n = (int)position.Y; nextY = n - (n % Level.TILE_SIZE) + Level.TILE_SIZE / 2; } break; case Direction.Left: case Direction.Right: moved = canMove(new Vector2(movement.X, 0)); if (!moved) { n = (int)position.X; nextX = n - (n % Level.TILE_SIZE) + Level.TILE_SIZE / 2; } break; default: nextX = position.X; nextY = position.Y; break; } } if (controllerDirection != Direction.None) { direction = controllerDirection; } rotation = DIR_TO_ROTATION[direction]; position = new Vector2(nextX, nextY); // check corners LevelManager levelManager = RetroGame.TopLevelManagerScreen.levelManager; if (moved && (levelManager.collidesWithWall(new Vector2(getLeft().X, getTop().Y)) || //topleft levelManager.collidesWithWall(new Vector2(getLeft().X, getBottom().Y)) || //botleft levelManager.collidesWithWall(new Vector2(getRight().X, getBottom().Y)) || //botright levelManager.collidesWithWall(new Vector2(getRight().X, getTop().Y)))) //topright { switch (controllerDirection) { case Direction.Up: case Direction.Down: n = (int)position.X; nextX = n - (n % Level.TILE_SIZE) + Level.TILE_SIZE / 2; break; case Direction.Left: case Direction.Right: n = (int)position.Y; nextY = n - (n % Level.TILE_SIZE) + Level.TILE_SIZE / 2; break; default: break; } } position = new Vector2(nextX, nextY); nextTileX = -1; nextTileY = -1; switch (direction) { case Direction.Up: nextTileX = tileX; nextTileY = tileY - 1; break; case Direction.Down: nextTileX = tileX; nextTileY = tileY + 1; break; case Direction.Left: nextTileX = tileX - 1; nextTileY = tileY; break; case Direction.Right: nextTileX = tileX + 1; nextTileY = tileY; break; } nextLevelX = -1; nextLevelY = -1; nextLevel = null; if (nextTileX < 0) { nextLevelX = levelX - 1; nextLevelY = levelY; if (nextLevelX >= 0) nextLevel = RetroGame.getLevels()[nextLevelX, nextLevelY]; nextTileX = Level.GRID_SIZE - 1; } else if (nextTileX >= Level.GRID_SIZE) { nextLevelX = levelX + 1; nextLevelY = levelY; if (nextLevelX < LevelManager.MAX_LEVELS) nextLevel = RetroGame.getLevels()[nextLevelX, nextLevelY]; nextTileX = 0; } else if (nextTileY < 0) { nextLevelX = levelX; nextLevelY = levelY - 1; if (nextLevelY >= 0) nextLevel = RetroGame.getLevels()[nextLevelX, nextLevelY]; nextTileY = Level.GRID_SIZE - 1; } else if (nextTileY >= Level.GRID_SIZE) { nextLevelX = levelX; nextLevelY = levelY + 1; if (nextLevelY < LevelManager.MAX_LEVELS) nextLevel = RetroGame.getLevels()[nextLevelX, nextLevelY]; nextTileY = 0; } else { nextLevel = level; } //collision with collectables if (Alive) { foreach (Level l in levelManager.CurrentLevels) { foreach (Collectable c in l.collectables) if (c.ableToBeCollected && hitbox.intersects(c.hitbox)) c.collectedBy(this); foreach (Prisoner p in l.prisoners) if (p.ableToBeCollected && hitbox.intersects(p.hitbox)) p.collectedBy(this); foreach (PowerupIcon p in l.powerups) if (p.ableToBeCollected && hitbox.intersects(p.hitbox)) p.collectedBy(this); } } //flashing float flashTotalDuration = individualFlashDuration * flashCount; if (flashTime < flashTotalDuration) { flashTime += seconds; float flashInterp = (flashTime % individualFlashDuration) / individualFlashDuration; float colorInterp = 1f - (Math.Abs(flashInterp - 0.5f) * 2); //map 0.0 - 0.5 to 0.0 - 1.0 and 0.5 - 1.0 to 1.0 - 0.0 maskingColor = Color.Lerp(color, flashColor, colorInterp); } else { maskingColor = color; } base.Update(gameTime); }