public LightingEngine() { Instance = this; CurrentSunColor = sunColors[8]; CurrentShadowVect = shadowVects[8]; }
public void Draw(SpriteBatch sb, LightingEngine lightingEngine, HeroDude gameHero) { foreach (Item i in Items.Where(it => (gameHero.Position - it.Position).Length() < 2000f)) { sb.Draw(SpriteSheet, i.Position, rectDict[i.Type], lightingEngine.CurrentSunColor, i.Rotation, new Vector2(25, 25), 1f, SpriteEffects.None, 1); } }
public void LoadContent(ContentManager content, GraphicsDevice gd, LightingEngine le) { SpriteSheet = content.Load<Texture2D>("dude"); graphicsDevice = gd; lightingEngine = le; }
public void DrawShadows(SpriteBatch sb, LightingEngine lightingEngine, HeroDude gameHero) { foreach (AIDude e in Enemies.Where(en => (gameHero.Position - en.Position).Length() < 2000f)) { e.DrawShadows(sb, lightingEngine); } }
public void LoadContent(Texture2D sheet, GraphicsDevice gd, LightingEngine le) { spriteSheet = sheet; Initialize(gd, le); engineSound = AudioController.effects["boat"].CreateInstance(); }
public void DrawShadows(SpriteBatch sb, LightingEngine lightingEngine, HeroDude gameHero) { foreach (Vehicle v in Vehicles.Where(veh => (gameHero.Position - veh.Position).Length() < 2000f)) { if (v is Chopper && ((Chopper)v).Height > 0f) continue; v.DrawShadows(sb, lightingEngine); } }
public override void DrawShadows(SpriteBatch sb, LightingEngine lightingEngine) { for (int i = 1; i < 40; i += 2) { Vector2 pos = Position + new Vector2(lightingEngine.CurrentShadowVect.X * i, lightingEngine.CurrentShadowVect.Y * i); sb.Draw(spriteSheet, pos, new Rectangle(0, 400, 200, 300), Color.Black * 0.03f, Rotation + MathHelper.PiOver2, new Vector2(200, 300) / 2, 1f, SpriteEffects.None, 1); } }
public virtual void DrawShadows(SpriteBatch sb, LightingEngine lightingEngine) { //for (int i = 1; i < 20; i += 2) //{ // Vector2 pos = Position + new Vector2(lightingEngine.CurrentShadowVect.X * i, lightingEngine.CurrentShadowVect.Y * i); // sb.Draw(spriteSheet, pos, Animations["arms"].CellRect, Color.Black * 0.03f, Rotation, new Vector2(100, 100) / 2, 1f, SpriteEffects.None, 1); //} }
public void DrawShadows(SpriteBatch sb, LightingEngine lightingEngine, HeroDude gameHero) { foreach (Item i in Items.Where(it => (gameHero.Position - it.Position).Length() < 2000f)) { for (int s = 1; s < 20; s += 2) { Vector2 pos = i.Position + new Vector2(lightingEngine.CurrentShadowVect.X * s, lightingEngine.CurrentShadowVect.Y * s); sb.Draw(SpriteSheet, pos, rectDict[i.Type], Color.Black * 0.03f, i.Rotation, new Vector2(25, 25), 1f, SpriteEffects.None, 1); } } }
public void LoadContent(ContentManager content, GraphicsDevice gd, LightingEngine le) { spriteSheet = content.Load<Texture2D>("dude"); Initialize(gd, le); Weapons.Add(new Knife(this)); //Weapons.Add(new Pistol(this)); //Weapons.Add(new Shotgun(this)); //Weapons.Add(new SMG(this)); //Weapons.Add(new Rifle(this)); SelectedWeapon = 0; }
public void LoadContent(Texture2D sheet, GraphicsDevice gd, LightingEngine le) { spriteSheet = sheet; Initialize(gd, le); engineSound = AudioController.effects["engine"].CreateInstance(); engineIdleSound = AudioController.effects["truck"].CreateInstance(); engineIdleSound.Volume = 0f; engineIdleSound.IsLooped = true; engineSound.Volume = 0f; engineSound.IsLooped = true; }
public void Draw(SpriteBatch sb, LightingEngine lightingEngine, HeroDude gameHero) { foreach (Vehicle v in Vehicles.Where(veh => (gameHero.Position - veh.Position).Length() < 2000f && !(veh is Chopper))) { v.Draw(sb, lightingEngine); } // Draw helis on top of other vehicles because of rotor blades foreach (Vehicle v in Vehicles.Where(veh => (gameHero.Position - veh.Position).Length() < 2000f && veh is Chopper)) { if (((Chopper)v).Height > 0f) continue; v.Draw(sb, lightingEngine); } }
public void LoadContent(ContentManager content, GraphicsDevice gd, LightingEngine le) { SpriteSheet = content.Load<Texture2D>("items"); rectDict.Add(ItemType.Health, new Rectangle(0, 0, 50, 50)); rectDict.Add(ItemType.Ammo, new Rectangle(50, 0, 50, 50)); rectDict.Add(ItemType.CompoundMap, new Rectangle(100, 0, 50, 50)); rectDict.Add(ItemType.GeneralMap, new Rectangle(150, 0, 50, 50)); rectDict.Add(ItemType.Pistol, new Rectangle(200, 0, 50, 50)); rectDict.Add(ItemType.Shotgun, new Rectangle(250, 0, 50, 50)); rectDict.Add(ItemType.SMG, new Rectangle(300, 0, 50, 50)); rectDict.Add(ItemType.Rifle, new Rectangle(350, 0, 50, 50)); graphicsDevice = gd; lightingEngine = le; }
public virtual void Draw(SpriteBatch sb, LightingEngine lightingEngine) { if (Dead) return; if (drivingVehicle != null) return; // Feet sb.Draw(spriteSheet, Position, Animations["feet"].CellRect, lightingEngine.CurrentSunColor, (Speed.Length()>0f)?Helper.V2ToAngle(Speed)+MathHelper.PiOver2:Rotation, new Vector2(100,100)/2, 1f, SpriteEffects.None, 1); // Hands sb.Draw(spriteSheet, Position, Animations["hands"].CellRect, lightingEngine.CurrentSunColor, Rotation-0.15f, new Vector2(100, 100) / 2, 1f, SpriteEffects.None, 1); // Gun sb.Draw(spriteSheet, Position, Animations["gun"].CellRect, lightingEngine.CurrentSunColor, Rotation - 0.15f, new Vector2(50, 60), 1f, SpriteEffects.None, 1); // Arms sb.Draw(spriteSheet, Position, Animations["arms"].CellRect, lightingEngine.CurrentSunColor, Rotation - 0.15f, new Vector2(100, 100) / 2, 1f, SpriteEffects.None, 1); // Head sb.Draw(spriteSheet, Position, Animations["head"].CellRect, lightingEngine.CurrentSunColor, Rotation - 0.15f, new Vector2(100, 100) / 2, 1f, SpriteEffects.None, 1); }
public override void Draw(SpriteBatch sb, LightingEngine lightingEngine) { sb.Draw(spriteSheet, Position, new Rectangle(0,400,200,300), lightingEngine.CurrentSunColor, Rotation+MathHelper.PiOver2, new Vector2(200,300)/2, 1f, SpriteEffects.None, 1); }
internal void Initialize(GraphicsDevice gd, LightingEngine le) { //HeadTorch = new LightSource(gd, 500, LightAreaQuality.High, Color.White, BeamStencilType.Narrow, SpotStencilType.None); //le.LightSources.Add(HeadTorch); Lights.Add(new LightSource(gd, 500, LightAreaQuality.High, Color.White, BeamStencilType.Narrow, SpotStencilType.None)); //Lights.Add(new LightSource(gd, 500, LightAreaQuality.High, Color.White, BeamStencilType.Narrow, SpotStencilType.None)); le.LightSources.Add(Lights[0]); //le.LightSources.Add(Lights[1]); base.Initialize(); }
private static void CreateCompounds(Map map, TileLayer terrainLayer, TileLayer wallLayer, TileLayer roofLayer, List<Compound> compounds, float[][] noise, float height, float distance, int minsize, LightingEngine lightingEngine, GraphicsDevice gd) { for (int y = 40; y < map.Width - 40; y++) { for (int x = 40; x < map.Height - 40; x++) { if (noise[y][x] > height) { Vector2 thisLoc = new Vector2(x * map.TileWidth, y * map.TileHeight); bool tooClose = false; foreach (Compound c in compounds) if ((c.Position - thisLoc).Length() < distance) tooClose = true; if (!tooClose) { Rectangle bounds = new Rectangle(x, y, 1, 1); bounds.Inflate(minsize, minsize); bounds.Inflate(rand.Next(5) * 2, rand.Next(5) * 2); bool tooBig = true; while (tooBig) { if (GetTileIndex(map, terrainLayer, bounds.Left, bounds.Top) != GRASS || GetTileIndex(map, terrainLayer, bounds.Right, bounds.Top) != GRASS || GetTileIndex(map, terrainLayer, bounds.Left, bounds.Bottom) != GRASS || GetTileIndex(map, terrainLayer, bounds.Right, bounds.Bottom) != GRASS) { tooBig = true; bounds.Inflate(-1, -1); } else tooBig = false; } if (bounds.Width >= minsize && bounds.Height >= minsize) { Compound newCompound = new Compound() { Position = thisLoc }; for (int xx = bounds.Left; xx <= bounds.Right; xx++) { for (int yy = bounds.Top; yy <= bounds.Bottom; yy++) { wallLayer.Tiles[xx, yy] = null; if (xx > bounds.Left + 2 && xx < bounds.Right - 2 && yy > bounds.Top + 2 && yy < bounds.Bottom - 2) terrainLayer.Tiles[xx, yy] = map.Tiles[MUD]; } } Rectangle innerBounds = bounds; innerBounds.Inflate(-3, -3); // Outer walls wallLayer.Tiles[innerBounds.Left, innerBounds.Top] = map.Tiles[WALL_TL]; wallLayer.Tiles[innerBounds.Right, innerBounds.Top] = map.Tiles[WALL_TR]; wallLayer.Tiles[innerBounds.Left, innerBounds.Bottom] = map.Tiles[WALL_BL]; wallLayer.Tiles[innerBounds.Right, innerBounds.Bottom] = map.Tiles[WALL_BR]; for (int xx = innerBounds.Left + 1; xx <= innerBounds.Right - 1; xx++) { wallLayer.Tiles[xx, innerBounds.Top] = map.Tiles[WALL_EDGE_UP]; wallLayer.Tiles[xx, innerBounds.Bottom] = map.Tiles[WALL_EDGE_DOWN]; } for (int yy = innerBounds.Top + 1; yy <= innerBounds.Bottom - 1; yy++) { wallLayer.Tiles[innerBounds.Left, yy] = map.Tiles[WALL_EDGE_LEFT]; wallLayer.Tiles[innerBounds.Right,yy] = map.Tiles[WALL_EDGE_RIGHT]; } newCompound.Bounds = bounds; newCompound.InnerBounds = innerBounds; // Exits bool[] exits = new bool[4] { false, false, false, false }; for(int i=0;i<4;i++) exits[rand.Next(4)] = true; bool carparkPlaced = false; Building carpark = null; if (exits[0]) { int doorx = rand.Next(innerBounds.Width - 7) + 3; for (int xx = innerBounds.Left + doorx; xx < (innerBounds.Left + doorx) + 4; xx++) wallLayer.Tiles[xx, innerBounds.Top] = null; if (!carparkPlaced && rand.Next(2) == 0) { carpark = new Building() { Type = BuildingType.Carpark, Rect = new Rectangle((innerBounds.Left + doorx), innerBounds.Top + 2, 4, 4) }; newCompound.Buildings.Add(carpark); carparkPlaced = true; } } if (exits[1]) { int doorx = rand.Next(innerBounds.Width - 7) + 3; for (int xx = innerBounds.Left + doorx; xx < (innerBounds.Left + doorx) + 4; xx++) wallLayer.Tiles[xx, innerBounds.Bottom] = null; if (!carparkPlaced && rand.Next(2) == 0) { carpark = new Building() { Type = BuildingType.Carpark, Rect = new Rectangle((innerBounds.Left + doorx), innerBounds.Bottom - 6, 4, 4) }; newCompound.Buildings.Add(carpark); carparkPlaced = true; } } if (exits[2]) { int doory = rand.Next(innerBounds.Height - 7) + 3; for (int yy = innerBounds.Top + doory; yy < (innerBounds.Top + doory) + 4; yy++) wallLayer.Tiles[innerBounds.Left,yy] = null; if (!carparkPlaced && rand.Next(2) == 0) { carpark = new Building() { Type = BuildingType.Carpark, Rect = new Rectangle(innerBounds.Left + 2, (innerBounds.Top + doory), 4, 4) }; newCompound.Buildings.Add(carpark); carparkPlaced = true; } } if (exits[3]) { int doory = rand.Next(innerBounds.Height - 7) + 3; for (int yy = innerBounds.Top + doory; yy < (innerBounds.Top + doory) + 4; yy++) wallLayer.Tiles[innerBounds.Right, yy] = null; if (!carparkPlaced && rand.Next(2) == 0) { carpark = new Building() { Type = BuildingType.Carpark, Rect = new Rectangle(innerBounds.Right - 6, (innerBounds.Top + doory), 4, 4) }; newCompound.Buildings.Add(carpark); carparkPlaced = true; } } int lightSpacing = 5; for (int xx = innerBounds.Left + 4; xx <= innerBounds.Right - 4; xx++) { lightSpacing++; if (lightSpacing == 6) { lightSpacing = 0; if (GetTileIndex(map, wallLayer, xx, innerBounds.Top) == WALL_EDGE_UP && GetTileIndex(map, wallLayer, xx - 2, innerBounds.Top) == WALL_EDGE_UP && GetTileIndex(map, wallLayer, xx + 2, innerBounds.Top) == WALL_EDGE_UP) { LightSource ls = new LightSource(gd, 300, LightAreaQuality.Low, Color.White, BeamStencilType.None, SpotStencilType.Half); ls.Rotation = MathHelper.PiOver2; ls.Position = new Vector2((xx * map.TileWidth) + (map.TileWidth / 2), ((innerBounds.Top + 1) * map.TileHeight)); lightingEngine.LightSources.Add(ls); } if (GetTileIndex(map, wallLayer, xx, innerBounds.Bottom) == WALL_EDGE_DOWN && GetTileIndex(map, wallLayer, xx - 2, innerBounds.Bottom) == WALL_EDGE_DOWN && GetTileIndex(map, wallLayer, xx + 2, innerBounds.Bottom) == WALL_EDGE_DOWN) { LightSource ls = new LightSource(gd, 300, LightAreaQuality.Low, Color.White, BeamStencilType.None, SpotStencilType.Half); ls.Rotation = MathHelper.PiOver2 + MathHelper.Pi; ls.Position = new Vector2((xx * map.TileWidth) + (map.TileWidth / 2), ((innerBounds.Bottom) * map.TileHeight)); lightingEngine.LightSources.Add(ls); } } } lightSpacing = 5; for (int yy = innerBounds.Top + 4; yy <= innerBounds.Bottom - 4; yy++) { lightSpacing++; if (lightSpacing == 6) { lightSpacing = 0; if (GetTileIndex(map, wallLayer, innerBounds.Left, yy) == WALL_EDGE_LEFT && GetTileIndex(map, wallLayer, innerBounds.Left, yy - 2) == WALL_EDGE_LEFT && GetTileIndex(map, wallLayer, innerBounds.Left, yy + 2) == WALL_EDGE_LEFT) { LightSource ls = new LightSource(gd, 300, LightAreaQuality.Low, Color.White, BeamStencilType.None, SpotStencilType.Half); //ls.Rotation = MathHelper.PiOver2; ls.Position = new Vector2(((innerBounds.Left+1) * map.TileWidth), (yy * map.TileHeight)+(map.TileHeight/2)); lightingEngine.LightSources.Add(ls); } if (GetTileIndex(map, wallLayer, innerBounds.Right, yy) == WALL_EDGE_RIGHT && GetTileIndex(map, wallLayer, innerBounds.Right, yy - 2) == WALL_EDGE_RIGHT && GetTileIndex(map, wallLayer, innerBounds.Right, yy + 2) == WALL_EDGE_RIGHT) { LightSource ls = new LightSource(gd, 300, LightAreaQuality.Low, Color.White, BeamStencilType.None, SpotStencilType.Half); ls.Rotation = MathHelper.Pi; ls.Position = new Vector2(((innerBounds.Right) * map.TileWidth), (yy * map.TileHeight) + (map.TileHeight / 2)); lightingEngine.LightSources.Add(ls); } } } //if (carpark!=null) // for (int xx = carpark.Rect.Left; xx < carpark.Rect.Right; xx++) // for (int yy = carpark.Rect.Top; yy < carpark.Rect.Bottom; yy++) // terrainLayer.Tiles[xx, yy] = map.Tiles[CARPARK]; MakeBuildings(map, wallLayer, terrainLayer, roofLayer, newCompound); compounds.Add(newCompound); } } } } } }
public static void GenerateTerrain(Map map, LightingEngine lightingEngine, GraphicsDevice gd) { Generating = true; PercentComplete = 0; Thread.Sleep(1000); bool compoundsOK = false; map.Jetties.Clear(); List<Compound> compounds = new List<Compound>(); TileLayer terrainLayer = map.GetLayer("Terrain") as TileLayer; TileLayer wallLayer = map.GetLayer("Wall") as TileLayer; TileLayer waterLayer = map.GetLayer("Water") as TileLayer; TileLayer roofLayer = map.GetLayer("Roof") as TileLayer; float[][] noise = null; while (!compoundsOK) { compounds.Clear(); for (int i = lightingEngine.LightSources.Count - 1; i >= 0; i--) if (lightingEngine.LightSources[i].SpotStencil != null) lightingEngine.LightSources.RemoveAt(i); for (int y = 0; y < map.Width; y++) { for (int x = 0; x < map.Height; x++) { terrainLayer.Tiles[x, y] = null; wallLayer.Tiles[x, y] = null; } } PercentComplete = 5; // Inital terrain noise = PerlinNoise.GeneratePerlinNoise(map.Width, map.Height, 8); for (int y = 0; y < map.Width; y++) { for (int x = 0; x < map.Height; x++) if (noise[y][x] < 0.5f) { terrainLayer.Tiles[x, y] = map.Tiles[WATER]; waterLayer.Tiles[x, y] = map.Tiles[WATER]; } else if (noise[y][x] < 0.6f) { terrainLayer.Tiles[x, y] = map.Tiles[SAND]; waterLayer.Tiles[x, y] = null; } else { terrainLayer.Tiles[x, y] = map.Tiles[GRASS]; waterLayer.Tiles[x, y] = null; } } PercentComplete = 10; // Trees float[][] treeNoise = PerlinNoise.GeneratePerlinNoise(map.Width, map.Height, 4); for (int y = 0; y < map.Width; y++) { for (int x = 0; x < map.Height; x++) { if (noise[y][x] > 0.62f) if (treeNoise[y][x] > 0.5f) wallLayer.Tiles[x, y] = map.Tiles[TREE]; } } PercentComplete = 20; // Compounds CreateCompounds(map, terrainLayer, wallLayer, roofLayer, compounds, noise, 0.65f, 20000f, 20, lightingEngine, gd); CreateCompounds(map, terrainLayer, wallLayer, roofLayer, compounds, noise, 0.75f, 12000f, 30, lightingEngine, gd); // Test to see if compounds are okay int numOKComps = 0; foreach (Compound c in compounds) { if (c.Buildings.Count(b => b.Type != BuildingType.Carpark && b.Type != BuildingType.Helipad) > 0) numOKComps++; } if (numOKComps > 5) compoundsOK = true; } PercentComplete = 35; // Remove stray tiles for (int y = 0; y < map.Width; y++) { for (int x = 0; x < map.Height; x++) { if (GetTileIndex(map, terrainLayer, x, y) == SAND) if (CountSurroundingTiles(map, terrainLayer, x, y, WATER) >= 5) { terrainLayer.Tiles[x, y] = map.Tiles[WATER]; waterLayer.Tiles[x, y] = map.Tiles[WATER]; } //if (GetTileIndex(map, terrainLayer, (map.Width-1) - x, (map.Height-1) - y) == SAND) // if (CountSurroundingTiles(map, terrainLayer, (map.Width - 1) - x, (map.Height - 1) - y, WATER) >= 5) terrainLayer.Tiles[(map.Width - 1) - x, (map.Height - 1) - y] = map.Tiles[WATER]; if (GetTileIndex(map, terrainLayer, x, y) == GRASS) if (CountSurroundingTiles(map, terrainLayer, x, y, SAND) >= 5) terrainLayer.Tiles[x, y] = map.Tiles[SAND]; //if (GetTileIndex(map, terrainLayer, (map.Width - 1) - x, (map.Height - 1) - y) == GRASS) // if (CountSurroundingTiles(map, terrainLayer, (map.Width - 1) - x, (map.Height - 1) - y, SAND) >= 5) terrainLayer.Tiles[(map.Width - 1) - x, (map.Height - 1) - y] = map.Tiles[SAND]; } } PercentComplete = 45; // Jetties! for (int y = 40; y < map.Width - 40; y+=2) { for (int x = 40; x < map.Height - 40; x+=2) { if (GetTileIndex(map, terrainLayer, x, y) == SAND) { switch (Helper.Random.Next(4)) { case 0: if (GetTileIndex(map, terrainLayer, x, y - 10) == WATER && GetTileIndex(map, terrainLayer, x, y - 4) == WATER && GetTileIndex(map, terrainLayer, x, y - 2) == SAND) if (TryMakeJetty(map, terrainLayer, waterLayer, new Point(x, y), new Point(0, -1))) continue; break; case 1: if (GetTileIndex(map, terrainLayer, x, y + 10) == WATER && GetTileIndex(map, terrainLayer, x, y + 4) == WATER && GetTileIndex(map, terrainLayer, x, y + 2) == SAND) if (TryMakeJetty(map, terrainLayer, waterLayer, new Point(x, y), new Point(0, 1))) continue; break; case 2: if (GetTileIndex(map, terrainLayer, x - 10, y) == WATER && GetTileIndex(map, terrainLayer, x - 4, y) == WATER && GetTileIndex(map, terrainLayer, x - 2, y) == SAND) if (TryMakeJetty(map, terrainLayer, waterLayer, new Point(x, y), new Point(-1, 0))) continue; break; case 3: if (GetTileIndex(map, terrainLayer, x + 10, y) == WATER && GetTileIndex(map, terrainLayer, x + 4, y) == WATER && GetTileIndex(map, terrainLayer, x + 2, y) == SAND) if (TryMakeJetty(map, terrainLayer, waterLayer, new Point(x, y), new Point(1, 0))) continue; break; } } } } PercentComplete = 55; // Detail tiling! for (int y = 0; y < map.Width; y++) { for (int x = 0; x < map.Height; x++) { // Sand/Water if (GetTileIndex(map, terrainLayer, x, y) == SAND) { // Edges if (GetTileIndex(map, terrainLayer, x - 1, y) == WATER) if (GetTileIndex(map, terrainLayer, x, y - 1) != WATER) if (GetTileIndex(map, terrainLayer, x, y + 1) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_EDGE_LEFT]; if (GetTileIndex(map, terrainLayer, x + 1, y) == WATER) if (GetTileIndex(map, terrainLayer, x, y - 1) != WATER) if (GetTileIndex(map, terrainLayer, x, y + 1) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_EDGE_RIGHT]; if (GetTileIndex(map, terrainLayer, x, y + 1) == WATER) if (GetTileIndex(map, terrainLayer, x - 1, y) != WATER) if (GetTileIndex(map, terrainLayer, x + 1, y) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_EDGE_DOWN]; if (GetTileIndex(map, terrainLayer, x, y - 1) == WATER) if (GetTileIndex(map, terrainLayer, x - 1, y) != WATER) if (GetTileIndex(map, terrainLayer, x + 1, y) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_EDGE_UP]; // Corners - water inside if (GetTileIndex(map, terrainLayer, x - 1, y - 1) == WATER) if (GetTileIndex(map, terrainLayer, x, y - 1) != WATER) if (GetTileIndex(map, terrainLayer, x - 1, y) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_INSIDE_BR]; if (GetTileIndex(map, terrainLayer, x - 1, y + 1) == WATER) if (GetTileIndex(map, terrainLayer, x, y + 1) != WATER) if (GetTileIndex(map, terrainLayer, x - 1, y) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_INSIDE_TR]; if (GetTileIndex(map, terrainLayer, x + 1, y - 1) == WATER) if (GetTileIndex(map, terrainLayer, x, y - 1) != WATER) if (GetTileIndex(map, terrainLayer, x + 1, y) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_INSIDE_BL]; if (GetTileIndex(map, terrainLayer, x + 1, y + 1) == WATER) if (GetTileIndex(map, terrainLayer, x, y + 1) != WATER) if (GetTileIndex(map, terrainLayer, x + 1, y) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_INSIDE_TL]; // Corners - water outside if (GetTileIndex(map, terrainLayer, x - 1, y - 1) == WATER) if (GetTileIndex(map, terrainLayer, x, y - 1) == WATER) if (GetTileIndex(map, terrainLayer, x - 1, y) == WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_OUTSIDE_TL]; if (GetTileIndex(map, terrainLayer, x - 1, y + 1) == WATER) if (GetTileIndex(map, terrainLayer, x, y + 1) == WATER) if (GetTileIndex(map, terrainLayer, x - 1, y) == WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_OUTSIDE_BL]; if (GetTileIndex(map, terrainLayer, x + 1, y - 1) == WATER) if (GetTileIndex(map, terrainLayer, x, y - 1) == WATER) if (GetTileIndex(map, terrainLayer, x + 1, y) == WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_OUTSIDE_TR]; if (GetTileIndex(map, terrainLayer, x + 1, y + 1) == WATER) if (GetTileIndex(map, terrainLayer, x, y + 1) == WATER) if (GetTileIndex(map, terrainLayer, x + 1, y) == WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_OUTSIDE_BR]; } // Grass/Sand if (GetTileIndex(map, terrainLayer, x, y) == GRASS || GetTileIndex(map, terrainLayer, x, y) == GRASS_ALT1 || GetTileIndex(map, terrainLayer, x, y) == GRASS_ALT2) { // Edges if (GetTileIndex(map, terrainLayer, x - 1, y) == SAND) if (GetTileIndex(map, terrainLayer, x, y - 1) != SAND) if (GetTileIndex(map, terrainLayer, x, y + 1) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_EDGE_LEFT]; if (GetTileIndex(map, terrainLayer, x + 1, y) == SAND) if (GetTileIndex(map, terrainLayer, x, y - 1) != SAND) if (GetTileIndex(map, terrainLayer, x, y + 1) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_EDGE_RIGHT]; if (GetTileIndex(map, terrainLayer, x, y + 1) == SAND) if (GetTileIndex(map, terrainLayer, x - 1, y) != SAND) if (GetTileIndex(map, terrainLayer, x + 1, y) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_EDGE_DOWN]; if (GetTileIndex(map, terrainLayer, x, y - 1) == SAND) if (GetTileIndex(map, terrainLayer, x - 1, y) != SAND) if (GetTileIndex(map, terrainLayer, x + 1, y) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_EDGE_UP]; // Corners - water inside if (GetTileIndex(map, terrainLayer, x - 1, y - 1) == SAND) if (GetTileIndex(map, terrainLayer, x, y - 1) != SAND) if (GetTileIndex(map, terrainLayer, x - 1, y) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_INSIDE_BR]; if (GetTileIndex(map, terrainLayer, x - 1, y + 1) == SAND) if (GetTileIndex(map, terrainLayer, x, y + 1) != SAND) if (GetTileIndex(map, terrainLayer, x - 1, y) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_INSIDE_TR]; if (GetTileIndex(map, terrainLayer, x + 1, y - 1) == SAND) if (GetTileIndex(map, terrainLayer, x, y - 1) != SAND) if (GetTileIndex(map, terrainLayer, x + 1, y) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_INSIDE_BL]; if (GetTileIndex(map, terrainLayer, x + 1, y + 1) == SAND) if (GetTileIndex(map, terrainLayer, x, y + 1) != SAND) if (GetTileIndex(map, terrainLayer, x + 1, y) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_INSIDE_TL]; // Corners - water outside if (GetTileIndex(map, terrainLayer, x - 1, y - 1) == SAND) if (GetTileIndex(map, terrainLayer, x, y - 1) == SAND) if (GetTileIndex(map, terrainLayer, x - 1, y) == SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_OUTSIDE_TL]; if (GetTileIndex(map, terrainLayer, x - 1, y + 1) == SAND) if (GetTileIndex(map, terrainLayer, x, y + 1) == SAND) if (GetTileIndex(map, terrainLayer, x - 1, y) == SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_OUTSIDE_BL]; if (GetTileIndex(map, terrainLayer, x + 1, y - 1) == SAND) if (GetTileIndex(map, terrainLayer, x, y - 1) == SAND) if (GetTileIndex(map, terrainLayer, x + 1, y) == SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_OUTSIDE_TR]; if (GetTileIndex(map, terrainLayer, x + 1, y + 1) == SAND) if (GetTileIndex(map, terrainLayer, x, y + 1) == SAND) if (GetTileIndex(map, terrainLayer, x + 1, y) == SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_OUTSIDE_BR]; } } } PercentComplete = 75; // Alt tiles for (int y = 0; y < map.Width; y++) { for (int x = 0; x < map.Height; x++) { if (GetTileIndex(map, terrainLayer, x, y) == GRASS) { int r = rand.Next(50); if (r == 9) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_ALT1]; else if (r == 8) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_ALT2]; } if (GetTileIndex(map, terrainLayer, x, y) == SAND) { int r = rand.Next(50); if (r == 9) terrainLayer.Tiles[x, y] = map.Tiles[SAND_ALT]; } // Tree alts if (GetTileIndex(map, wallLayer, x, y) == TREE) { //if (rand.Next(10) == 0) //{ // Big tree if(!TryDrawBigTree(map, wallLayer, x, y)) wallLayer.Tiles[x, y] = map.Tiles[TREES[rand.Next(TREES.Length)]]; } } } PercentComplete = 90; Rectangle spawnRect = new Rectangle((map.Width / 2) - 5, (map.Height / 2) - 5, 10, 10); bool foundspawn = false; while (!foundspawn) { map.HeroSpawn = TryFindSpawn(spawnRect.Left, spawnRect.Top, map, terrainLayer, out foundspawn); if (!foundspawn) map.HeroSpawn = TryFindSpawn(spawnRect.Right, spawnRect.Top, map, terrainLayer, out foundspawn); if (!foundspawn) map.HeroSpawn = TryFindSpawn(spawnRect.Left, spawnRect.Bottom, map, terrainLayer, out foundspawn); if (!foundspawn) map.HeroSpawn = TryFindSpawn(spawnRect.Right, spawnRect.Bottom, map, terrainLayer, out foundspawn); spawnRect.Inflate(5, 5); } map.GetAStarData(); map.Compounds = compounds; PercentComplete = 100; //Generating = false; }
public virtual void DrawShadows(SpriteBatch sb, LightingEngine lightingEngine) { if (Dead) return; if (drivingVehicle != null) return; for (int i = 1; i < 20; i += 2) { Vector2 pos = Position + new Vector2(lightingEngine.CurrentShadowVect.X * i, lightingEngine.CurrentShadowVect.Y * i); sb.Draw(spriteSheet, pos, Animations["hands"].CellRect, Color.Black * 0.03f, Rotation - 0.15f, new Vector2(100, 100) / 2, 1f, SpriteEffects.None, 1); sb.Draw(spriteSheet, pos, Animations["gun"].CellRect, Color.Black * 0.03f, Rotation - 0.15f, new Vector2(100, 100) / 2, 1f, SpriteEffects.None, 1); sb.Draw(spriteSheet, pos, Animations["arms"].CellRect, Color.Black * 0.03f, Rotation - 0.15f, new Vector2(100, 100) / 2, 1f, SpriteEffects.None, 1); } }
internal void Initialize(GraphicsDevice gd, LightingEngine le) { //HeadTorch = new LightSource(gd, 500, LightAreaQuality.High, Color.White, BeamStencilType.Narrow, SpotStencilType.None); //le.LightSources.Add(HeadTorch); Lights.Add(new LightSource(gd, 500, LightAreaQuality.High, Color.White, BeamStencilType.Narrow, SpotStencilType.None)); Lights.Add(new LightSource(gd, 500, LightAreaQuality.High, Color.White, BeamStencilType.Narrow, SpotStencilType.None)); le.LightSources.Add(Lights[0]); le.LightSources.Add(Lights[1]); 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.Initialize(); }
internal void DrawInAir(SpriteBatch sb, LightingEngine lightingEngine) { sb.Draw(spriteSheet, Position, new Rectangle(200, 0, 300, 400), lightingEngine.CurrentSunColor, Rotation + MathHelper.PiOver2, new Vector2(150, 135), 1f + (maxCameraScale * Height), SpriteEffects.None, 1); sb.Draw(spriteSheet, Position, new Rectangle(500, 0, 400, 400), lightingEngine.CurrentSunColor, bladesRot, new Vector2(400, 400) / 2, 1f + (maxCameraScale * Height), SpriteEffects.None, 1); }
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); // } // } //} //} } } } }
internal void DrawShadowsInAir(SpriteBatch sb, LightingEngine lightingEngine) { for (int i = 1; i < 40; i += 2) { Vector2 pos = Position + ((lightingEngine.CurrentShadowVect * 750f) * Height) + new Vector2(lightingEngine.CurrentShadowVect.X * i, lightingEngine.CurrentShadowVect.Y * i); sb.Draw(spriteSheet, pos, new Rectangle(200, 0, 300, 400), Color.Black * 0.03f, Rotation + MathHelper.PiOver2, new Vector2(150, 125), 1f, SpriteEffects.None, 1); sb.Draw(spriteSheet, pos, new Rectangle(500, 0, 400, 400), Color.Black * 0.01f, bladesRot, new Vector2(400, 400) / 2, 1f, SpriteEffects.None, 1); } }
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 LoadContent(Texture2D sheet, GraphicsDevice gd, LightingEngine le, HeroDude gameHero) { spriteSheet = sheet; Initialize(gd, le); Weapons.Add(new Knife(this)); if (Helper.Random.Next(gameHero.Weapons.Count>1?2:10) == 1) { Weapons.Add(new Pistol(this)); } if (IsGeneral) { Weapons.Add(new Rifle(this)); } else { if (BelongsToCompound) { switch (Helper.Random.Next(20)) { case 1: Weapons.Add(new Shotgun(this)); break; case 2: Weapons.Add(new SMG(this)); break; case 3: Weapons.Add(new Rifle(this)); break; } } else { switch (Helper.Random.Next(gameHero.Weapons.Count > 1 ? (gameHero.Weapons.Count > 2 ? 30 : 50) : 100)) { case 1: Weapons.Add(new Shotgun(this)); break; case 2: Weapons.Add(new SMG(this)); break; case 3: Weapons.Add(new Rifle(this)); break; } } } SelectedWeapon = Weapons.Count - 1; }
public override void Draw(SpriteBatch sb, LightingEngine lightingEngine) { if (Dead) return; //DrawChasePath(sb, chasePath); base.Draw(sb, lightingEngine); // Head //if(IsGeneral) // sb.Draw(spriteSheet, Position, Animations["head"].CellRect, Color.Red, Rotation, new Vector2(100, 100) / 2, 1f, SpriteEffects.None, 1); //else // sb.Draw(spriteSheet, Position, Animations["head"].CellRect, Color.LightBlue, Rotation, new Vector2(100, 100) / 2, 1f, SpriteEffects.None, 1); }
public override void Draw(SpriteBatch sb, LightingEngine lightingEngine) { base.Draw(sb, lightingEngine); }
public void Draw(SpriteBatch sb, ParticleBlendMode blend, LightingEngine le, bool onTop) { foreach (Particle p in Particles.Where(part => part.Active && part.BlendMode==blend && part.OnTop==onTop)) { sb.Draw(_texParticles, p.Position, p.SourceRect, le.CurrentSunColor * p.Alpha, p.Rotation, new Vector2(p.SourceRect.Width / 2, p.SourceRect.Height / 2), p.Scale, SpriteEffects.None, 1); } }
/// <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); } }
public virtual void Draw(SpriteBatch sb, LightingEngine lightingEngine) { //sb.Draw(spriteSheet, Position, , lightingEngine.CurrentSunColor, Rotation, new Vector2(100,100)/2, 1f, SpriteEffects.None, 1); }