-
Notifications
You must be signed in to change notification settings - Fork 0
/
Path.cs
126 lines (97 loc) · 3.41 KB
/
Path.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace PathOfThal
{
public class Path : Game
{
public GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
//My variables
int size = 100;
Map map;
public Square rect3;
public Player player;
Camera camera;
//THREADING EXPIRIMENT
Thread t;
//ONLY IN DEBUG, SHOW COLLISION AND TILENUMBER. PRESS BUTTON Q OR W
#if DEBUG
bool ShowCollision = false;
bool ShowTileNumber = false;
#endif
public Path()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
Window.AllowUserResizing = false;
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
graphics.ApplyChanges();
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
rect3 = new Square(size / 2, Color.White, 3);
player = new Player(rect3, 2f);
camera = new Camera(GraphicsDevice.Viewport);
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
ContentHandler.Instance.Load(Content, GraphicsDevice);
// TODO: use this.Content to load your game content here
MapParser mapParser = new MapParser();
EventParser evetnParser = new EventParser();
map = mapParser.Parse("MapExample.txt");
Console.WriteLine(map.ToString());
rect3.Load();
map.Load();
player.Load(map);
}
protected override void Update(GameTime gameTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
//InputHandling
InputManger.Update();
//Event handling
EventHandler.Update(gameTime, player);
//ONLY IN DEBUG, SHOW COLLISION AND TILENUMBER. PRESS BUTTON Q OR W
#if DEBUG
if(InputManger.IsKeyPressed(Keys.Q)){
ShowCollision = !ShowCollision;
}else if(InputManger.IsKeyPressed(Keys.W)){
ShowTileNumber = !ShowTileNumber;
}
#endif
//PlayerHandling
player.Update(gameTime);
//Camera
camera.Update(gameTime, this, GraphicsDevice.Viewport);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, camera.Transform);
map.Draw(spriteBatch, 0, 0);
//ONLY IN DEBUG, SHOW COLLISION AND TILENUMBER. PRESS BUTTON Q OR W
#if DEBUG
if(ShowCollision)
map.DrawColisions(spriteBatch);
if(ShowTileNumber)
map.DrawTileNumbers(spriteBatch);
#endif
player.Draw(spriteBatch);
spriteBatch.End();
//event
EventHandler.Draw(spriteBatch);
base.Draw(gameTime);
}
}
}