On google drive the download button is the arrow on the top right.
Well it works now including jumping and gravity, the tile blocks can have interacting effects with your player. I made it so you can climb the ladder and walk thru non active walls but that is about all i did on that.
clarity why rewriting half was nessecairy
Sorry that was a figure of speech, to say i rewrote a lot of stuff and deleted stuff and renamed it. If you look at your game1 you'll see its much smaller now.
The main idea i wanted to impart in the changes i made is that each class now is responsible for a much more specific thing. As well that each class now serves as a tool for the other classes.
Interfaces can be useful and i know a lot of people scream do this and do that but the way you were using them all over was actually screwing you over huge.
The rule of thumb is if you don't need it, then you don't.
You know you need it when you run into a problem were you need it.
Basically you were painting yourself into a corner the way you were doing movement with the directions. You need the up down and left right checks to be separated.
If you were earlier in i would of recommended you used a quad tree or spacial collision map to track collisions but you are so far into it i think a bit of encapsulation is about as good as can be done. Though i do recommend you read up on spacial collision mapping quadtrees and such so you get a idea about it.
I added some stuff as well to help you visually debug collisions so you can see what is actually colliding and what isn't. This sort of thing is a huge help typically.
I added jumping and interactions with specific kinds of tiles differently.
All that is based off how i restructured the map data encapsulation.
Which is most of what i did just so i could fix up the player motion later.
But also because i removed all your old collision rectangles and replaced that with the tiles textures themselves to collide with.
This works as follows....
public class Game1 : Game
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.PreferredBackBufferWidth = 1800; // set this value to the desired width of your window
graphics.PreferredBackBufferHeight = 960; // set this value to the desired height of your window
protected override void Initialize()
protected override void LoadContent()
spriteBatch = new SpriteBatch(GraphicsDevice);
Globals.SetMeUpInLoad(spriteBatch, GraphicsDevice); // --- shortcut added for testing can be comment out.... and everything that errors after that.... gets deleted with it.
background = Content.Load<Texture2D>("background");
var level1 = new Level1LoadingData(Content);
currentLevel = new CurrentLevel(level1.tileMapDescriptorLoadingData);
heroTexture = Content.Load<Texture2D>("man");
hero = new Hero(heroTexture, new Vector2(200,610));
collisionManager = new CollisionManager();
protected override void UnloadContent()
protected override void Update(GameTime gameTime)
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
protected override void Draw(GameTime gameTime)
spriteBatch.Draw(background, new Rectangle(0, 0, 1800, 960), Color.White);
collisionManager.DrawDebugColliders(spriteBatch, hero, CurrentLevel.mapTiles);
Globals.DrawString(hero.CollisionRectangle.Location.ToVector2(), CollisionManager.collistionDebugString.ToString(), Color.Red);
I made you a TileDescriptor class which is used per level.
A array of these objects are created in Level1LoadingData
If you look at the Level1LoadingData class you can see how it takes on the responsibility of not just describing what textures are used but what their intended behavior is.
They both hold the textures and load them and you input a bunch of bools that describe how a tile behaves. such as IsActive IsLadder IsTriggerable ect...
The loading data is passed to a CurrentLevel which makes your map from your int[,] map data which represents which texture and those Tile Descriptions. It creates the map as Tile objects these are nearly the same as the Tile Descriptors but the destination drawing rectangles are created from the descriptors and the map x y.
The collision class then uses this mapData and the hero to determine what sort of interactions are taking place per frame.
The hero class update method has its parts separated out into methods and the physical behavior of the character is more controllable.
The collisions class draw method is just for debugging.
So is the Globals mostly the deflate extension i did use in the hero update and collision checks.
I put in a lot that would be too much to explain without a tutorial but it should be straight forward other then the tile vs the tile descriptor and level interactions
The one concern is that map tile positional offset you are doing might bite you later on. but it seems to be ok. Anyways i just basically encapsulated the logic of what you were doing before.
In the Globals class i would keep the extensions there are about 4 or 5 of them the deflate is used in the hero class. The rest of the globals class is used mostly just for debuging and you can probably comment ou and everything that errors after it directly. line by line then delete or you can keep it for debugging. I added a timer class for animations but didn't use it
I probably could of cleaned it up more.