public WaterController(GraphicsDevice gd, Map gameMap) { var layer = GameManager.Map.Layers.Where(l => l.Name == "Water").First(); if (layer != null) { MapObjectLayer objectlayer = layer as MapObjectLayer; foreach (MapObject o in objectlayer.Objects) { Color top = Color.White; Color bottom = Color.Black; if (o.Properties.Contains("TopColor")) { top = new Color(byte.Parse(o.Properties["TopColor"].Split(',')[0]), byte.Parse(o.Properties["TopColor"].Split(',')[1]), byte.Parse(o.Properties["TopColor"].Split(',')[2])); } if (o.Properties.Contains("BottomColor")) { bottom = new Color(byte.Parse(o.Properties["BottomColor"].Split(',')[0]), byte.Parse(o.Properties["BottomColor"].Split(',')[1]), byte.Parse(o.Properties["BottomColor"].Split(',')[2])); } Add(gd, gameMap, o.Location, top, bottom); } } GameManager.WaterController = this; }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); blank = new Texture2D(GraphicsDevice, 1, 1); blank.SetData(new[] { Color.White }); // load the map map = Content.Load<Map>("Map"); // find the "Box" and "Point" objects we made in the level MapObjectLayer objects = map.GetLayer("Objects") as MapObjectLayer; point = objects.GetObject("Point"); box = objects.GetObject("Box"); // attempt to read the box color from the box object properties try { boxColor.R = (byte)box.Properties["R"]; boxColor.G = (byte)box.Properties["G"]; boxColor.B = (byte)box.Properties["B"]; boxColor.A = 255; } catch { // on failure, default to yellow boxColor = Color.Yellow; } // find one tile from our tile layer TileLayer tileLayer = map.GetLayer("Tiles") as TileLayer; tile = tileLayer.Tiles[0, 0]; }
public override void Update(GameTime gameTime, Map gameMap) { Speed = Vector2.Lerp(Speed, Vector2.Zero, 0.05f); if (Vector2.Distance(Ship.Instance.Position, Position) < 50f) { Vector2 dir = Ship.Instance.Position - Position; dir.Normalize(); Speed += dir*0.25f; } //Position = Vector2.Lerp(Position, Ship.Instance.Position, 0.1f); if (gameMap.CheckCollision(Position + new Vector2(Speed.X, 0)).GetValueOrDefault()) { Speed.X = -(Speed.X * (0.1f + Helper.RandomFloat(0.4f))); Speed.Y *= 0.9f; } if (gameMap.CheckCollision(Position + new Vector2(0, Speed.Y)).GetValueOrDefault()) { Speed.Y = -(Speed.Y * (0.1f + Helper.RandomFloat(0.4f))); Speed.X *= 0.9f; } base.Update(gameTime); }
public TriggerController(Map gameMap) { Instance = this; MapObjectLayer triggerLayer = gameMap.GetLayer("Triggers") as MapObjectLayer; foreach (MapObject o in triggerLayer.Objects) { triggers.Add(new Trigger() { Object = o, HasTriggered = false }); } triggerLayer = gameMap.GetLayer("Valves") as MapObjectLayer; foreach (MapObject o in triggerLayer.Objects) { valves.Add(new Trigger() { Object = o, HasTriggered = false, Position = new Vector2(o.Location.Center.X, o.Location.Center.Y), Speed = new Vector2(3f, 0.1f) }); } }
public override void Draw(SpriteBatch sb, Map gameMap) { sb.Draw(SpriteSheet, Position, null, Color.White, 0f, new Vector2(3,3), 1f, SpriteEffects.None, 0); if (Position.X >= 0 && Position.X < 200) sb.Draw(SpriteSheet, Position + new Vector2(gameMap.Width * gameMap.TileWidth, 0), null, Color.White, Rotation, new Vector2(3,3), 1f, SpriteEffects.None, 0); if (Position.X >= (gameMap.Width * gameMap.TileWidth) - 200 && Position.X < (gameMap.Width * gameMap.TileWidth)) sb.Draw(SpriteSheet, Position - new Vector2(gameMap.Width * gameMap.TileWidth, 0), null, Color.White, Rotation, new Vector2(3, 3), 1f, SpriteEffects.None, 0); base.Draw(sb, gameMap); }
public override void Draw(SpriteBatch sb, Map gameMap) { base.Draw(sb, gameMap); sb.Draw(SpriteSheet, Position+new Vector2(0,4), new Rectangle(32, 64, 16, 16), Color.White, _turretRot*-_faceDir, new Vector2(8, 9), _scale, _faceDir == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0); if(_hitAlpha>0f) sb.Draw(SpriteSheet, Position + new Vector2(0, 4), new Rectangle(32, 160, 16, 16), Color.White * _hitAlpha, _turretRot * -_faceDir, new Vector2(8, 8), _scale, _faceDir == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0); }
public override void Update(GameTime gameTime, Map gameMap) { projectileTime -= gameTime.ElapsedGameTime.TotalMilliseconds; if (!gameMap.CheckTileCollision(Position + new Vector2(_faceDir*8, 10))) Speed.X = -Speed.X; if (Helper.Random.Next(20) == 0) _turretRotTarget = Helper.RandomFloat(MathHelper.PiOver2); _turretRot = MathHelper.Lerp(_turretRot, _turretRotTarget, 0.01f); if (_firing) { Vector2 screenPos = Vector2.Transform(Position, Camera.Instance.CameraMatrix); float pan = (screenPos.X - (Camera.Instance.Width / 2f)) / (Camera.Instance.Width / 2f); if (pan < -1f || pan > 1f) gunLoop.Volume = 0f; else gunLoop.Volume = 0.3f; if (Ship.Instance.Position.Y >= 260) gunLoop.Volume = 0f; gunLoop.Pan = MathHelper.Clamp(pan,-1f,1f); if (projectileTime <= 0) { projectileTime = projectileCoolDown; ProjectileController.Instance.Spawn(entity => { ((Projectile) entity).Type = ProjectileType.Forward1; ((Projectile) entity).SourceRect = new Rectangle(8, 8, 20, 8); ((Projectile) entity).Life = 1000; ((Projectile) entity).EnemyOwner = true; ((Projectile) entity).Damage = 1f; entity.Speed = Helper.AngleToVector(_turretRot, -5f); entity.Speed.X *= -_faceDir; entity.Position = Position + entity.Speed; }); } if (Helper.Random.Next(20) == 0) { gunLoop.Pause(); _firing = false; } } else { if (Helper.Random.Next(50) == 0) { gunLoop.Resume(); _firing = true; } } base.Update(gameTime, gameMap); }
/// <summary> /// Constructor. /// </summary> public MapScreen(Map map, bool[,] fog, HeroDude hero, Texture2D icons) { TransitionOnTime = TimeSpan.FromSeconds(0.5); TransitionOffTime = TimeSpan.FromSeconds(0.5); gameMap = map; mapFog = fog; mapIcons = icons; gameHero = hero; IsPopup = true; }
/// <summary> /// Just a quick and dirty method for generating any object in our Tiled map that has a corresponding entity definition /// in an XML file. /// </summary> public List<IGameObject> GenerateXMLEnvironmentObjectsFromTiled(Map map, TileLayer layer) { List<IGameObject> gameObjects = new List<IGameObject>(); for (int i = 0; i < layer.Width; i++) { for (int j = 0; j < layer.Height; j++) { if (layer.Tiles[i, j] != null) { IGameObject gameObject = rawPool.New(); gameObject.Position = new Vector2(map.TileWidth * i, map.TileHeight * j); //Load in the correct element from the entity definitions file. string objectName = layer.Tiles[i, j].Properties["name"].RawValue; if (xmlDoc.Root != null) { List<XElement> elements = (xmlDoc.Root.Elements("entity") .Where(el => (string)el.Attribute("name") == objectName)).ToList(); //We'll let the IRenderableComponent build itself but before finishing it off we'll swap the texture, so just //generate all the components via the Tiled file... if (elements.Count > 0) GenerateComponents(gameObject, elements[0]); } //And then swap the texture with the one from Tiled... IRenderComponent renderComponent = gameObject.GetComponent<IRenderComponent>(); if (renderComponent != null) { ITexturedRenderable renderable = (ITexturedRenderable)renderComponent.GetRenderable(0); if (renderable != null) { renderable.AssetName = layer.Tiles[i, j].Properties["texture"].RawValue; renderComponent.Load(content); renderComponent.SetLayer(1f); } } FireOnGameObjectCreated(gameObject); gameObjects.Add(gameObject); gameObject.Initialize(); } } } return gameObjects; }
public override void Update(GameTime gameTime, Map gameMap) { if (Speed.Y < 0f && Position.Y < 250) Speed.Y = -Speed.Y; if (Helper.Random.Next(50) == 0) _faceDir = Helper.Random.Next(2) == 0 ? -1 : 1; if (_idleAnim.State == SpriteAnimState.Paused) { _idleAnim.Reset(); _hitAnim.Reset(); _idleAnim.Play(); _hitAnim.Play(); } if (_idleAnim.CurrentFrame == 4 && (_idleAnim.TargetFrameTime - _idleAnim.CurrentFrameTime) <= 10) { if(Ship.Instance.Position.Y>260) AudioController.PlaySFX("gorgershoot", 1f, -0.1f, 0.1f, Camera.Instance, Position); ProjectileController.Instance.Spawn(entity => { ((Projectile)entity).Type = ProjectileType.GorgerAcid; ((Projectile)entity).SourceRect = new Rectangle(0, 0, 1, 1); entity.HitBox = new Rectangle(0, 0, 16, 16); ((Projectile)entity).Life = 10000; ((Projectile)entity).EnemyOwner = true; ((Projectile)entity).Damage = 0.5f; entity.Speed = new Vector2(Helper.RandomFloat(1f, 4f) * _faceDir, 0f); entity.Position = Position + new Vector2(_faceDir * 10, 0); }); } if (_idleAnim.CurrentFrame == 1 && (_idleAnim.TargetFrameTime - _idleAnim.CurrentFrameTime) <= 10) { _idleAnim.CurrentFrameTime = 0; _idleAnim.CurrentFrame = 0; } if (Helper.Random.Next(100) == 0 && _idleAnim.CurrentFrame <=1) { _idleAnim.Reset(); _hitAnim.Reset(); _idleAnim.CurrentFrame = 2; _hitAnim.CurrentFrame = 2; _idleAnim.Play(); _hitAnim.Play(); } base.Update(gameTime, gameMap); }
public override void Update(GameTime gameTime, Map gameMap) { if(Helper.Random.Next(10)==0) ParticleController.Instance.Add(Position + new Vector2(0,5), new Vector2(Helper.RandomFloat(-0.1f,0.1f), 0f), 100, 3000, 1000, true, true, new Rectangle(0, 0, 2, 2), new Color(new Vector3(1f, 0f, 0f) * (0.25f + Helper.RandomFloat(0.5f))), part => { ParticleFunctions.FadeInOut(part); if (part.Position.Y > 260) part.State = ParticleState.Done; } , 1f, 0f, 0f, 1, ParticleBlend.Alpha); if (Helper.Random.Next(200) == 0) { if (Ship.Instance.Position.Y <= 260) AudioController.PlaySFX("laser", 1f, -0.1f, 0.1f, Camera.Instance, Position); ProjectileController.Instance.Spawn(entity => { ((Projectile)entity).Type = ProjectileType.ManOWarLaser; ((Projectile)entity).SourceRect = new Rectangle(0, 158, 23, 2); entity.HitBox = new Rectangle(0, 0, 23, 2); ((Projectile)entity).Life = 2000; ((Projectile)entity).EnemyOwner = true; ((Projectile)entity).Damage = 5f; entity.Speed = new Vector2(_faceDir * 5f, 0f); entity.Position = Position + new Vector2(_faceDir * 20, -2); }); } if (Helper.Random.Next(300) == 0 && GameController.Wave >= 7) { ProjectileController.Instance.Spawn(entity => { ((Projectile)entity).Type = ProjectileType.Bomb; ((Projectile)entity).SourceRect = new Rectangle(16, 0, 8, 8); ((Projectile)entity).Life = 5000; ((Projectile)entity).Scale = 0.5f; ((Projectile)entity).EnemyOwner = true; ((Projectile)entity).Damage = 10f; entity.Speed = new Vector2(1f * _faceDir, 0f); entity.Position = Position + new Vector2(0, 5); }); } base.Update(gameTime, gameMap); }
private void LoadMap(string assetName) { //List of Portals declared for traveling between World map and scrolling levels Statics.Portals = new List<Portal>(); Statics.ClipMap = new Dictionary<Vector2, Rectangle>(); map = content.Load<Map>(assetName); camera = new WorldMapCamera(new Vector2(map.Width, map.Height), new Vector2(map.TileWidth, map.TileHeight), new Vector2(Statics.Game.GraphicsDevice.Viewport.Width, Statics.Game.GraphicsDevice.Viewport.Height)); MapObjectLayer objects = map.GetLayer("Objects") as MapObjectLayer; //Read in information about portals from tmx file foreach (MapObject obj in objects.Objects) { switch (obj.Name) { case "PlayerStart": if (Statics.WorldPlayer == null) { Statics.WorldPlayer = new WorldPlayer(new Vector2(obj.Location.X + (obj.Location.Width / 2), obj.Location.Y), new Vector2(91f, 91f)); Statics.WorldPlayer.LoadContent(content, "Sprites\\Characters\\Warrior1WalkLeft"); Statics.WorldPlayer.Map = map; } else { Statics.WorldPlayer.Position = new Vector2(obj.Location.X + (obj.Location.Width / 2), obj.Location.Y); } break; case "Portal1": case "Portal2": case "Portal3": case "Portal4": Portal portal = new Portal(); portal.Position = new Vector2(obj.Location.X, obj.Location.Y); portal.Size = new Vector2(obj.Location.Width, obj.Location.Height); portal.LevelName = obj.Properties["LevelName"].Value; string[] tileLoc = obj.Properties["DestinationTileLocation"].Value.Split(','); portal.DestinationTileLocation = new Vector2(Convert.ToInt32(tileLoc[0]), Convert.ToInt32(tileLoc[1])); Statics.Portals.Add(portal); break; } } Statics.WorldPlayer.UpdateBounds(map.TileWidth, map.TileHeight); // camera.FocusOn(Statics.WorldPlayer); LoadClipMap(); }
internal TileLayer(string name, int width, int height, bool visible, float opacity, PropertyCollection properties, Map map, int[] data) : base(name, width, height, visible, opacity, properties) { Tiles = new Tile[width, height]; // data is left-to-right, top-to-bottom for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int index = data[y * width + x]; Tiles[x, y] = map.Tiles[index]; } } }
public void Update(GameTime gameTime, Map gameMap, HeroDude gameHero, bool[,] mapFog) { int count = 0; foreach (Item i in Items.Where(it => (gameHero.Position - it.Position).Length() < 4000f)) { count++; i.Update(gameTime); if ((gameHero.Position - i.Position).Length() < 50f && gameHero.drivingVehicle==null) { Pickup(i, gameHero, gameMap, mapFog); } } Items.RemoveAll(it => !it.Active); }
public GravPadController(Map gameMap) { var layer = GameManager.Map.Layers.Where(l => l.Name == "GravPads").First(); if (layer != null) { MapObjectLayer objectlayer = layer as MapObjectLayer; foreach (MapObject o in objectlayer.Objects) { GravDirection dir = GravDirection.Up; List<Point> path = new List<Point>(); bool pathLoops = false; int pathnode = 0; int opp = 0; int id = 0; bool health = false; if (o.Properties.Contains("HealthPad")) health = true; id = int.Parse(o.Name); if (health == false) { if (o.Properties.Contains("Direction")) dir = (GravDirection)Enum.Parse(typeof(GravDirection), o.Properties["Direction"], true); if (o.Properties.Contains("Opposite")) opp = int.Parse(o.Properties["Opposite"]); var pathLayer = GameManager.Map.Layers.Where(l => l.Name == "Paths").First(); MapObjectLayer pathObjectLayer = pathLayer as MapObjectLayer; foreach (MapObject mappath in pathObjectLayer.Objects) { foreach (Point p in mappath.LinePoints) { if (o.Location.Contains(p)) { path = mappath.LinePoints; pathnode = mappath.LinePoints.IndexOf(p); pathLoops = bool.Parse(mappath.Properties["Looping"]); } } } } GravPads.Add(id, new GravPad(id, o.Location, dir, opp, path, pathLoops, pathnode, health)); } } }
public override void Update(GameTime gameTime, Map gameMap) { Speed.Y += GRAVITY; Speed.X = FaceDir; _idleAnim.Update(gameTime); _runAnim.Update(gameTime); Life--; if (Life <= 0) Active = false; CheckMapCollisions(gameMap); _tint = Color.White; base.Update(gameTime, gameMap); }
public virtual void Update(GameTime gameTime, Map gameMap, float planeRot) { coolDownTime -= gameTime.ElapsedGameTime.TotalMilliseconds; if (InWorld) { Speed.Y += 0.25f; if (Position.Y >= DroppedPosition.Y) { Position.Y = DroppedPosition.Y; if (Speed.Y > 2f) { Speed.Y = -(Speed.Y * 0.5f); } else { Speed.Y = 0f; } } Position.X -= (planeRot * 2f); Position.Y += Speed.Y; Position.X = MathHelper.Clamp(Position.X, 1150, gameMap.Width * gameMap.TileWidth - 400f); Position.Y = MathHelper.Clamp(Position.Y, 0, gameMap.Height * gameMap.TileHeight); } if (Health <= 0f) { if(!InWorld) { InWorld = true; Owner.Item = null; DroppedPosition = Owner.Position; Position = Owner.Position + new Vector2(Owner.faceDir * 75, -75); } alpha -= 0.01f; alpha = MathHelper.Clamp(alpha, 0f, 1f); if(alpha<=0f) Dead = true; } }
public virtual void CheckMapCollisions(Map gameMap) { // Check upward collision if (Speed.Y < 0) for (int x = HitBox.Left + 2; x <= HitBox.Right - 2; x += 2) { bool? coll = gameMap.CheckCollision(new Vector2(x, HitBox.Top + Speed.Y)); if (coll.HasValue && coll.Value) Speed.Y = -Speed.Y; } // Check downward collision if (Speed.Y > 0) for (int x = HitBox.Left + 2; x <= HitBox.Right - 2; x += 2) { bool? coll = gameMap.CheckCollision(new Vector2(x, HitBox.Bottom + Speed.Y)); if (coll.HasValue && coll.Value) Speed.Y = -Speed.Y; } // Check left collision if (Speed.X < 0) for (int y = HitBox.Top + 2; y <= HitBox.Bottom - 2; y += 2) { bool? coll = gameMap.CheckCollision(new Vector2(HitBox.Left + Speed.X, y)); if (coll.HasValue && coll.Value) { Speed.X = -Speed.X; } } // Check right collision if (Speed.X > 0) for (int y = HitBox.Top + 2; y <= HitBox.Bottom - 2; y += 2) { bool? coll = gameMap.CheckCollision(new Vector2(HitBox.Right + Speed.X, y)); if (coll.HasValue && coll.Value) { Speed.X = -Speed.X; } } }
public Camera(RenderTarget2D vp, Map map) { Position = new Vector2(0, 0); Width = vp.Width; Height = vp.Height; ClampRect = new Rectangle(0, 0, map.Width * map.TileWidth, map.Height * map.TileHeight); if (map.Properties.Contains("CameraBoundsLeft")) ClampRect.X = Convert.ToInt32(map.Properties["CameraBoundsLeft"]) * map.TileWidth; if (map.Properties.Contains("CameraBoundsTop")) ClampRect.Y = Convert.ToInt32(map.Properties["CameraBoundsTop"]) * map.TileHeight; if (map.Properties.Contains("CameraBoundsWidth")) ClampRect.Width = Convert.ToInt32(map.Properties["CameraBoundsWidth"]) * map.TileWidth; if (map.Properties.Contains("CameraBoundsHeight")) ClampRect.Height = Convert.ToInt32(map.Properties["CameraBoundsHeight"]) * map.TileHeight; // Set initial position and target Position.X = ClampRect.X; Position.Y = ClampRect.Y; Target = new Vector2(ClampRect.X, ClampRect.Y); }
public void Update(GameTime gameTime, Map gameMap, HeroDude gameHero, bool[,] mapFog, Camera gameCamera) { int count = 0; foreach (AIDude e in Enemies.Where(en => (gameHero.Position - en.Position).Length() < 4000f)) { count++; if ((gameHero.Position - e.Position).Length() < 2000f) { e.Update(gameTime, gameMap, gameHero, mapFog, gameCamera); bool alerted = false; if (gameHero.HuntedLevel.Level > 0f) { if (!alerted && Helper.Random.Next(11000 - (int)(gameHero.HuntedLevel.Level * 100)) == 1 && e.State == AIState.Patrolling && (gameHero.Position - e.Position).Length() < 2000f) { //e.InvestigatePosition(); alerted = true; } } } } // Spawn some new enemies if (count < 10 + (int)(gameHero.HuntedLevel.Level / 10)) { Vector2 pos = Helper.RandomPointInCircle(gameHero.Position, 2000f, 4000f); if (!gameMap.CheckTileCollision(pos) && pos.X > 0 && pos.X < (gameMap.Width * gameMap.TileWidth) && pos.Y > 0 && pos.Y < (gameMap.Height * gameMap.TileHeight) && !VehicleController.Instance.CheckVehicleCollision(pos)) { AIDude newDude = new AIDude(pos); newDude.LoadContent(SpriteSheet, graphicsDevice, lightingEngine, gameHero); newDude.Health = 10 + Helper.Random.Next(30); Enemies.Add(newDude); } } Enemies.RemoveAll(e => !e.Active); }
//, Texture2D particleTexture) public Water(GraphicsDevice device, Map map, Rectangle dest, Color top, Color bottom, float scale) { Scale = scale; pb = new PrimitiveBatch(device); //this.particleTexture = particleTexture; spriteBatch = new SpriteBatch(device); gameMap = map; topColor = top * 0.8f; bottomColor = bottom; bounds = dest; //metaballTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height); //particlesTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height); //alphaTest = new AlphaTestEffect(device); //alphaTest.ReferenceAlpha = 175; //var view = device.Viewport; //alphaTest.Projection = Matrix.CreateTranslation(-0.5f, -0.5f, 0) * // Matrix.CreateOrthographicOffCenter(0, view.Width, view.Height, 0, 0, 1); columns = new WaterColumn[bounds.Width / 30]; for (int i = 0; i < columns.Length; i++) { columns[i] = new WaterColumn() { Height = bounds.Height, TargetHeight = bounds.Height, Speed = 0 }; } rDeltas = new float[columns.Length]; lDeltas = new float[columns.Length]; }
public override void Update(GameTime gameTime, Map gameMap) { if (Speed.Y < 0f && Position.Y < 250) Speed.Y = -Speed.Y; if(Helper.Random.Next(20)==0) ParticleController.Instance.Add(Position, new Vector2(Helper.RandomFloat(-0.1f, 0.1f), Helper.RandomFloat(-0.1f, 0.1f)), 0, Helper.Random.NextDouble() * 1000, Helper.Random.NextDouble() * 1000, false, false, new Rectangle(128, 0, 16, 16), new Color(new Vector3(1f) * (0.25f + Helper.RandomFloat(0.5f))), ParticleFunctions.FadeInOut, 0.5f, 0f, 0f, 1, ParticleBlend.Alpha); if (Helper.Random.Next(200) == 0) { if (Ship.Instance.Position.Y > 260) AudioController.PlaySFX("eyespew", 1f, -0.1f, 0.1f, Camera.Instance, Position); float start = Helper.RandomFloat(0f, 0.25f); for (float a = start; a < start + MathHelper.TwoPi; a += 0.25f) ProjectileController.Instance.Spawn(entity => { ((Projectile) entity).Type = ProjectileType.EyesPew; ((Projectile) entity).SourceRect = new Rectangle(44, 3, 4, 10); entity.HitBox = new Rectangle(0, 0, 6, 6); ((Projectile) entity).Life = 5000; ((Projectile) entity).EnemyOwner = true; ((Projectile) entity).Damage = 3f; entity.Speed = Helper.AngleToVector(a, 1f); entity.Position = Position + Helper.AngleToVector(a, 5f); }); } base.Update(gameTime, gameMap); }
public void Update(GameTime gameTime, int waterLevel, Hero gameHero, Map gameMap) { if (ShowingSouls) { soulsAlpha = MathHelper.Lerp(soulsAlpha, 1f, 0.05f); } if (ShowingWater) { waterAlpha = MathHelper.Lerp(waterAlpha, 1f, 0.05f); } //waterLevelHeight = MathHelper.Clamp((1f / ((gameMap.Height * gameMap.TileHeight) - (gameHero.Position.Y-200))) * (float)waterLevel, 0f, 1f); //((float)texHud.Height / (gameHero.Position.Y - 200f)) * (float)waterLevel; waterLevelHeight = MathHelper.Clamp((1f / 700f) * (700f - (((float)(gameMap.TileHeight * gameMap.Height) - (float)waterLevel)-gameHero.Position.Y+200f)), 0f, 1f); //((float)texHud.Height / (gameHero.Position.Y - 200f)) * (float)waterLevel; waterAnimTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (waterAnimTime >= 200) { waterAnimTime = 0; waterAnimFrame = 1 - waterAnimFrame; } if (gameHero.Dead) { ShowingSouls = true; soulsToCenterAmount = MathHelper.Lerp(soulsToCenterAmount, 1f, 0.05f); if (!endPromptsDone) { PromptController.Instance.ClearPrompts(); PromptController.Instance.AddPrompt("dead1", PromptController.PromptType.Text, " ", false, 0, 0); PromptController.Instance.AddPrompt("dead2", PromptController.PromptType.Text, " ", false, 0, 0); PromptController.Instance.AddPrompt("dead3", PromptController.PromptType.Text, "...and one.", false, 0, 4000); PromptController.Instance.AddPrompt("dead4", PromptController.PromptType.Image, "use", false, 0, 8000); endPromptsDone = true; } if (soulsToCenterAmount > 0.98f) ReadyForRestart = true; } if (gameHero.Complete) { ShowingSouls = true; soulsToCenterAmount = MathHelper.Lerp(soulsToCenterAmount, 1f, 0.05f); if (!endPromptsDone) { PromptController.Instance.ClearPrompts(); PromptController.Instance.AddPrompt("comp1", PromptController.PromptType.Text, " ", false, 0, 0); PromptController.Instance.AddPrompt("comp2", PromptController.PromptType.Text, " ", false, 0, 0); PromptController.Instance.AddPrompt("comp3", PromptController.PromptType.Text, "...but Gerde had saved untold numbers", false, 0, 4000); PromptController.Instance.AddPrompt("comp4", PromptController.PromptType.Text, "of her people. She was happy.", false, 0, 4000); PromptController.Instance.AddPrompt("comp5", PromptController.PromptType.Image, "use", false, 0, 8000); endPromptsDone = true; } if (soulsToCenterAmount > 0.98f) ReadyForRestart = true; } }
public override void Update(GameTime gameTime, Map gameMap, HeroDude gameHero, Camera gameCamera) { CollisionVerts.Clear(); CollisionVerts.Add(Helper.PointOnCircle(ref Position, 150, -0.44f + (Rotation))); CollisionVerts.Add(Helper.PointOnCircle(ref Position, 150, 0.44f + (Rotation))); CollisionVerts.Add(Helper.PointOnCircle(ref Position, 150, -0.44f + MathHelper.Pi + (Rotation))); CollisionVerts.Add(Helper.PointOnCircle(ref Position, 150, 0.44f + MathHelper.Pi + (Rotation))); base.Update(gameTime, gameMap, gameHero, gameCamera); if (linearSpeed > 0f) linearSpeed -= decelerate; if (linearSpeed < 0f) linearSpeed += decelerate; linearSpeed = MathHelper.Clamp(linearSpeed, -(limitedSpeed / 2), limitedSpeed); Vector2 moveVect = Helper.AngleToVector(Rotation, 100f); moveVect.Normalize(); if (!turning) { turnAmount = MathHelper.Lerp(turnAmount, 0f, 0.05f); } if ((turnAmount > 0f && turnAmount < 0.001f) || (turnAmount < 0f && turnAmount > -0.001f)) turnAmount = 0f; if (linearSpeed >= 0.1f || linearSpeed <= -0.1f) Rotation += MathHelper.Clamp((linearSpeed / 100f) * turnAmount, -0.025f, 0.025f); Speed = moveVect * linearSpeed; turning = false; foreach (Dude d in EnemyController.Instance.Enemies) { if (Helper.IsPointInShape(d.Position, this.CollisionVerts) && d.Health >= 0f) { Health -= 0.5f; d.HitByVehicle(this); } } if (Health < 50f) { limitedSpeed = 10f; } if (Health < 20f) { limitedSpeed = 5f; } if (Health <= 0f) { limitedSpeed = 2f; } //HeadTorch.Position = Helper.PointOnCircle(ref Position, 30, Rotation - MathHelper.PiOver2); //HeadTorch.Rotation = Rotation - MathHelper.PiOver2; Lights[0].Position = Helper.PointOnCircle(ref Position, 145, (Rotation)); //Lights[1].Position = Helper.PointOnCircle(ref Position, 137, (Rotation) + 0.2f); Lights[0].Rotation = Rotation; //Lights[1].Rotation = Rotation; if (gameHero.drivingVehicle == this) { engineSound.Play(); if (maxSpeed > 0f) gameCamera.ZoomTarget = 1f - ((0.5f / maxSpeed) * (float)Math.Abs(linearSpeed)); else gameCamera.ZoomTarget = 1f; if (Health > 0f) { engineSound.Volume = MathHelper.Clamp(0.2f + ((1f / 18f) * (float)Math.Abs(linearSpeed)), 0f, 1f); engineSound.Pitch = -0.3f + (((0.6f / 18f) * (float)Math.Abs(linearSpeed))); } else { engineSound.Volume = 0f; } } else { engineSound.Stop(); } }
internal override void DoCollisions(Map gameMap) { bool Collision = false; if (Speed == Vector2.Zero) return; Vector2 test = Speed; test.Normalize(); float rot = Helper.V2ToAngle(test); if (gameMap.GetTile(Helper.PointOnCircle(ref Position, 135, rot), "Terrain")!=null && gameMap.GetTile(Helper.PointOnCircle(ref Position, 135, rot), "Terrain").Properties.Contains("CanBoat")) { if (gameMap.GetTile(Helper.PointOnCircle(ref Position, 135, rot), "Water") == null) linearSpeed = MathHelper.Lerp(linearSpeed, 0f, 0.05f); if (gameMap.GetTile(Helper.PointOnCircle(ref Position, 50, rot), "Water") == null) linearSpeed = MathHelper.Lerp(linearSpeed, 0f, 1f); } else Collision = true; if (gameMap.GetTile(Helper.PointOnCircle(ref Position, 135, rot-0.2f), "Terrain") != null && gameMap.GetTile(Helper.PointOnCircle(ref Position, 135, rot - 0.2f), "Terrain").Properties.Contains("CanBoat")) { if (gameMap.GetTile(Helper.PointOnCircle(ref Position, 135, rot-0.2f), "Water") == null) linearSpeed = MathHelper.Lerp(linearSpeed, 0f, 0.05f); } else Collision = true; if (gameMap.GetTile(Helper.PointOnCircle(ref Position, 135, rot+0.2f), "Terrain") != null && gameMap.GetTile(Helper.PointOnCircle(ref Position, 135, rot + 0.2f), "Terrain").Properties.Contains("CanBoat")) { if (gameMap.GetTile(Helper.PointOnCircle(ref Position, 135, rot+0.2f), "Water") == null) linearSpeed = MathHelper.Lerp(linearSpeed, 0f, 0.05f); } else Collision = true; foreach (Vehicle veh in VehicleController.Instance.Vehicles) { if (veh == this) continue; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 135, rot), veh.CollisionVerts)) Collision = true; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 135, rot - 0.2f), veh.CollisionVerts)) Collision = true; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 135, rot + 0.2f), veh.CollisionVerts)) Collision = true; } if (Collision) { Collided(); } }
private static bool TryMakeJetty(Map map, TileLayer terrainLayer, TileLayer waterLayer, Point start, Point direction) { Vector2 jettyPos = Helper.PtoV(start) * map.TileWidth; foreach (Jetty otherJ in map.Jetties) if ((otherJ.Position - jettyPos).Length() < 5000) return false; Rectangle bounds = new Rectangle(); Vector2 boatPos = Vector2.Zero; float boatRot = 0f; if (direction.Y == -1) { bounds = new Rectangle(start.X - 1, start.Y - 10, 2, 10); boatPos = (new Vector2(bounds.Left, bounds.Top) * map.TileWidth) + new Vector2(100, -100); } if (direction.Y == 1) { bounds = new Rectangle(start.X - 1, start.Y, 2, 10); boatPos = (new Vector2(bounds.Left, bounds.Bottom) * map.TileWidth) + new Vector2(100, 100); } if (direction.X == -1) { bounds = new Rectangle(start.X - 10, start.Y - 1, 10, 2); boatPos = (new Vector2(bounds.Left, bounds.Top) * map.TileWidth) + new Vector2(-100, 100); boatRot = MathHelper.PiOver2; } if (direction.X == 1) { bounds = new Rectangle(start.X, start.Y - 1, 10, 2); boatPos = (new Vector2(bounds.Right, bounds.Top) * map.TileWidth) + new Vector2(100, 100); boatRot = MathHelper.PiOver2; } for (int xx = bounds.Left; xx < bounds.Right; xx++) { for (int yy = bounds.Top; yy < bounds.Bottom; yy++) { terrainLayer.Tiles[xx, yy] = (direction.Y!=0?map.Tiles[JETTY_H]:map.Tiles[JETTY_V]); waterLayer.Tiles[xx, yy] = null; } } Jetty newJ = new Jetty(); newJ.Position = jettyPos; newJ.Bounds = bounds; newJ.BoatPosition = boatPos; newJ.BoatRotation = boatRot; map.Jetties.Add(newJ); return true; }
private static Vector2 TryFindSpawn(int x, int y, Map map, TileLayer layer, out bool foundspawn) { Vector2 returnPos = new Vector2(x * map.TileWidth, y * map.TileHeight) + (new Vector2(map.TileWidth, map.TileHeight)/2); if (GetTileIndex(map, layer, x, y) == SAND || GetTileIndex(map, layer, x, y) == SAND_ALT) { if(GetTileIndex(map, layer, x-5, y) == WATER || GetTileIndex(map, layer, x+5, y) == WATER || GetTileIndex(map, layer, x, y-5) == WATER || GetTileIndex(map, layer, x, y+5) == WATER) { foundspawn = true; } else foundspawn = false; } else foundspawn = false; return returnPos; }
private static bool TryDrawBigTree(Map map, TileLayer wallLayer, int x, int y) { Rectangle thisTree = BIG_TREES[rand.Next(7)]; bool canFit = true; for (int xx = x; xx < x + thisTree.Width; xx++) for (int yy = y; yy < y + thisTree.Height; yy++) if (GetTileIndex(map, wallLayer, xx, yy) != TREE) canFit = false; if (canFit) { int mapx = x; int mapy = y; for (int xx = thisTree.Left; xx < thisTree.Right; xx++) { for (int yy = thisTree.Top; yy < thisTree.Bottom; yy++) { int tile = ((yy-1) * TILESHEET_WIDTH) + (xx % (TILESHEET_WIDTH+1)); wallLayer.Tiles[mapx, mapy] = map.Tiles[tile]; mapy++; } mapy = y; mapx++; } } return canFit; }
private static void MakeBuildings(Map map, TileLayer wallLayer, TileLayer terrainLayer, TileLayer roofLayer, Compound newCompound) { Rectangle innerBounds = newCompound.InnerBounds; innerBounds.Inflate(-2, -2); // Helipad Building heliPad = null; for (int i = 0; i < 10; i++) { Point pos = new Point(innerBounds.Left + rand.Next(innerBounds.Width), innerBounds.Top + rand.Next(innerBounds.Height)); Rectangle rect = new Rectangle(pos.X - 3, pos.Y - 3, 6, 6); bool canPlace = true; foreach (Building b in newCompound.Buildings) { Rectangle br = b.Rect; br.Inflate(2, 2); if (br.Intersects(rect)) canPlace = false; } if (!innerBounds.Contains(rect)) canPlace = false; if (canPlace) { heliPad = new Building() { Rect = rect, Type = BuildingType.Helipad }; break; } } if (heliPad != null) { newCompound.Buildings.Add(heliPad); //for (int xx = heliPad.Rect.Left; xx < heliPad.Rect.Right; xx++) // for (int yy = heliPad.Rect.Top; yy < heliPad.Rect.Bottom; yy++) // terrainLayer.Tiles[xx, yy] = map.Tiles[CARPARK]; } // Buildings! for (int i = 0; i < 100; i++) { Building newBuilding = null; Point pos = new Point(innerBounds.Left + 4 + rand.Next(innerBounds.Width - 8), innerBounds.Top + 4 + rand.Next(innerBounds.Height-8)); Rectangle rect = new Rectangle(pos.X, pos.Y, 1, 1); rect.Inflate(5 + rand.Next(10), 5 + rand.Next(10)); bool canPlace = true; foreach (Building b in newCompound.Buildings) { Rectangle br = b.Rect; br.Inflate(2, 2); if (br.Intersects(rect)) canPlace = false; } if (!innerBounds.Contains(rect)) canPlace = false; if (canPlace) { newBuilding = new Building() { Rect = rect, Type = BuildingType.Building }; } if (newBuilding != null) { newCompound.Buildings.Add(newBuilding); // Outer walls wallLayer.Tiles[rect.Left, rect.Top] = map.Tiles[WALL_TL]; wallLayer.Tiles[rect.Right, rect.Top] = map.Tiles[WALL_TR]; wallLayer.Tiles[rect.Left, rect.Bottom] = map.Tiles[WALL_BL]; wallLayer.Tiles[rect.Right, rect.Bottom] = map.Tiles[WALL_BR]; roofLayer.Tiles[rect.Left, rect.Top] = map.Tiles[ROOF_TL]; roofLayer.Tiles[rect.Right, rect.Top] = map.Tiles[ROOF_TR]; roofLayer.Tiles[rect.Left, rect.Bottom] = map.Tiles[ROOF_BL]; roofLayer.Tiles[rect.Right, rect.Bottom] = map.Tiles[ROOF_BR]; for (int xx = rect.Left + 1; xx <= rect.Right - 1; xx++) { wallLayer.Tiles[xx, rect.Top] = map.Tiles[WALL_EDGE_UP]; wallLayer.Tiles[xx, rect.Bottom] = map.Tiles[WALL_EDGE_DOWN]; roofLayer.Tiles[xx, rect.Top] = map.Tiles[ROOF_EDGE_UP]; roofLayer.Tiles[xx, rect.Bottom] = map.Tiles[ROOF_EDGE_DOWN]; } for (int yy = rect.Top + 1; yy <= rect.Bottom - 1; yy++) { wallLayer.Tiles[rect.Left,yy] = map.Tiles[WALL_EDGE_LEFT]; wallLayer.Tiles[rect.Right,yy] = map.Tiles[WALL_EDGE_RIGHT]; roofLayer.Tiles[rect.Left, yy] = map.Tiles[ROOF_EDGE_LEFT]; roofLayer.Tiles[rect.Right, yy] = map.Tiles[ROOF_EDGE_RIGHT]; } for (int xx = rect.Left+1; xx <= rect.Right-1; xx++) { for (int yy = rect.Top+1; yy <= rect.Bottom-1; yy++) { roofLayer.Tiles[xx, yy] = map.Tiles[ROOF]; } } // Exits bool[] exits = new bool[4] { false, false, false, false }; exits[rand.Next(4)] = true; if (exits[0]) { int doorx = rand.Next(rect.Width - 7) + 3; for (int xx = rect.Left + doorx; xx < (rect.Left + doorx) + 4; xx++) { wallLayer.Tiles[xx, rect.Top] = null; roofLayer.Tiles[xx, rect.Top] = null; } } if (exits[1]) { int doorx = rand.Next(rect.Width - 7) + 3; for (int xx = rect.Left + doorx; xx < (rect.Left + doorx) + 4; xx++) { wallLayer.Tiles[xx, rect.Bottom] = null; roofLayer.Tiles[xx, rect.Bottom] = null; } } if (exits[2]) { int doory = rand.Next(rect.Height - 7) + 3; for (int yy = rect.Top + doory; yy < (rect.Top + doory) + 4; yy++) {wallLayer.Tiles[rect.Left, yy] = null; roofLayer.Tiles[rect.Left, yy] = null;} } if (exits[3]) { int doory = rand.Next(rect.Height - 7) + 3; for (int yy = rect.Top + doory; yy < (rect.Top + doory) + 4; yy++){ wallLayer.Tiles[rect.Right, yy] = null; roofLayer.Tiles[rect.Right, yy] = null;} } //for (int xx = newBuilding.Rect.Left; xx < newBuilding.Rect.Right; xx++) // for (int yy = newBuilding.Rect.Top; yy < newBuilding.Rect.Bottom; yy++) // terrainLayer.Tiles[xx, yy] = map.Tiles[WALL_HORIZ]; } } }
static int GetTileIndex(Map map, TileLayer layer, int x, int y) { if (x > -1 && x < map.Width && y > -1 && y < map.Height && layer.Tiles[x, y]!=null) { return map.Tiles.IndexOf(layer.Tiles[x, y]); } return -1; }