Shitty example of tilemap moving around

tiles_moving_bad
BraydonKains 5 years ago
parent 9ec55c4c7e
commit d90bf6dffe

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

@ -0,0 +1,40 @@
{ "height":12,
"infinite":false,
"layers":[
{
"data":[1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":12,
"id":1,
"name":"Tile Layer 1",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":24,
"x":0,
"y":0
}],
"nextlayerid":2,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"left-down",
"tiledversion":"1.2.1",
"tileheight":32,
"tilesets":[
{
"columns":3,
"firstgid":1,
"image":"pond.png",
"imageheight":97,
"imagewidth":97,
"margin":0,
"name":"pond",
"spacing":0,
"tilecount":9,
"tileheight":32,
"tilewidth":32
}],
"tilewidth":32,
"type":"map",
"version":1.2,
"width":24
}

@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 15
VisualStudioVersion = 15.0.26124.0 VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0 MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeeNoEvil.Game", "SeeNoEvil.Game\SeeNoEvil.Game.csproj", "{8DAEBE8F-06ED-447C-952D-CC99828BB243}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeeNoEvil.Tests", "SeeNoEvil.Tests\SeeNoEvil.Tests.csproj", "{68F2154E-8FB0-4C33-834D-CE4A8175AF73}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeeNoEvil.Tests", "SeeNoEvil.Tests\SeeNoEvil.Tests.csproj", "{68F2154E-8FB0-4C33-834D-CE4A8175AF73}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeeNoEvil", "SeeNoEvil\SeeNoEvil.csproj", "{C56E63A2-B2D6-41D8-A26C-86A58DAC0841}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeeNoEvil", "SeeNoEvil\SeeNoEvil.csproj", "{C56E63A2-B2D6-41D8-A26C-86A58DAC0841}"
@ -22,18 +20,6 @@ Global
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8DAEBE8F-06ED-447C-952D-CC99828BB243}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8DAEBE8F-06ED-447C-952D-CC99828BB243}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DAEBE8F-06ED-447C-952D-CC99828BB243}.Debug|x64.ActiveCfg = Debug|Any CPU
{8DAEBE8F-06ED-447C-952D-CC99828BB243}.Debug|x64.Build.0 = Debug|Any CPU
{8DAEBE8F-06ED-447C-952D-CC99828BB243}.Debug|x86.ActiveCfg = Debug|Any CPU
{8DAEBE8F-06ED-447C-952D-CC99828BB243}.Debug|x86.Build.0 = Debug|Any CPU
{8DAEBE8F-06ED-447C-952D-CC99828BB243}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DAEBE8F-06ED-447C-952D-CC99828BB243}.Release|Any CPU.Build.0 = Release|Any CPU
{8DAEBE8F-06ED-447C-952D-CC99828BB243}.Release|x64.ActiveCfg = Release|Any CPU
{8DAEBE8F-06ED-447C-952D-CC99828BB243}.Release|x64.Build.0 = Release|Any CPU
{8DAEBE8F-06ED-447C-952D-CC99828BB243}.Release|x86.ActiveCfg = Release|Any CPU
{8DAEBE8F-06ED-447C-952D-CC99828BB243}.Release|x86.Build.0 = Release|Any CPU
{68F2154E-8FB0-4C33-834D-CE4A8175AF73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {68F2154E-8FB0-4C33-834D-CE4A8175AF73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68F2154E-8FB0-4C33-834D-CE4A8175AF73}.Debug|Any CPU.Build.0 = Debug|Any CPU {68F2154E-8FB0-4C33-834D-CE4A8175AF73}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68F2154E-8FB0-4C33-834D-CE4A8175AF73}.Debug|x64.ActiveCfg = Debug|Any CPU {68F2154E-8FB0-4C33-834D-CE4A8175AF73}.Debug|x64.ActiveCfg = Debug|Any CPU

@ -1,24 +1,39 @@
using Microsoft.Xna.Framework; using System.Collections.Generic;
using System.Linq;
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 SeeNoEvil.Tiled;
using SeeNoEvil.Level;
namespace SeeNoEvil namespace SeeNoEvil
{ {
public class Game1 : Game public class Game1 : Game
{ {
GraphicsDeviceManager graphics; GraphicsDeviceManager graphics;
SpriteBatch spriteBatch; SpriteBatch spriteBatch;
TilemapLevel level;
Dictionary<string, Texture2D> tilesets;
Camera viewport;
public Game1() public Game1()
{ {
graphics = new GraphicsDeviceManager(this); graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content"; Content.RootDirectory = "Content";
IsMouseVisible = true; IsMouseVisible = true;
viewport.height = 720;
viewport.width = 1280;
viewport.x = 0;
viewport.y = 0;
} }
protected override void Initialize() protected override void Initialize()
{ {
// TODO: Add your initialization logic here // TODO: Add your initialization logic here
level = new TilemapLevel("./Maps/MagicLandCsv.json");
level.LoadMap();
base.Initialize(); base.Initialize();
} }
@ -26,8 +41,12 @@ namespace SeeNoEvil
protected override void LoadContent() protected override void LoadContent()
{ {
spriteBatch = new SpriteBatch(GraphicsDevice); spriteBatch = new SpriteBatch(GraphicsDevice);
tilesets = new Dictionary<string, Texture2D>();
// TODO: use this.Content to load your game content here tilesets = level.GetTilesetNames().Aggregate(new Dictionary<string, Texture2D>(),
(content, contentName) => {
content.Add(contentName, Content.Load<Texture2D>(contentName));
return content;
});
} }
protected override void Update(GameTime gameTime) protected override void Update(GameTime gameTime)
@ -35,7 +54,14 @@ namespace SeeNoEvil
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit(); Exit();
// TODO: Add your update logic here if(Keyboard.GetState().IsKeyDown(Keys.Down))
viewport.y += 16;
if(Keyboard.GetState().IsKeyDown(Keys.Up))
viewport.y -= 16;
if(Keyboard.GetState().IsKeyDown(Keys.Left))
viewport.x -= 16;
if(Keyboard.GetState().IsKeyDown(Keys.Right))
viewport.x += 16;
base.Update(gameTime); base.Update(gameTime);
} }
@ -44,7 +70,9 @@ namespace SeeNoEvil
{ {
GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here spriteBatch.Begin();
level.Draw(viewport, spriteBatch, tilesets);
spriteBatch.End();
base.Draw(gameTime); base.Draw(gameTime);
} }

@ -0,0 +1,15 @@
{
"FormattingOptions": {
"NewLinesForBracesInLambdaExpressionBody": false,
"NewLinesForBracesInAnonymousMethods": false,
"NewLinesForBracesInAnonymousTypes": false,
"NewLinesForBracesInControlBlocks": false,
"NewLinesForBracesInTypes": false,
"NewLinesForBracesInMethods": false,
"NewLinesForBracesInProperties": false,
"NewLinesForBracesInAccessors": false,
"NewLineForElse": false,
"NewLineForCatch": false,
"NewLineForFinally": false
}
}
Loading…
Cancel
Save