public override bool Use(GameTime gameTime, Vector2 target, bool trigger, Camera gameCamera, bool canCollide) { if (!trigger) { roundsCount = 0; coolDownTarget = 100; } if (!base.Use(gameTime, target, trigger, gameCamera, canCollide)) return false; roundsCount++; if (roundsCount == 3) { roundsCount = 0; coolDownTarget = 600; } else coolDownTarget = 75; if (owner.GetType() == typeof(HeroDude)) owner.Ammo--; AudioController.PlaySFX("rifle", 1f, 0f,0.3f, owner.Position); ProjectileController.Instance.Add(ProjectileType.Rifle, owner, muzzlePos, target - muzzlePos, canCollide); return true; }
public virtual bool Use(GameTime gameTime, Vector2 target, bool trigger, Camera gameCamera, bool canCollide) { if (!trigger) { triggerHeld = false; return false; } if (triggerHeld && !isAuto && (owner.GetType() == typeof(HeroDude))) return false; triggerHeld = true; if (coolDown < coolDownTarget * ((owner is HeroDude)?1f:2f)) return false; coolDown = 0; if (this.GetType() != typeof(Knife)) { //if (clipAmmo <= 0) return false; if (owner.Ammo <= 0 && owner.GetType() == typeof(HeroDude)) return false; //if (owner.GetType() == typeof(HeroDude)) clipAmmo--; } //if ((owner.GetType() == typeof(AIDude))) //{ //} if (owner is HeroDude && !(this is Knife)) EnemyController.Instance.HeroFiredShot((HeroDude)owner); return true; }
public override bool Use(GameTime gameTime, Vector2 target, bool trigger, Camera gameCamera, bool canCollide) { if (!base.Use(gameTime, target, trigger, gameCamera, canCollide)) return false; if(owner is AIDude) AIroundscount++; roundsCount++; if (roundsCount == 2) { roundsCount = 0; if (owner.GetType() == typeof(HeroDude)) owner.Ammo--; } if (AIroundscount >= 20) { AIroundscount = 0; coolDownTarget = 1000; } else coolDownTarget = 30; //AudioController.PlaySFX("smg", 1f, -0.2f,0.2f, owner.Position); sound.Volume = 1f; sound.Pitch = -0.2f + ((float)Helper.Random.NextDouble() * (0.4f)); sound.Pan = MathHelper.Clamp((Vector2.Transform(owner.Position, Camera.Instance.CameraMatrix).X - (Camera.Instance.Width / 2)) / (Camera.Instance.Width / 2), -1f, 1f); sound.Stop(); sound.Play(); ProjectileController.Instance.Add(ProjectileType.SMG, owner, muzzlePos, target - muzzlePos, canCollide); return true; }
public void Draw(GraphicsDevice gd, SpriteBatch sb, Camera gameCamera, float minY, float maxY) { foreach (Robot r in Enemies.OrderBy(rob=>rob.landingHeight)) { if(r.Position.Y>=minY && r.Position.Y<maxY) r.Draw(gd,sb,gameCamera); } }
public void Draw(GraphicsDevice gd, SpriteBatch sb, Camera gameCamera, float minY, float maxY, bool inPlane) { foreach (Dude r in Enemies.Where(en=>en.IsInPlane==inPlane).OrderBy(en=>en.HasParachute)) { //if(r.Position.Y>=minY && r.Position.Y<maxY) r.Draw(gd,sb,gameCamera); } }
public void Draw(GraphicsDevice gd, SpriteBatch sb, Camera gameCamera, float minY, float maxY) { sb.Begin(SpriteSortMode.Deferred, null,null,null,null,null,gameCamera.CameraMatrix); foreach (Item i in Items.OrderBy(it=>it.DroppedPosition.Y).Where(it=>it.InWorld)) { if(i.Position.Y>=minY && i.Position.Y<maxY) i.Draw(sb,gameCamera); } sb.End(); }
public void Draw(SpriteBatch sb, Camera gameCamera) { if (Visible) { sb.Begin(SpriteSortMode.Deferred, null, null, null, null, null, gameCamera.CameraMatrix); sb.Draw(texBG, Position, null, Color.White, 0f, new Vector2(62, 280), 1f, SpriteEffects.None, 1); sb.DrawString(font, WrapText(Text, 315), Position + new Vector2(-10, -175), Color.Black); sb.End(); } }
public void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, Camera gameCamera) { skeletonRenderer.Begin(gameCamera.CameraMatrix); skeletonRenderer.Draw(skeleton); skeletonRenderer.End(); // Draw collision box //spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, gameCamera.CameraMatrix); //spriteBatch.Draw(blankTex, collisionRect, Color.White * 0.3f); //spriteBatch.End(); }
public override bool Use(GameTime gameTime, Vector2 target, bool trigger, Camera gameCamera, bool canCollide) { if (!base.Use(gameTime, target, trigger, gameCamera, canCollide)) return false; if (owner.GetType() == typeof(HeroDude)) owner.Ammo--; AudioController.PlaySFX("pistol", 1f, -0.2f,0.2f, owner.Position); ProjectileController.Instance.Add(ProjectileType.Pistol, owner, muzzlePos, target - muzzlePos, canCollide); return true; }
public override bool Use(GameTime gameTime, Vector2 target, bool trigger, Camera gameCamera, bool canCollide) { if (!base.Use(gameTime, target, trigger, gameCamera, canCollide)) return false; // ProjectileController.Instance.Add(ProjectileType.Pistol, owner, Helper.PointOnCircle(ref owner.Position, 40, owner.Rotation - MathHelper.PiOver2), owner.Position - Helper.PointOnCircle(ref owner.Position, 100, owner.Rotation + MathHelper.PiOver2)); AudioController.PlaySFX("sword", 1f, -0.3f, 0.3f, owner.Position); ProjectileController.Instance.Add(ProjectileType.Knife, owner, Helper.PointOnCircle(ref owner.Position, 75, owner.Rotation - MathHelper.PiOver2), Vector2.Zero, true); ProjectileController.Instance.Add(ProjectileType.Knife, owner, Helper.PointOnCircle(ref owner.Position, 15, owner.Rotation - MathHelper.PiOver2), Vector2.Zero, true); return true; }
public Camera(int width, int height, int boundswidth, int boundsheight) { Instance = this; Position = new Vector2(0, 0); Width = width; Height = height; BoundsWidth = boundswidth; BoundsHeight = boundsheight; ClampRect = new Rectangle((Width / 2), (Height / 2), (boundswidth) - (Width / 2), (boundsheight) - (Height / 2)); // Set initial position and target Position.X = ClampRect.X; Position.Y = ClampRect.Y; Target = new Vector2(ClampRect.X, ClampRect.Y); }
public override bool Use(GameTime gameTime, Vector2 target, bool trigger, Camera gameCamera, bool canCollide) { if (!base.Use(gameTime, target, trigger, gameCamera, canCollide)) return false; if (owner.GetType() == typeof(HeroDude)) owner.Ammo-=5; AudioController.PlaySFX("shotgun", 1f, -0.2f,0.2f, owner.Position); for (float r = -0.3f; r <= 0.3f; r += 0.15f) { ProjectileController.Instance.Add(ProjectileType.Shot, owner, muzzlePos, muzzlePos - Helper.PointOnCircle(ref owner.Position, 100, (owner.Rotation + MathHelper.PiOver2 + r + (((float)Helper.Random.NextDouble() * 0.1f) - 0.05f)) - 0.25f), canCollide); } //ProjectileController.Instance.Add(ProjectileType.Shot, owner, Helper.PointOnCircle(ref owner.Position, 40, owner.Rotation - MathHelper.PiOver2), owner.Position - Helper.PointOnCircle(ref owner.Position, 100, owner.Rotation + MathHelper.PiOver2-0.25f), canCollide); //ProjectileController.Instance.Add(ProjectileType.Shot, owner, Helper.PointOnCircle(ref owner.Position, 40, owner.Rotation - MathHelper.PiOver2), owner.Position - Helper.PointOnCircle(ref owner.Position, 100, owner.Rotation + MathHelper.PiOver2), canCollide); //ProjectileController.Instance.Add(ProjectileType.Shot, owner, Helper.PointOnCircle(ref owner.Position, 40, owner.Rotation - MathHelper.PiOver2), owner.Position - Helper.PointOnCircle(ref owner.Position, 100, owner.Rotation + MathHelper.PiOver2+0.25f), canCollide); //ProjectileController.Instance.Add(ProjectileType.Shot, owner, Helper.PointOnCircle(ref owner.Position, 40, owner.Rotation - MathHelper.PiOver2), owner.Position - Helper.PointOnCircle(ref owner.Position, 100, owner.Rotation + MathHelper.PiOver2+0.5f), canCollide); return true; }
public void Draw(SpriteBatch sb, Viewport vp, Camera gameCamera, bool radar, SpriteFont font, int mapwidth) { sb.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null); sb.Draw(_sheet, new Vector2(vp.Bounds.Center.X - 100, hbPos), new Rectangle(0, 0, 201, 4), Color.White); sb.Draw(_sheet, new Vector2(vp.Bounds.Center.X - 100, hbPos), new Rectangle(0, 5, (200/100) * (int)Ship.Instance.Life, 4), Color.White); Vector2 pos = new Vector2(vp.Bounds.Center.X - 99, hbPos + 6); for (int i = 0; i < 20; i++) { sb.Draw(_sheet, pos, new Rectangle(Ship.Instance.PowerUpMeter>i?8:0, 10, 8, 6), Color.White); pos.X += 10; } foreach (var hbs in hbSegments) sb.Draw(_sheet, hbs.Position, new Rectangle(0, 6, hbs.Amount, 2), Color.White * hbs.Alpha); if (radar) { Vector2 campos = (gameCamera.Position - new Vector2(vp.Width/2, vp.Height/2)); foreach (Enemy e in EnemyController.Instance.Enemies) { Vector2 epos = e.Position - campos; if (Vector2.Distance(e.Position + new Vector2(mapwidth, 0), campos) < Vector2.Distance(e.Position, campos)) epos = (e.Position + new Vector2(mapwidth, 0)) - campos; if (Vector2.Distance(e.Position - new Vector2(mapwidth, 0), campos) < Vector2.Distance(e.Position, campos)) epos = (e.Position - new Vector2(mapwidth, 0)) - campos; epos = Vector2.Clamp(epos, Vector2.One, new Vector2(vp.Bounds.Right - 2, vp.Bounds.Bottom - 2)); if (epos.X > 1 && epos.X < vp.Bounds.Right - 2 && epos.Y > 1 && epos.Y < vp.Bounds.Bottom - 2) continue; sb.Draw(_sheet, epos, new Rectangle(17, 11, 3, 3), Color.White, 0f, new Vector2(1, 1), 1f, SpriteEffects.None, 0); } } pos = new Vector2(30,vp.Bounds.Bottom - 8); sb.DrawString(font, Ship.Instance.Multiplier.ToString() + "x", pos + Vector2.One, Color.Black, 0f, font.MeasureString(Ship.Instance.Multiplier.ToString() + "x")/2, multScale, SpriteEffects.None, 0); sb.DrawString(font, Ship.Instance.Multiplier.ToString() + "x", pos, Color.White, 0f, font.MeasureString(Ship.Instance.Multiplier.ToString() + "x")/2, multScale, SpriteEffects.None, 0); pos = new Vector2(vp.Bounds.Right - 58, vp.Bounds.Bottom - 20); sb.DrawString(font, Ship.Instance.Score.ToString("000000"), pos + Vector2.One, Color.Black, 0f, Vector2.Zero,1f, SpriteEffects.None,0); sb.DrawString(font, Ship.Instance.Score.ToString("000000"), pos, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0); sb.End(); }
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); }
/// <summary> /// Initialise the camera, using the game map to define the boundaries /// </summary> /// <param name="vp">Graphics viewport</param> /// <param name="map">Game Map</param> public Camera(Viewport vp, Map map) { Instance = this; 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 virtual void Attack(GameTime gameTime, Vector2 target, bool trigger, Camera gameCamera, bool canCollide) { if (Dead || !Active) return; Weapons[SelectedWeapon].Use(gameTime, target, trigger, gameCamera, canCollide); }
public void Draw(GraphicsDevice gd, SpriteBatch sb, Camera gameCamera) { sb.Begin(SpriteSortMode.Deferred, null,null,null,null,null,gameCamera.CameraMatrix); foreach (Item i in Items.OrderBy(it=>it.Type== ItemType.Chute)) { i.Draw(sb,gameCamera); } sb.End(); }
public void Update(GameTime gameTime, Camera gameCamera, Map gameMap, Dude gameHero, float planeRot) { foreach (Item i in Items) { i.Update(gameTime, gameMap, planeRot); } for (int i = Items.Count - 1; i >= 0; i--) { if (Items[i].Dead) Items.RemoveAt(i); } }
/// <summary> /// Load graphics content for the game. /// </summary> public override void LoadContent() { if (content == null) content = new ContentManager(ScreenManager.Game.Services, "Content"); AudioController.LoadContent(content); //gameFont = content.Load<SpriteFont>("menufont"); lightingEngine.LoadContent(content, ScreenManager.GraphicsDevice, ScreenManager.SpriteBatch); enemyController = new EnemyController(); enemyController.LoadContent(content, ScreenManager.GraphicsDevice, lightingEngine); particleController = new ParticleController(); particleController.LoadContent(content); projectileController = new ProjectileController(); projectileController.LoadContent(content); itemController = new ItemController(); itemController.LoadContent(content, ScreenManager.GraphicsDevice, lightingEngine); vehicleController = new VehicleController(); vehicleController.LoadContent(content, ScreenManager.GraphicsDevice, lightingEngine); gameMap = content.Load<Map>("map/map"); gameHud = new Hud(); gameHud.LoadContent(content); mapFog = new bool[gameMap.Width, gameMap.Height]; ThreadPool.QueueUserWorkItem(new WaitCallback(GenerateTerrainAsync)); gameHero = new HeroDude(gameMap.HeroSpawn); gameHero.LoadContent(content, ScreenManager.GraphicsDevice, lightingEngine); gameCamera = new Camera(ScreenManager.GraphicsDevice.Viewport, gameMap); gameCamera.ClampRect = new Rectangle(0, 0, gameMap.Width * gameMap.TileWidth, gameMap.Height * gameMap.TileHeight); gameCamera.ZoomTarget = 1f; //gameCamera.Position = gameHero.Position - (new Vector2(ScreenManager.GraphicsDevice.Viewport.Width, ScreenManager.GraphicsDevice.Viewport.Height) / 2); gameCamera.Position = gameHero.Position; gameCamera.Target = gameCamera.Position; gameCamera.Update(ScreenManager.GraphicsDevice.Viewport.Bounds); //cameraLightSource.Type = LightSourceType.Spot; //lightingEngine.LightSources.Add(cameraLightSource); minimapRT = new RenderTarget2D(ScreenManager.GraphicsDevice, 200, 200); crosshairTex = content.Load<Texture2D>("crosshair"); mapIcons = content.Load<Texture2D>("mapicons"); //lightSource1 = new LightSource(ScreenManager.GraphicsDevice, 600, LightAreaQuality.Low, new Color(1f, 1f, 1f), BeamStencilType.Wide, SpotStencilType.None); //lightingEngine.LightSources.Add(lightSource1); ScreenManager.Game.ResetElapsedTime(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); AudioController.LoadContent(Content); sfxEngine = Content.Load<SoundEffect>("sfx/engine").CreateInstance(); sfxPanic = Content.Load<SoundEffect>("sfx/panic").CreateInstance(); sfxWind = Content.Load<SoundEffect>("sfx/wind").CreateInstance(); sfxRattle = Content.Load<SoundEffect>("sfx/rattle").CreateInstance(); sfxEngine.IsLooped = true; sfxPanic.IsLooped = true; sfxWind.IsLooped = true; sfxRattle.IsLooped = true; texBlank = Content.Load<Texture2D>("blank"); texDoor = Content.Load<Texture2D>("door"); texGradient = Content.Load<Texture2D>("skygradient"); texParachute = Content.Load<Texture2D>("parachute"); fontAltitude = Content.Load<SpriteFont>("altfont"); speechBubble = new Speechbubble(Content); gameMap = Content.Load<Map>("planemap"); gameCamera = new Camera(GraphicsDevice.Viewport, gameMap); Reset(); }
/// <summary> /// Draws a single layer of the map /// </summary> /// <param name="spriteBatch">The SpriteBatch to use to render the layer.</param> /// <param name="tileLayer">The layer to draw.</param> /// <param name="gameCamera">The camera to use for positioning.</param> /// <param name="offset">A pixel amount to offset the tile positioning by</param> /// <param name="alpha">Layer opacity.</param> /// <param name="color">The color to use when drawing.</param> public void DrawLayer(SpriteBatch spriteBatch, Layer layer, Camera gameCamera, Vector2 offset, float alpha, Color color) { if (!layer.Visible) return; TileLayer tileLayer = layer as TileLayer; if (tileLayer != null) { Rectangle worldArea = new Rectangle((int)gameCamera.Position.X - (gameCamera.Width+200), (int)gameCamera.Position.Y - (int)(gameCamera.Height*1.5), (gameCamera.Width *2)+400, gameCamera.Height*3); // figure out the min and max tile indices to draw int minX = Math.Max((int)Math.Floor((float)worldArea.Left / TileWidth), 0); int maxX = Math.Min((int)Math.Ceiling((float)worldArea.Right / TileWidth), Width); int minY = Math.Max((int)Math.Floor((float)worldArea.Top / TileHeight), 0); int maxY = Math.Min((int)Math.Ceiling((float)worldArea.Bottom / TileHeight), Height); for (int x = minX; x < maxX; x++) { for (int y = minY; y < maxY; y++) { //if ((new Vector2((x * TileWidth) + (TileWidth/2), (y * TileHeight) + (TileHeight/2)) - new Vector2(worldArea.Center.X, worldArea.Center.Y)).Length() < gameCamera.Width * 3f) //{ Tile tile = tileLayer.Tiles[x, y]; if (tile == null) continue; // - tile.Source.Height + TileHeight; Rectangle r = new Rectangle(x * TileWidth, y * TileHeight, tile.Source.Width, tile.Source.Height); spriteBatch.Draw(tile.Texture, r, tile.Source, color); //} } } } }
/// <summary> /// Draws a single layer as shadows, by layer name /// </summary> /// <param name="spriteBatch">The SpriteBatch to use to render the layer.</param> /// <param name="layerName">The name of the layer to draw.</param> /// <param name="gameCamera">The camera to use for positioning.</param> /// <param name="shadowOffset">Pixel amount to offset the shadowing by.</param> /// <param name="alpha">Shadow opacity</param> public void DrawLayer(SpriteBatch spriteBatch, string layerName, Camera gameCamera, Vector2 shadowOffset, float alpha) { var l = GetLayer(layerName); if (l == null) return; if (!l.Visible) return; TileLayer tileLayer = l as TileLayer; if (tileLayer != null) { //for (float mult = 0f; mult < 1f; mult += 0.1f) //{ DrawLayer(spriteBatch, l, gameCamera, shadowOffset, alpha, Color.Black); //DrawLayer(spriteBatch, l, gameCamera, shadowOffset, alpha, Color.Black); //} //DrawLayer(spriteBatch, l, gameCamera, shadowOffset * 0.5f, alpha * 0.75f, Color.Black); //DrawLayer(spriteBatch, l, gameCamera, shadowOffset * 0.75f, alpha * 0.5f, Color.Black); //DrawLayer(spriteBatch, l, gameCamera, shadowOffset, alpha *0.25f, Color.Black); } }
/// <summary> /// Draws a single layer by layer name, with a specified color /// </summary> /// <param name="spriteBatch">The SpriteBatch to use to render the layer.</param> /// <param name="layerName">The name of the layer to draw.</param> /// <param name="gameCamera">The camera to use for positioning.</param> public void DrawLayer(SpriteBatch spriteBatch, string layerName, Camera gameCamera, Color color) { var l = GetLayer(layerName); if (l == null) return; if (!l.Visible) return; TileLayer tileLayer = l as TileLayer; if (tileLayer != null) { if(tileLayer.Properties.Contains("Shadows")) DrawLayer(spriteBatch, tileLayer.Name, gameCamera, new Vector2(-10f, -10f), 0.2f); DrawLayer(spriteBatch, l, gameCamera, new Vector2(0, 0), tileLayer.Opacity, color); } }
/// <summary> /// Draws all layers of the map /// </summary> /// <param name="spriteBatch">The SpriteBatch to use to render the map.</param> /// <param name="gameCamera">The camera to use for positioning.</param> public void Draw(SpriteBatch spriteBatch, Camera gameCamera) { foreach (var l in Layers) { if (!l.Visible) continue; DrawLayer(spriteBatch, l, gameCamera, Vector2.Zero, 1.0f, Color.White * l.Opacity); } }
public void DrawShadows(SpriteBatch spriteBatch, string layerName, Camera gameCamera, LightingEngine lightingEngine) { var l = GetLayer(layerName); if (l == null) return; if (!l.Visible) return; if (gameCamera.Zoom < 0.4f) return; TileLayer tileLayer = l as TileLayer; if (tileLayer != null) { Rectangle worldArea = new Rectangle((int)((gameCamera.Position.X - (int)(((float)gameCamera.Width)))), (int)((gameCamera.Position.Y - (int)(((float)gameCamera.Height)))), (int)((gameCamera.Width) * 2), (int)((gameCamera.Height) * 2)); //Rectangle worldArea = new Rectangle(0, (int)gameCamera.Position.Y - (int)(((float)gameCamera.Height) * (2f-scale)), TileWidth * Width, (int)(((float)gameCamera.Height*2 ) * (3f-(2f*scale)))); // figure out the min and max tile indices to draw worldArea.Inflate((int)((gameCamera.Width / gameCamera.Zoom) - gameCamera.Width), (int)((gameCamera.Height / gameCamera.Zoom) - gameCamera.Height)); int minX = Math.Max((int)Math.Floor((float)worldArea.Left / TileWidth), 0); int maxX = Math.Min((int)Math.Ceiling((float)worldArea.Right / TileWidth), Width); int minY = Math.Max((int)Math.Floor((float)worldArea.Top / TileHeight), 0); int maxY = Math.Min((int)Math.Ceiling((float)worldArea.Bottom / TileHeight), Height); //minX = 0; //maxX = 1000; //minY = 0; //maxY = 1000; for (int x = minX; x < maxX; x++) { for (int y = minY; y < maxY; y++) { //if ((new Vector2((x * TileWidth) + (TileWidth / 2), (y * TileHeight) + (TileHeight / 2)) - new Vector2(worldArea.Center.X, worldArea.Center.Y)).Length() < gameCamera.Width * 0.75) //{ Tile tile = tileLayer.Tiles[x, y]; if (tile == null) continue; // - tile.Source.Height + TileHeight; #if WINRT int qual = 5; float defbright = 0.06f; #else int qual = 2; float defbright = 0.03f; #endif // Ambient shadow for (int i = 1; i < 40; i += qual) { Rectangle r = new Rectangle((x * TileWidth) + (int)(lightingEngine.CurrentShadowVect.X * i), (y * TileHeight) + (int)(lightingEngine.CurrentShadowVect.Y * i), tile.Source.Width, tile.Source.Height); spriteBatch.Draw(tile.Texture, r, tile.Source, Color.Black * defbright); } //foreach (LightSource ls in lightingEngine.LightSources) //{ // Vector2 tilepos = new Vector2(x * TileWidth, y * TileWidth) + (new Vector2(TileWidth, TileHeight) / 2); // float dist = (tilepos - ls.Position).Length(); // if (dist < 400f) // { // Vector2 dir = Vector2.Zero; // switch (ls.Type) // { // case LightSourceType.Spot: // dir = tilepos - ls.Position; // dir.Normalize(); // break; // case LightSourceType.Directional: // dir = ls.Direction; // break; // } // float shadowAmount = (2f / 400f) * (400f - dist); // float shadowBrightness = (defbright + 0.01f) * (1f - (lightingEngine.CurrentSunColor.ToVector3().Z)); // for (int i = 1; i < 40; i += qual) // { // //Rectangle r = new Rectangle((x * TileWidth) + (int)(dir.X * shadowAmount * i), (y * TileHeight) + (int)(dir.Y * shadowAmount * i), tile.Source.Width, tile.Source.Height); // spriteBatch.Draw(tile.Texture, new Vector2((x * TileWidth) + (dir.X * shadowAmount * i), (y * TileHeight) + (dir.Y * shadowAmount * i)), tile.Source, Color.Black * shadowBrightness); // } // } //} //} } } } }
public void DrawRoofLayer(SpriteBatch spriteBatch, Camera gameCamera, LightingEngine lightingEngine, Color color, Vector2 vector2) { TileLayer tileLayer = GetLayer("Roof") as TileLayer; if (tileLayer != null) { Rectangle worldArea = new Rectangle((int)((gameCamera.Position.X - (int)(((float)gameCamera.Width)))), (int)((gameCamera.Position.Y - (int)(((float)gameCamera.Height)))), (int)((gameCamera.Width) * 2), (int)((gameCamera.Height) * 2)); //Rectangle worldArea = new Rectangle(0, (int)gameCamera.Position.Y - (int)(((float)gameCamera.Height) * (2f-scale)), TileWidth * Width, (int)(((float)gameCamera.Height*2 ) * (3f-(2f*scale)))); // figure out the min and max tile indices to draw worldArea.Inflate((int)((gameCamera.Width / gameCamera.Zoom) - (gameCamera.Width)), (int)((gameCamera.Height / gameCamera.Zoom) - (gameCamera.Height))); int minX = Math.Max((int)Math.Floor((float)worldArea.Left / TileWidth), 0); int maxX = Math.Min((int)Math.Ceiling((float)worldArea.Right / TileWidth), Width); int minY = Math.Max((int)Math.Floor((float)worldArea.Top / TileHeight), 0); int maxY = Math.Min((int)Math.Ceiling((float)worldArea.Bottom / TileHeight), Height); //minX = 0; //maxX = 1000; //minY = 0; //maxY = 1000; for (int x = minX; x < maxX; x++) { for (int y = minY; y < maxY; y++) { //if ((new Vector2((x * TileWidth) + (TileWidth / 2), (y * TileHeight) + (TileHeight / 2)) - new Vector2(worldArea.Center.X, worldArea.Center.Y)).Length() < gameCamera.Width * 0.75) //{ Tile tile = tileLayer.Tiles[x, y]; if (tile == null) continue; if (AnimFrame > 0 && tile.Properties.Contains("Anim")) { tile = TileSetDictionary["ts" + (AnimFrame + 1)][TileSetDictionary["ts1"].IndexOf(tile)]; } // if (tile.Properties.Contains("Anim")) tile = Tiles.Where(t => t!=null && t.Properties.Contains("Anim") && t.Properties["Anim"] == tile.Properties["Anim"] + AnimFrame).First(); // - tile.Source.Height + TileHeight; //Rectangle r = new Rectangle(x * TileWidth, y * TileHeight, tile.Source.Width, tile.Source.Height); float a = 1f; foreach (Compound c in Compounds) foreach (Building b in c.Buildings) { Rectangle r = b.Rect; r.Inflate(2, 2); if (r.Contains(x, y)) a = b.RoofFade; } spriteBatch.Draw(tile.Texture, new Vector2((x * TileWidth), (y * TileHeight)), tile.Source, (color == Color.White ? lightingEngine.CurrentSunColor : color) * a); //if (!AStarWorld.PositionIsFree(new AStar.Point3D(x, y, 0))) // spriteBatch.Draw(tile.Texture, new Vector2((x * TileWidth), (y * TileHeight)), new Rectangle(0,0,100,100), Color.Red); //} } } } }
public void DrawMinimap(SpriteBatch spriteBatch, Camera gameCamera, float zoom, RenderTarget2D minimapRT, bool[,] mapFog, Vector2 playerPos) { Rectangle worldArea = new Rectangle((int)((playerPos.X - (int)(((float)minimapRT.Width)))), (int)((playerPos.Y - (int)(((float)minimapRT.Height)))), (int)((minimapRT.Width) * 2), (int)((minimapRT.Height) * 2)); //Rectangle worldArea = new Rectangle(0, (int)gameCamera.Position.Y - (int)(((float)gameCamera.Height) * (2f-scale)), TileWidth * Width, (int)(((float)gameCamera.Height*2 ) * (3f-(2f*scale)))); // figure out the min and max tile indices to draw worldArea.Inflate((int)((minimapRT.Width / zoom) - minimapRT.Width), (int)((minimapRT.Height / zoom) - minimapRT.Height)); int minX = Math.Max((int)Math.Floor((float)worldArea.Left / TileWidth), 0); int maxX = Math.Min((int)Math.Ceiling((float)worldArea.Right / TileWidth), Width); int minY = Math.Max((int)Math.Floor((float)worldArea.Top / TileHeight), 0); int maxY = Math.Min((int)Math.Ceiling((float)worldArea.Bottom / TileHeight), Height); //minX = 0; //maxX = 1000; //minY = 0; //maxY = 1000; TileLayer terrainLayer = GetLayer("Terrain") as TileLayer; TileLayer wallLayer = GetLayer("Wall") as TileLayer; TileLayer roofLayer = GetLayer("Roof") as TileLayer; for (int x = minX; x < maxX; x++) // for (int x = 0; x < 1; x++) { for (int y = minY; y < maxY; y++) // for (int y = minY; y <= minY; y++) { if (!mapFog[x, y]) continue; Tile tile = terrainLayer.Tiles[x, y]; if (tile != null) { //Rectangle r = new Rectangle(x * TileWidth, y * TileHeight, tile.Source.Width, tile.Source.Height); spriteBatch.Draw(tile.Texture, new Vector2(x * TileWidth, y * TileHeight), tile.Source, Color.White); } tile = wallLayer.Tiles[x, y]; if (tile != null) { //Rectangle r = new Rectangle(x * TileWidth, y * TileHeight, tile.Source.Width, tile.Source.Height); spriteBatch.Draw(tile.Texture, new Vector2(x * TileWidth, y * TileHeight), tile.Source, Color.White); } tile = roofLayer.Tiles[x, y]; if (tile != null) { //Rectangle r = new Rectangle(x * TileWidth, y * TileHeight, tile.Source.Width, tile.Source.Height); spriteBatch.Draw(tile.Texture, new Vector2(x * TileWidth, y * TileHeight), tile.Source, Color.White); } } } }
internal static void PlaySFX(string name, float volume, float minpitch, float maxpitch, Camera gameCamera, Vector2 position) { Vector2 screenPos = Vector2.Transform(position, gameCamera.CameraMatrix); float pan = (screenPos.X - (gameCamera.Width / 2f)) / (gameCamera.Width / 2f); if(pan>-1f && pan<1f) _effects[name].Play(volume * _sfxVolume, minpitch + (Helper.RandomFloat(1f) * (maxpitch - minpitch)), pan); }
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(); } }
/// <summary> /// Draws a single layer by layer name /// </summary> /// <param name="spriteBatch">The SpriteBatch to use to render the layer.</param> /// <param name="layerName">The name of the layer to draw.</param> /// <param name="gameCamera">The camera to use for positioning.</param> //public void DrawLayer(SpriteBatch spriteBatch, string layerName, Camera gameCamera) //{ // var l = GetLayer(layerName); // if (l == null) // return; // if (!l.Visible) // return; // TileLayer tileLayer = l as TileLayer; // if (tileLayer != null) // { // if (tileLayer.Properties.Contains("Shadows")) // DrawLayer(spriteBatch, tileLayer.Name, gameCamera, new Vector2(-10f, -10f), 0.2f); // DrawLayer(spriteBatch, l, gameCamera, new Vector2(0,0), tileLayer.Opacity, Color.White, false); // } //} /// <summary> /// Draws a single layer by layer name, with a specified color /// </summary> /// <param name="spriteBatch">The SpriteBatch to use to render the layer.</param> /// <param name="layerName">The name of the layer to draw.</param> /// <param name="gameCamera">The camera to use for positioning.</param> public void DrawLayer(SpriteBatch spriteBatch, string layerName, Camera gameCamera, LightingEngine lightingEngine, Color color) { var l = GetLayer(layerName); if (l == null) return; if (!l.Visible) return; TileLayer tileLayer = l as TileLayer; if (tileLayer != null) { DrawLayer(spriteBatch, l, gameCamera, lightingEngine, color); } }