-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame1.cs
108 lines (93 loc) · 3.03 KB
/
Game1.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
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using XNAHelpers;
namespace _2DVisbility
{
public class Game1 : Microsoft.Xna.Framework.Game
{
public const int TileSize = 16;
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
InputHelper input;
Player player;
Level level;
public LineDrawer DebugLineDrawer { get; set; }
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.PreferredBackBufferWidth = 512;
graphics.PreferredBackBufferHeight = 512;
this.IsMouseVisible = true;
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
input = new InputHelper();
spriteBatch = new SpriteBatch(GraphicsDevice);
level = new Level(this);
player = new Player(input, Content, level);
level.Player = player;
DebugLineDrawer = new LineDrawer(GraphicsDevice, spriteBatch);
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
input.Update();
if (input.ExitRequested)
this.Exit();
if (input.IsNewPress(Keys.Q))
{
Player.VisionRadius += 1;
}
if (input.IsNewPress(Keys.A))
{
Player.VisionRadius -= 1;
}
if (input.IsNewPress(Keys.W))
{
Player.ConeWidth += (5f / 180f) * (float)Math.PI;
}
if (input.IsNewPress(Keys.S))
{
Player.ConeWidth -= (5f / 180f) * (float)Math.PI;
}
level.PlayerOrientation = input.MousePosition - (player.Position * Game1.TileSize);
player.Update();
level.Update();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.FrontToBack, SaveStateMode.None);
level.Draw(spriteBatch);
player.Draw(spriteBatch);
spriteBatch.End();
DebugLineDrawer.QueueLine(new Line2D
{
Start = player.Position * TileSize,
End = input.MousePosition,
Color = Color.Yellow
});
DebugLineDrawer.Draw();
level.HasDrawn = false;
base.Draw(gameTime);
}
}
}