public void LoadContent(ContentManager content, Map map, string mapID) { layer = new Layer(); id = mapID; layer.LoadContent(map, "Layer1"); }
public override void Update(GameTime gameTime, InputManager input, Map map, Camera camera, EntityManager entityManager, SoundEngine soundEngine) { base.Update(gameTime, input, map, camera, entityManager, soundEngine); moveAnimation.IsActive = true; syncTilePosition = true; if (direction == 1) { moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 0); velocity.X = moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; } else if (direction == 2) { moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 1); velocity.X = -moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; } if (ActivateGravity) velocity.Y += gravity * (float)gameTime.ElapsedGameTime.TotalSeconds; else velocity.Y = 0; position += velocity; if (direction == 1 && position.X >= destPosition.X) { direction = 2; destPosition.X = origPosition.X - range; } else if (direction == 2 && position.X <= destPosition.X) { direction = 1; destPosition.X = origPosition.X + range; } ssAnimation.Update(gameTime, ref moveAnimation); moveAnimation.Position = position; if (gameTime.TotalGameTime - previousEnemySoundTime > enemySoundTime) { soundEngine.PlaySound("zombie moan", this.position); // Update the time left next enemy spawn previousEnemySoundTime = gameTime.TotalGameTime; var soundSeconds = random.Next(5, 8); // random should be a member of the class enemySoundTime = TimeSpan.FromSeconds(soundSeconds); } }
public void Update(Map map,GameTime gameTime) { if (isActive) { int total = 2; for (int i = 0; i < total; i++) { particles.Add(GenerateNewParticle()); } for (int particle = 0; particle < particles.Count; particle++) { particles[particle].Update(); if (particles[particle].TTL <= 0) { particles.RemoveAt(particle); particle--; } } } else { for (int particle = 0; particle < particles.Count; particle++) { particles[particle].Update(); if (particles[particle].TTL <= 0) { particles.RemoveAt(particle); particle--; } } } }
public void LoadContent(Map map, string layerID) { tiles = new List<Tile>(); motion = new List<string>(); solid = new List<string>(); platform = new List<string>(); fileManager = new FileManager(); content = new ContentManager(ScreenManager.Instance.Content.ServiceProvider, "Content"); font = content.Load<SpriteFont>("Coolvetica Rg"); fileManager.LoadContent("Load/Maps/" + map.ID + ".txt", layerID); int indexY = 0; for (int i = 0; i < fileManager.Attributes.Count; i++) { for (int j = 0; j < fileManager.Attributes[i].Count; j++) { switch (fileManager.Attributes[i][j]) { case "TileSet" : tileSheet = content.Load<Texture2D>("TileSets/" + fileManager.Contents[i][j]); break; case "TileDimensions": string[] split = fileManager.Contents[i][j].Split(','); this.tileDimensions = new Vector2(int.Parse(split[0]), int.Parse(split[1])); break; case "MapDimensions": string[] split2 = fileManager.Contents[i][j].Split(','); this.mapDimensions = new Vector2(int.Parse(split2[0]), int.Parse(split2[1])); break; case "Solid": solid.Add(fileManager.Contents[i][j]); break; case "Platform": platform.Add(fileManager.Contents[i][j]); break; case "NullTile": nullTile = fileManager.Contents[i][j]; break; case "Motion": motion.Add(fileManager.Contents[i][j]); break; case "StartLayer": Tile.Motion tempMotion = Tile.Motion.Static; Tile.State tempState; for (int k = 0; k < fileManager.Contents[i].Count; k++) { if (fileManager.Contents[i][k] != nullTile) { split = fileManager.Contents[i][k].Split(','); tiles.Add(new Tile()); if (solid.Contains(fileManager.Contents[i][k])) tempState = Tile.State.Solid; else if (platform.Contains(fileManager.Contents[i][k])) tempState = Tile.State.Platform; else tempState = Tile.State.Passive; foreach (string m in motion) { getMotion = m.Split(':'); if (getMotion[0] == fileManager.Contents[i][k]) { tempMotion = (Tile.Motion)Enum.Parse(typeof(Tile.Motion), getMotion[1]); break; } } tiles[tiles.Count - 1].SetTile(tempState, tempMotion, new Vector2(k * (int)TileDimensions.X, indexY * (int)TileDimensions.Y), tileSheet, new Rectangle(int.Parse(split[0]) * (int)TileDimensions.X, int.Parse(split[1]) * (int)TileDimensions.Y, (int)TileDimensions.X, (int)TileDimensions.Y)); } } indexY++; break; } } } }
public void Update(GameTime gameTime, Camera camera, Map map) { minX = (int)(MathHelper.Clamp((camera.CurrentPosision.X - camera.HalfViewportWidth) / map.layer.TileDimensions.X - 3 / camera.Zoom, 0, this.MapDimensions.X)); maxX = (int)(MathHelper.Clamp((camera.CurrentPosision.X + camera.HalfViewportWidth) / map.layer.TileDimensions.X + 3 / camera.Zoom, 0, this.MapDimensions.X)); minY = (int)(MathHelper.Clamp((camera.CurrentPosision.Y - camera.HalfViewportHeight) / map.layer.TileDimensions.Y - 3 / camera.Zoom, 0, this.MapDimensions.Y)); maxY = (int)(MathHelper.Clamp((camera.CurrentPosision.Y + camera.HalfViewportHeight) / map.layer.TileDimensions.Y + 3 / camera.Zoom, 0, this.MapDimensions.Y)); for (int i = 0; i < tiles.Count; i++) { tiles[i].Update(gameTime); } }
public void Update(GameTime gameTime, Map map, Camera camera, EntityManager entityManager, SoundEngine soundEngine) { for (int i = 0; i < entities.Count; i++) entities[i].Update(gameTime, inputManager, map, camera, entityManager, soundEngine); }
public override void Update(GameTime gameTime, InputManager input, Map map, Camera camera, EntityManager entityManager, SoundEngine soundEngine) { if (shaking) camera.Zoom = 1.2f; else camera.Zoom = 1.0f; base.Update(gameTime, input, map, camera, entityManager, soundEngine); this.moveAnimation.IsActive = true; this.Bleeding = false; this.shaking = false; syncTilePosition = true; if (input.KeyDown(Keys.Right, Keys.D)) { moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 3); velocity.X = moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; this.direction = 0; } else if (input.KeyDown(Keys.Left, Keys.A)) { moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 2); velocity.X = -moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; this.direction = 1; } else { velocity.X = 0; } if (input.KeyDown(Keys.Up, Keys.W) && !activateGravity) { velocity.Y = -jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; activateGravity = true; } if (activateGravity && this.velocity.Y > 0) { moveAnimation.IsActive = true; if (this.Direction == 1) moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 4); else moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 5); } else if (activateGravity && this.velocity.Y < 0) { moveAnimation.IsActive = true; if (this.Direction == 1) moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 6); else moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 7); } else if (!input.KeyDown(Keys.Up, Keys.W, Keys.Left, Keys.A, Keys.Right, Keys.D)) { if (this.Direction == 1) { moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 2); } else { moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 3); } } if (!input.KeyDown(Keys.Up, Keys.W, Keys.Left, Keys.A, Keys.Right, Keys.D) & velocity.X == 0) { moveAnimation.IsActive = true; if (this.Direction == 1) { moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 0); } else { moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 1); } } if (ActivateGravity) velocity.Y += gravity * (float)gameTime.ElapsedGameTime.TotalSeconds; else velocity.Y = 0; position += velocity; moveAnimation.Position = position; ssAnimation.Update(gameTime, ref moveAnimation); particleEngine.EmitterLocation = new Vector2(this.Position.X + this.Animation.FrameWidth / 2, this.Position.Y + this.Animation.FrameHeight / 2); particleEngine.Update(map, gameTime); }
public virtual void Update(GameTime gameTime, InputManager input, Map map, Camera camera, EntityManager entityManager, SoundEngine soundEngine) { syncTilePosition = false; prevPosition = position; camMinX = (int)(MathHelper.Clamp((camera.CurrentPosision.X - camera.HalfViewportWidth) / map.layer.TileDimensions.X - 3 / camera.Zoom, 0, map.layer.MapDimensions.X)); camMaxX = (int)(MathHelper.Clamp((camera.CurrentPosision.X + camera.HalfViewportWidth) / map.layer.TileDimensions.X + 3 / camera.Zoom, 0, map.layer.MapDimensions.X)); camMinY = (int)(MathHelper.Clamp((camera.CurrentPosision.Y - camera.HalfViewportHeight) / map.layer.TileDimensions.Y - 3 / camera.Zoom, 0, map.layer.MapDimensions.Y)); camMaxY = (int)(MathHelper.Clamp((camera.CurrentPosision.Y + camera.HalfViewportHeight) / map.layer.TileDimensions.Y + 3 / camera.Zoom, 0, map.layer.MapDimensions.Y)); }
public void Update(GameTime gameTime, Camera camera, Map map) { layer.Update(gameTime, camera, map); }
/* Random random = new Random(); TimeSpan previousEnemySoundTime, enemySoundTime; */ public override void LoadContent(ContentManager content, InputManager input) { //make 1x1 pixel dummy texture pixel = content.Load<Texture2D>("fade"); //pixel.SetData(new[] { Color.White }); camera = new Camera(ScreenManager.Instance.graphicsDevice); //viewport = new Viewport(0, 0, (int)ScreenManager.Instance.Dimensions.X, (int)ScreenManager.Instance.Dimensions.Y); playerIndex = 0; zoom = 1.0f; font = content.Load<SpriteFont>("Coolvetica Rg 12"); base.LoadContent(content, input); audio = new AudioManager(); audio.LoadContent(content, "Map1"); audio.MusicVolume = 0.5f; //audio.PlaySong(0, true); map = new Map(); map.LoadContent(content, map, "Map1"); player = new EntityManager(); player.LoadContent("Player", content, "Load/Player.txt", "", input); //player.SetPlayer(playerIndex); enemies = new EntityManager(); enemies.LoadContent("Enemy", content, "Load/Enemy.txt", "Level1", input); guiManager = new GUIManager(); guiManager.LoadContent(content, "Map1"); highlight = content.Load<Texture2D>("highlight"); soundEngine = new SoundEngine(); soundEngine.LoadContent(content); }