Load all textures & fonts in one place.
GitOrigin-RevId: 076c86b24f4e4e314a52457a01d5c77e197a2fa2
This commit is contained in:
parent
8f5514b776
commit
57d15cbbd9
@ -96,13 +96,13 @@ namespace SemiColinGames {
|
||||
AddLine(start.ToPoint(), end.ToPoint(), color);
|
||||
}
|
||||
|
||||
public static void DrawToasts(SpriteBatch spriteBatch, SpriteFont font) {
|
||||
public static void DrawToasts(SpriteBatch spriteBatch) {
|
||||
if (!Enabled) {
|
||||
return;
|
||||
}
|
||||
int y = 10;
|
||||
foreach (var toast in toasts) {
|
||||
spriteBatch.DrawString(font, toast, new Vector2(10, y), Color.Teal);
|
||||
spriteBatch.DrawString(Textures.DebugFont, toast, new Vector2(10, y), Color.Teal);
|
||||
y += 30;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ namespace SemiColinGames {
|
||||
private const int spriteWidth = 96;
|
||||
private const int spriteHeight = 64;
|
||||
private const int spriteCenterYOffset = 1;
|
||||
private readonly Texture2D texture;
|
||||
|
||||
// Details of the actual Player model.
|
||||
|
||||
@ -36,8 +35,7 @@ namespace SemiColinGames {
|
||||
private const int swordSwingMax = 6;
|
||||
private float ySpeed = 0;
|
||||
|
||||
public Player(ContentManager content) {
|
||||
this.texture = content.Load<Texture2D>("sprites/ccg/ninja_female");
|
||||
public Player() {
|
||||
}
|
||||
|
||||
public int Facing { get; private set; } = 1;
|
||||
@ -234,8 +232,8 @@ namespace SemiColinGames {
|
||||
Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset);
|
||||
SpriteEffects effect = Facing == 1 ?
|
||||
SpriteEffects.FlipHorizontally : SpriteEffects.None;
|
||||
spriteBatch.Draw(texture, position.ToVector2(), textureSource, Color.White, 0f, spriteCenter,
|
||||
Vector2.One, effect, 0f);
|
||||
spriteBatch.Draw(Textures.Player, position.ToVector2(), textureSource, Color.White, 0f,
|
||||
spriteCenter, Vector2.One, effect, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace SemiColinGames {
|
||||
class Scene {
|
||||
public bool Enabled = false;
|
||||
|
||||
Color backgroundColor = Color.CornflowerBlue;
|
||||
|
||||
readonly GraphicsDevice graphics;
|
||||
@ -14,12 +16,8 @@ namespace SemiColinGames {
|
||||
readonly BasicEffect lightingEffect;
|
||||
|
||||
readonly SpriteBatch spriteBatch;
|
||||
readonly SpriteFont font;
|
||||
readonly Texture2D grasslandBg1;
|
||||
readonly Texture2D grasslandBg2;
|
||||
|
||||
public Scene(ContentManager content, GraphicsDevice graphics, Camera camera) {
|
||||
Enabled = false;
|
||||
public Scene(GraphicsDevice graphics, Camera camera) {
|
||||
this.graphics = graphics;
|
||||
this.camera = camera;
|
||||
|
||||
@ -35,15 +33,9 @@ namespace SemiColinGames {
|
||||
lightingEffect.View = Matrix.CreateLookAt(Vector3.Backward, Vector3.Zero, Vector3.Up);
|
||||
lightingEffect.VertexColorEnabled = true;
|
||||
|
||||
// TODO: handle unloading of resources when the level is done.
|
||||
spriteBatch = new SpriteBatch(graphics);
|
||||
font = content.Load<SpriteFont>("font");
|
||||
grasslandBg1 = content.Load<Texture2D>("backgrounds/anokolisa/grassland_bg1");
|
||||
grasslandBg2 = content.Load<Texture2D>("backgrounds/anokolisa/grassland_bg2");
|
||||
}
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public void Draw(World world, Player player, LinesOfSight linesOfSight) {
|
||||
graphics.SetRenderTarget(null);
|
||||
graphics.Clear(backgroundColor);
|
||||
@ -62,10 +54,10 @@ namespace SemiColinGames {
|
||||
Rectangle bgSource = new Rectangle(
|
||||
(int) (camera.Left * 0.25), 0, camera.Width, camera.Height);
|
||||
Rectangle bgTarget = new Rectangle(0, 0, camera.Width, camera.Height);
|
||||
spriteBatch.Draw(grasslandBg2, bgTarget, bgSource, bgBlend);
|
||||
spriteBatch.Draw(Textures.Background2, bgTarget, bgSource, bgBlend);
|
||||
bgSource = new Rectangle(
|
||||
(int) (camera.Left * 0.5), 0, camera.Width, camera.Height);
|
||||
spriteBatch.Draw(grasslandBg1, bgTarget, bgSource, bgBlend);
|
||||
spriteBatch.Draw(Textures.Background1, bgTarget, bgSource, bgBlend);
|
||||
spriteBatch.End();
|
||||
|
||||
// Set up transformation matrix for drawing world objects.
|
||||
@ -102,7 +94,7 @@ namespace SemiColinGames {
|
||||
spriteBatch.Draw(lightingTarget, drawRect, Color.White);
|
||||
|
||||
// Draw debug toasts.
|
||||
Debug.DrawToasts(spriteBatch, font);
|
||||
Debug.DrawToasts(spriteBatch);
|
||||
|
||||
spriteBatch.End();
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Camera.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Textures.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Clock.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Geometry.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Input.cs" />
|
||||
|
@ -63,6 +63,7 @@ namespace SemiColinGames {
|
||||
// Called once per game. Loads all game content.
|
||||
protected override void LoadContent() {
|
||||
base.LoadContent();
|
||||
Textures.Load(Content);
|
||||
linesOfSight = new LinesOfSight(GraphicsDevice);
|
||||
LoadLevel();
|
||||
}
|
||||
@ -70,9 +71,9 @@ namespace SemiColinGames {
|
||||
private void LoadLevel() {
|
||||
framesToSuppress = 2;
|
||||
camera = new Camera();
|
||||
player = new Player(Content);
|
||||
world = new World(Content, Levels.ONE_ONE);
|
||||
scene = new Scene(Content, GraphicsDevice, camera);
|
||||
player = new Player();
|
||||
world = new World(Levels.ONE_ONE);
|
||||
scene = new Scene(GraphicsDevice, camera);
|
||||
}
|
||||
|
||||
// Called once per game. Unloads all game content.
|
||||
|
45
Shared/Textures.cs
Normal file
45
Shared/Textures.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace SemiColinGames {
|
||||
class Textures {
|
||||
|
||||
public static Texture2D Player;
|
||||
|
||||
public static Texture2D Background1;
|
||||
public static Texture2D Background2;
|
||||
|
||||
public static Texture2D Cemetery;
|
||||
public static Texture2D Crypt;
|
||||
public static Texture2D Dungeon;
|
||||
public static Texture2D Forest;
|
||||
public static Texture2D Garden;
|
||||
public static Texture2D Grassland;
|
||||
public static Texture2D Ruins;
|
||||
public static Texture2D Sewer;
|
||||
public static Texture2D Temple;
|
||||
public static Texture2D Village;
|
||||
|
||||
public static SpriteFont DebugFont;
|
||||
|
||||
public static void Load(ContentManager content) {
|
||||
Player = content.Load<Texture2D>("sprites/ccg/ninja_female");
|
||||
|
||||
Background1 = content.Load<Texture2D>("backgrounds/anokolisa/grassland_bg1");
|
||||
Background2 = content.Load<Texture2D>("backgrounds/anokolisa/grassland_bg2");
|
||||
|
||||
Cemetery = content.Load<Texture2D>("tiles/anokolisa/cemetery");
|
||||
Crypt = content.Load<Texture2D>("tiles/anokolisa/crypt");
|
||||
Dungeon = content.Load<Texture2D>("tiles/anokolisa/dungeon");
|
||||
Forest = content.Load<Texture2D>("tiles/anokolisa/forest");
|
||||
Garden = content.Load<Texture2D>("tiles/anokolisa/garden");
|
||||
Grassland = content.Load<Texture2D>("tiles/anokolisa/grassland");
|
||||
Ruins = content.Load<Texture2D>("tiles/anokolisa/ruins");
|
||||
Sewer = content.Load<Texture2D>("tiles/anokolisa/sewer");
|
||||
Temple = content.Load<Texture2D>("tiles/anokolisa/temple");
|
||||
Village = content.Load<Texture2D>("tiles/anokolisa/village");
|
||||
|
||||
DebugFont = content.Load<SpriteFont>("font");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -17,19 +16,6 @@ namespace SemiColinGames {
|
||||
Block
|
||||
}
|
||||
|
||||
enum TileSet {
|
||||
Cemetery,
|
||||
Crypt,
|
||||
Dungeon,
|
||||
Forest,
|
||||
Garden,
|
||||
Grassland,
|
||||
Ruins,
|
||||
Sewer,
|
||||
Temple,
|
||||
Village,
|
||||
}
|
||||
|
||||
class TileFactory {
|
||||
|
||||
struct TextureSource {
|
||||
@ -42,40 +28,19 @@ namespace SemiColinGames {
|
||||
}
|
||||
}
|
||||
|
||||
static readonly Dictionary<TileSet, string> tileSetToContentPath =
|
||||
new Dictionary<TileSet, string>() {
|
||||
{ TileSet.Cemetery, "tiles/anokolisa/cemetery" },
|
||||
{ TileSet.Crypt, "tiles/anokolisa/crypt" },
|
||||
{ TileSet.Dungeon, "tiles/anokolisa/dungeon" },
|
||||
{ TileSet.Forest, "tiles/anokolisa/forest" },
|
||||
{ TileSet.Garden, "tiles/anokolisa/garden" },
|
||||
{ TileSet.Grassland, "tiles/anokolisa/grassland" },
|
||||
{ TileSet.Ruins, "tiles/anokolisa/ruins" },
|
||||
{ TileSet.Sewer, "tiles/anokolisa/sewer" },
|
||||
{ TileSet.Temple, "tiles/anokolisa/temple" },
|
||||
{ TileSet.Village, "tiles/anokolisa/village" },
|
||||
readonly Dictionary<Terrain, TextureSource> terrainToTexture;
|
||||
|
||||
public TileFactory() {
|
||||
terrainToTexture = new Dictionary<Terrain, TextureSource>() {
|
||||
{ Terrain.GrassL, GetTextureSource(Textures.Grassland, 2, 0) },
|
||||
{ Terrain.Grass, GetTextureSource(Textures.Grassland, 3, 0) },
|
||||
{ Terrain.GrassR, GetTextureSource(Textures.Grassland, 4, 0) },
|
||||
{ Terrain.Rock, GetTextureSource(Textures.Grassland, 3, 1) },
|
||||
{ Terrain.RockL, GetTextureSource(Textures.Grassland, 1, 2) },
|
||||
{ Terrain.RockR, GetTextureSource(Textures.Grassland, 5, 2) },
|
||||
{ Terrain.Water, GetTextureSource(Textures.Grassland, 9, 2) },
|
||||
{ Terrain.Block, GetTextureSource(Textures.Grassland, 6, 3) },
|
||||
};
|
||||
|
||||
readonly Dictionary<Terrain, TextureSource> terrainToTexture =
|
||||
new Dictionary<Terrain, TextureSource>();
|
||||
|
||||
readonly Texture2D[] textures;
|
||||
|
||||
public TileFactory(ContentManager content) {
|
||||
Array tileSets = Enum.GetValues(typeof(TileSet));
|
||||
textures = new Texture2D[tileSets.Length];
|
||||
foreach (TileSet tileSet in tileSets) {
|
||||
textures[(int) tileSet] = content.Load<Texture2D>(tileSetToContentPath[tileSet]);
|
||||
}
|
||||
|
||||
terrainToTexture[Terrain.Grass] = GetTextureSource(TileSet.Grassland, 3, 0);
|
||||
terrainToTexture[Terrain.GrassL] = GetTextureSource(TileSet.Grassland, 2, 0);
|
||||
terrainToTexture[Terrain.GrassR] = GetTextureSource(TileSet.Grassland, 4, 0);
|
||||
terrainToTexture[Terrain.Rock] = GetTextureSource(TileSet.Grassland, 3, 1);
|
||||
terrainToTexture[Terrain.RockL] = GetTextureSource(TileSet.Grassland, 1, 2);
|
||||
terrainToTexture[Terrain.RockR] = GetTextureSource(TileSet.Grassland, 5, 2);
|
||||
terrainToTexture[Terrain.Water] = GetTextureSource(TileSet.Grassland, 9, 2);
|
||||
terrainToTexture[Terrain.Block] = GetTextureSource(TileSet.Grassland, 6, 3);
|
||||
}
|
||||
|
||||
public Tile MakeTile(Terrain terrain, Rectangle position) {
|
||||
@ -83,8 +48,7 @@ namespace SemiColinGames {
|
||||
return new Tile(terrain, position, textureSource.texture, textureSource.source);
|
||||
}
|
||||
|
||||
private TextureSource GetTextureSource(TileSet tileSet, int x, int y) {
|
||||
Texture2D texture = textures[(int) tileSet];
|
||||
private TextureSource GetTextureSource(Texture2D texture, int x, int y) {
|
||||
int size = World.TileSize;
|
||||
Rectangle position = new Rectangle(x * size, y * size, size, size);
|
||||
return new TextureSource(texture, position);
|
||||
@ -140,8 +104,8 @@ namespace SemiColinGames {
|
||||
{ 'X', Terrain.Block }
|
||||
};
|
||||
|
||||
public World(ContentManager content, string levelSpecification) {
|
||||
TileFactory factory = new TileFactory(content);
|
||||
public World(string levelSpecification) {
|
||||
TileFactory factory = new TileFactory();
|
||||
var tilesList = new List<Tile>();
|
||||
string[] worldDesc = levelSpecification.Split('\n');
|
||||
tileWidth = worldDesc.AsQueryable().Max(a => a.Length);
|
||||
|
Loading…
Reference in New Issue
Block a user