Adding initial files
This commit is contained in:
126
axios/Engine/AxiosBreakableGameObject.cs
Normal file
126
axios/Engine/AxiosBreakableGameObject.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using FarseerPhysics.Dynamics;
|
||||
|
||||
using Axios.Engine.Interfaces;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
//I think using a template here would be good
|
||||
//It would solve the problem of having to repeat methods in DrawableBreakableAxiosGameObject
|
||||
abstract class AxiosBreakableGameObject : AxiosGameObject
|
||||
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// BodyParts is what the body will break into
|
||||
/// Body is what will be used to show the object as a whole
|
||||
/// </summary>
|
||||
protected List<SimpleAxiosGameObject> BodyParts = new List<SimpleAxiosGameObject>();
|
||||
protected SimpleAxiosGameObject BodyPart = null;
|
||||
|
||||
|
||||
public delegate void BodyBroken(AxiosBreakableGameObject body);
|
||||
|
||||
public event BodyBroken OnBodyBreak;
|
||||
|
||||
protected bool _calledBodyBroken = false;
|
||||
|
||||
protected bool _isbroken = false;
|
||||
|
||||
private int _draworder;
|
||||
|
||||
public bool Broken
|
||||
{
|
||||
get { return _isbroken; }
|
||||
set { _isbroken = true; Break(); }
|
||||
}
|
||||
|
||||
public override void LoadContent(AxiosGameScreen gameScreen)
|
||||
{
|
||||
base.LoadContent(gameScreen);
|
||||
|
||||
BodyParts = new List<SimpleAxiosGameObject>();
|
||||
|
||||
|
||||
CreateBodyPart(gameScreen);
|
||||
CreateBodyParts(gameScreen);
|
||||
|
||||
gameScreen.AddGameObject(BodyPart);
|
||||
BodyPart.BodyPart.Enabled = true;
|
||||
foreach (SimpleAxiosGameObject obj in BodyParts)
|
||||
{
|
||||
gameScreen.AddGameObject(obj);
|
||||
obj.BodyPart.Enabled = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//The developer will have to define the BodyPart creation in an overriden method
|
||||
public abstract void CreateBodyPart(AxiosGameScreen gameScreen);
|
||||
|
||||
//The developer will have to define the BodyParts creation in an overriden method
|
||||
public abstract void CreateBodyParts(AxiosGameScreen gameScreen);
|
||||
|
||||
public void Break()
|
||||
{
|
||||
OnBodyBreak(this);
|
||||
_isbroken = true;
|
||||
|
||||
BodyPart.BodyPart.Enabled = false;
|
||||
foreach (SimpleAxiosGameObject s in BodyParts)
|
||||
s.BodyPart.Enabled = true;
|
||||
}
|
||||
|
||||
public override void Update(AxiosGameScreen gameScreen, Microsoft.Xna.Framework.GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
|
||||
{
|
||||
base.Update(gameScreen, gameTime, otherScreenHasFocus, coveredByOtherScreen);
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected override void OnRemove(AxiosGameObject gameObject)
|
||||
{
|
||||
base.OnRemove(gameObject);
|
||||
|
||||
if (BodyPart != null)
|
||||
BodyPart.Remove();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int DrawOrder
|
||||
{
|
||||
get
|
||||
{
|
||||
return _draworder;
|
||||
}
|
||||
set
|
||||
{
|
||||
_draworder = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Draw(AxiosGameScreen gameScreen, Microsoft.Xna.Framework.GameTime gameTime)
|
||||
{
|
||||
if (_isbroken)
|
||||
{
|
||||
if (BodyParts.Count > 0 && BodyParts[0] is IDrawableAxiosGameObject)
|
||||
{
|
||||
foreach (SimpleAxiosGameObject b in BodyParts)
|
||||
((IDrawableAxiosGameObject)b).Draw(gameScreen, gameTime);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (BodyPart != null && BodyPart is IDrawableAxiosGameObject)
|
||||
((IDrawableAxiosGameObject)BodyPart).Draw(gameScreen, gameTime);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
138
axios/Engine/AxiosEvents.cs
Normal file
138
axios/Engine/AxiosEvents.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
public abstract class AxiosEvents
|
||||
{
|
||||
protected Boolean _hasFocus;
|
||||
|
||||
public bool HasFocus
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._hasFocus;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._hasFocus = value;
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void AxiosHandler(object sender, AxiosGameScreen gameScreen, InputHelper input);
|
||||
|
||||
public delegate void AxiosGameObjectHandler(AxiosGameObject sender);
|
||||
|
||||
#region GameObjectEventMethods
|
||||
|
||||
public virtual void OnFocusEnter(AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
this.HasFocus = true;
|
||||
this.OnEvent(FocusEnter, gameScreen, input);
|
||||
}
|
||||
|
||||
public virtual void OnFocusLeave(AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
this.HasFocus = false;
|
||||
this.OnEvent(FocusLeave, gameScreen, input);
|
||||
}
|
||||
|
||||
public virtual void OnMouseHover(AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
this.OnEvent(MouseHover, gameScreen, input);
|
||||
}
|
||||
|
||||
public virtual void OnMouseLeave(AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
this.OnEvent(MouseLeave, gameScreen, input);
|
||||
}
|
||||
|
||||
public virtual void OnValueChange(AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
this.OnEvent(ValueChange, gameScreen, input);
|
||||
}
|
||||
|
||||
public virtual void OnMouseDown(AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
this.OnEvent(MouseDown, gameScreen, input);
|
||||
}
|
||||
|
||||
public virtual void OnMouseUp(AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
this.OnEvent(MouseUp, gameScreen, input);
|
||||
}
|
||||
|
||||
public virtual void OnScaleChange(AxiosGameObject gameObject)
|
||||
{
|
||||
if (this.ScaleChanged != null)
|
||||
this.ScaleChanged(gameObject);
|
||||
}
|
||||
|
||||
private void OnEvent(AxiosHandler e, AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
AxiosHandler handle = e;
|
||||
if (handle != null)
|
||||
handle(this, gameScreen, input);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GameObjectEvents
|
||||
|
||||
/// <summary>
|
||||
/// This event is fired when the the object looses focus
|
||||
/// </summary>
|
||||
/// <param name="sender">The object sending the event</param>
|
||||
/// <param name="gameScreen">The gamescreen that this happened on</param>
|
||||
/// <param name="kworld">The current version of the kosmos world</param>
|
||||
public event AxiosHandler FocusLeave;
|
||||
|
||||
public event AxiosHandler MouseHover;
|
||||
|
||||
public event AxiosHandler MouseLeave;
|
||||
|
||||
public event AxiosHandler MouseDown;
|
||||
|
||||
public event AxiosHandler MouseUp;
|
||||
|
||||
/// <summary>
|
||||
/// This event is fired when the the object gains focus
|
||||
/// </summary>
|
||||
/// <param name="sender">The object sending the event</param>
|
||||
/// <param name="gameScreen">The gamescreen that this happened on</param>
|
||||
/// <param name="kworld">The current version of the kosmos world</param>
|
||||
public event AxiosHandler FocusEnter;
|
||||
|
||||
/// <summary>
|
||||
/// This event is fired when the object's value changes
|
||||
/// </summary>
|
||||
/// <param name="sender">The object sending the event</param>
|
||||
/// <param name="gameScreen">The gamescreen that this happened on</param>
|
||||
/// <param name="kworld">The current version of the kosmos world</param>
|
||||
public event AxiosHandler ValueChange;
|
||||
|
||||
public event AxiosGameObjectHandler RemoveObject;
|
||||
|
||||
public event AxiosGameObjectHandler ScaleChanged;
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void OnRemove(AxiosGameObject gameObject)
|
||||
{
|
||||
RemoveObject(gameObject);
|
||||
}
|
||||
|
||||
protected void RemoveEvents()
|
||||
{
|
||||
this.MouseDown = null;
|
||||
this.MouseHover = null;
|
||||
this.MouseLeave = null;
|
||||
this.MouseUp = null;
|
||||
this.FocusEnter = null;
|
||||
this.FocusLeave = null;
|
||||
}
|
||||
}
|
||||
}
|
88
axios/Engine/AxiosGameObject.cs
Normal file
88
axios/Engine/AxiosGameObject.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Axios.Engine.Interfaces;
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
using Microsoft.Xna.Framework;
|
||||
using FarseerPhysics.Dynamics;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
public abstract class AxiosGameObject : AxiosEvents, IAxiosGameObject
|
||||
{
|
||||
protected float _scale = 1f;
|
||||
protected bool removing = false;
|
||||
|
||||
public float Scale
|
||||
{
|
||||
get { return _scale; }
|
||||
set
|
||||
{
|
||||
if (value != _scale)
|
||||
{
|
||||
_scale = value;
|
||||
OnScaleChange(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _name;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._name = value;
|
||||
}
|
||||
}
|
||||
public virtual void Update(AxiosGameScreen gameScreen, Microsoft.Xna.Framework.GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void LoadContent(AxiosGameScreen gameScreen)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void HandleInput(AxiosGameScreen gameScreen, InputHelper input, GameTime gameTime)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void HandleCursor(AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void UnloadContent(AxiosGameScreen gameScreen)
|
||||
{
|
||||
RemoveEvents();
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
this.OnRemove(this);
|
||||
}
|
||||
|
||||
protected void SetCollideWithAll(Body b)
|
||||
{
|
||||
if (b != null)
|
||||
{
|
||||
b.CollidesWith = Category.All;
|
||||
b.CollisionCategories = Category.All;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
397
axios/Engine/AxiosGameScreen.cs
Normal file
397
axios/Engine/AxiosGameScreen.cs
Normal file
@@ -0,0 +1,397 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
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 FarseerPhysics.Dynamics;
|
||||
using FarseerPhysics.Dynamics.Joints;
|
||||
using FarseerPhysics.Dynamics.Contacts;
|
||||
using FarseerPhysics.Factories;
|
||||
using FarseerPhysics.Common;
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
using Axios.Engine.Interfaces;
|
||||
using Axios.Engine.UI;
|
||||
using Axios.Engine.Log;
|
||||
using Axios.Engine.File;
|
||||
using System.IO;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
|
||||
public abstract class AxiosGameScreen : PhysicsGameScreen
|
||||
{
|
||||
private List<AxiosGameObject> _gameObjects;
|
||||
private AxiosGameObject prevobj;
|
||||
private AxiosGameObject prevfocusobj;
|
||||
|
||||
#region DebugTextVariables
|
||||
#if DEBUG
|
||||
public SpriteFont DebugSpriteFont;
|
||||
public String DebugTextFont = "Fonts/helptext";
|
||||
public Color DebugTextColor = Color.Red;
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
private List<AxiosTimer> _timers;
|
||||
private List<AxiosUIObject> _uiobjects;
|
||||
|
||||
private AxiosUIObject prevuiobj;
|
||||
private AxiosUIObject prevuifocusobj;
|
||||
|
||||
public AxiosGameScreen()
|
||||
: base()
|
||||
{
|
||||
this._gameObjects = new List<AxiosGameObject>();
|
||||
_timers = new List<AxiosTimer>();
|
||||
prevobj = null;
|
||||
prevfocusobj = null;
|
||||
this._uiobjects = new List<AxiosUIObject>();
|
||||
prevuiobj = null;
|
||||
prevuifocusobj = null;
|
||||
}
|
||||
|
||||
/*public void AddGameObject<T>(T gameobject)
|
||||
{
|
||||
if (gameobject is AxiosGameObject || gameobject is AxiosUIObject)
|
||||
gameobject.LoadContent(this);
|
||||
|
||||
if (gameobject is AxiosGameObject || gameobject is AxiosUIObject)
|
||||
gameobject.RemoveObject += new AxiosGameObject.RemoveAxiosGameObjectHandler(RemoveGameObject);
|
||||
|
||||
if (gameobject is AxiosGameObject)
|
||||
{
|
||||
this._gameObjects.Add(gameobject);
|
||||
}
|
||||
else if (gameobject is AxiosUIObject)
|
||||
{
|
||||
this._uiobjects.Add(gameobject);
|
||||
}
|
||||
}*/
|
||||
|
||||
/*public void AddGameObject(AxiosGameObject gameobject)
|
||||
{
|
||||
gameobject.LoadContent(this);
|
||||
gameobject.RemoveObject += new AxiosGameObject.AxiosGameObjectHandler(RemoveGameObject);
|
||||
this._gameObjects.Add(gameobject);
|
||||
}
|
||||
|
||||
public void AddGameObject(AxiosTimer timer)
|
||||
{
|
||||
timer.LoadContent(this);
|
||||
_timers.Add(timer);
|
||||
}
|
||||
|
||||
public void AddGameObject(AxiosUIObject uiobject)
|
||||
{
|
||||
uiobject.LoadContent(this);
|
||||
uiobject.RemoveObject += new AxiosEvents.AxiosGameObjectHandler(RemoveGameObject);
|
||||
_uiobjects.Add(uiobject);
|
||||
}*/
|
||||
|
||||
public void AddGameObject(object obj)
|
||||
{
|
||||
|
||||
if (obj is AxiosGameObject || obj is AxiosUIObject || obj is AxiosTimer)
|
||||
{
|
||||
AxiosGameObject tmp = obj as AxiosGameObject;
|
||||
tmp.LoadContent(this);
|
||||
|
||||
if (obj is AxiosGameObject || obj is AxiosUIObject)
|
||||
tmp.RemoveObject += new AxiosEvents.AxiosGameObjectHandler(RemoveGameObject);
|
||||
if (obj is AxiosGameObject && !(obj is AxiosUIObject))
|
||||
{
|
||||
_gameObjects.Add(tmp);
|
||||
}
|
||||
else if (obj is AxiosUIObject)
|
||||
{
|
||||
_uiobjects.Add(obj as AxiosUIObject);
|
||||
}
|
||||
else if (obj is AxiosTimer)
|
||||
{
|
||||
_timers.Add(obj as AxiosTimer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void RemoveGameObject(AxiosTimer timer)
|
||||
{
|
||||
_timers.Remove(timer);
|
||||
}
|
||||
|
||||
public void RemoveGameObject(AxiosUIObject uiobject)
|
||||
{
|
||||
uiobject.RemoveObject -= new AxiosGameObject.AxiosGameObjectHandler(RemoveGameObject);
|
||||
uiobject.UnloadContent(this);
|
||||
_uiobjects.Remove(uiobject);
|
||||
}
|
||||
|
||||
public void RemoveGameObject(AxiosGameObject gameobject)
|
||||
{
|
||||
gameobject.RemoveObject -= new AxiosGameObject.AxiosGameObjectHandler(RemoveGameObject);
|
||||
try
|
||||
{
|
||||
gameobject.UnloadContent(this);
|
||||
this._gameObjects.Remove(gameobject);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Not sure what is going on - but in certain cases an exception will be triggered that the body has already been marked for removal
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void RemoveAll()
|
||||
{
|
||||
AxiosLog.Instance.AddLine("Memory usage before cleanup: " + GC.GetTotalMemory(true).ToString(), LoggingFlag.DEBUG);
|
||||
foreach (AxiosGameObject g in _gameObjects)
|
||||
g.UnloadContent(this);
|
||||
foreach (AxiosUIObject ui in _uiobjects)
|
||||
ui.UnloadContent(this);
|
||||
this.World.Clear();
|
||||
this._gameObjects.Clear();
|
||||
_timers.Clear();
|
||||
_uiobjects.Clear();
|
||||
AxiosLog.Instance.AddLine("Memory usage after cleanup: ", LoggingFlag.DEBUG);
|
||||
}
|
||||
|
||||
public override void ExitScreen()
|
||||
{
|
||||
base.ExitScreen();
|
||||
|
||||
}
|
||||
|
||||
public override void LoadContent()
|
||||
{
|
||||
base.LoadContent();
|
||||
|
||||
#if DEBUG
|
||||
if (!Axios.Settings.ScreenSaver)
|
||||
this.DebugSpriteFont = this.ScreenManager.Content.Load<SpriteFont>(this.DebugTextFont);
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Draw(GameTime gameTime)
|
||||
{
|
||||
base.Draw(gameTime);
|
||||
|
||||
foreach (AxiosGameObject g in (from x in (from i in _gameObjects where i is IDrawableAxiosGameObject select (IDrawableAxiosGameObject)i) orderby x.DrawOrder select x))
|
||||
((IDrawableAxiosGameObject)g).Draw(this, gameTime);
|
||||
|
||||
foreach(AxiosUIObject g in (from x in _uiobjects orderby x.DrawOrder select x))
|
||||
((IDrawableAxiosGameObject)g).Draw(this, gameTime);
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
|
||||
{
|
||||
base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
|
||||
|
||||
foreach (AxiosGameObject g in _gameObjects)
|
||||
g.Update(this, gameTime, otherScreenHasFocus, coveredByOtherScreen);
|
||||
|
||||
foreach (AxiosTimer t in _timers)
|
||||
t.Update(this, gameTime, otherScreenHasFocus, coveredByOtherScreen);
|
||||
|
||||
foreach(AxiosUIObject g in _uiobjects)
|
||||
g.Update(this, gameTime, otherScreenHasFocus, coveredByOtherScreen);
|
||||
|
||||
}
|
||||
|
||||
public override void HandleCursor(InputHelper input)
|
||||
{
|
||||
base.HandleCursor(input);
|
||||
HandleMouseEvents(input);
|
||||
|
||||
foreach (AxiosGameObject g in _gameObjects)
|
||||
g.HandleCursor(this, input);
|
||||
}
|
||||
|
||||
private void HandleMouseEvents(InputHelper input)
|
||||
{
|
||||
Vector2 position = this.Camera.ConvertScreenToWorld(input.Cursor);
|
||||
Fixture fix = this.World.TestPoint(position);
|
||||
AxiosGameObject gobj;
|
||||
if (fix != null && fix.UserData != null && fix.UserData is AxiosGameObject)
|
||||
{
|
||||
gobj = (AxiosGameObject)fix.UserData;
|
||||
|
||||
if (gobj != null && gobj != prevobj)
|
||||
{
|
||||
gobj.OnMouseHover(this, input);
|
||||
|
||||
|
||||
if (prevobj != gobj && prevobj != null)
|
||||
prevobj.OnMouseLeave(this, input);
|
||||
}
|
||||
else if (gobj != null)
|
||||
{
|
||||
if (input.IsNewMouseButtonRelease(MouseButtons.LeftButton))
|
||||
{
|
||||
if (prevobj != null)
|
||||
prevobj.OnFocusLeave(this, input);
|
||||
gobj.OnFocusEnter(this, input);
|
||||
gobj.OnMouseUp(this, input);
|
||||
prevfocusobj = gobj;
|
||||
//prevobj = gobj;
|
||||
}
|
||||
|
||||
if (input.IsNewMouseButtonPress(MouseButtons.LeftButton))
|
||||
gobj.OnMouseDown(this, input);
|
||||
}
|
||||
|
||||
if (gobj != null)
|
||||
prevobj = gobj;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (prevobj != null)
|
||||
prevobj.OnMouseLeave(this, input);
|
||||
if (input.IsNewMouseButtonPress(MouseButtons.LeftButton) && prevfocusobj != null)
|
||||
{
|
||||
prevfocusobj.OnFocusLeave(this, input);
|
||||
prevfocusobj = null;
|
||||
}
|
||||
prevobj = null;
|
||||
}
|
||||
|
||||
Vector2 uiobjpos;
|
||||
Rectangle uirect;
|
||||
bool foundobject = false;
|
||||
Vector2 mousepos = ConvertUnits.ToSimUnits(input.Cursor);
|
||||
Vector2 objpos;
|
||||
//System.Diagnostics.Debugger.Break();
|
||||
foreach(AxiosUIObject uiobject in _uiobjects)
|
||||
{
|
||||
uiobjpos = uiobject.Position;
|
||||
objpos = this.Camera.ConvertScreenToWorld(uiobjpos);
|
||||
|
||||
uirect = new Rectangle((int)uiobjpos.X, (int)uiobjpos.Y, (int)ConvertUnits.ToSimUnits(uiobject.Width), (int)ConvertUnits.ToSimUnits(uiobject.Height));
|
||||
|
||||
if (uirect.Contains((int)position.X, (int)position.Y))
|
||||
{
|
||||
|
||||
if (input.IsNewMouseButtonPress(MouseButtons.LeftButton))
|
||||
{
|
||||
uiobject.OnMouseDown(this, input);
|
||||
}
|
||||
|
||||
if (input.IsNewMouseButtonRelease(MouseButtons.LeftButton))
|
||||
{
|
||||
//System.Diagnostics.Debugger.Break();
|
||||
if (prevuifocusobj != uiobject)
|
||||
{
|
||||
uiobject.OnFocusEnter(this, input);
|
||||
if (prevuifocusobj != null)
|
||||
prevuifocusobj.OnFocusLeave(this, input);
|
||||
prevuifocusobj = uiobject;
|
||||
}
|
||||
uiobject.OnMouseUp(this, input);
|
||||
}
|
||||
|
||||
if (prevuiobj != uiobject)
|
||||
{
|
||||
//System.Diagnostics.Debugger.Break();
|
||||
uiobject.OnMouseHover(this, input);
|
||||
if (prevuiobj != null)
|
||||
prevuiobj.OnMouseLeave(this, input);
|
||||
prevuiobj = uiobject;
|
||||
}
|
||||
foundobject = true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
if (!foundobject && prevuiobj != null)
|
||||
{
|
||||
//mouse moved away from object
|
||||
prevuiobj.OnMouseLeave(this, input);
|
||||
prevuiobj = null;
|
||||
}
|
||||
|
||||
if (input.IsNewMouseButtonRelease(MouseButtons.LeftButton))
|
||||
{
|
||||
if (!foundobject && prevuifocusobj != null)
|
||||
{
|
||||
|
||||
prevuifocusobj.OnFocusLeave(this, input);
|
||||
prevuifocusobj = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleInput(InputHelper input, GameTime gameTime)
|
||||
{
|
||||
base.HandleInput(input, gameTime);
|
||||
|
||||
foreach (AxiosGameObject g in _gameObjects)
|
||||
g.HandleInput(this, input, gameTime);
|
||||
|
||||
foreach (AxiosUIObject g in _uiobjects)
|
||||
g.HandleInput(this, input, gameTime);
|
||||
}
|
||||
|
||||
public override void UnloadContent()
|
||||
{
|
||||
base.UnloadContent();
|
||||
//AxiosLog.Instance.AddLine("Memory usage before cleanup: " + GC.GetTotalMemory(true).ToString(), LoggingFlag.DEBUG);
|
||||
foreach (AxiosGameObject g in _gameObjects)
|
||||
g.UnloadContent(this);
|
||||
|
||||
foreach (AxiosUIObject g in _uiobjects)
|
||||
g.UnloadContent(this);
|
||||
|
||||
this._gameObjects.Clear();
|
||||
this._uiobjects.Clear();
|
||||
this.World.Clear();
|
||||
_timers.Clear();
|
||||
_uiobjects.Clear();
|
||||
//AxiosLog.Instance.AddLine("Memory usage after cleanup: " + GC.GetTotalMemory(true).ToString(), LoggingFlag.DEBUG);
|
||||
//AxiosRegularFile f = new AxiosRegularFile("log.log");
|
||||
//f.WriteData(AxiosLog.Instance.GetLog(), FileMode.Append);
|
||||
//AxiosIsolatedFile f = new AxiosIsolatedFile("log.log");
|
||||
//f.WriteData(AxiosLog.Instance.GetLog(), FileMode.Append);
|
||||
//CleanUp();
|
||||
}
|
||||
|
||||
#if WINDOWS
|
||||
// System.Drawing is NOT avaiable on WP7 or Xbox
|
||||
/*
|
||||
* http://stackoverflow.com/a/7394185/195722
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public Texture2D GetTexture(System.Drawing.Bitmap bitmap)
|
||||
{
|
||||
BlendState oldstate = ScreenManager.GraphicsDevice.BlendState;
|
||||
ScreenManager.GraphicsDevice.BlendState = BlendState.AlphaBlend;
|
||||
Texture2D tex = new Texture2D(this.ScreenManager.GraphicsDevice, bitmap.Width, bitmap.Height, true, SurfaceFormat.Color);
|
||||
|
||||
System.Drawing.Imaging.BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||
|
||||
int bufferSize = data.Height * data.Stride;
|
||||
|
||||
//create data buffer
|
||||
byte[] bytes = new byte[bufferSize];
|
||||
|
||||
// copy bitmap data into buffer
|
||||
System.Runtime.InteropServices.Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
|
||||
|
||||
// copy our buffer to the texture
|
||||
tex.SetData(bytes);
|
||||
|
||||
// unlock the bitmap data
|
||||
bitmap.UnlockBits(data);
|
||||
|
||||
this.ScreenManager.GraphicsDevice.BlendState = oldstate;
|
||||
return tex;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
80
axios/Engine/AxiosTimer.cs
Normal file
80
axios/Engine/AxiosTimer.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Axios.Engine.Interfaces;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
/*
|
||||
* Modeled after Nicks' implemenentation
|
||||
* Source: http://www.gamedev.net/topic/473544-how-to-make-a-timer-using-xna/page__view__findpost__p__4107032
|
||||
*
|
||||
*/
|
||||
public class AxiosTimer : IAxiosGameObject
|
||||
{
|
||||
TimeSpan interval = new TimeSpan(0, 0, 1);
|
||||
TimeSpan lastTick = new TimeSpan();
|
||||
private bool _enabled = false;
|
||||
|
||||
public event EventHandler Tick;
|
||||
|
||||
public TimeSpan Interval
|
||||
{
|
||||
get { return interval; }
|
||||
set { interval = value; }
|
||||
}
|
||||
|
||||
public Boolean Enabled
|
||||
{
|
||||
get { return _enabled; }
|
||||
set { _enabled = value; }
|
||||
}
|
||||
|
||||
public AxiosTimer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Update(AxiosGameScreen gameScreen, GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
|
||||
{
|
||||
|
||||
if (_enabled)
|
||||
{
|
||||
if (gameTime.TotalGameTime - lastTick >= interval)
|
||||
{
|
||||
if (Tick != null)
|
||||
Tick(this, null);
|
||||
|
||||
lastTick = gameTime.TotalGameTime;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lastTick = gameTime.TotalGameTime;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void LoadContent(AxiosGameScreen gameScreen)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void HandleInput(AxiosGameScreen gameScreen, FarseerPhysics.SamplesFramework.InputHelper input, Microsoft.Xna.Framework.GameTime gameTime)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void HandleCursor(AxiosGameScreen gameScreen, FarseerPhysics.SamplesFramework.InputHelper input)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void UnloadContent(AxiosGameScreen gameScreen)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
44
axios/Engine/BreakableAxiosGameObject.cs
Normal file
44
axios/Engine/BreakableAxiosGameObject.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using FarseerPhysics.Dynamics;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
class BreakableAxiosGameObject : AxiosGameObject
|
||||
{
|
||||
|
||||
public BreakableBody Body;
|
||||
|
||||
public delegate void BodyBroken(BreakableAxiosGameObject body);
|
||||
|
||||
public event BodyBroken OnBodyBreak;
|
||||
|
||||
protected bool _calledBodyBroken = false;
|
||||
|
||||
public override void LoadContent(AxiosGameScreen gameScreen)
|
||||
{
|
||||
base.LoadContent(gameScreen);
|
||||
|
||||
Body = new BreakableBody();
|
||||
}
|
||||
|
||||
protected virtual void LoadSimpleBreakableBody()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Update(AxiosGameScreen gameScreen, Microsoft.Xna.Framework.GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
|
||||
{
|
||||
base.Update(gameScreen, gameTime, otherScreenHasFocus, coveredByOtherScreen);
|
||||
|
||||
if (!_calledBodyBroken)
|
||||
{
|
||||
if (Body.Broken == true)
|
||||
OnBodyBreak(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
49
axios/Engine/ComplexAxiosGameObject.cs
Normal file
49
axios/Engine/ComplexAxiosGameObject.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
using Axios.Engine;
|
||||
using Axios.Engine.Interfaces;
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
|
||||
public abstract class ComplexAxiosGameObject : AxiosGameObject
|
||||
{
|
||||
|
||||
public List<SimpleAxiosGameObject> GameObjects;
|
||||
|
||||
public ComplexAxiosGameObject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void LoadContent(AxiosGameScreen gameScreen)
|
||||
{
|
||||
base.LoadContent(gameScreen);
|
||||
|
||||
CreateObjects(gameScreen);
|
||||
|
||||
foreach (SimpleAxiosGameObject obj in GameObjects)
|
||||
{
|
||||
gameScreen.AddGameObject(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override void OnRemove(AxiosGameObject gameObject)
|
||||
{
|
||||
base.OnRemove(gameObject);
|
||||
|
||||
foreach (SimpleAxiosGameObject g in GameObjects)
|
||||
g.Remove();
|
||||
}
|
||||
|
||||
public abstract void CreateObjects(AxiosGameScreen gameScreen);
|
||||
}
|
||||
|
||||
}
|
18
axios/Engine/Data/AxiosCSV.cs
Normal file
18
axios/Engine/Data/AxiosCSV.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Axios.Engine.File;
|
||||
|
||||
namespace Axios.Engine.Data
|
||||
{
|
||||
class AxiosCSV
|
||||
{
|
||||
private AxiosFile _file;
|
||||
public AxiosCSV(AxiosFile file)
|
||||
{
|
||||
_file = file;
|
||||
}
|
||||
}
|
||||
}
|
252
axios/Engine/Data/AxiosDataTable.cs
Normal file
252
axios/Engine/Data/AxiosDataTable.cs
Normal file
@@ -0,0 +1,252 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.Collections;
|
||||
|
||||
namespace Axios.Engine.Data
|
||||
{
|
||||
#if USECUSTOMDATATABLE
|
||||
public enum CollectionChangeAction
|
||||
{
|
||||
Add,
|
||||
Remove,
|
||||
Refresh
|
||||
}
|
||||
|
||||
|
||||
|
||||
public delegate void CollectionChangeEventHandler(
|
||||
Object sender,
|
||||
CollectionChangeEventArgs e
|
||||
);
|
||||
|
||||
class DataTable
|
||||
{
|
||||
private DataColumnCollection _columnCollection = new DataColumnCollection();
|
||||
private DataRowCollection _rowCollection = new DataRowCollection();
|
||||
public DataTable()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DataColumnCollection Columns
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._columnCollection;
|
||||
}
|
||||
private set
|
||||
{
|
||||
this._columnCollection = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return _columnCollection.Count();
|
||||
}
|
||||
}
|
||||
|
||||
public DataRowCollection Rows
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._rowCollection;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._rowCollection = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DataRow NewRow()
|
||||
{
|
||||
DataRow r = new DataRow();
|
||||
r.Table = this;
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DataRowCollection
|
||||
{
|
||||
private List<DataRow> _rows = new List<DataRow>();
|
||||
|
||||
public DataRowCollection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*public AxiosDataRow Add(params Object[] values)
|
||||
{
|
||||
AxiosDataRow row = new AxiosDataRow();
|
||||
//row.Table
|
||||
foreach (object obj in values)
|
||||
{
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
public void Add(DataRow row)
|
||||
{
|
||||
_rows.Add(row);
|
||||
}
|
||||
}
|
||||
|
||||
class DataRow
|
||||
{
|
||||
private DataTable _table;
|
||||
private Dictionary<string, object> _row = new Dictionary<string, object>();
|
||||
|
||||
public DataRow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Object this[string columnName]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_row.ContainsKey(columnName))
|
||||
return _row[columnName];
|
||||
else
|
||||
throw new ArgumentException("The column specified by " + columnName + " cannot be found.");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_row.ContainsKey(columnName))
|
||||
_row[columnName] = value;
|
||||
else
|
||||
throw new ArgumentException("The column specified by " + columnName + " cannot be found.");
|
||||
}
|
||||
}
|
||||
|
||||
//Does this really reference a list of ints rather than a list of strings?
|
||||
public Object this[int columnIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
return _row.ElementAt(columnIndex).Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_row[_row.ElementAt(columnIndex).Key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DataTable Table
|
||||
{
|
||||
get
|
||||
{
|
||||
return _table;
|
||||
}
|
||||
set
|
||||
{
|
||||
_row.Clear();
|
||||
foreach (DataColumn col in _table.Columns)
|
||||
_row[col.ColumnName] = "";
|
||||
this._table = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DataColumn
|
||||
{
|
||||
private string _columnName;
|
||||
private Type _datatype;
|
||||
public DataColumn(string columnName, Type dataType)
|
||||
{
|
||||
_columnName = columnName;
|
||||
_datatype = dataType;
|
||||
}
|
||||
|
||||
public string ColumnName
|
||||
{
|
||||
get
|
||||
{
|
||||
return _columnName;
|
||||
}
|
||||
set
|
||||
{
|
||||
_columnName = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DataColumnCollection : IEnumerable<DataColumn>
|
||||
{
|
||||
List<DataColumn> _datacolumns = new List<DataColumn>();
|
||||
|
||||
public event CollectionChangeEventHandler CollectionChanged;
|
||||
|
||||
public DataColumnCollection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DataColumn Add(string columnName)
|
||||
{
|
||||
DataColumn col = new DataColumn(columnName, typeof(string));
|
||||
_datacolumns.Add(col);
|
||||
CollectionChanged(this, new CollectionChangeEventArgs(CollectionChangeAction.Add, col));
|
||||
return col;
|
||||
}
|
||||
|
||||
public DataColumn Add(string columnName, Type dataType)
|
||||
{
|
||||
DataColumn col = new DataColumn(columnName, dataType);
|
||||
_datacolumns.Add(col);
|
||||
return col;
|
||||
}
|
||||
|
||||
public void Add(DataColumn column)
|
||||
{
|
||||
_datacolumns.Add(column);
|
||||
}
|
||||
|
||||
public void Remove(DataColumn column)
|
||||
{
|
||||
_datacolumns.Remove(column);
|
||||
}
|
||||
|
||||
public void Remove(string column)
|
||||
{
|
||||
for (int i = 0; i < _datacolumns.Count; i++)
|
||||
{
|
||||
if (_datacolumns[i].ColumnName == column)
|
||||
{
|
||||
_datacolumns.RemoveAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
_datacolumns.RemoveAt(index);
|
||||
}
|
||||
|
||||
public int Count()
|
||||
{
|
||||
return _datacolumns.Count();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IEnumerator<DataColumn> GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return _datacolumns.GetEnumerator();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
43
axios/Engine/Data/DataEvents.cs
Normal file
43
axios/Engine/Data/DataEvents.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Axios.Engine.Data
|
||||
{
|
||||
#if USECUSTOMDATATABLE
|
||||
public class CollectionChangeEventArgs : EventArgs
|
||||
{
|
||||
private object _element;
|
||||
private CollectionChangeAction _action;
|
||||
public CollectionChangeEventArgs(CollectionChangeAction action, Object element)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public object Element
|
||||
{
|
||||
get
|
||||
{
|
||||
return _element;
|
||||
}
|
||||
private set
|
||||
{
|
||||
_element = value;
|
||||
}
|
||||
}
|
||||
|
||||
public CollectionChangeAction Action
|
||||
{
|
||||
get
|
||||
{
|
||||
return _action;
|
||||
}
|
||||
set
|
||||
{
|
||||
_action = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
175
axios/Engine/DrawableAxiosGameObject.cs
Normal file
175
axios/Engine/DrawableAxiosGameObject.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
using Axios.Engine.Interfaces;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
public class DrawableAxiosGameObject : AxiosGameObject, IDrawableAxiosGameObject
|
||||
{
|
||||
protected int _draworder;
|
||||
protected Texture2D Texture;
|
||||
//protected float _scale = 1f;
|
||||
public Vector2 Position = new Vector2();
|
||||
public Vector2 Origin = new Vector2();
|
||||
|
||||
protected Boolean _adjustunits = true;
|
||||
protected Boolean _relativetocamera = true;
|
||||
|
||||
public override void LoadContent(AxiosGameScreen gameScreen)
|
||||
{
|
||||
base.LoadContent(gameScreen);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*public float Scale
|
||||
{
|
||||
get { return _scale; }
|
||||
set { _scale = value; }
|
||||
}*/
|
||||
|
||||
public virtual void Draw(AxiosGameScreen gameScreen, GameTime gameTime)
|
||||
{
|
||||
/*#if DEBUG
|
||||
System.Diagnostics.Debugger.Break();
|
||||
#endif*/
|
||||
if (_relativetocamera)
|
||||
gameScreen.ScreenManager.SpriteBatch.Begin(0, null, null, null, null, null, gameScreen.Camera.View);
|
||||
else
|
||||
gameScreen.ScreenManager.SpriteBatch.Begin();
|
||||
if (_adjustunits)
|
||||
gameScreen.ScreenManager.SpriteBatch.Draw(Texture, ConvertUnits.ToDisplayUnits(Position), null, Color.White, 0, Origin, _scale, SpriteEffects.None, 0);
|
||||
else
|
||||
gameScreen.ScreenManager.SpriteBatch.Draw(Texture, Position, null, Color.White, 0, Origin, _scale, SpriteEffects.None, 0);
|
||||
gameScreen.ScreenManager.SpriteBatch.End();
|
||||
}
|
||||
|
||||
public int DrawOrder
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._draworder;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._draworder = value;
|
||||
}
|
||||
}
|
||||
|
||||
//Copied/adapted from http://create.msdn.com/en-US/education/catalog/tutorial/collision_2d_perpixel
|
||||
/// <summary>
|
||||
/// This method is a very simple collision detection based on textures.
|
||||
/// While Farseer (Box2D) is an excellent physics engine - it doesn't know, or care, about the textures.
|
||||
/// This method does a AABB test and if that is true - it tests the individual pixels in the textures.
|
||||
/// </summary>
|
||||
/// <param name="obj">Object to test against</param>
|
||||
/// <returns>true if the object is colliding, false if it isn't</returns>
|
||||
public bool CollidesWith(DrawableAxiosGameObject obj)
|
||||
{
|
||||
Rectangle thisobj = new Rectangle((int)this.Position.X, (int)this.Position.Y, this.Texture.Width, this.Texture.Height);
|
||||
Rectangle otherobj = new Rectangle((int)obj.Position.X, (int)obj.Position.Y, obj.Texture.Width, obj.Texture.Height);
|
||||
|
||||
if (thisobj.Intersects(otherobj))
|
||||
{
|
||||
|
||||
int top = Math.Max(thisobj.Top, otherobj.Top);
|
||||
int bottom = Math.Min(thisobj.Bottom, otherobj.Bottom);
|
||||
int left = Math.Max(thisobj.Left, otherobj.Left);
|
||||
int right = Math.Min(thisobj.Right, otherobj.Right);
|
||||
|
||||
Color[] thisobjcolor = new Color[this.Texture.Width * this.Texture.Height];
|
||||
Color[] otherobjcolor = new Color[obj.Texture.Width * obj.Texture.Height];
|
||||
|
||||
Texture.GetData(thisobjcolor);
|
||||
obj.Texture.GetData(otherobjcolor);
|
||||
|
||||
// Check every point within the intersection bounds
|
||||
for (int y = top; y < bottom; y++)
|
||||
{
|
||||
for (int x = left; x < right; x++)
|
||||
{
|
||||
// Get the color of both pixels at this point
|
||||
Color colorA = thisobjcolor[(x - thisobj.Left) +
|
||||
(y - thisobj.Top) * thisobj.Width];
|
||||
Color colorB = otherobjcolor[(x - otherobj.Left) +
|
||||
(y - otherobj.Top) * otherobj.Width];
|
||||
|
||||
// If both pixels are not completely transparent,
|
||||
if (colorA.A != 0 && colorB.A != 0)
|
||||
{
|
||||
// then an intersection has been found
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Copied/adapted from http://create.msdn.com/en-US/education/catalog/tutorial/collision_2d_perpixel
|
||||
/// <summary>
|
||||
/// This method is a very simple collision detection based on textures.
|
||||
/// While Farseer (Box2D) is an excellent physics engine - it doesn't know, or care, about the textures.
|
||||
/// This method does a AABB test and if that is true - it tests the individual pixels in the textures.
|
||||
/// </summary>
|
||||
/// <param name="obj">Object to test against</param>
|
||||
/// <returns>true if the object is colliding, false if it isn't</returns>
|
||||
public bool CollidesWith(Vector2 pos, Rectangle rect)
|
||||
{
|
||||
Rectangle thisobj = new Rectangle((int)this.Position.X, (int)this.Position.Y, this.Texture.Width, this.Texture.Height);
|
||||
Rectangle otherobj = new Rectangle((int)pos.X, (int)pos.Y, rect.Width, rect.Height);
|
||||
|
||||
Texture2D obj = new Texture2D(Texture.GraphicsDevice, rect.Width, rect.Height);
|
||||
Color[] arr = new Color[rect.Width * rect.Height];
|
||||
for (int i = 0; i < rect.Width * rect.Height; ++i)
|
||||
arr[i] = Color.Black;
|
||||
|
||||
obj.SetData(arr);
|
||||
|
||||
if (thisobj.Intersects(otherobj))
|
||||
{
|
||||
|
||||
int top = Math.Max(thisobj.Top, otherobj.Top);
|
||||
int bottom = Math.Min(thisobj.Bottom, otherobj.Bottom);
|
||||
int left = Math.Max(thisobj.Left, otherobj.Left);
|
||||
int right = Math.Min(thisobj.Right, otherobj.Right);
|
||||
|
||||
Color[] thisobjcolor = new Color[this.Texture.Width * this.Texture.Height];
|
||||
Color[] otherobjcolor = new Color[obj.Width * obj.Height];
|
||||
|
||||
Texture.GetData(thisobjcolor);
|
||||
obj.GetData(otherobjcolor);
|
||||
|
||||
// Check every point within the intersection bounds
|
||||
for (int y = top; y < bottom; y++)
|
||||
{
|
||||
for (int x = left; x < right; x++)
|
||||
{
|
||||
// Get the color of both pixels at this point
|
||||
Color colorA = thisobjcolor[(x - thisobj.Left) +
|
||||
(y - thisobj.Top) * thisobj.Width];
|
||||
Color colorB = otherobjcolor[(x - otherobj.Left) +
|
||||
(y - otherobj.Top) * otherobj.Width];
|
||||
|
||||
// If both pixels are not completely transparent,
|
||||
if (colorA.A != 0 && colorB.A != 0)
|
||||
{
|
||||
// then an intersection has been found
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
70
axios/Engine/DrawableBreakableAxiosGameObject.cs
Normal file
70
axios/Engine/DrawableBreakableAxiosGameObject.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Axios.Engine.Interfaces;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
#if DFDSF
|
||||
class DrawableBreakableAxiosGameObject : AxiosBreakableGameObject, IDrawableAxiosGameObject
|
||||
{
|
||||
protected int _draworder;
|
||||
|
||||
protected new List<SimpleDrawableAxiosGameObject> BodyParts = new List<SimpleDrawableAxiosGameObject>();
|
||||
protected new SimpleDrawableAxiosGameObject BodyPart = null;
|
||||
|
||||
protected Boolean _adjustunits = true;
|
||||
protected Boolean _relativetocamera = true;
|
||||
|
||||
public int DrawOrder
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._draworder;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._draworder = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override void LoadContent(AxiosGameScreen gameScreen)
|
||||
{
|
||||
base.LoadContent(gameScreen);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public virtual void Draw(AxiosGameScreen gameScreen, GameTime gameTime)
|
||||
{
|
||||
|
||||
/*for(int i = 0; i < Body.Parts.Count; i++)
|
||||
{
|
||||
if (_relativetocamera)
|
||||
gameScreen.ScreenManager.SpriteBatch.Begin(0, null, null, null, null, null, gameScreen.Camera.View);
|
||||
else
|
||||
gameScreen.ScreenManager.SpriteBatch.Begin();
|
||||
if (_adjustunits)
|
||||
DrawObject(gameScreen.ScreenManager.SpriteBatch, Textures[i], Body.Parts[i].Body, Origins[i], true);
|
||||
else
|
||||
DrawObject(gameScreen.ScreenManager.SpriteBatch, Textures[i], Body.Parts[i].Body, Origins[i]);
|
||||
gameScreen.ScreenManager.SpriteBatch.End();
|
||||
}*/
|
||||
if (_isbroken)
|
||||
if (BodyParts.Count > 0)
|
||||
foreach (SimpleDrawableAxiosGameObject obj in BodyParts)
|
||||
obj.Draw(gameScreen, gameTime);
|
||||
else
|
||||
if (BodyPart != null)
|
||||
BodyPart.Draw(gameScreen, gameTime);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
24
axios/Engine/Extensions/String.cs
Normal file
24
axios/Engine/Extensions/String.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Axios.Engine.Extenions
|
||||
{
|
||||
public static class AxiosExtensions_String
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the string slice between the two indexes.
|
||||
/// Inclusive for start index, exclusive for end index.
|
||||
/// </summary>
|
||||
public static string Slice(this string source, int start, int end)
|
||||
{
|
||||
if (end < 0) // Keep this for negative end support
|
||||
{
|
||||
end = source.Length + end;
|
||||
}
|
||||
int len = end - start; // Calculate length
|
||||
return source.Substring(start, len); // Return Substring of length
|
||||
}
|
||||
}
|
||||
}
|
199
axios/Engine/Extensions/Texture2D.cs
Normal file
199
axios/Engine/Extensions/Texture2D.cs
Normal file
@@ -0,0 +1,199 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
|
||||
namespace Axios.Engine.Extenions
|
||||
{
|
||||
public enum TextureUnionLocation {
|
||||
Right,
|
||||
Bottom,
|
||||
Top,
|
||||
Left
|
||||
}
|
||||
public static class AxiosExtensions_Texture2D
|
||||
{
|
||||
/// http://gamedev.stackexchange.com/questions/11584/xna-splitting-one-large-texture-into-an-array-of-smaller-textures
|
||||
/// <summary>
|
||||
/// Splits a texture into an array of smaller textures of the specified size.
|
||||
/// </summary>
|
||||
/// <param name="original">The texture to be split into smaller textures</param>
|
||||
/// <param name="partWidth">The width of each of the smaller textures that will be contained in the returned array.</param>
|
||||
/// <param name="partHeight">The height of each of the smaller textures that will be contained in the returned array.</param>
|
||||
/// <returns>A multidimensional array represting the rows/coulmns in the texture.</returns>
|
||||
public static Texture2D[,] Split(this Texture2D original, int partWidth, int partHeight, out int xCount, out int yCount)
|
||||
{
|
||||
yCount = original.Height / partHeight; //+ (partHeight % original.Height == 0 ? 0 : 1);//The number of textures in each horizontal row
|
||||
xCount = original.Width / partWidth; //+(partWidth % original.Width == 0 ? 0 : 1);//The number of textures in each vertical column
|
||||
Texture2D[,] r = new Texture2D[yCount,xCount];//Number of parts = (area of original) / (area of each part).
|
||||
int dataPerPart = partWidth * partHeight;//Number of pixels in each of the split parts
|
||||
|
||||
//Get the pixel data from the original texture:
|
||||
Color[] originalData = new Color[original.Width * original.Height];
|
||||
original.GetData<Color>(originalData);
|
||||
|
||||
//int index = 0;
|
||||
int currxidx = 0;
|
||||
int curryidx = 0;
|
||||
for (int y = 0; y < yCount * partHeight; y += partHeight)
|
||||
{
|
||||
for (int x = 0; x < xCount * partWidth; x += partWidth)
|
||||
{
|
||||
//The texture at coordinate {x, y} from the top-left of the original texture
|
||||
Texture2D part = new Texture2D(original.GraphicsDevice, partWidth, partHeight);
|
||||
//The data for part
|
||||
Color[] partData = new Color[dataPerPart];
|
||||
|
||||
//Fill the part data with colors from the original texture
|
||||
for (int py = 0; py < partHeight; py++)
|
||||
for (int px = 0; px < partWidth; px++)
|
||||
{
|
||||
int partIndex = px + py * partWidth;
|
||||
//If a part goes outside of the source texture, then fill the overlapping part with Color.Transparent
|
||||
if (y + py >= original.Height || x + px >= original.Width)
|
||||
partData[partIndex] = Color.Transparent;
|
||||
else
|
||||
partData[partIndex] = originalData[(x + px) + (y + py) * original.Width];
|
||||
}
|
||||
|
||||
//Fill the part with the extracted data
|
||||
part.SetData<Color>(partData);
|
||||
//Stick the part in the return array:
|
||||
r[curryidx, currxidx] = part;
|
||||
curryidx++;
|
||||
}
|
||||
curryidx = 0;
|
||||
curryidx++;
|
||||
}
|
||||
//Return the array of parts.
|
||||
return r;
|
||||
}
|
||||
|
||||
// http://gamedev.stackexchange.com/questions/11584/xna-splitting-one-large-texture-into-an-array-of-smaller-textures
|
||||
/// <summary>
|
||||
/// Splits a texture into an array of smaller textures of the specified size.
|
||||
/// </summary>
|
||||
/// <param name="original">The texture to be split into smaller textures</param>
|
||||
/// <param name="partWidth">The width of each of the smaller textures that will be contained in the returned array.</param>
|
||||
/// <param name="partHeight">The height of each of the smaller textures that will be contained in the returned array.</param>
|
||||
/// <param name="offsetWidth">The width offset whitespace to ignore</param>
|
||||
/// <param name="offsetHeight">The height offset whitespace to ignore</param>
|
||||
/// <param name="xCount">The number of textures per row</param>
|
||||
/// <param name="yCount">The number of texture per column</param>
|
||||
/// <returns>A multidimensional array represting the rows/coulmns in the texture.</returns>
|
||||
public static Texture2D[,] Split(this Texture2D original, int partWidth, int partHeight, int offsetWidth, int offsetHeight, out int xCount, out int yCount)
|
||||
{
|
||||
yCount = original.Height / partHeight; //+ (partHeight % original.Height == 0 ? 0 : 1);//The number of textures in each horizontal row
|
||||
xCount = original.Width / partWidth; //+(partWidth % original.Width == 0 ? 0 : 1);//The number of textures in each vertical column
|
||||
|
||||
//xCount -= (xCount % offsetWidth);
|
||||
//yCount -= (yCount % offsetHeight);
|
||||
Texture2D[,] r = new Texture2D[yCount, xCount];//Number of parts = (area of original) / (area of each part).
|
||||
int dataPerPart = partWidth * partHeight;//Number of pixels in each of the split parts
|
||||
|
||||
//Get the pixel data from the original texture:
|
||||
Color[] originalData = new Color[original.Width * original.Height];
|
||||
original.GetData<Color>(originalData);
|
||||
|
||||
//int index = 0;
|
||||
int currxidx = 0;
|
||||
int curryidx = 0;
|
||||
for (int y = 0; y < yCount * partHeight; y += (partHeight + offsetHeight))
|
||||
{
|
||||
for (int x = 0; x < xCount * partWidth; x += (partWidth + offsetWidth))
|
||||
{
|
||||
//The texture at coordinate {x, y} from the top-left of the original texture
|
||||
Texture2D part = new Texture2D(original.GraphicsDevice, partWidth, partHeight);
|
||||
//The data for part
|
||||
Color[] partData = new Color[dataPerPart];
|
||||
|
||||
//Fill the part data with colors from the original texture
|
||||
for (int py = 0; py < partHeight; py++)
|
||||
for (int px = 0; px < partWidth; px++)
|
||||
{
|
||||
int partIndex = px + py * partWidth;
|
||||
//If a part goes outside of the source texture, then fill the overlapping part with Color.Transparent
|
||||
if (y + py >= original.Height || x + px >= original.Width)
|
||||
partData[partIndex] = Color.Transparent;
|
||||
else
|
||||
partData[partIndex] = originalData[(x + px) + (y + py) * original.Width];
|
||||
}
|
||||
|
||||
//Fill the part with the extracted data
|
||||
part.SetData<Color>(partData);
|
||||
//Stick the part in the return array:
|
||||
r[curryidx, currxidx] = part;
|
||||
currxidx++;
|
||||
}
|
||||
currxidx = 0;
|
||||
curryidx++;
|
||||
}
|
||||
//Return the array of parts.
|
||||
return r;
|
||||
}
|
||||
|
||||
/// http://forums.create.msdn.com/forums/t/79258.aspx
|
||||
/// <summary>
|
||||
/// Combines one texture with another
|
||||
/// </summary>
|
||||
/// <param name="original">The first texture</param>
|
||||
/// <param name="texturetoadd">The second texture</param>
|
||||
/// <param name="loc">The location where to put the texture in reference to the first</param>
|
||||
/// <returns></returns>
|
||||
public static Texture2D Union(this Texture2D original, Texture2D texturetoadd, TextureUnionLocation loc)
|
||||
{
|
||||
int newWidth = 0;
|
||||
int newHeight = 0;
|
||||
if (loc == TextureUnionLocation.Right || loc == TextureUnionLocation.Left)
|
||||
{
|
||||
newWidth = original.Width + texturetoadd.Width;
|
||||
newHeight = original.Height;
|
||||
}
|
||||
else if (loc == TextureUnionLocation.Bottom || loc == TextureUnionLocation.Top)
|
||||
{
|
||||
newWidth = original.Width;
|
||||
newHeight = original.Height + texturetoadd.Height;
|
||||
}
|
||||
Texture2D r = new Texture2D(original.GraphicsDevice, newWidth, newHeight);
|
||||
Color[] originaldata = new Color[original.Width * original.Height];
|
||||
Color[] texturetoadddata = new Color[texturetoadd.Width * texturetoadd.Height];
|
||||
Color[] newtexturedata = new Color[newHeight * newWidth];
|
||||
|
||||
original.GetData(originaldata);
|
||||
texturetoadd.GetData(texturetoadddata);
|
||||
|
||||
if (loc == TextureUnionLocation.Right)
|
||||
{
|
||||
r.SetData(0, new Rectangle(0, 0, original.Width, original.Height), originaldata, 0, original.Width * original.Height);
|
||||
|
||||
r.SetData(0, new Rectangle(original.Width, 0, texturetoadd.Width, texturetoadd.Height), texturetoadddata, 0, texturetoadd.Width * texturetoadd.Height);
|
||||
}
|
||||
else if (loc == TextureUnionLocation.Bottom)
|
||||
{
|
||||
r.SetData(0, new Rectangle(0, 0, original.Width, original.Height), originaldata, 0, original.Width * original.Height);
|
||||
|
||||
r.SetData(0, new Rectangle(0, original.Height, texturetoadd.Width, texturetoadd.Height), texturetoadddata, 0, texturetoadd.Width * texturetoadd.Height);
|
||||
}
|
||||
else if (loc == TextureUnionLocation.Left)
|
||||
{
|
||||
r.SetData(0, new Rectangle(0, 0, texturetoadd.Width, texturetoadd.Height), texturetoadddata, 0, texturetoadd.Width * texturetoadd.Height);
|
||||
|
||||
r.SetData(0, new Rectangle(texturetoadd.Width, 0, original.Width, original.Height), originaldata, 0, original.Width * original.Height);
|
||||
}
|
||||
else if (loc == TextureUnionLocation.Top)
|
||||
{
|
||||
r.SetData(0, new Rectangle(0, 0, texturetoadd.Width, texturetoadd.Height), texturetoadddata, 0, texturetoadd.Width * texturetoadd.Height);
|
||||
|
||||
r.SetData(0, new Rectangle(0, texturetoadd.Height, original.Width, original.Height), originaldata, 0, original.Width * original.Height);
|
||||
}
|
||||
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
35
axios/Engine/File/AxiosFile.cs
Normal file
35
axios/Engine/File/AxiosFile.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
using Axios.Engine.Interfaces;
|
||||
|
||||
namespace Axios.Engine.File
|
||||
{
|
||||
public class AxiosFile : IAxiosFile
|
||||
{
|
||||
protected string _content;
|
||||
|
||||
public String Content
|
||||
{
|
||||
get { return _content; }
|
||||
protected set { this._content = value; }
|
||||
}
|
||||
|
||||
protected string _filename;
|
||||
|
||||
|
||||
|
||||
public virtual void WriteData(string data, FileMode mode)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual string ReadData()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
59
axios/Engine/File/AxiosIsolatedFile.cs
Normal file
59
axios/Engine/File/AxiosIsolatedFile.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO.IsolatedStorage;
|
||||
using System.IO;
|
||||
|
||||
using Axios.Engine.Interfaces;
|
||||
|
||||
namespace Axios.Engine.File
|
||||
{
|
||||
public class AxiosIsolatedFile : AxiosFile, IAxiosFile
|
||||
{
|
||||
|
||||
public AxiosIsolatedFile(string filename)
|
||||
{
|
||||
this._filename = filename;
|
||||
}
|
||||
|
||||
public override void WriteData(string data, FileMode mode)
|
||||
{
|
||||
//Make sure that a proper mode is passed
|
||||
if (mode == FileMode.Append
|
||||
|| mode == FileMode.Create
|
||||
|| mode == FileMode.CreateNew
|
||||
|| mode == FileMode.Truncate)
|
||||
{
|
||||
#if WINDOWS
|
||||
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForDomain();
|
||||
#else
|
||||
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
|
||||
#endif
|
||||
IsolatedStorageFileStream fs = null;
|
||||
fs = savegameStorage.OpenFile(_filename, mode);
|
||||
StreamWriter sw = new StreamWriter(fs);
|
||||
sw.Write(data);
|
||||
sw.Close();
|
||||
this.Content = data;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ReadData()
|
||||
{
|
||||
string ret = "";
|
||||
#if WINDOWS
|
||||
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForDomain();
|
||||
#else
|
||||
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
|
||||
#endif
|
||||
IsolatedStorageFileStream fs = null;
|
||||
fs = savegameStorage.OpenFile(_filename, System.IO.FileMode.Open);
|
||||
StreamReader sr = new StreamReader(fs);
|
||||
ret = sr.ReadToEnd();
|
||||
sr.Close();
|
||||
Content = ret;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
44
axios/Engine/File/AxiosRegularFile.cs
Normal file
44
axios/Engine/File/AxiosRegularFile.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
using Axios.Engine.Interfaces;
|
||||
|
||||
namespace Axios.Engine.File
|
||||
{
|
||||
public class AxiosRegularFile : AxiosFile, IAxiosFile
|
||||
{
|
||||
public AxiosRegularFile(string file)
|
||||
{
|
||||
_filename = file;
|
||||
}
|
||||
|
||||
public override void WriteData(string data, FileMode mode)
|
||||
{
|
||||
//Make sure that a proper mode is passed
|
||||
if (mode == FileMode.Append
|
||||
|| mode == FileMode.Create
|
||||
|| mode == FileMode.CreateNew
|
||||
|| mode == FileMode.Truncate)
|
||||
{
|
||||
FileStream fs = new FileStream(_filename, mode);
|
||||
StreamWriter sw = new StreamWriter(fs);
|
||||
sw.Write(data);
|
||||
sw.Close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override string ReadData()
|
||||
{
|
||||
string ret = "";
|
||||
FileStream fs = new FileStream(_filename, FileMode.Open);
|
||||
StreamReader sr = new StreamReader(fs);
|
||||
ret = sr.ReadToEnd();
|
||||
sr.Close();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
35
axios/Engine/File/AxiosTitleFile.cs
Normal file
35
axios/Engine/File/AxiosTitleFile.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Axios.Engine.File;
|
||||
using Axios.Engine.Interfaces;
|
||||
|
||||
namespace Axios.Engine.File
|
||||
{
|
||||
public class AxiosTitleFile : AxiosFile, IAxiosFile
|
||||
{
|
||||
public AxiosTitleFile(string filename)
|
||||
{
|
||||
//Title Files can only be opened for reading!
|
||||
|
||||
this._filename = filename;
|
||||
}
|
||||
|
||||
|
||||
public override void WriteData(string data, FileMode mode)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ReadData()
|
||||
{
|
||||
StreamReader sr = new StreamReader(TitleContainer.OpenStream(_filename));
|
||||
this.Content = sr.ReadToEnd();
|
||||
sr.Close();
|
||||
return this.Content;
|
||||
}
|
||||
}
|
||||
}
|
14
axios/Engine/Interfaces/IAxiosFile.cs
Normal file
14
axios/Engine/Interfaces/IAxiosFile.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Axios.Engine.Interfaces
|
||||
{
|
||||
interface IAxiosFile
|
||||
{
|
||||
void WriteData(string data, FileMode mode);
|
||||
string ReadData();
|
||||
}
|
||||
}
|
19
axios/Engine/Interfaces/IAxiosGameObject.cs
Normal file
19
axios/Engine/Interfaces/IAxiosGameObject.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
|
||||
|
||||
namespace Axios.Engine.Interfaces
|
||||
{
|
||||
interface IAxiosGameObject
|
||||
{
|
||||
void Update(AxiosGameScreen gameScreen, GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen);
|
||||
void LoadContent(AxiosGameScreen gameScreen);
|
||||
void HandleInput(AxiosGameScreen gameScreen, InputHelper input, GameTime gameTime);
|
||||
void HandleCursor(AxiosGameScreen gameScreen, InputHelper input);
|
||||
void UnloadContent(AxiosGameScreen gameScreen);
|
||||
}
|
||||
}
|
18
axios/Engine/Interfaces/IDrawableAxiosGameObject.cs
Normal file
18
axios/Engine/Interfaces/IDrawableAxiosGameObject.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Axios.Engine.Interfaces
|
||||
{
|
||||
interface IDrawableAxiosGameObject
|
||||
{
|
||||
int DrawOrder
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
void Draw(AxiosGameScreen gameScreen, GameTime gameTime);
|
||||
}
|
||||
}
|
52
axios/Engine/Log/AxiosLog.cs
Normal file
52
axios/Engine/Log/AxiosLog.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Axios.Engine;
|
||||
|
||||
namespace Axios.Engine.Log
|
||||
{
|
||||
[Flags]
|
||||
public enum LoggingFlag
|
||||
{
|
||||
NONE = 0,
|
||||
DEBUG = 1,
|
||||
INFO = 2,
|
||||
WARN = 4,
|
||||
ERROR = 8,
|
||||
FATAL = 16,
|
||||
ALL = 32
|
||||
}
|
||||
public class AxiosLog : Singleton<AxiosLog>
|
||||
{
|
||||
private List<string> _log;
|
||||
|
||||
public AxiosLog()
|
||||
{
|
||||
_log = new List<string>();
|
||||
}
|
||||
|
||||
public void AddLine(string line, LoggingFlag flag)
|
||||
{
|
||||
|
||||
if (flag <= Settings.Loglevel)
|
||||
_log.Add("[" + DateTime.Now.ToString("M/d/yyyy H:mm:ss") + " - " + flag.ToString() + "]" + line);
|
||||
}
|
||||
|
||||
public List<string> GetLogList()
|
||||
{
|
||||
return _log;
|
||||
}
|
||||
|
||||
public string GetLog(string seperator)
|
||||
{
|
||||
return String.Join(seperator, _log.ToArray()) + seperator;
|
||||
}
|
||||
|
||||
public string GetLog()
|
||||
{
|
||||
return GetLog("\r\n");
|
||||
}
|
||||
}
|
||||
}
|
66
axios/Engine/SimpleAxiosGameObject.cs
Normal file
66
axios/Engine/SimpleAxiosGameObject.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
using Axios.Engine.Log;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
public abstract class SimpleAxiosGameObject : AxiosGameObject
|
||||
{
|
||||
public Body BodyPart;
|
||||
public Vector2 Position;
|
||||
public Vector2 Origin;
|
||||
|
||||
public bool ApplyConstantVelocity = false;
|
||||
public Vector2 ConstantVelocity;
|
||||
|
||||
public SimpleAxiosGameObject()
|
||||
{
|
||||
AxiosLog.Instance.AddLine("[Axios Engine] - Creating SimpleAxiosGameObject " + Name, LoggingFlag.DEBUG);
|
||||
Position = new Vector2();
|
||||
}
|
||||
|
||||
public override void UnloadContent(AxiosGameScreen gameScreen)
|
||||
{
|
||||
AxiosLog.Instance.AddLine("[Axios Engine] - Unloading SimpleAxiosGameObject " + Name, LoggingFlag.DEBUG);
|
||||
base.UnloadContent(gameScreen);
|
||||
gameScreen.World.RemoveBody(BodyPart);
|
||||
}
|
||||
|
||||
public override void Update(AxiosGameScreen gameScreen, GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
|
||||
{
|
||||
base.Update(gameScreen, gameTime, otherScreenHasFocus, coveredByOtherScreen);
|
||||
|
||||
if (ApplyConstantVelocity)
|
||||
{
|
||||
if (Math.Abs(BodyPart.LinearVelocity.X) > ConstantVelocity.X || Math.Abs(BodyPart.LinearVelocity.X) < ConstantVelocity.X)
|
||||
{
|
||||
//Figure which direction it's going and adjust
|
||||
|
||||
if (Math.Abs(BodyPart.LinearVelocity.X) > BodyPart.LinearVelocity.X) //negative
|
||||
BodyPart.LinearVelocity = new Vector2(-ConstantVelocity.X, BodyPart.LinearVelocity.Y);
|
||||
else
|
||||
BodyPart.LinearVelocity = new Vector2(ConstantVelocity.X, BodyPart.LinearVelocity.Y);
|
||||
|
||||
}
|
||||
|
||||
if (Math.Abs(BodyPart.LinearVelocity.Y) > ConstantVelocity.Y || Math.Abs(BodyPart.LinearVelocity.Y) < ConstantVelocity.Y)
|
||||
{
|
||||
//Figure which direction it's going and adjust
|
||||
|
||||
if (Math.Abs(BodyPart.LinearVelocity.Y) > BodyPart.LinearVelocity.Y) //negative
|
||||
BodyPart.LinearVelocity = new Vector2(BodyPart.LinearVelocity.X, -ConstantVelocity.Y);
|
||||
else
|
||||
BodyPart.LinearVelocity = new Vector2(BodyPart.LinearVelocity.X, ConstantVelocity.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
92
axios/Engine/SimpleDrawableAxiosGameObject.cs
Normal file
92
axios/Engine/SimpleDrawableAxiosGameObject.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
using Axios.Engine.Interfaces;
|
||||
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
public abstract class SimpleDrawableAxiosGameObject : SimpleAxiosGameObject, IDrawableAxiosGameObject
|
||||
{
|
||||
protected Texture2D Texture;
|
||||
|
||||
protected Boolean _adjustunits = true;
|
||||
protected Boolean _relativetocamera = true;
|
||||
protected int _draworder;
|
||||
|
||||
|
||||
|
||||
public SimpleDrawableAxiosGameObject()
|
||||
{
|
||||
this.BodyPart = new Body();
|
||||
this.Position = new Vector2();
|
||||
this.Origin = new Vector2();
|
||||
|
||||
}
|
||||
|
||||
public override void LoadContent(AxiosGameScreen gameScreen)
|
||||
{
|
||||
base.LoadContent(gameScreen);
|
||||
|
||||
//this.Texture = new Texture2D(gameScreen.ScreenManager.GraphicsDevice, 1, 1);
|
||||
}
|
||||
|
||||
public virtual void Draw(AxiosGameScreen gameScreen, GameTime gameTime)
|
||||
{
|
||||
|
||||
/*#if DEBUG
|
||||
System.Diagnostics.Debugger.Break();
|
||||
#endif*/
|
||||
if (_relativetocamera)
|
||||
gameScreen.ScreenManager.SpriteBatch.Begin(0, null, null, null, null, null, gameScreen.Camera.View);
|
||||
else
|
||||
gameScreen.ScreenManager.SpriteBatch.Begin();
|
||||
if (_adjustunits)
|
||||
DrawObject(gameScreen.ScreenManager.SpriteBatch, Texture, BodyPart, Origin, true, _scale);
|
||||
else
|
||||
DrawObject(gameScreen.ScreenManager.SpriteBatch, Texture, BodyPart, Origin, _scale);
|
||||
gameScreen.ScreenManager.SpriteBatch.End();
|
||||
}
|
||||
|
||||
protected void DrawObject(SpriteBatch sb, Texture2D texture, Body body, Vector2 origin)
|
||||
{
|
||||
DrawObject(sb, texture, body, origin, false, _scale);
|
||||
}
|
||||
|
||||
protected void DrawObject(SpriteBatch sb, Texture2D texture, Body body, Vector2 origin, float scale)
|
||||
{
|
||||
DrawObject(sb, texture, body, origin, false, scale);
|
||||
}
|
||||
|
||||
protected void DrawObject(SpriteBatch sb, Texture2D texture, Body body, Vector2 origin, bool Convertunits, float scale)
|
||||
{
|
||||
if (Convertunits)
|
||||
sb.Draw(texture, ConvertUnits.ToDisplayUnits(body.Position),
|
||||
null,
|
||||
Color.White, body.Rotation, origin, scale,
|
||||
SpriteEffects.None, 0);
|
||||
else
|
||||
sb.Draw(texture, body.Position,
|
||||
null,
|
||||
Color.White, body.Rotation, origin, scale,
|
||||
SpriteEffects.None, 0f);
|
||||
}
|
||||
|
||||
public int DrawOrder
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._draworder;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._draworder = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
32
axios/Engine/Singleton.cs
Normal file
32
axios/Engine/Singleton.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
//http://ralch.wordpress.com/2008/11/22/the-singleton-pattern-how-to-make-it-reusable/
|
||||
//http://msdn.microsoft.com/en-us/library/ff650316.aspx
|
||||
public abstract class Singleton<T> where T: new()
|
||||
{
|
||||
private static T instance;
|
||||
private static object syncRoot = new Object();
|
||||
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (instance == null)
|
||||
instance = new T();
|
||||
}
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
97
axios/Engine/UI/AxiosButton.cs
Normal file
97
axios/Engine/UI/AxiosButton.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
using FarseerPhysics.Factories;
|
||||
using FarseerPhysics.Dynamics;
|
||||
|
||||
namespace Axios.Engine.UI
|
||||
{
|
||||
public class AxiosButton : AxiosUIObject
|
||||
{
|
||||
protected Texture2D _hovertexture;
|
||||
protected Texture2D _clicktexture;
|
||||
protected Texture2D _normaltexture;
|
||||
|
||||
/// <summary>
|
||||
/// HoverTexture is the texture that will be set when the mouse hovers over the button
|
||||
/// </summary>
|
||||
public Texture2D HoverTexture
|
||||
{
|
||||
get { return this._hovertexture; }
|
||||
set { this._hovertexture = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The ClickTexture is the texture that will be set when the user clicks on the button
|
||||
/// </summary>
|
||||
public Texture2D ClickTexture
|
||||
{
|
||||
get { return this._clicktexture; }
|
||||
set { this._clicktexture = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The normal texture is the texture when the button is not active
|
||||
/// </summary>
|
||||
public Texture2D NormalTexture
|
||||
{
|
||||
get { return this._normaltexture; }
|
||||
set { this._normaltexture = value; this.Texture = value; }
|
||||
}
|
||||
|
||||
public AxiosButton()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void LoadContent(AxiosGameScreen gameScreen)
|
||||
{
|
||||
base.LoadContent(gameScreen);
|
||||
|
||||
}
|
||||
|
||||
public override void OnMouseHover(AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
base.OnMouseHover(gameScreen, input);
|
||||
|
||||
this.Texture = _hovertexture;
|
||||
|
||||
}
|
||||
|
||||
public override void OnMouseLeave(AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
base.OnMouseLeave(gameScreen, input);
|
||||
|
||||
this.Texture = _normaltexture;
|
||||
}
|
||||
|
||||
public override void OnMouseDown(AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
base.OnMouseDown(gameScreen, input);
|
||||
|
||||
this.Texture = _clicktexture;
|
||||
}
|
||||
|
||||
public override void OnMouseUp(AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
base.OnMouseUp(gameScreen, input);
|
||||
|
||||
this.Texture = _hovertexture;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void HandleCursor(AxiosGameScreen gameScreen, InputHelper input)
|
||||
{
|
||||
base.HandleCursor(gameScreen, input);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
25
axios/Engine/UI/AxiosUIObject.cs
Normal file
25
axios/Engine/UI/AxiosUIObject.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Axios.Engine;
|
||||
|
||||
namespace Axios.Engine.UI
|
||||
{
|
||||
public class AxiosUIObject : DrawableAxiosGameObject
|
||||
{
|
||||
public int Width
|
||||
{
|
||||
get { return this.Texture.Width; }
|
||||
private set { }
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get { return this.Texture.Height; }
|
||||
private set {}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user