Browse Source

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

GitOrigin-RevId: 4f40548d9f
master
Colin McMillen 4 years ago
parent
commit
02aba3ad84
  1. 5
      Shared/Player.cs
  2. 2
      Shared/Scene.cs
  3. 11
      Shared/SneakGame.cs
  4. 4
      Shared/World.cs

5
Shared/Player.cs

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

2
Shared/Scene.cs

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

11
Shared/SneakGame.cs

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

4
Shared/World.cs

@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
@ -83,7 +84,8 @@ namespace SemiColinGames {
{ '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>();
string[] worldDesc = levelSpecification.Split('\n');
tileWidth = worldDesc.AsQueryable().Max(a => a.Length);

Loading…
Cancel
Save