Game objects now take in a ContentManager & load their own textures.

GitOrigin-RevId: 4f40548d9f100f4bad181a59f4df44397f7ccf76
This commit is contained in:
Colin McMillen 2020-02-18 13:57:02 -05:00
parent f0ea8d8ef2
commit 02aba3ad84
4 changed files with 13 additions and 9 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -35,8 +36,8 @@ namespace SemiColinGames {
private const int swordSwingMax = 6; private const int swordSwingMax = 6;
private float ySpeed = 0; private float ySpeed = 0;
public Player(Texture2D texture) { public Player(ContentManager content) {
this.texture = texture; this.texture = content.Load<Texture2D>("sprites/ccg/ninja_female");
} }
public int Facing { get; private set; } = 1; public int Facing { get; private set; } = 1;

View File

@ -18,7 +18,7 @@ namespace SemiColinGames {
readonly Texture2D grasslandBg1; readonly Texture2D grasslandBg1;
readonly Texture2D grasslandBg2; readonly Texture2D grasslandBg2;
public Scene(GraphicsDevice graphics, Camera camera, ContentManager content) { public Scene(ContentManager content, GraphicsDevice graphics, Camera camera) {
Enabled = false; Enabled = false;
this.graphics = graphics; this.graphics = graphics;
this.camera = camera; this.camera = camera;

View File

@ -1,9 +1,8 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using MonoGame.Framework.Utilities;
using System; using System;
using System.Collections.Generic;
namespace SemiColinGames { namespace SemiColinGames {
public class SneakGame : Game { public class SneakGame : Game {
@ -33,6 +32,8 @@ namespace SemiColinGames {
Camera camera = new Camera(); Camera camera = new Camera();
public SneakGame() { public SneakGame() {
Debug.WriteLine("MonoGame platform: " + PlatformInfo.MonoGamePlatform +
" w/ graphics backend: " + PlatformInfo.GraphicsBackend);
graphics = new GraphicsDeviceManager(this) { graphics = new GraphicsDeviceManager(this) {
SynchronizeWithVerticalRetrace = true, SynchronizeWithVerticalRetrace = true,
GraphicsProfile = GraphicsProfile.HiDef GraphicsProfile = GraphicsProfile.HiDef
@ -69,9 +70,9 @@ namespace SemiColinGames {
private void LoadLevel() { private void LoadLevel() {
framesToSuppress = 2; framesToSuppress = 2;
camera = new Camera(); camera = new Camera();
player = new Player(Content.Load<Texture2D>("sprites/ccg/ninja_female")); player = new Player(Content);
world = new World(Content.Load<Texture2D>("tiles/anokolisa/grassland"), Levels.ONE_ONE); world = new World(Content, Levels.ONE_ONE);
scene = new Scene(GraphicsDevice, camera, Content); scene = new Scene(Content, GraphicsDevice, camera);
} }
// Called once per game. Unloads all game content. // Called once per game. Unloads all game content.

View File

@ -1,4 +1,5 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -83,7 +84,8 @@ namespace SemiColinGames {
{ 'X', Terrain.Block } { 'X', Terrain.Block }
}; };
public World(Texture2D texture, string levelSpecification) { public World(ContentManager content, string levelSpecification) {
Texture2D texture = content.Load<Texture2D>("tiles/anokolisa/grassland");
var tilesList = new List<Tile>(); var tilesList = new List<Tile>();
string[] worldDesc = levelSpecification.Split('\n'); string[] worldDesc = levelSpecification.Split('\n');
tileWidth = worldDesc.AsQueryable().Max(a => a.Length); tileWidth = worldDesc.AsQueryable().Max(a => a.Length);