axiosengine 

axiosengine Commit Details


Date:2012-04-15 19:17:34 (12 years 6 months ago)
Author:nathan@daedalus
Branch:master
Commit:2277056e6b17f95740935ad1fe96653651d5c167
Parents: a93df07c6ed6fe642607e9b1f6c1113a4ffc5917
Message:More progress in updating the GSM

--HG--
branch : axios-newgsm
Changes:

File differences

axios/Axios_Windows.csproj.user
11
22
33
4
4
55
66
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
axios/Engine/AxiosGameObject.cs
22
33
44
5
56
67
78
......
4647
4748
4849
49
50
5051
5152
5253
5354
54
55
5556
5657
5758
using FarseerPhysics.Dynamics;
using FarseerPhysics.SamplesFramework;
using Microsoft.Xna.Framework;
using GameStateManagement;
namespace Axios.Engine
{
}
public virtual void HandleInput(AxiosGameScreen gameScreen, InputHelper input, GameTime gameTime)
public virtual void HandleInput(AxiosGameScreen gameScreen, InputState input, GameTime gameTime)
{
}
public virtual void HandleCursor(AxiosGameScreen gameScreen, InputHelper input)
public virtual void HandleCursor(AxiosGameScreen gameScreen, InputState input)
{
}
axios/Engine/AxiosGameScreen.cs
210210
211211
212212
213
213
214214
215215
216216
......
219219
220220
221221
222
222
223223
224224
225225
}
public override void HandleCursor(InputHelper input)
public override void HandleCursor(InputState input)
{
base.HandleCursor(input);
HandleMouseEvents(input);
g.HandleCursor(this, input);
}
private void HandleMouseEvents(InputHelper input)
private void HandleMouseEvents(InputState input)
{
Vector2 position = this.Camera.ConvertScreenToWorld(input.Cursor);
Fixture fix = this.World.TestPoint(position);
axios/ScreenSystem/InputState.cs
99
1010
1111
12
1213
1314
1415
16
1517
1618
1719
20
21
22
23
24
25
26
27
28
29
30
31
32
1833
1934
2035
......
4762
4863
4964
50
51
52
53
65
66
5467
5568
69
70
71
5672
5773
5874
......
6884
6985
7086
87
88
89
7190
7291
7392
7493
7594
76
95
7796
97
7898
7999
80100
......
82102
83103
84104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
85245
86246
87247
......
89249
90250
91251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
92277
93278
94279
......
229414
230415
231416
417
418
419
420
421
422
423
424
425
426
427
428
232429
233430
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using FarseerPhysics.SamplesFramework;
using Microsoft.Xna.Framework.Graphics;
namespace GameStateManagement
{
/// <summary>
/// an enum of all available mouse buttons.
/// </summary>
public enum MouseButtons
{
LeftButton,
MiddleButton,
RightButton,
ExtraButton1,
ExtraButton2
}
/// <summary>
/// Helper for reading input from keyboard, gamepad, and touch input. This class
/// tracks both the current and previous state of the input devices, and implements
/*
*
*
*
*
* Adding variables for the cursor
* -- Nathan Adams [adamsna@datanethost.net] - 4/15/2012
*
*/
private MouseState _currentMouseState;
private MouseState _lastMouseState;
private Vector2 _cursor;
private bool _cursorIsValid;
private bool _cursorIsVisible;
public TouchCollection TouchState;
public readonly List<GestureSample> Gestures = new List<GestureSample>();
private ScreenManager _manager;
private Viewport _viewport;
/// <summary>
/// Constructs a new input state.
/// </summary>
public InputState()
public InputState(ScreenManager manager)
{
_manager = manager;
CurrentKeyboardStates = new KeyboardState[MaxInputs];
CurrentGamePadStates = new GamePadState[MaxInputs];
LastGamePadStates = new GamePadState[MaxInputs];
GamePadWasConnected = new bool[MaxInputs];
_currentVirtualState = new GamePadState();
_lastVirtualState = new GamePadState();
_cursorIsVisible = false;
_cursorMoved = false;
#if WINDOWS_PHONE
_cursorIsValid = false;
#else
_cursorIsValid = true;
#endif
_cursor = Vector2.Zero;
_handleVirtualStick = false;
}
public MouseState MouseState
{
get { return _currentMouseState; }
}
public GamePadState VirtualState
{
get { return _currentVirtualState; }
}
public MouseState PreviousMouseState
{
get { return _lastMouseState; }
}
public GamePadState PreviousVirtualState
{
get { return _lastVirtualState; }
}
public bool ShowCursor
{
get { return _cursorIsVisible && _cursorIsValid; }
set { _cursorIsVisible = value; }
}
public bool EnableVirtualStick
{
get { return _handleVirtualStick; }
set { _handleVirtualStick = value; }
}
public Vector2 Cursor
{
get { return _cursor; }
}
public bool IsCursorMoved
{
get { return _cursorMoved; }
}
public bool IsCursorValid
{
get { return _cursorIsValid; }
}
public void LoadContent()
{
ContentManager man = new ContentManager(_manager.Game.Services, "Content");
_cursorSprite = new Sprite(man.Load<Texture2D>("Common/cursor"));
#if WINDOWS_PHONE
// virtual stick content
_phoneStick = new VirtualStick(man.Load<Texture2D>("Common/socket"),
man.Load<Texture2D>("Common/stick"), new Vector2(80f, 400f));
Texture2D temp = man.Load<Texture2D>("Common/buttons");
_phoneA = new VirtualButton(temp, new Vector2(695f, 380f), new Rectangle(0, 0, 40, 40), new Rectangle(0, 40, 40, 40));
_phoneB = new VirtualButton(temp, new Vector2(745f, 360f), new Rectangle(40, 0, 40, 40), new Rectangle(40, 40, 40, 40));
#endif
_viewport = _manager.GraphicsDevice.Viewport;
}
private GamePadState HandleVirtualStickWin()
{
Vector2 _leftStick = Vector2.Zero;
List<Buttons> _buttons = new List<Buttons>();
PlayerIndex pout;
if (IsNewKeyPress(Keys.A, PlayerIndex.One, out pout))
{
_leftStick.X -= 1f;
}
if (IsNewKeyPress(Keys.S, PlayerIndex.One, out pout))
{
_leftStick.Y -= 1f;
}
if (IsNewKeyPress(Keys.D, PlayerIndex.One, out pout))
{
_leftStick.X += 1f;
}
if (IsNewKeyPress(Keys.W, PlayerIndex.One, out pout))
{
_leftStick.Y += 1f;
}
if (IsNewKeyPress(Keys.Space, PlayerIndex.One, out pout))
{
_buttons.Add(Buttons.A);
}
if (IsNewKeyPress(Keys.LeftControl, PlayerIndex.One, out pout))
{
_buttons.Add(Buttons.B);
}
if (_leftStick != Vector2.Zero)
{
_leftStick.Normalize();
}
return new GamePadState(_leftStick, Vector2.Zero, 0f, 0f, _buttons.ToArray());
}
private GamePadState HandleVirtualStickWP7()
{
List<Buttons> _buttons = new List<Buttons>();
Vector2 _stick = Vector2.Zero;
#if WINDOWS_PHONE
_phoneA.Pressed = false;
_phoneB.Pressed = false;
TouchCollection touchLocations = TouchPanel.GetState();
foreach (TouchLocation touchLocation in touchLocations)
{
_phoneA.Update(touchLocation);
_phoneB.Update(touchLocation);
_phoneStick.Update(touchLocation);
}
if (_phoneA.Pressed)
{
_buttons.Add(Buttons.A);
}
if (_phoneB.Pressed)
{
_buttons.Add(Buttons.B);
}
_stick = _phoneStick.StickPosition;
#endif
return new GamePadState(_stick, Vector2.Zero, 0f, 0f, _buttons.ToArray());
}
/// <summary>
/// </summary>
public void Update()
{
_lastMouseState = _currentMouseState;
if (_handleVirtualStick)
{
_lastVirtualState = _currentVirtualState;
}
_currentMouseState = Mouse.GetState();
if (_handleVirtualStick)
{
#if XBOX
_currentVirtualState= GamePad.GetState(PlayerIndex.One);
#elif WINDOWS
if (GamePad.GetState(PlayerIndex.One).IsConnected)
{
_currentVirtualState = GamePad.GetState(PlayerIndex.One);
}
else
{
_currentVirtualState = HandleVirtualStickWin();
}
#elif WINDOWS_PHONE
_currentVirtualState = HandleVirtualStickWP7();
#endif
}
for (int i = 0; i < MaxInputs; i++)
{
LastKeyboardStates[i] = CurrentKeyboardStates[i];
IsNewButtonPress(button, PlayerIndex.Four, out playerIndex));
}
}
public bool IsNewVirtualButtonPress(Buttons button)
{
return (_lastVirtualState.IsButtonUp(button) &&
_currentVirtualState.IsButtonDown(button));
}
public bool IsNewVirtualButtonRelease(Buttons button)
{
return (_lastVirtualState.IsButtonDown(button) &&
_currentVirtualState.IsButtonUp(button));
}
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.11681s using 13 queries.