public virtual void UnloadContent() { content.Unload(); inputManager = null; attributes.Clear(); contents.Clear(); }
public virtual void LoadContent(ContentManager Content, InputManager inputManager) { content = new ContentManager(Content.ServiceProvider, "Content"); attributes = new List<List<string>>(); contents = new List<List<string>>(); this.inputManager = inputManager; audioManager = new AudioManager(); }
public override void LoadContent(ContentManager content, List<string> attributes, List<string> contents, InputManager input) { base.LoadContent(content, attributes, contents,input); jumpSpeed = 1700f; List<Texture2D> textures = new List<Texture2D>(); textures.Add(content.Load<Texture2D>("square2")); particleEngine = new ParticleEngine(textures, this.Position); }
public override void LoadContent(ContentManager content, List<string> attributes, List<string> contents, InputManager input) { base.LoadContent(content, attributes, contents, input); rangeCounter = 0; direction = 1; origPosition = position; if (direction == 1) destPosition.X = origPosition.X + range; else destPosition.X = origPosition.X - range; }
public override void LoadContent(ContentManager content, InputManager inputManager) { images = new List<Texture2D>(); base.LoadContent(content, inputManager); menu = new MenuManager(); menu.LoadContent(content, "Option"); audio = new AudioManager(); audio.LoadContent(content, "Option"); audio.MusicVolume = 1.0f; audio.FadeSong(1.0f, new TimeSpan(0, 0, 0, 1)); }
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 override void LoadContent(ContentManager content, InputManager inputManager) { images = new List<Texture2D>(); base.LoadContent(content, inputManager); font = this.content.Load<SpriteFont>("TitleScreen/Coolvetica Rg"); gui = new GUIManager(); gui.LoadContent(content, "CharacterSelect"); menu = new MenuManager(); menu.LoadContent(content, "CharacterSelect"); audio = new AudioManager(); audio.LoadContent(content, "CharacterSelect"); audio.PlaySong(0, true); //audio.FadeSong(0.0f, new TimeSpan(0, 0, 5)); }
public void LoadContent(string entityType, ContentManager Content, string fileName, string identifier, InputManager inputManager) { this.inputManager = inputManager; entities = new List<Entity>(); fileManager = new FileManager(); if (identifier == String.Empty) fileManager.LoadContent(fileName); else fileManager.LoadContent(fileName, identifier); for (int i = 0; i < fileManager.Attributes.Count; i++) { Type newClass = Type.GetType("TM2." + entityType); entities.Add((Entity)Activator.CreateInstance(newClass)); entities[i].LoadContent(Content, fileManager.Attributes[i], fileManager.Contents[i], this.inputManager); } }
public override void LoadContent(ContentManager Content, InputManager inputManager) { base.LoadContent(Content, inputManager); font = this.content.Load<SpriteFont>("CreditsScreen/Coolvetica Rg"); gui = new GUIManager(); gui.LoadContent(Content, "Credits"); audio = new AudioManager(); audio.LoadContent(Content, "Credits"); dul = false; fileManager = new FileManager(); fileManager.LoadContent("Load/Credits.txt"); 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 "Videos" : video = this.content.Load<Video>(fileManager.Contents[i][j]); videoPlayer = new VideoPlayer(); videoPlayer.Play(video); videoPlayer.IsLooped = true; videoPlayer.Pause(); break; } } } audio.PlaySong(0, true); audio.FadeSong(1.0f, new TimeSpan(0, 0, 0, 1)); }
public void UpdateCollision(ref Entity entity, InputManager inputManager, SoundEngine soundEngine) { for (int i = 0; i < tiles.Count; i++) { tiles[i].UpdateCollision(ref entity, inputManager, soundEngine); } }
public void Initialize() { Animation = new Animation(); ssAnimation = new SpriteSheetAnimation(); fAnimation = new FadeAnimation(); currentScreen = new SplashScreen(); inputManager = new InputManager(); }
public void AddScreen(GameScreen screen, InputManager inputManager, float alpha) { transition = true; newScreen = screen; Animation.IsActive = true; fAnimation.ActivateValue = 1.0f; if (alpha != 1.0f) { fAnimation.Alpha = 1.0f - alpha; } else { fAnimation.Alpha = alpha; } fAnimation.Increase = true; this.inputManager = inputManager; //audio.Play(0); }
public void AddScreen(GameScreen screen, InputManager inputManager) { transition = true; newScreen = screen; Animation.IsActive = true; Animation.Alpha = 0.0f; fAnimation.ActivateValue = 1.0f; fAnimation.Increase = true; this.inputManager = inputManager; //audio.FadeSong(0.0f, new TimeSpan(0, 0, 0, 0, 1200)); }
public void UpdateCollision(ref Entity entity, InputManager inputManager, SoundEngine soundEngine) { layer.UpdateCollision(ref entity, inputManager, soundEngine); }
public virtual void LoadContent(ContentManager content, List<string> attributes, List<string> contents, InputManager input) { this.content = new ContentManager(content.ServiceProvider, "Content"); moveAnimation = new Animation(); ssAnimation = new SpriteSheetAnimation(); fAnimation = new FadeAnimation(); images = new List<Texture2D>(); healths = new List<int>(); framesList = new List<Vector2>(); moveSpeeds = new List<float>(); for (int i = 0; i < attributes.Count; i++) { switch (attributes[i]) { case "Image": Texture2D tempImage = this.content.Load<Texture2D>(contents[i]); string[] name = contents[i].Split('/'); tempImage.Name = name[name.Count() - 1]; image = tempImage; break; case "Frames": string[] framesTemp = contents[i].Split(','); moveAnimation.Frames = new Vector2(int.Parse(framesTemp[0]), int.Parse(framesTemp[1])); break; case "Position": string[] pos = contents[i].Split(','); position = new Vector2(int.Parse(pos[0]) * Layer.Instance.TileDimensions.X, int.Parse(pos[1]) * Layer.Instance.TileDimensions.Y); break; case "Health": health = int.Parse(contents[i]); break; case "MoveSpeed" : moveSpeed = float.Parse(contents[i]); break; case "Range": range = int.Parse(contents[i]); break; } } gravity = 100f; velocity = Vector2.Zero; syncTilePosition = false; activateGravity = true; moveAnimation.LoadContent(content, image, "", position, Color.White); }
private void SelectMenuItem(int itemNumber, InputManager inputManager) { optionNumber = (int)variable[itemNumber]; if (axis == 2) { if (inputManager.KeyPressed(Keys.Right, Keys.D) && limits.Y > optionNumber) { //System.Diagnostics.Debug.WriteLine("Option" + limits.X + "," + limits.Y); variable[itemNumber]++; } else if (inputManager.KeyPressed(Keys.Left, Keys.A) && limits.X < optionNumber) variable[itemNumber]--; } else { if (inputManager.KeyPressed(Keys.Down, Keys.S) && limits.Y > optionNumber) variable[itemNumber]++; else if (inputManager.KeyPressed(Keys.Up, Keys.W) && limits.X < optionNumber) variable[itemNumber]--; } }
public void Update(GameTime gameTime, InputManager inputManager) { if (axis == 1) { if (inputManager.KeyPressed(Keys.Right, Keys.D)) itemNumber++; else if (inputManager.KeyPressed(Keys.Left, Keys.A)) itemNumber--; } else { if (inputManager.KeyPressed(Keys.Down, Keys.S)) itemNumber++; else if (inputManager.KeyPressed(Keys.Up, Keys.W)) itemNumber--; } if (itemNumber != null) { if (linkType[itemNumber] == "Screen") { Type newClass = Type.GetType("TM2." + linkID[itemNumber]); ScreenManager.Instance.AddScreen((GameScreen)Activator.CreateInstance(newClass), inputManager); } else if (linkType[itemNumber] == "Option") { SelectMenuItem(itemNumber, inputManager); } } if (itemNumber < 0) itemNumber = optionsItems.Count - 1; else if (itemNumber > optionsItems.Count - 1) itemNumber = 0; for (int i = 0; i < animation.Count; i++) { for (int j = 0; j < animation[i].Count; j++) { if (itemNumber == i) animation[i][j].IsActive = true; else animation[i][j].IsActive = false; animation[i][j].Update(gameTime); } } }
/* 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); }
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 override void LoadContent(ContentManager Content, InputManager inputManager) { base.LoadContent(Content, inputManager); splashItems = new List<string>(); splashImages = new List<Texture2D>(); Animation = new List<Animation>(); fAnimation = new FadeAnimation(); fAnimation.DefaultAlpha = 0.001f; ssAnimation = new SpriteSheetAnimation(); animationTypes = new List<string>(); alpha = new List<float>(); itemNumber = 0; position = Vector2.Zero; align = "Center"; fileManager = new FileManager(); fileManager.LoadContent("Load/Splash.txt"); audio = new AudioManager(); audio.LoadContent(content, "Splash"); audio.PlaySong(0); audio.MusicVolume = 0.0f; audio.FadeSong(1.0f, new TimeSpan(0,0,1)); 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 "Font": font = this.content.Load<SpriteFont>(fileManager.Contents[i][j]); break; case "Item": splashItems.Add(fileManager.Contents[i][j]); break; case "Image": splashImages.Add(content.Load<Texture2D>(fileManager.Contents[i][j])); break; case "Axis": axis = int.Parse(fileManager.Contents[i][j]); break; case "Position": string[] temp = fileManager.Contents[i][j].Split(' '); position = new Vector2(float.Parse(temp[0]), float.Parse(temp[1])); break; case "Animation": animationTypes.Add(fileManager.Contents[i][j]); break; case "Alpha": alpha.Add(float.Parse(fileManager.Contents[i][j])); break; case "FadeSpeed": fadeSpeed = float.Parse(fileManager.Contents[i][j]); break; case "Align": align = fileManager.Contents[i][j]; break; } } } SetSplashItems(); SetAnimations(); }
public void UpdateCollision(ref Entity entity, InputManager inputManager, SoundEngine soundEngine) { FloatRect rect = new FloatRect(position.X, position.Y, layer.TileDimensions.X, layer.TileDimensions.Y); if (entity.OnTile && containsEntity) { if (!entity.SyncTilePosition) { entity.Position += this.velocity; entity.SyncTilePosition = true; } if (entity.Rect.Right < rect.Left || entity.Rect.Left > rect.Right || entity.Rect.Bottom != rect.Top) { containsEntity = false; entity.ActivateGravity = true; entity.CanJump = false; } } if (entity.Rect.Intersects(rect) && state == State.Solid) { FloatRect preventity = new FloatRect(entity.PrevPosition.X, entity.PrevPosition.Y, entity.Animation.FrameWidth, entity.Animation.FrameHeight); FloatRect prevTile = new FloatRect(this.prevPosition.X, this.prevPosition.Y, layer.TileDimensions.X, layer.TileDimensions.Y); if (entity.Rect.Bottom >= rect.Top && preventity.Bottom <= prevTile.Top) { //bottom collision entity.Position = new Vector2(entity.Position.X, position.Y - entity.Animation.FrameHeight); entity.ActivateGravity = false; entity.OnTile = true; containsEntity = true; } else if (entity.Rect.Top <= rect.Bottom && preventity.Top >= prevTile.Bottom) { //top collision entity.Position = new Vector2(entity.Position.X, position.Y + layer.TileDimensions.Y); entity.ActivateGravity = true; } else if (entity.Rect.Right >= rect.Left && preventity.Right <= prevTile.Left) { entity.Position = new Vector2(position.X - entity.Animation.FrameWidth, entity.Position.Y); entity.Direction = (entity.Direction == 1) ? entity.Direction = 2 : entity.Direction = 1; entity.CanJump = true; entity.Velocity = new Vector2(0, entity.Velocity.Y); } else if (entity.Rect.Left <= rect.Right && preventity.Left >= prevTile.Left) { entity.Position = new Vector2(position.X + layer.TileDimensions.X, entity.Position.Y); entity.Direction = (entity.Direction == 1) ? entity.Direction = 2 : entity.Direction = 1; entity.CanJump = true; entity.Velocity = new Vector2(0, entity.Velocity.Y); } } else if (entity.Rect.Intersects(rect) && state == State.Platform) { FloatRect preventity = new FloatRect(entity.PrevPosition.X, entity.PrevPosition.Y, entity.Animation.FrameWidth, entity.Animation.FrameHeight); FloatRect prevTile = new FloatRect(this.prevPosition.X, this.prevPosition.Y, layer.TileDimensions.X, layer.TileDimensions.Y); if (entity.Rect.Bottom >= rect.Top && preventity.Bottom <= prevTile.Top && inputManager.KeyDown(Keys.Down)) { //bottom collision //entity.Position = new Vector2(entity.Position.X, position.Y - entity.Animation.FrameHeight); entity.ActivateGravity = true; entity.OnTile = false; containsEntity = false; } else if (entity.Rect.Bottom >= rect.Top && preventity.Bottom <= prevTile.Top) { //bottom collision entity.Position = new Vector2(entity.Position.X, position.Y - entity.Animation.FrameHeight); entity.ActivateGravity = false; entity.OnTile = true; containsEntity = true; } } entity.Animation.Position = entity.Position; }