public CharSprites(Gender gender, ContentManager content) { #if DEBUG PRPGame.npcSprited++; #endif if (gender == Gender.Male) { baseSheet = RandUtil.Index(maleBodySheets); hairSheet = RandUtil.Index(maleHairSheets); eyeSheet = RandUtil.Index(maleEyeSheets); } else { baseSheet = RandUtil.Index(femaleBodySheets); hairSheet = RandUtil.Index(femaleHairSheets); eyeSheet = RandUtil.Index(femaleHairSheets); } // Compose a bunch of sprite sheets to make a uniqe npc as they // come on screen. The sheets contain all the animation frames. shirtSheet = RandUtil.Index(shirtSheets); pantSheet = RandUtil.Index(pantsSheets); shoeSheet = RandUtil.Index(shoeSheets); hairColor = new Color(new Vector3(RandUtil.Float(1.0f), RandUtil.Float(1.0f), RandUtil.Float(1.0f))); walkingAnimation = new Rectangle[4, WALKING_WIDTH]; for (int y = 0; y < 4; y++) { for (int x = 0; x < WALKING_WIDTH; x++) { int walkIndex = y + WALKING_INDEX; walkingAnimation[y, x] = new Rectangle(x * CHAR_SIZE, walkIndex * CHAR_SIZE, CHAR_SIZE, CHAR_SIZE); } } swingAnimation = new Rectangle[4, SWING_WIDTH]; for (int y = 0; y < 4; y++) { for (int x = 0; x < SWING_WIDTH; x++) { int swingIndex = y + SWING_INDEX; swingAnimation[y, x] = new Rectangle(x * CHAR_SIZE, swingIndex * CHAR_SIZE, CHAR_SIZE, CHAR_SIZE); } } oversizeWeaponAnimation = new Rectangle[4, SWING_WIDTH]; for (int y = 0; y < 4; y++) { for (int x = 0; x < SWING_WIDTH; x++) { int swingIndex = y; oversizeWeaponAnimation[y, x] = new Rectangle(x * OVERSIZE_WEAPON_SIZE, swingIndex * OVERSIZE_WEAPON_SIZE, OVERSIZE_WEAPON_SIZE, OVERSIZE_WEAPON_SIZE); } } }
public World(int w, int h, ContentManager content) { Noise.InitNoise(tileSize, 5, 2.0f, 0.6f, 0.6f); texColor = new Color[(tileSize) * (tileSize)]; texCache = new LRACache <int, Texture2D>(10000); simpleTex = new Dictionary <TerrainTile, Texture2D>(); simpleTex.Add(TerrainTile.WATER, GetSolidTex(tileSize, tileSize, Color.Blue)); simpleTex.Add(TerrainTile.GRASS, GetSolidTex(tileSize, tileSize, Color.ForestGreen)); simpleTex.Add(TerrainTile.DIRT, GetSolidTex(tileSize, tileSize, Color.SaddleBrown)); simpleTex.Add(TerrainTile.ROCK, GetSolidTex(tileSize, tileSize, Color.Gray)); simpleTex.Add(TerrainTile.SNOW, GetSolidTex(tileSize, tileSize, Color.White)); width = w; height = h; var pal = new List <Color>(2560); var tilePal = new List <TerrainTile>(2560); int waterRange = 800; for (int i = 0; i < waterRange; i++) { pal.Add(Color.Lerp(Color.DarkBlue, Color.DeepSkyBlue, (float)i / (float)waterRange)); tilePal.Add(TerrainTile.WATER); } tilePal.Add(TerrainTile.GRASS); pal.Add(Color.LightGoldenrodYellow); tilePal.Add(TerrainTile.GRASS); pal.Add(Color.LightGoldenrodYellow); tilePal.Add(TerrainTile.GRASS); pal.Add(Color.LightGoldenrodYellow); tilePal.Add(TerrainTile.GRASS); pal.Add(Color.LightGoldenrodYellow); int grassRange = 1100; for (int i = 0; i < grassRange; i++) { pal.Add(Color.Lerp(Color.ForestGreen, Color.DarkGreen, (float)i / (float)grassRange)); tilePal.Add(TerrainTile.GRASS); } int dirtRange = 100; for (int i = 0; i < dirtRange; i++) { pal.Add(Color.Lerp(Color.DarkGreen, Color.SaddleBrown, (float)i / (float)dirtRange)); tilePal.Add(TerrainTile.DIRT); } float rockRange = 550; for (int i = 0; i < rockRange; i++) { pal.Add(Color.Lerp(Color.Gray, Color.White, (float)i / (float)rockRange)); if (i < rockRange / 2) { tilePal.Add(TerrainTile.ROCK); } else { tilePal.Add(TerrainTile.SNOW); } } tilePallette = tilePal.ToArray(); pallette = pal.ToArray(); resources = new List <Resource>(TREE_COUNT + COAL_COUNT + IRON_COUNT); deadResources = new List <Resource>(32); for (int i = 0; i < IRON_COUNT; i++) { var pos = RandUtil.Vector2(width, height); while (GetTile(pos) != TerrainTile.ROCK) { pos = RandUtil.Vector2(width, height); } resources.Add(new IronMine(pos, RandUtil.Int(10, 1000), content)); } for (int i = 0; i < COAL_COUNT; i++) { var pos = RandUtil.Vector2(width, height); while (GetTile(pos) != TerrainTile.GRASS) { pos = RandUtil.Vector2(width, height); } resources.Add(new CoalMine(pos, RandUtil.Int(10, 1000), content)); } for (int i = 0; i < TREE_COUNT; i++) { var pos = RandUtil.Vector2(width, height); while (GetTile(pos) != TerrainTile.GRASS) { pos = RandUtil.Vector2(width, height); } resources.Add(new Tree(pos, RandUtil.Int(1, 3), content)); } npcs = new List <NPC>(NPC_COUNT); var worldArea = w * h; var numCities = (int)(worldArea * cityDensity); int npcIndex = 0; int npcsPerCity = 5; for (int i = 0; i < numCities; i++) { var cityPos = new Vector2(RandUtil.IntEx(4, w - 4), RandUtil.IntEx(4, h - 4)); var tile = GetTile(cityPos); if (tile != TerrainTile.WATER) { for (int j = 0; j < npcsPerCity; j++) { var npcVector = new Vector2(RandUtil.Float(-2.0f, 2.0f), RandUtil.Float(-2.0f, 2.0f)); var npcPos = cityPos + npcVector; tile = GetTile(npcPos); if (tile != TerrainTile.WATER) { npcs.Add(new NPC(npcPos, content)); npcIndex++; } } } } while (npcIndex < NPC_COUNT) { var npcPos = new Vector2(RandUtil.Float(w - 1), RandUtil.Float(h - 1)); var tile = GetTile(npcPos); if (tile != TerrainTile.WATER) { npcs.Add(new NPC(npcPos, content)); npcIndex++; } } }