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
127 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using AIRendering;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Brains.Framework;
namespace AIDemos.Screens.Demos
{
public class DemoGameScreen:GameScreen
{
protected PrimitiveBatch primitiveBatch;
protected ContentManager content;
protected SpriteFont gameFont;
protected SpriteFont titleFont;
protected AIEngine _engine;
public string Title { get; set; }
public string Description{ get; set; }
public DemoGameScreen(string title,string description)
{
Title = title;
Description = description;
}
protected void CenterCamOnMap()
{
primitiveBatch.CameraPosition = new Vector2(
-ScreenManager.GraphicsDevice.Viewport.Width / 2 +
_engine.World.Map.ClusterGrid.Grids[0].Width / 2,
-ScreenManager.GraphicsDevice.Viewport.Height / 2 +
_engine.World.Map.ClusterGrid.Grids[0].Height / 2);
}
public override void LoadContent()
{
if (content == null)
content = new ContentManager(ScreenManager.Game.Services, "Content");
gameFont = content.Load<SpriteFont>("gamefont");
titleFont= content.Load<SpriteFont>("titlefont");
primitiveBatch = new PrimitiveBatch(ScreenManager.GraphicsDevice);
_engine = new AIEngine();
}
public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
{
ScreenManager.SpriteBatch.DrawString(
titleFont,
Title,
new Vector2(10, 10),
Color.White,
0,
new Vector2(0),
0.5f, SpriteEffects.None,
0
);
ScreenManager.SpriteBatch.DrawString(
gameFont,
Description,
new Vector2(10,50),
Color.White,
0,
new Vector2(0),
0.5f,SpriteEffects.None,
0
);
base.Draw(gameTime);
}
GameTime lastGameTime;
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
{
lastGameTime = gameTime;
Vector2 _moveCam = Vector2.Zero;
KeyboardState _currentKB = Keyboard.GetState();
if (_currentKB.IsKeyDown(Keys.Up))
_moveCam.Y = -1;
if (_currentKB.IsKeyDown(Keys.Down))
_moveCam.Y = 1;
if (_currentKB.IsKeyDown(Keys.Left))
_moveCam.X = -1;
if (_currentKB.IsKeyDown(Keys.Right))
_moveCam.X = 1;
if (_moveCam != Vector2.Zero)
{
primitiveBatch.CameraPosition += _moveCam * lastGameTime.GetElapsed() * 500;
}
base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
}
public override void HandleInput(InputState input)
{
int playerIndex = (int)ControllingPlayer.Value;
GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];
PlayerIndex index;
if (input.IsNewKeyPress(Keys.PageDown, null, out index))
{
primitiveBatch.Zoom -= 0.1f;
}
if (input.IsNewKeyPress(Keys.PageUp,null,out index))
{
primitiveBatch.Zoom += 0.1f;
}
if (input.IsNewKeyPress(Keys.Space, null, out index))
{
primitiveBatch.Zoom = 1f;
}
bool gamePadDisconnected = !gamePadState.IsConnected &&
input.GamePadWasConnected[playerIndex];
if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected)
{
ScreenManager.AddScreen(new AIDemosPauseMenuScreen(), ControllingPlayer);
}
base.HandleInput(input);
}
}
} |