Browse Source
Make TextureRef class for holding textures.
Make TextureRef class for holding textures.
Use it in World so that all Terrain-specific configuration can be specified in
one place.
GitOrigin-RevId: 31acf292ae
master
Colin McMillen
4 years ago
4 changed files with 93 additions and 135 deletions
@ -1,47 +1,64 @@ |
|||||
using Microsoft.Xna.Framework.Content; |
using Microsoft.Xna.Framework.Content; |
||||
using Microsoft.Xna.Framework.Graphics; |
using Microsoft.Xna.Framework.Graphics; |
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
|
||||
namespace SemiColinGames { |
namespace SemiColinGames { |
||||
|
|
||||
|
class TextureRef { |
||||
|
private static readonly List<TextureRef> allTextures = new List<TextureRef>(); |
||||
|
|
||||
|
public static void LoadAll(ContentManager content) { |
||||
|
foreach (TextureRef texture in allTextures) { |
||||
|
texture.Load(content); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private readonly string contentPath; |
||||
|
private Texture2D texture; |
||||
|
|
||||
|
public TextureRef(string contentPath) { |
||||
|
allTextures.Add(this); |
||||
|
this.contentPath = contentPath; |
||||
|
} |
||||
|
|
||||
|
public Texture2D Get() { |
||||
|
return texture; |
||||
|
} |
||||
|
|
||||
|
private void Load(ContentManager content) { |
||||
|
texture = content.Load<Texture2D>(contentPath); |
||||
|
} |
||||
|
} |
||||
|
|
||||
class Textures { |
class Textures { |
||||
|
|
||||
public static Texture2D Player; |
|
||||
|
public static SpriteFont DebugFont; |
||||
|
|
||||
|
public static TextureRef Player = new TextureRef("sprites/ccg/ninja_female"); |
||||
|
|
||||
// Backgrounds are indexed by draw order; the first element should be drawn furthest back.
|
// Backgrounds are indexed by draw order; the first element should be drawn furthest back.
|
||||
public static Texture2D[] Backgrounds = new Texture2D[4]; |
|
||||
|
|
||||
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 TextureRef[] Backgrounds = new TextureRef[] { |
||||
|
new TextureRef("backgrounds/szadiart/pf4/background1_day"), |
||||
|
new TextureRef("backgrounds/szadiart/pf4/background2a_day"), |
||||
|
new TextureRef("backgrounds/szadiart/pf4/background3_day"), |
||||
|
new TextureRef("backgrounds/szadiart/pf4/background4_day"), |
||||
|
}; |
||||
|
|
||||
public static SpriteFont DebugFont; |
|
||||
|
public static TextureRef Cemetery = new TextureRef("tiles/anokolisa/cemetery"); |
||||
|
public static TextureRef Crypt = new TextureRef("tiles/anokolisa/crypt"); |
||||
|
public static TextureRef Dungeon = new TextureRef("tiles/anokolisa/dungeon"); |
||||
|
public static TextureRef Forest = new TextureRef("tiles/anokolisa/forest"); |
||||
|
public static TextureRef Garden = new TextureRef("tiles/anokolisa/garden"); |
||||
|
public static TextureRef Grassland = new TextureRef("tiles/anokolisa/grassland"); |
||||
|
public static TextureRef Ruins = new TextureRef("tiles/anokolisa/ruins"); |
||||
|
public static TextureRef Sewer = new TextureRef("tiles/anokolisa/sewer"); |
||||
|
public static TextureRef Temple = new TextureRef("tiles/anokolisa/temple"); |
||||
|
public static TextureRef Village = new TextureRef("tiles/anokolisa/village"); |
||||
|
|
||||
public static void Load(ContentManager content) { |
public static void Load(ContentManager content) { |
||||
Player = content.Load<Texture2D>("sprites/ccg/ninja_female"); |
|
||||
|
|
||||
Backgrounds[0] = content.Load<Texture2D>("backgrounds/szadiart/pf4/background1_day"); |
|
||||
Backgrounds[1] = content.Load<Texture2D>("backgrounds/szadiart/pf4/background2a_day"); |
|
||||
Backgrounds[2] = content.Load<Texture2D>("backgrounds/szadiart/pf4/background3_day"); |
|
||||
Backgrounds[3] = content.Load<Texture2D>("backgrounds/szadiart/pf4/background4_day"); |
|
||||
|
|
||||
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"); |
DebugFont = content.Load<SpriteFont>("font"); |
||||
|
TextureRef.LoadAll(content); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue