├── LDEngine ├── LDEngine │ ├── Game.ico │ ├── GameThumbnail.png │ ├── Spine │ │ ├── SpriteBatcher.cs │ │ ├── Attachments │ │ │ ├── AttachmentType.cs │ │ │ ├── AttachmentLoader.cs │ │ │ ├── Attachment.cs │ │ │ ├── AtlasAttachmentLoader.cs │ │ │ └── RegionAttachment.cs │ │ ├── BoneData.cs │ │ ├── SlotData.cs │ │ ├── Slot.cs │ │ ├── Skin.cs │ │ ├── Bone.cs │ │ ├── Atlas.cs │ │ ├── SkeletonData.cs │ │ └── SkeletonRenderer.cs │ ├── Program.cs │ ├── Content │ │ └── map.tmx │ ├── TimerController.cs │ ├── Entities │ │ ├── RotBox.cs │ │ ├── Entity.cs │ │ ├── Hero.cs │ │ └── EntityPool.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Timer.cs │ ├── Screens │ │ ├── GameplayScreen.cs │ │ ├── MainMenuScreen.cs │ │ ├── PauseMenuScreen.cs │ │ ├── OptionsMenuScreen.cs │ │ ├── MessageBoxScreen.cs │ │ ├── MenuEntry.cs │ │ └── LoadingScreen.cs │ ├── AudioController.cs │ ├── Tween.cs │ ├── ScreenManager │ │ └── InputState.cs │ ├── Game.cs │ ├── TweenController.cs │ └── SpriteAnim.cs ├── LDEngineContent │ ├── blank.png │ ├── testhero.ase │ ├── testhero.png │ ├── particles.png │ ├── testtiles.ase │ ├── testtiles.png │ ├── font.spritefont │ ├── map.tmx │ └── LDEngineContent.contentproj ├── LDEngineContent.Linux │ ├── blank.png │ ├── Silkscreen.ttf │ ├── particles.png │ ├── testhero.png │ ├── testtiles.png │ ├── font.spritefont │ └── LDEngineContent.Linux.contentproj ├── TiledLib │ ├── Orientation.cs │ ├── MapReader.cs │ ├── Tile.cs │ ├── MapObject.cs │ ├── Layer.cs │ ├── MapObjectLayer.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── PropertyCollection.cs │ ├── TileLayer.cs │ ├── Camera.cs │ ├── TiledLib.csproj │ ├── TiledLib.Linux.csproj │ └── Helper.cs ├── TiledContentPipeline │ ├── ContentTypes │ │ ├── Property.cs │ │ ├── MapObjectLayerContent.cs │ │ ├── TileLayerContent.cs │ │ ├── LayerContent.cs │ │ ├── MapContent.cs │ │ ├── MapObjectContent.cs │ │ └── TileSetContent.cs │ ├── TmxImporter.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── TmxWriter.cs │ ├── TmxProcessor.cs │ └── TiledContentPipeline.csproj └── TiledLib.Mono.Windows │ ├── Properties │ └── AssemblyInfo.cs │ └── TiledLib.Mono.Windows.csproj ├── dependencies ├── Silkscreen.zip └── MonoGame │ ├── Linux │ ├── SDL.dll │ ├── OpenTK.dll │ ├── Tao.Sdl.dll │ ├── SDL_Mixer.dll │ ├── MonoGame.Framework.dll │ ├── OpenTK.dll.config │ └── Tao.Sdl.dll.config │ ├── MacOS │ ├── MonoMac.dll │ ├── Tao.Sdl.dll │ ├── Lidgren.Network.dll │ ├── MonoGame.Framework.dll │ ├── Lidgren.Network.dll.mdb │ ├── MonoGame.Framework.dll.mdb │ └── Tao.Sdl.dll.config │ └── WindowsGL │ ├── OpenTK.dll │ ├── Tao.Sdl.dll │ └── MonoGame.Framework.dll ├── .gitmodules ├── .gitattributes ├── .gitignore └── LDEngine.sln /LDEngine/LDEngine/Game.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngine/Game.ico -------------------------------------------------------------------------------- /dependencies/Silkscreen.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/Silkscreen.zip -------------------------------------------------------------------------------- /LDEngine/LDEngine/GameThumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngine/GameThumbnail.png -------------------------------------------------------------------------------- /LDEngine/LDEngineContent/blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngineContent/blank.png -------------------------------------------------------------------------------- /dependencies/MonoGame/Linux/SDL.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/Linux/SDL.dll -------------------------------------------------------------------------------- /LDEngine/LDEngineContent/testhero.ase: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngineContent/testhero.ase -------------------------------------------------------------------------------- /LDEngine/LDEngineContent/testhero.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngineContent/testhero.png -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/SpriteBatcher.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngine/Spine/SpriteBatcher.cs -------------------------------------------------------------------------------- /LDEngine/LDEngineContent.Linux/blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngineContent.Linux/blank.png -------------------------------------------------------------------------------- /LDEngine/LDEngineContent/particles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngineContent/particles.png -------------------------------------------------------------------------------- /LDEngine/LDEngineContent/testtiles.ase: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngineContent/testtiles.ase -------------------------------------------------------------------------------- /LDEngine/LDEngineContent/testtiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngineContent/testtiles.png -------------------------------------------------------------------------------- /dependencies/MonoGame/Linux/OpenTK.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/Linux/OpenTK.dll -------------------------------------------------------------------------------- /dependencies/MonoGame/Linux/Tao.Sdl.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/Linux/Tao.Sdl.dll -------------------------------------------------------------------------------- /dependencies/MonoGame/MacOS/MonoMac.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/MacOS/MonoMac.dll -------------------------------------------------------------------------------- /dependencies/MonoGame/MacOS/Tao.Sdl.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/MacOS/Tao.Sdl.dll -------------------------------------------------------------------------------- /dependencies/MonoGame/Linux/SDL_Mixer.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/Linux/SDL_Mixer.dll -------------------------------------------------------------------------------- /dependencies/MonoGame/WindowsGL/OpenTK.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/WindowsGL/OpenTK.dll -------------------------------------------------------------------------------- /LDEngine/LDEngineContent.Linux/Silkscreen.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngineContent.Linux/Silkscreen.ttf -------------------------------------------------------------------------------- /LDEngine/LDEngineContent.Linux/particles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngineContent.Linux/particles.png -------------------------------------------------------------------------------- /LDEngine/LDEngineContent.Linux/testhero.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngineContent.Linux/testhero.png -------------------------------------------------------------------------------- /LDEngine/LDEngineContent.Linux/testtiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/LDEngine/LDEngineContent.Linux/testtiles.png -------------------------------------------------------------------------------- /dependencies/MonoGame/WindowsGL/Tao.Sdl.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/WindowsGL/Tao.Sdl.dll -------------------------------------------------------------------------------- /dependencies/MonoGame/MacOS/Lidgren.Network.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/MacOS/Lidgren.Network.dll -------------------------------------------------------------------------------- /LDEngine/TiledLib/Orientation.cs: -------------------------------------------------------------------------------- 1 | namespace TiledLib 2 | { 3 | public enum Orientation : byte 4 | { 5 | Orthogonal, 6 | Isometric, 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dependencies/MonoGame/Linux/MonoGame.Framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/Linux/MonoGame.Framework.dll -------------------------------------------------------------------------------- /dependencies/MonoGame/MacOS/MonoGame.Framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/MacOS/MonoGame.Framework.dll -------------------------------------------------------------------------------- /dependencies/MonoGame/MacOS/Lidgren.Network.dll.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/MacOS/Lidgren.Network.dll.mdb -------------------------------------------------------------------------------- /dependencies/MonoGame/MacOS/MonoGame.Framework.dll.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/MacOS/MonoGame.Framework.dll.mdb -------------------------------------------------------------------------------- /dependencies/MonoGame/WindowsGL/MonoGame.Framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarethIW/LDEngine/HEAD/dependencies/MonoGame/WindowsGL/MonoGame.Framework.dll -------------------------------------------------------------------------------- /LDEngine/TiledContentPipeline/ContentTypes/Property.cs: -------------------------------------------------------------------------------- 1 | namespace TiledContentPipeline 2 | { 3 | public class Property 4 | { 5 | public string Name; 6 | public string Value; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ThirdParty/TiledSharp"] 2 | path = ThirdParty/TiledSharp 3 | url = https://github.com/marshallward/TiledSharp.git 4 | [submodule "ThirdParty/MonoGame-SDL2"] 5 | path = ThirdParty/MonoGame-SDL2 6 | url = https://github.com/flibitijibibo/MonoGame.git 7 | -------------------------------------------------------------------------------- /LDEngine/TiledLib/MapReader.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework.Content; 2 | 3 | namespace TiledLib 4 | { 5 | /// 6 | /// Reads in a Map from an XNB. 7 | /// 8 | public sealed class MapReader : ContentTypeReader 9 | { 10 | protected override Map Read(ContentReader input, Map existingInstance) 11 | { 12 | return new Map(input); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LDEngine 4 | { 5 | static class Program 6 | { 7 | /// 8 | /// The main entry point for the application. 9 | /// 10 | static void Main(string[] args) 11 | { 12 | using (Game game = new Game()) 13 | { 14 | game.Run(); 15 | } 16 | } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /LDEngine/TiledContentPipeline/TmxImporter.cs: -------------------------------------------------------------------------------- 1 | using System.Xml; 2 | using Microsoft.Xna.Framework.Content.Pipeline; 3 | 4 | namespace TiledContentPipeline 5 | { 6 | [ContentImporter(".tmx", DisplayName = "TMX Importer", DefaultProcessor = "TmxProcessor")] 7 | public class TmxImporter : ContentImporter 8 | { 9 | public override XmlDocument Import(string filename, ContentImporterContext context) 10 | { 11 | XmlDocument doc = new XmlDocument(); 12 | doc.Load(filename); 13 | return doc; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LDEngine/TiledContentPipeline/ContentTypes/MapObjectLayerContent.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Xml; 3 | 4 | namespace TiledContentPipeline 5 | { 6 | public class MapObjectLayerContent : LayerContent 7 | { 8 | public List Objects = new List(); 9 | 10 | public MapObjectLayerContent(XmlNode node) 11 | : base(node) 12 | { 13 | foreach (XmlNode objectNode in node.SelectNodes("object")) 14 | { 15 | Objects.Add(new MapObjectContent(objectNode)); 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /LDEngine/LDEngineContent/font.spritefont: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Silkscreen 5 | 13 6 | 1 7 | 8 | _ 9 | 10 | 11 | 12 | ~ 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /LDEngine/LDEngineContent.Linux/font.spritefont: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Silkscreen 5 | 13 6 | 1 7 | 8 | _ 9 | 10 | 11 | 12 | ~ 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /LDEngine/TiledLib/Tile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Xna.Framework.Content; 6 | using Microsoft.Xna.Framework.Graphics; 7 | using System.Collections.ObjectModel; 8 | using Microsoft.Xna.Framework; 9 | 10 | namespace TiledLib 11 | { 12 | public class Tile 13 | { 14 | public Texture2D Texture { get; private set; } 15 | public Rectangle Source { get; private set; } 16 | public PropertyCollection Properties { get; private set; } 17 | public bool[] CollisionData { get; private set; } 18 | 19 | internal Tile(Texture2D texture, Rectangle source, PropertyCollection properties, bool[] collision) 20 | { 21 | Texture = texture; 22 | Source = source; 23 | Properties = properties; 24 | CollisionData = collision; 25 | } 26 | 27 | internal void UnloadContent() 28 | { 29 | CollisionData = null; 30 | //Texture = null; 31 | //Properties = null; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /dependencies/MonoGame/Linux/OpenTK.dll.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Content/map.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | H4sIAAAAAAAAC+NmYGDgHsWjeBQPSQwAod8NQ8ADAAA= 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | H4sIAAAAAAAAC+NgYGDgoDKmFiDWPHLVYXM3KX4gRi0h+ygxjxCg1Dxc4YXLDFz+w+VnYsWIlcdlHj6Aze24zCMmjRPjdmpiAAXm373AAwAA 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /LDEngine/LDEngineContent/map.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | H4sIAAAAAAAAC+NmYGDgHsWjeBQPSQwAod8NQ8ADAAA= 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | H4sIAAAAAAAAC+NgYGDgoDKmFiDWPHLVYXM3KX4gRi0h+ygxjxCg1Dxc4YXLDFz+w+VnYsWIlcdlHj6Aze24zCMmjRPjdmpiAAXm373AAwAA 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/TimerController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using Microsoft.Xna.Framework; 7 | 8 | namespace TimersAndTweens 9 | { 10 | class TimerController 11 | { 12 | public static TimerController Instance; 13 | 14 | public List Timers = new List(); 15 | 16 | public TimerController() 17 | { 18 | Instance = this; 19 | } 20 | 21 | public void Update(GameTime gameTime) 22 | { 23 | foreach(Timer t in Timers) t.Update(gameTime); 24 | 25 | Timers.RemoveAll(t => t.State == TimerState.Finished); 26 | } 27 | 28 | public Timer Create(string name, Action callback, double time, bool loop) 29 | { 30 | Timer t = new Timer(name, callback, time, loop); 31 | Timers.Add(t); 32 | 33 | return t; 34 | } 35 | 36 | public Timer Get(string name) 37 | { 38 | return Timers.FirstOrDefault(t => t.Name == name); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /LDEngine/TiledContentPipeline/ContentTypes/TileLayerContent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.IO.Compression; 4 | using System.Xml; 5 | 6 | namespace TiledContentPipeline 7 | { 8 | public class TileLayerContent : LayerContent 9 | { 10 | public int[] Data; 11 | 12 | public TileLayerContent(XmlNode node) 13 | : base(node) 14 | { 15 | XmlNode dataNode = node["data"]; 16 | string encoding = dataNode.Attributes["encoding"].Value; 17 | string compression = dataNode.Attributes["compression"].Value; 18 | Data = new int[Width * Height]; 19 | 20 | if (encoding != "base64") 21 | { 22 | throw new Exception("Unknown encoding: " + encoding); 23 | } 24 | 25 | Stream data = new MemoryStream(Convert.FromBase64String(node.InnerText), false); 26 | if (compression == "gzip") 27 | { 28 | data = new GZipStream(data, CompressionMode.Decompress, false); 29 | } 30 | 31 | using (data) 32 | { 33 | using (BinaryReader reader = new BinaryReader(data)) 34 | { 35 | for (int i = 0; i < Data.Length; i++) 36 | { 37 | Data[i] = reader.ReadInt32(); 38 | } 39 | } 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /LDEngine/TiledLib/MapObject.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using System.Collections.Generic; 3 | 4 | namespace TiledLib 5 | { 6 | /// 7 | /// An arbitrary object placed on an ObjectLayer. 8 | /// 9 | public class MapObject 10 | { 11 | /// 12 | /// Gets the name of the object. 13 | /// 14 | public string Name { get; private set; } 15 | 16 | /// 17 | /// Gets the type of the object. 18 | /// 19 | public string Type { get; private set; } 20 | 21 | /// 22 | /// Gets the location of the object. 23 | /// 24 | public Rectangle Location { get; private set; } 25 | 26 | /// 27 | /// Gets a list of the object's properties. 28 | /// 29 | public PropertyCollection Properties { get; private set; } 30 | 31 | public List LinePoints { get; private set; } 32 | 33 | internal MapObject(string name, string type, Rectangle location, List linePoints, PropertyCollection properties) 34 | { 35 | Name = name; 36 | Type = type; 37 | Location = location; 38 | Properties = properties; 39 | LinePoints = linePoints; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /LDEngine/TiledContentPipeline/ContentTypes/LayerContent.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Xml; 3 | 4 | namespace TiledContentPipeline 5 | { 6 | public abstract class LayerContent 7 | { 8 | public string Name; 9 | public string Type; 10 | public int Width; 11 | public int Height; 12 | public float Opacity = 1f; 13 | public bool Visible = true; 14 | public List Properties = new List(); 15 | 16 | public LayerContent(XmlNode node) 17 | { 18 | Type = node.Name; 19 | Name = node.Attributes["name"].Value; 20 | Width = int.Parse(node.Attributes["width"].Value); 21 | Height = int.Parse(node.Attributes["height"].Value); 22 | 23 | if (node.Attributes["opacity"] != null) 24 | { 25 | Opacity = float.Parse(node.Attributes["opacity"].Value); 26 | } 27 | 28 | if (node.Attributes["visible"] != null) 29 | { 30 | Visible = int.Parse(node.Attributes["visible"].Value) == 1; 31 | } 32 | 33 | XmlNode propertiesNode = node["properties"]; 34 | if (propertiesNode != null) 35 | { 36 | foreach (XmlNode property in propertiesNode.ChildNodes) 37 | { 38 | Properties.Add(new Property 39 | { 40 | Name = property.Attributes["name"].Value, 41 | Value = property.Attributes["value"].Value, 42 | }); 43 | } 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /LDEngine/TiledLib/Layer.cs: -------------------------------------------------------------------------------- 1 | namespace TiledLib 2 | { 3 | /// 4 | /// An abstract base for a layer in a map. 5 | /// 6 | public abstract class Layer 7 | { 8 | /// 9 | /// Gets the name of the layer. 10 | /// 11 | public string Name { get; private set; } 12 | 13 | /// 14 | /// Gets the width (in tiles) of the layer. 15 | /// 16 | public int Width { get; private set; } 17 | 18 | /// 19 | /// Gets the height (in tiles) of the layer. 20 | /// 21 | public int Height { get; private set; } 22 | 23 | /// 24 | /// Gets or sets the whether the layer is visible. 25 | /// 26 | public bool Visible { get; set; } 27 | 28 | /// 29 | /// Gets or sets the opacity of the layer. 30 | /// 31 | public float Opacity { get; set; } 32 | 33 | /// 34 | /// Gets the list of properties for the layer. 35 | /// 36 | public PropertyCollection Properties { get; private set; } 37 | 38 | internal Layer(string name, int width, int height, bool visible, float opacity, PropertyCollection properties) 39 | { 40 | Name = name; 41 | Width = width; 42 | Height = height; 43 | Visible = visible; 44 | Opacity = opacity; 45 | Properties = properties; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Entities/RotBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using Microsoft.Xna.Framework; 7 | using Microsoft.Xna.Framework.Graphics; 8 | using TimersAndTweens; 9 | using Timer = TimersAndTweens.Timer; 10 | 11 | namespace LDEngine.Entities 12 | { 13 | class RotBox : Entity 14 | { 15 | private Color _tint = Color.White; 16 | 17 | public RotBox(Texture2D spritesheet, Rectangle hitbox, List hitPolyPoints, Vector2 hitboxoffset) 18 | : base(spritesheet, hitbox, hitPolyPoints, hitboxoffset) 19 | { 20 | TimerController.Instance.Create("", () => { Rotation += 0.1f; }, 100, true); 21 | } 22 | 23 | public override void Update(GameTime gameTime) 24 | { 25 | _tint = Color.White; 26 | 27 | base.Update(gameTime); 28 | } 29 | 30 | public override void OnPolyCollision(Entity collided) 31 | { 32 | _tint = Color.Red; 33 | 34 | base.OnPolyCollision(collided); 35 | } 36 | 37 | public override void Draw(SpriteBatch sb) 38 | { 39 | sb.Draw(SpriteSheet, Position, null, _tint, Rotation, new Vector2(SpriteSheet.Width, SpriteSheet.Height)/2, 2f, SpriteEffects.None, 0); 40 | base.Draw(sb); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /LDEngine/TiledLib/MapObjectLayer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | using System; 4 | 5 | namespace TiledLib 6 | { 7 | /// 8 | /// A layer comprised of objects. 9 | /// 10 | public class MapObjectLayer : Layer 11 | { 12 | private readonly Dictionary namedObjects = new Dictionary(); 13 | 14 | /// 15 | /// Gets the objects on the current layer. 16 | /// 17 | public ReadOnlyCollection Objects { get; private set; } 18 | 19 | internal MapObjectLayer(string name, int width, int height, bool visible, float opacity, PropertyCollection properties, IList objects) 20 | : base(name, width, height, visible, opacity, properties) 21 | { 22 | Objects = new ReadOnlyCollection(objects); 23 | foreach (var o in objects) 24 | { 25 | string oname = o.Name; 26 | if (namedObjects.ContainsKey(o.Name)) oname += "-" + Guid.NewGuid(); 27 | namedObjects.Add(oname, o); 28 | } 29 | } 30 | 31 | /// 32 | /// Gets a MapObject by name. 33 | /// 34 | /// The name of the object to retrieve. 35 | /// The MapObject with the given name. 36 | public MapObject GetObject(string objectName) 37 | { 38 | return namedObjects[objectName]; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /LDEngine/TiledContentPipeline/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TiledContentPipeline")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TiledContentPipeline")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a9149119-6e40-4649-aaa7-7590a3461678")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | [assembly: AssemblyVersion("1.0.0.0")] 33 | [assembly: AssemblyFileVersion("1.0.0.0")] 34 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("LDEngine")] 9 | [assembly: AssemblyProduct("LDEngine")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2014")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("14102030-f652-4947-ba2c-86ceaef0831b")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /LDEngine/TiledLib/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TiledLib")] 9 | [assembly: AssemblyProduct("TiledLib")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2013")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("c908930e-1bab-47fa-aa11-25825bf8622c")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /LDEngine/TiledLib/PropertyCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.Xna.Framework.Content; 3 | using System; 4 | 5 | namespace TiledLib 6 | { 7 | public class PropertyCollection : IEnumerable> 8 | { 9 | private readonly Dictionary values = new Dictionary(); 10 | 11 | public string this[string key] 12 | { 13 | get { return values[key]; } 14 | set { values[key] = value; } 15 | } 16 | 17 | internal PropertyCollection() { } 18 | 19 | public void Add(KeyValuePair kvp) 20 | { 21 | Add(kvp.Key, kvp.Value); 22 | } 23 | 24 | internal void Add(string key, string value) 25 | { 26 | if (this.Contains(key)) key = key + Guid.NewGuid().ToString(); 27 | values.Add(key, value); 28 | } 29 | 30 | internal void Read(ContentReader reader) 31 | { 32 | int count = reader.ReadInt32(); 33 | for (int i = 0; i < count; i++) 34 | { 35 | Add(reader.ReadString(), reader.ReadString()); 36 | } 37 | } 38 | 39 | public IEnumerator> GetEnumerator() 40 | { 41 | return values.GetEnumerator(); 42 | } 43 | 44 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 45 | { 46 | return values.GetEnumerator(); 47 | } 48 | 49 | public bool Contains(string key) 50 | { 51 | bool contains = false; 52 | 53 | if (values.ContainsKey(key)) contains = true; 54 | 55 | return contains; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /LDEngine/TiledLib.Mono.Windows/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TiledLib.Mono.Windows")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TiledLib.Mono.Windows")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9b7d073b-5085-4c7e-bfba-dcaa94d7e7d1")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/Attachments/AttachmentType.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Esoteric Software 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | ******************************************************************************/ 25 | 26 | namespace Spine { 27 | public enum AttachmentType { 28 | region, regionSequence 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /LDEngine/TiledLib/TileLayer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.Xna.Framework; 3 | 4 | using TiledSharp; 5 | 6 | namespace TiledLib 7 | { 8 | /// 9 | /// A map layer containing tiles. 10 | /// 11 | public class TileLayer : Layer 12 | { 13 | /// 14 | /// Gets the layout of tiles on the layer. 15 | /// 16 | public Tile[,] Tiles { get; private set; } 17 | 18 | internal TileLayer(string name, int width, int height, bool visible, float opacity, PropertyCollection properties, Map map, int[] data) 19 | : base(name, width, height, visible, opacity, properties) 20 | { 21 | Tiles = new Tile[width, height]; 22 | 23 | // data is left-to-right, top-to-bottom 24 | for (int x = 0; x < width; x++) 25 | { 26 | for (int y = 0; y < height; y++) 27 | { 28 | int index = data[y * width + x]; 29 | Tiles[x, y] = map.Tiles[index]; 30 | } 31 | } 32 | } 33 | 34 | internal TileLayer( 35 | string name, 36 | int width, 37 | int height, 38 | bool visible, 39 | float opacity, 40 | PropertyCollection properties, 41 | Map map, 42 | List data 43 | ) : base(name, width, height, visible, opacity, properties) 44 | { 45 | Tiles = new Tile[width, height]; 46 | 47 | // data is left-to-right, top-to-bottom 48 | for (int x = 0; x < width; x++) 49 | { 50 | for (int y = 0; y < height; y++) 51 | { 52 | int index = data[y * width + x].Gid; 53 | Tiles[x, y] = map.Tiles[index]; 54 | } 55 | } 56 | } 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Timer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Policy; 5 | using System.Text; 6 | using Microsoft.Xna.Framework; 7 | 8 | namespace TimersAndTweens 9 | { 10 | enum TimerState 11 | { 12 | Running, 13 | Paused, 14 | Finished 15 | } 16 | 17 | class Timer 18 | { 19 | public double CurrentTime; 20 | public double TargetTime; 21 | public bool Looping; 22 | public string Name; 23 | 24 | public TimerState State; 25 | 26 | private readonly Action _callback; 27 | 28 | public Timer(string name, Action callback, double time, bool loop) 29 | { 30 | Name = name; 31 | _callback = callback; 32 | TargetTime = time; 33 | Looping = loop; 34 | 35 | CurrentTime = 0; 36 | } 37 | 38 | public void Update(GameTime gameTime) 39 | { 40 | if(State!=TimerState.Running) return; 41 | 42 | CurrentTime += gameTime.ElapsedGameTime.TotalMilliseconds; 43 | if (CurrentTime >= TargetTime) 44 | { 45 | CurrentTime = 0; 46 | 47 | if (!Looping) State = TimerState.Finished; 48 | 49 | _callback(); 50 | } 51 | } 52 | 53 | public void Pause() 54 | { 55 | State = TimerState.Paused; 56 | } 57 | 58 | public void Resume() 59 | { 60 | State = TimerState.Running; 61 | } 62 | 63 | public void Reset() 64 | { 65 | CurrentTime = 0; 66 | } 67 | 68 | public void Kill() 69 | { 70 | State = TimerState.Finished; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /dependencies/MonoGame/Linux/Tao.Sdl.dll.config: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /dependencies/MonoGame/MacOS/Tao.Sdl.dll.config: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/Attachments/AttachmentLoader.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Esoteric Software 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | ******************************************************************************/ 25 | 26 | using System; 27 | 28 | namespace Spine { 29 | public interface AttachmentLoader { 30 | /** @return May be null to not load any attachment. */ 31 | Attachment NewAttachment (AttachmentType type, String name); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/Attachments/Attachment.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Esoteric Software 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | ******************************************************************************/ 25 | 26 | using System; 27 | 28 | namespace Spine { 29 | abstract public class Attachment { 30 | public String Name { get; private set; } 31 | 32 | public Attachment (String name) { 33 | if (name == null) throw new ArgumentNullException("name cannot be null."); 34 | Name = name; 35 | } 36 | 37 | override public String ToString () { 38 | return Name; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /LDEngine/TiledContentPipeline/ContentTypes/MapContent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using TiledLib; 4 | using System.Xml; 5 | using System.Diagnostics; 6 | 7 | namespace TiledContentPipeline 8 | { 9 | public class MapContent 10 | { 11 | public string Version = string.Empty; 12 | public Orientation Orientation; 13 | public int Width; 14 | public int Height; 15 | public int TileWidth; 16 | public int TileHeight; 17 | public List Properties = new List(); 18 | 19 | public List TileSets = new List(); 20 | public List Layers = new List(); 21 | 22 | public MapContent(XmlDocument document) 23 | { 24 | XmlNode mapNode = document["map"]; 25 | 26 | Version = mapNode.Attributes["version"].Value; 27 | Orientation = (Orientation)Enum.Parse(typeof(Orientation), mapNode.Attributes["orientation"].Value, true); 28 | Width = int.Parse(mapNode.Attributes["width"].Value); 29 | Height = int.Parse(mapNode.Attributes["height"].Value); 30 | TileWidth = int.Parse(mapNode.Attributes["tilewidth"].Value); 31 | TileHeight = int.Parse(mapNode.Attributes["tileheight"].Value); 32 | 33 | XmlNode propertiesNode = document.SelectSingleNode("map/properties"); 34 | if (propertiesNode != null) 35 | { 36 | foreach (XmlNode property in propertiesNode.ChildNodes) 37 | { 38 | Properties.Add(new Property 39 | { 40 | Name = property.Attributes["name"].Value, 41 | Value = property.Attributes["value"].Value, 42 | }); 43 | } 44 | } 45 | 46 | foreach (XmlNode tileSet in document.SelectNodes("map/tileset")) 47 | { 48 | TileSets.Add(new TileSetContent(tileSet)); 49 | } 50 | 51 | foreach (XmlNode layerNode in document.SelectNodes("map/layer|map/objectgroup")) 52 | { 53 | if (layerNode.Name == "layer") 54 | { 55 | Layers.Add(new TileLayerContent(layerNode)); 56 | } 57 | else if (layerNode.Name == "objectgroup") 58 | { 59 | Layers.Add(new MapObjectLayerContent(layerNode)); 60 | } 61 | else 62 | { 63 | throw new Exception("Unknown layer name: " + layerNode.Name); 64 | } 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Screens/GameplayScreen.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using GameStateManagement; 6 | using LDEngine.Entities; 7 | using Microsoft.Xna.Framework; 8 | using Microsoft.Xna.Framework.Content; 9 | using Microsoft.Xna.Framework.Graphics; 10 | using TiledLib; 11 | using TimersAndTweens; 12 | 13 | namespace LDEngine.Screens 14 | { 15 | class GameplayScreen : GameScreen 16 | { 17 | private Camera camera; 18 | private Map map; 19 | 20 | private ParticleController particleController = new ParticleController(); 21 | 22 | public GameplayScreen() 23 | { 24 | TransitionOnTime = TimeSpan.FromSeconds(0.5); 25 | TransitionOffTime = TimeSpan.FromSeconds(0.5); 26 | } 27 | 28 | public override void LoadContent() 29 | { 30 | ContentManager content = ScreenManager.Game.Content; 31 | 32 | map = content.Load("map"); 33 | 34 | camera = new Camera(ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight, map); 35 | 36 | particleController.LoadContent(content); 37 | 38 | base.LoadContent(); 39 | } 40 | 41 | public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) 42 | { 43 | camera.Update(gameTime); 44 | 45 | particleController.Update(gameTime, map); 46 | 47 | base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); 48 | } 49 | 50 | public override void Draw(GameTime gameTime) 51 | { 52 | Vector2 center = new Vector2(ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight) / 2f; 53 | SpriteBatch sb = ScreenManager.SpriteBatch; 54 | 55 | sb.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, camera.CameraMatrix); 56 | map.DrawLayer(sb, "fg", camera); 57 | sb.End(); 58 | 59 | particleController.Draw(sb, camera, 1); 60 | 61 | sb.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null); 62 | sb.End(); 63 | 64 | ScreenManager.FadeBackBufferToBlack(1f - TransitionAlpha); 65 | 66 | base.Draw(gameTime); 67 | 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/BoneData.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Esoteric Software 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | ******************************************************************************/ 25 | 26 | using System; 27 | 28 | namespace Spine { 29 | public class BoneData { 30 | /** May be null. */ 31 | public BoneData Parent { get; private set; } 32 | public String Name { get; private set; } 33 | public float Length { get; set; } 34 | public float X { get; set; } 35 | public float Y { get; set; } 36 | public float Rotation { get; set; } 37 | public float ScaleX { get; set; } 38 | public float ScaleY { get; set; } 39 | 40 | /** @param parent May be null. */ 41 | public BoneData (String name, BoneData parent) { 42 | if (name == null) throw new ArgumentNullException("name cannot be null."); 43 | Name = name; 44 | Parent = parent; 45 | ScaleX = 1; 46 | ScaleY = 1; 47 | } 48 | 49 | override public String ToString () { 50 | return Name; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/SlotData.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Esoteric Software 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | ******************************************************************************/ 25 | 26 | using System; 27 | 28 | namespace Spine { 29 | public class SlotData { 30 | public String Name { get; private set; } 31 | public BoneData BoneData { get; private set; } 32 | public float R { get; set; } 33 | public float G { get; set; } 34 | public float B { get; set; } 35 | public float A { get; set; } 36 | /** @param attachmentName May be null. */ 37 | public String AttachmentName { get; set; } 38 | 39 | public SlotData (String name, BoneData boneData) { 40 | if (name == null) throw new ArgumentNullException("name cannot be null."); 41 | if (boneData == null) throw new ArgumentNullException("boneData cannot be null."); 42 | Name = name; 43 | BoneData = boneData; 44 | R = 1; 45 | G = 1; 46 | B = 1; 47 | A = 1; 48 | } 49 | 50 | override public String ToString () { 51 | return Name; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/Attachments/AtlasAttachmentLoader.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Esoteric Software 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | ******************************************************************************/ 25 | 26 | using System; 27 | 28 | namespace Spine { 29 | public class AtlasAttachmentLoader : AttachmentLoader { 30 | private BaseAtlas atlas; 31 | 32 | public AtlasAttachmentLoader (BaseAtlas atlas) { 33 | if (atlas == null) throw new ArgumentNullException("atlas cannot be null."); 34 | this.atlas = atlas; 35 | } 36 | 37 | public Attachment NewAttachment (AttachmentType type, String name) { 38 | switch (type) { 39 | case AttachmentType.region: 40 | AtlasRegion region = atlas.FindRegion(name); 41 | if (region == null) throw new Exception("Region not found in atlas: " + name + " (" + type + ")"); 42 | RegionAttachment attachment = new RegionAttachment(name); 43 | attachment.Region = region; 44 | return attachment; 45 | } 46 | throw new Exception("Unknown attachment type: " + type); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /LDEngine/TiledContentPipeline/ContentTypes/MapObjectContent.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Xml; 3 | using Microsoft.Xna.Framework; 4 | using System; 5 | 6 | namespace TiledContentPipeline 7 | { 8 | public enum ObjectType 9 | { 10 | Rectangle, 11 | PolyLine 12 | } 13 | 14 | public class MapObjectContent 15 | { 16 | public string Name = string.Empty; 17 | public string Type = string.Empty; 18 | public ObjectType ObjectType; 19 | public Rectangle Location; 20 | public List LinePoints = new List(); 21 | public List Properties = new List(); 22 | 23 | public MapObjectContent(XmlNode node) 24 | { 25 | if (node.Attributes["name"] != null) 26 | { 27 | Name = node.Attributes["name"].Value; 28 | } 29 | 30 | if (node.Attributes["type"] != null) 31 | { 32 | Type = node.Attributes["type"].Value; 33 | } 34 | 35 | Location = new Rectangle( 36 | int.Parse(node.Attributes["x"].Value), 37 | int.Parse(node.Attributes["y"].Value), 38 | 0, 39 | 0); 40 | 41 | XmlNode polyNode = node["polyline"]; 42 | if (polyNode != null) 43 | { 44 | // Polyline node 45 | ObjectType = ObjectType.PolyLine; 46 | 47 | 48 | 49 | string pointsString = polyNode.Attributes["points"].Value; 50 | foreach (string point in pointsString.Split(' ')) 51 | { 52 | LinePoints.Add(new Point(Location.X + Convert.ToInt32(point.Split(',')[0]), Location.Y + Convert.ToInt32(point.Split(',')[1]))); 53 | } 54 | } 55 | else 56 | { 57 | ObjectType = ObjectType.Rectangle; 58 | 59 | Location = new Rectangle( 60 | int.Parse(node.Attributes["x"].Value), 61 | int.Parse(node.Attributes["y"].Value), 62 | int.Parse(node.Attributes["width"].Value), 63 | int.Parse(node.Attributes["height"].Value)); 64 | } 65 | 66 | XmlNode propertiesNode = node["properties"]; 67 | if (propertiesNode != null) 68 | { 69 | foreach (XmlNode property in propertiesNode.ChildNodes) 70 | { 71 | Properties.Add(new Property 72 | { 73 | Name = property.Attributes["name"].Value, 74 | Value = property.Attributes["value"].Value, 75 | }); 76 | } 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Screens/MainMenuScreen.cs: -------------------------------------------------------------------------------- 1 | #region File Description 2 | //----------------------------------------------------------------------------- 3 | // MainMenuScreen.cs 4 | // 5 | // Microsoft XNA Community Game Platform 6 | // Copyright (C) Microsoft Corporation. All rights reserved. 7 | //----------------------------------------------------------------------------- 8 | #endregion 9 | 10 | #region Using Statements 11 | using LDEngine.Screens; 12 | using Microsoft.Xna.Framework; 13 | using System; 14 | #endregion 15 | 16 | namespace GameStateManagement 17 | { 18 | /// 19 | /// The main menu screen is the first thing displayed when the game starts up. 20 | /// 21 | class MainMenuScreen : MenuScreen 22 | { 23 | #region Initialization 24 | 25 | 26 | /// 27 | /// Constructor fills in the menu contents. 28 | /// 29 | public MainMenuScreen() 30 | : base("Main Menu") 31 | { 32 | // Create our menu entries. 33 | 34 | MenuEntry playGameMenuEntry = new MenuEntry("Play", true); 35 | MenuEntry optionsMenuEntry = new MenuEntry("Options", true); 36 | MenuEntry exitMenuEntry = new MenuEntry("Exit", true); 37 | 38 | // Hook up menu event handlers. 39 | playGameMenuEntry.Selected += PlayGameMenuEntrySelected; 40 | optionsMenuEntry.Selected += OptionsMenuEntrySelected; 41 | exitMenuEntry.Selected += OnCancel; 42 | 43 | // Add entries to the menu. 44 | MenuEntries.Add(playGameMenuEntry); 45 | MenuEntries.Add(optionsMenuEntry); 46 | MenuEntries.Add(exitMenuEntry); 47 | } 48 | 49 | 50 | 51 | 52 | #endregion 53 | 54 | #region Handle Input 55 | 56 | 57 | void PlayGameMenuEntrySelected(object sender, EventArgs e) 58 | { 59 | LoadingScreen.Load(ScreenManager, false, new GameplayScreen()); 60 | } 61 | 62 | /// 63 | /// Event handler for when the Options menu entry is selected. 64 | /// 65 | void OptionsMenuEntrySelected(object sender, EventArgs e) 66 | { 67 | ScreenManager.AddScreen(new OptionsMenuScreen()); 68 | } 69 | 70 | 71 | /// 72 | /// When the user cancels the main menu, ask if they want to exit the sample. 73 | /// 74 | protected override void OnCancel(object sender, EventArgs e) 75 | { 76 | ScreenManager.Game.Exit(); 77 | } 78 | 79 | 80 | #endregion 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /LDEngine/TiledContentPipeline/ContentTypes/TileSetContent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Xml; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Content.Pipeline; 6 | using Microsoft.Xna.Framework.Content.Pipeline.Graphics; 7 | using Microsoft.Xna.Framework.Graphics; 8 | 9 | namespace TiledContentPipeline 10 | { 11 | public class Tile 12 | { 13 | public Rectangle Source; 14 | public List Properties = new List(); 15 | } 16 | 17 | public class TileSetContent 18 | { 19 | public int FirstId; 20 | public string Name; 21 | public bool CollisionSet = false; 22 | public int TileWidth; 23 | public int TileHeight; 24 | public int Spacing; 25 | public int Margin; 26 | public string Image; 27 | public Color? ColorKey; 28 | public ExternalReference Texture; 29 | public List Tiles = new List(); 30 | public Dictionary> TileProperties = new Dictionary>(); 31 | 32 | public TileSetContent(XmlNode node) 33 | { 34 | FirstId = int.Parse(node.Attributes["firstgid"].Value); 35 | Name = node.Attributes["name"].Value; 36 | TileWidth = int.Parse(node.Attributes["tilewidth"].Value); 37 | TileHeight = int.Parse(node.Attributes["tileheight"].Value); 38 | 39 | if (node.Attributes["spacing"] != null) 40 | { 41 | Spacing = int.Parse(node.Attributes["spacing"].Value); 42 | } 43 | 44 | if (node.Attributes["margin"] != null) 45 | { 46 | Margin = int.Parse(node.Attributes["margin"].Value); 47 | } 48 | 49 | XmlNode imageNode = node["image"]; 50 | Image = imageNode.Attributes["source"].Value; 51 | 52 | if (imageNode.Attributes["trans"] != null) 53 | { 54 | string color = imageNode.Attributes["trans"].Value; 55 | string r = color.Substring(0, 2); 56 | string g = color.Substring(2, 2); 57 | string b = color.Substring(4, 2); 58 | ColorKey = new Color((byte)Convert.ToInt32(r, 16), (byte)Convert.ToInt32(g, 16), (byte)Convert.ToInt32(b, 16)); 59 | } 60 | 61 | foreach (XmlNode tileProperty in node.SelectNodes("tile")) 62 | { 63 | int id = int.Parse(tileProperty.Attributes["id"].Value); 64 | List properties = new List(); 65 | 66 | foreach (XmlNode propertyNode in tileProperty.SelectNodes("properties/property")) 67 | { 68 | // If any tile has collisions set, mark the whole tileset as a collision set 69 | if (propertyNode.Attributes["name"].Value.StartsWith("CollisionSet")) CollisionSet = true; 70 | 71 | properties.Add(new Property 72 | { 73 | Name = propertyNode.Attributes["name"].Value, 74 | Value = propertyNode.Attributes["value"].Value, 75 | 76 | }); 77 | } 78 | 79 | TileProperties.Add(id, properties); 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /LDEngine/LDEngineContent.Linux/LDEngineContent.Linux.contentproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {D9FB0AFA-8F98-4DD9-A525-C674E338DA5E} 9 | {96E2B04D-8817-42C6-938A-82C39BA4D311};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10 | Exe 11 | LDEngineContent.Linux 12 | LDEngineContent.Linux 13 | 14 | 15 | true 16 | full 17 | false 18 | bin\Debug 19 | DEBUG; 20 | prompt 21 | 4 22 | False 23 | false 24 | Linux 25 | 26 | 27 | full 28 | true 29 | bin\Release 30 | prompt 31 | 4 32 | False 33 | false 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | TextureImporter 43 | blank 44 | TextureProcessor 45 | 46 | 47 | FontDescriptionImporter 48 | font 49 | FontDescriptionProcessor 50 | 51 | 52 | TextureImporter 53 | particles 54 | TextureProcessor 55 | 56 | 57 | TextureImporter 58 | testhero 59 | TextureProcessor 60 | 61 | 62 | TextureImporter 63 | testtiles 64 | TextureProcessor 65 | 66 | 67 | 68 | 69 | Silkscreen 70 | 71 | 72 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Entities/Entity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using GameStateManagement; 6 | using Microsoft.Xna.Framework; 7 | using Microsoft.Xna.Framework.Graphics; 8 | using TiledLib; 9 | 10 | namespace LDEngine.Entities 11 | { 12 | class Entity 13 | { 14 | public Vector2 Position; 15 | public Vector2 Speed; 16 | public float Rotation; 17 | public Rectangle HitBox; 18 | public List HitPolyPoints; 19 | public Texture2D SpriteSheet; 20 | public bool Active; 21 | 22 | private List _normalPolyPoints; 23 | private Vector2 _hitboxOffset; 24 | 25 | public Entity(Texture2D spritesheet, Rectangle hitbox, List hitPolyPoints, Vector2 hitboxoffset) 26 | { 27 | HitBox = hitbox; 28 | SpriteSheet = spritesheet; 29 | Active = false; 30 | 31 | _hitboxOffset = hitboxoffset; 32 | 33 | if (hitPolyPoints != null) 34 | _normalPolyPoints = hitPolyPoints; 35 | else 36 | _normalPolyPoints = new List() 37 | { 38 | new Vector2(-(HitBox.Width / 2), -(HitBox.Height / 2)), 39 | new Vector2((HitBox.Width / 2), -(HitBox.Height / 2)), 40 | new Vector2((HitBox.Width / 2), (HitBox.Height / 2)), 41 | new Vector2(-(HitBox.Width / 2), (HitBox.Height / 2)), 42 | }; 43 | 44 | HitPolyPoints = new List(); 45 | foreach(var pp in _normalPolyPoints) HitPolyPoints.Add(pp); 46 | } 47 | 48 | public virtual void Update(GameTime gameTime) 49 | { 50 | if (!Active) return; 51 | 52 | Position += Speed; 53 | 54 | HitBox.Location = new Point((int)Position.X,(int)Position.Y) + new Point(-(HitBox.Width/2),-(HitBox.Height/2)) + new Point((int)_hitboxOffset.X, (int)_hitboxOffset.Y); 55 | 56 | for (int index = 0; index < _normalPolyPoints.Count; index++) 57 | { 58 | HitPolyPoints[index] = _normalPolyPoints[index]; 59 | HitPolyPoints[index] = Vector2.Transform(_normalPolyPoints[index], Matrix.CreateRotationZ(Rotation)); 60 | HitPolyPoints[index] = HitPolyPoints[index] + _hitboxOffset + Position; 61 | } 62 | } 63 | public virtual void Update(GameTime gameTime, Map gameMap) 64 | { 65 | Update(gameTime); 66 | } 67 | 68 | public virtual void OnBoxCollision(Entity collided, Rectangle intersect) 69 | {} 70 | public virtual void OnPolyCollision(Entity collided) 71 | { } 72 | 73 | public virtual void HandleInput(InputState input) 74 | { 75 | 76 | } 77 | 78 | public virtual void Draw(SpriteBatch sb) 79 | { 80 | if (!Active) return; 81 | } 82 | 83 | // Reset values to defaults when an entity is spawned from a pool 84 | public virtual void Reset() 85 | { 86 | 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/Slot.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Esoteric Software 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | ******************************************************************************/ 25 | 26 | using System; 27 | 28 | namespace Spine { 29 | public class Slot { 30 | public SlotData Data { get; private set; } 31 | public Bone Bone { get; private set; } 32 | public Skeleton Skeleton { get; private set; } 33 | public float R { get; set; } 34 | public float G { get; set; } 35 | public float B { get; set; } 36 | public float A { get; set; } 37 | 38 | /** May be null. */ 39 | private Attachment attachment; 40 | public Attachment Attachment { 41 | get { 42 | return attachment; 43 | } 44 | set { 45 | attachment = value; 46 | attachmentTime = Skeleton.Time; 47 | } 48 | } 49 | 50 | private float attachmentTime; 51 | public float AttachmentTime { 52 | get { 53 | return Skeleton.Time - attachmentTime; 54 | } 55 | set { 56 | attachmentTime = Skeleton.Time - value; 57 | } 58 | } 59 | 60 | public Slot (SlotData data, Skeleton skeleton, Bone bone) { 61 | if (data == null) throw new ArgumentNullException("data cannot be null."); 62 | if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null."); 63 | if (bone == null) throw new ArgumentNullException("bone cannot be null."); 64 | Data = data; 65 | Skeleton = skeleton; 66 | Bone = bone; 67 | SetToBindPose(); 68 | } 69 | 70 | internal void SetToBindPose (int slotIndex) { 71 | R = Data.R; 72 | G = Data.G; 73 | B = Data.B; 74 | A = Data.A; 75 | Attachment = Data.AttachmentName == null ? null : Skeleton.GetAttachment(slotIndex, Data.AttachmentName); 76 | } 77 | 78 | public void SetToBindPose () { 79 | SetToBindPose(Skeleton.Data.Slots.IndexOf(Data)); 80 | } 81 | 82 | override public String ToString () { 83 | return Data.Name; 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /LDEngine/TiledLib/Camera.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Content; 5 | using Microsoft.Xna.Framework.Graphics; 6 | using Microsoft.Xna.Framework.Input; 7 | using TiledLib; 8 | 9 | namespace TiledLib 10 | { 11 | public class Camera 12 | { 13 | public static Camera Instance; 14 | 15 | public Vector2 Position; 16 | public int Width; 17 | public int Height; 18 | public int BoundsWidth; 19 | public int BoundsHeight; 20 | public Vector2 Target; 21 | public Rectangle ClampRect; 22 | public float Rotation; 23 | public float RotationTarget; 24 | public float Zoom = 1f; 25 | 26 | public Matrix CameraMatrix; 27 | 28 | float Speed = 0.2f; 29 | 30 | double shakeTime; 31 | float shakeAmount; 32 | Vector2 shakeOffset = Vector2.Zero; 33 | 34 | 35 | public Camera(int width, int height, int boundswidth, int boundsheight) 36 | { 37 | Instance = this; 38 | 39 | Position = new Vector2(0, 0); 40 | Width = width; 41 | Height = height; 42 | BoundsWidth = boundswidth; 43 | BoundsHeight = boundsheight; 44 | 45 | ClampRect = new Rectangle((Width / 2), (Height / 2), (boundswidth) - (Width / 2), (boundsheight) - (Height / 2)); 46 | 47 | // Set initial position and target 48 | Position.X = ClampRect.X; 49 | Position.Y = ClampRect.Y; 50 | Target = new Vector2(ClampRect.X, ClampRect.Y); 51 | } 52 | 53 | public Camera(int width, int height, Map map) 54 | : this(width, height, map.Width * map.TileWidth, map.Height * map.TileHeight) 55 | { 56 | } 57 | 58 | 59 | /// 60 | /// Update the camera 61 | /// 62 | /// 63 | public void Update(GameTime gameTime) 64 | { 65 | // Clamp target to map/camera bounds 66 | ClampRect = new Rectangle((int)((Width / 2f) / Zoom), (int)((Height / 2f) / Zoom), (BoundsWidth) - (int)((Width / 2f) / Zoom), (BoundsHeight) - (int)((Height / 2f) / Zoom)); 67 | 68 | Target.X = MathHelper.Clamp(Target.X, ClampRect.X, ClampRect.Width); 69 | Target.Y = MathHelper.Clamp(Target.Y, ClampRect.Y, ClampRect.Height); 70 | 71 | Position.X = MathHelper.Clamp(Position.X, ClampRect.X, ClampRect.Width); 72 | Position.Y = MathHelper.Clamp(Position.Y, ClampRect.Y, ClampRect.Height); 73 | 74 | if (shakeTime > 0) 75 | { 76 | shakeTime -= gameTime.ElapsedGameTime.TotalMilliseconds; 77 | shakeOffset = new Vector2((int)Helper.RandomFloat(-shakeAmount, shakeAmount), (int)Helper.RandomFloat(-shakeAmount, shakeAmount)); 78 | } 79 | else shakeOffset = Vector2.Zero; 80 | 81 | // Move camera toward target 82 | Position = Vector2.Lerp(Position, Target, Speed); 83 | 84 | CameraMatrix = Matrix.CreateTranslation(-Position.X + shakeOffset.X, -Position.Y + shakeOffset.Y, 0) * 85 | Matrix.CreateScale(Zoom) * 86 | Matrix.CreateRotationZ(Rotation) * 87 | Matrix.CreateTranslation(Width / 2f, Height / 2f, 0); 88 | } 89 | 90 | public void Shake(double time, float amount) 91 | { 92 | shakeTime = time; 93 | shakeAmount = amount; 94 | } 95 | 96 | 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Screens/PauseMenuScreen.cs: -------------------------------------------------------------------------------- 1 | #region File Description 2 | //----------------------------------------------------------------------------- 3 | // PauseMenuScreen.cs 4 | // 5 | // Microsoft XNA Community Game Platform 6 | // Copyright (C) Microsoft Corporation. All rights reserved. 7 | //----------------------------------------------------------------------------- 8 | #endregion 9 | 10 | #region Using Statements 11 | using Microsoft.Xna.Framework; 12 | using System; 13 | #endregion 14 | 15 | namespace GameStateManagement 16 | { 17 | /// 18 | /// The pause menu comes up over the top of the game, 19 | /// giving the player options to resume or quit. 20 | /// 21 | class PauseMenuScreen : MenuScreen 22 | { 23 | #region Initialization 24 | 25 | 26 | /// 27 | /// Constructor. 28 | /// 29 | public PauseMenuScreen() 30 | : base("Paused") 31 | { 32 | // Create our menu entries. 33 | MenuEntry resumeGameMenuEntry = new MenuEntry("Resume Game", true); 34 | MenuEntry optionsMenuEntry = new MenuEntry("Options", true); 35 | MenuEntry quitGameMenuEntry = new MenuEntry("Quit Game", true); 36 | 37 | 38 | 39 | resumeGameMenuEntry.Selected += resumeGameMenuEntry_Selected; 40 | quitGameMenuEntry.Selected += QuitGameMenuEntrySelected; 41 | optionsMenuEntry.Selected += OptionsMenuEntrySelected; 42 | 43 | // Add entries to the menu. 44 | MenuEntries.Add(resumeGameMenuEntry); 45 | MenuEntries.Add(optionsMenuEntry); 46 | MenuEntries.Add(quitGameMenuEntry); 47 | 48 | 49 | } 50 | 51 | void OptionsMenuEntrySelected(object sender, EventArgs e) 52 | { 53 | ScreenManager.AddScreen(new OptionsMenuScreen()); 54 | } 55 | 56 | void resumeGameMenuEntry_Selected(object sender, EventArgs e) 57 | { 58 | ScreenManager.CloseAllScreens(); 59 | } 60 | 61 | 62 | #endregion 63 | 64 | #region Handle Input 65 | 66 | 67 | protected override void OnCancel(object sender, EventArgs e) 68 | { 69 | ScreenManager.CloseAllScreens(); 70 | base.OnCancel(sender, e); 71 | } 72 | 73 | /// 74 | /// Event handler for when the Quit Game menu entry is selected. 75 | /// 76 | void QuitGameMenuEntrySelected(object sender, EventArgs e) 77 | { 78 | 79 | 80 | } 81 | 82 | void SaveGameMenuEntrySelected(object sender, EventArgs e) 83 | { 84 | OnCancel(sender, e); 85 | } 86 | 87 | void LoadGameMenuEntrySelected(object sender, EventArgs e) 88 | { 89 | //LoadingScreen.Load(ScreenManager, false, new MultiplayerGameplayScreen()); 90 | 91 | } 92 | 93 | /// 94 | /// Event handler for when the user selects ok on the "are you sure 95 | /// you want to quit" message box. This uses the loading screen to 96 | /// transition from the game back to the main menu screen. 97 | /// 98 | void ConfirmQuitMessageBoxAccepted(object sender, EventArgs e) 99 | { 100 | LoadingScreen.Load(ScreenManager, false, null, new MainMenuScreen()); 101 | } 102 | 103 | 104 | #endregion 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /LDEngine/TiledContentPipeline/TmxWriter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler; 3 | using Microsoft.Xna.Framework.Content.Pipeline; 4 | using System.Collections.Generic; 5 | 6 | namespace TiledContentPipeline 7 | { 8 | [ContentTypeWriter] 9 | public class TmxWriter : ContentTypeWriter 10 | { 11 | protected override void Write(ContentWriter output, MapContent value) 12 | { 13 | // write the map information 14 | output.Write(value.Version); 15 | output.Write((byte)value.Orientation); 16 | output.Write(value.Width); 17 | output.Write(value.Height); 18 | output.Write(value.TileWidth); 19 | output.Write(value.TileHeight); 20 | WritePropertyList(output, value.Properties); 21 | 22 | // write out our tile sets. we don't use a runtime TileSet, we read in as 23 | // a list of tile objects. so we don't write out a lot of the TileSet 24 | // information as most of it isn't useful. 25 | output.Write(value.TileSets.Count); 26 | foreach (var tileSet in value.TileSets) 27 | { 28 | // write out the first global ID of these tiles 29 | output.Write(tileSet.FirstId); 30 | 31 | // write out the name of the tileset 32 | output.Write(tileSet.Name); 33 | 34 | output.Write(tileSet.CollisionSet); 35 | 36 | // write out the texture used by the tiles 37 | output.WriteExternalReference(tileSet.Texture); 38 | 39 | // write out all the tiles in the tile set 40 | output.Write(tileSet.Tiles.Count); 41 | foreach (var tile in tileSet.Tiles) 42 | { 43 | output.WriteObject(tile.Source); 44 | WritePropertyList(output, tile.Properties); 45 | } 46 | } 47 | 48 | // write each layer 49 | output.Write(value.Layers.Count); 50 | foreach (var layer in value.Layers) 51 | { 52 | // basic information 53 | output.Write(layer.Type); 54 | output.Write(layer.Name); 55 | output.Write(layer.Width); 56 | output.Write(layer.Height); 57 | output.Write(layer.Visible); 58 | output.Write(layer.Opacity); 59 | WritePropertyList(output, layer.Properties); 60 | 61 | // figure out specific type of layer 62 | TileLayerContent tileLayer = layer as TileLayerContent; 63 | MapObjectLayerContent objLayer = layer as MapObjectLayerContent; 64 | 65 | // tile layers just write out index data 66 | if (tileLayer != null) 67 | { 68 | output.WriteObject(tileLayer.Data); 69 | } 70 | 71 | // object layers write out all the objects 72 | else if (objLayer != null) 73 | { 74 | output.Write(objLayer.Objects.Count); 75 | foreach (var mapObj in objLayer.Objects) 76 | { 77 | output.Write(mapObj.Name); 78 | output.Write(mapObj.Type); 79 | output.WriteObject(mapObj.Location); 80 | output.WriteObject(mapObj.LinePoints); 81 | WritePropertyList(output, mapObj.Properties); 82 | } 83 | } 84 | } 85 | } 86 | 87 | // helper for writing out property lists 88 | private void WritePropertyList(ContentWriter writer, List properties) 89 | { 90 | writer.Write(properties.Count); 91 | foreach (var p in properties) 92 | { 93 | writer.Write(p.Name); 94 | writer.Write(p.Value); 95 | } 96 | } 97 | 98 | public override string GetRuntimeReader(TargetPlatform targetPlatform) 99 | { 100 | return "TiledLib.MapReader, TiledLib"; 101 | } 102 | 103 | public override string GetRuntimeType(TargetPlatform targetPlatform) 104 | { 105 | return "TiledLib.Map, TiledLib"; 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | 217 | ############# 218 | ## MonoDevelop 219 | ############# 220 | 221 | *.userpref 222 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Entities/Hero.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Xna.Framework; 6 | using Microsoft.Xna.Framework.Graphics; 7 | using TiledLib; 8 | using TimersAndTweens; 9 | 10 | namespace LDEngine.Entities 11 | { 12 | class Hero : Entity 13 | { 14 | public const int MAX_LIFE = 1000; 15 | 16 | public int Life = MAX_LIFE; 17 | public int FaceDir = 1; 18 | 19 | private const float GRAVITY = 0.03f; 20 | 21 | private SpriteAnim _idleAnim; 22 | private SpriteAnim _runAnim; 23 | 24 | private Color _tint = Color.White; 25 | 26 | public Hero(Texture2D spritesheet, Rectangle hitbox, Vector2 hitboxoffset) 27 | : base(spritesheet, hitbox, null, hitboxoffset) 28 | { 29 | _idleAnim = new SpriteAnim(spritesheet, 0, 1, 16,16,0, new Vector2(8f,16f)); 30 | _runAnim = new SpriteAnim(spritesheet, 1, 7, 16, 16, 60, new Vector2(8f,16f)); 31 | _runAnim.Play(); 32 | } 33 | 34 | public override void Update(GameTime gameTime, Map gameMap) 35 | { 36 | Speed.Y += GRAVITY; 37 | 38 | Speed.X = FaceDir; 39 | 40 | _idleAnim.Update(gameTime); 41 | _runAnim.Update(gameTime); 42 | 43 | Life--; 44 | if (Life <= 0) Active = false; 45 | 46 | CheckMapCollisions(gameMap); 47 | 48 | _tint = Color.White; 49 | 50 | base.Update(gameTime, gameMap); 51 | } 52 | 53 | public override void OnBoxCollision(Entity collided, Rectangle intersect) 54 | { 55 | // Collides with another Hero 56 | if (collided.GetType() == typeof (Hero)) _tint = Color.Red; 57 | 58 | 59 | base.OnBoxCollision(collided, intersect); 60 | } 61 | 62 | private void CheckMapCollisions(Map gameMap) 63 | { 64 | // Check downward collision 65 | if(Speed.Y>0) 66 | for (int x = HitBox.Left+2; x <= HitBox.Right-2; x += 2) 67 | { 68 | bool? coll = gameMap.CheckCollision(new Vector2(x, HitBox.Bottom + Speed.Y)); 69 | if (coll.HasValue && coll.Value) Speed.Y = 0; 70 | } 71 | 72 | // Check left collision 73 | if(Speed.X<0) 74 | for (int y = HitBox.Top+2; y <= HitBox.Bottom-2; y += 2) 75 | { 76 | bool? coll = gameMap.CheckCollision(new Vector2(HitBox.Left - Speed.X, y)); 77 | if (coll.HasValue && coll.Value) 78 | { 79 | Speed.X = 0; 80 | FaceDir = 1; 81 | } 82 | } 83 | 84 | // Check right collision 85 | if (Speed.X > 0) 86 | for (int y = HitBox.Top+2; y <= HitBox.Bottom-2; y += 2) 87 | { 88 | bool? coll = gameMap.CheckCollision(new Vector2(HitBox.Right + Speed.X, y)); 89 | if (coll.HasValue && coll.Value) 90 | { 91 | Speed.X = 0; 92 | FaceDir = -1; 93 | } 94 | } 95 | } 96 | 97 | public override void Draw(SpriteBatch sb) 98 | { 99 | //_idleAnim.Draw(sb, Position); 100 | _runAnim.Draw(sb,Position,FaceDir==-1?SpriteEffects.FlipHorizontally:SpriteEffects.None, 1f, 0f, _tint); 101 | base.Draw(sb); 102 | } 103 | 104 | public override void Reset() 105 | { 106 | Life = MAX_LIFE; 107 | Speed = Vector2.Zero; 108 | 109 | base.Reset(); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /LDEngine/TiledLib.Mono.Windows/TiledLib.Mono.Windows.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {14AE59FB-38B9-4423-A3FF-3521ED686A33} 8 | Library 9 | Properties 10 | TiledLib 11 | TiledLib 12 | v4.0 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | False 35 | ..\..\dependencies\MonoGame\WindowsGL\MonoGame.Framework.dll 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | Camera.cs 48 | 49 | 50 | Helper.cs 51 | 52 | 53 | Layer.cs 54 | 55 | 56 | Map.cs 57 | 58 | 59 | MapObject.cs 60 | 61 | 62 | MapObjectLayer.cs 63 | 64 | 65 | MapReader.cs 66 | 67 | 68 | Orientation.cs 69 | 70 | 71 | PropertyCollection.cs 72 | 73 | 74 | Tile.cs 75 | 76 | 77 | TileLayer.cs 78 | 79 | 80 | 81 | 82 | 89 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Screens/OptionsMenuScreen.cs: -------------------------------------------------------------------------------- 1 | #region File Description 2 | //----------------------------------------------------------------------------- 3 | // OptionsMenuScreen.cs 4 | // 5 | // Microsoft XNA Community Game Platform 6 | // Copyright (C) Microsoft Corporation. All rights reserved. 7 | //----------------------------------------------------------------------------- 8 | #endregion 9 | 10 | #region Using Statements 11 | using Microsoft.Xna.Framework; 12 | using System; 13 | using System.Collections.Generic; 14 | using Microsoft.Xna.Framework.Graphics; 15 | using System.Linq; 16 | 17 | #endregion 18 | 19 | namespace GameStateManagement 20 | { 21 | /// 22 | /// The options screen is brought up over the top of the main menu 23 | /// screen, and gives the user a chance to configure the game 24 | /// in various hopefully useful ways. 25 | /// 26 | class OptionsMenuScreen : MenuScreen 27 | { 28 | #region Fields 29 | 30 | MenuEntry fullScreen; 31 | 32 | #endregion 33 | 34 | #region Initialization 35 | 36 | 37 | /// 38 | /// Constructor. 39 | /// 40 | public OptionsMenuScreen() 41 | : base("Options") 42 | { 43 | 44 | 45 | 46 | 47 | } 48 | 49 | public override void LoadContent() 50 | { 51 | // Create our menu entries. 52 | fullScreen = new MenuEntry(string.Empty, true); 53 | 54 | SetMenuEntryText(); 55 | 56 | MenuEntry back = new MenuEntry("Back", true); 57 | 58 | // Hook up menu event handlers. 59 | fullScreen.Selected += FullScreenMenuEntrySelected; 60 | back.Selected += (sender, args) => ExitScreen(); 61 | 62 | MenuEntries.Add(fullScreen); 63 | MenuEntries.Add(back); 64 | 65 | base.LoadContent(); 66 | } 67 | 68 | public override void HandleInput(InputState input) 69 | { 70 | 71 | base.HandleInput(input); 72 | } 73 | 74 | protected override void OnCancel(object sender, EventArgs e) 75 | { 76 | 77 | 78 | base.OnCancel(sender, e); 79 | } 80 | 81 | 82 | 83 | /// 84 | /// Fills in the latest values for the options screen menu text. 85 | /// 86 | void SetMenuEntryText() 87 | { 88 | fullScreen.Text = ScreenManager.Game.GraphicsDevice.PresentationParameters.IsFullScreen ? "Windowed":"Fullscreen"; 89 | } 90 | 91 | 92 | #endregion 93 | 94 | #region Handle Input 95 | 96 | 97 | /// 98 | /// Event handler for when the Ungulate menu entry is selected. 99 | /// 100 | void FullScreenMenuEntrySelected(object sender, EventArgs e) 101 | { 102 | ScreenManager.Game.ToggleFullScreen(); 103 | SetMenuEntryText(); 104 | } 105 | 106 | 107 | 108 | 109 | #endregion 110 | } 111 | 112 | 113 | 114 | public class Resolution 115 | { 116 | public int Width; 117 | public int Height; 118 | 119 | public Resolution(int w, int h) 120 | { 121 | Width = w; 122 | Height = h; 123 | } 124 | 125 | public override string ToString() 126 | { 127 | return Width.ToString() + "x" + Height.ToString(); 128 | } 129 | } 130 | 131 | public class ResolutionComparer : IEqualityComparer 132 | { 133 | public bool Equals(Resolution x, Resolution y) 134 | { 135 | return x.Width == y.Width && x.Height == y.Height; 136 | } 137 | 138 | public int GetHashCode(Resolution obj) 139 | { 140 | return obj.GetHashCode(); 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/Skin.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Esoteric Software 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | ******************************************************************************/ 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | 29 | namespace Spine { 30 | /** Stores attachments by slot index and attachment name. */ 31 | public class Skin { 32 | public String Name { get; private set; } 33 | private Dictionary, Attachment> attachments = new Dictionary, Attachment>(); 34 | 35 | public Skin (String name) { 36 | if (name == null) throw new ArgumentNullException("name cannot be null."); 37 | Name = name; 38 | } 39 | 40 | public void AddAttachment (int slotIndex, String name, Attachment attachment) { 41 | if (attachment == null) throw new ArgumentNullException("attachment cannot be null."); 42 | attachments.Add(new KeyValuePair(slotIndex, name), attachment); 43 | } 44 | 45 | /** @return May be null. */ 46 | public Attachment GetAttachment (int slotIndex, String name) { 47 | KeyValuePair key = new KeyValuePair(slotIndex, name); 48 | if (!attachments.ContainsKey(key)) return null; 49 | return attachments[key]; 50 | } 51 | 52 | public void FindNamesForSlot (int slotIndex, List names) { 53 | if (names == null) throw new ArgumentNullException("names cannot be null."); 54 | foreach (KeyValuePair key in attachments.Keys) 55 | if (key.Key == slotIndex) names.Add(key.Value); 56 | } 57 | 58 | public void FindAttachmentsForSlot (int slotIndex, List attachments) { 59 | if (attachments == null) throw new ArgumentNullException("attachments cannot be null."); 60 | foreach (KeyValuePair, Attachment> entry in this.attachments) 61 | if (entry.Key.Key == slotIndex) attachments.Add(entry.Value); 62 | } 63 | 64 | override public String ToString () { 65 | return Name; 66 | } 67 | 68 | /** Attach all attachments from this skin if the corresponding attachment from the old skin is currently attached. */ 69 | internal void AttachAll (Skeleton skeleton, Skin oldSkin) { 70 | foreach (KeyValuePair, Attachment> entry in oldSkin.attachments) { 71 | int slotIndex = entry.Key.Key; 72 | Slot slot = skeleton.Slots[slotIndex]; 73 | if (slot.Attachment == entry.Value) { 74 | Attachment attachment = GetAttachment(slotIndex, entry.Key.Value); 75 | if (attachment != null) slot.Attachment = attachment; 76 | } 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /LDEngine/TiledContentPipeline/TmxProcessor.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.IO; 3 | using System.Xml; 4 | using System.Drawing; 5 | using Microsoft.Xna.Framework.Content.Pipeline; 6 | using Microsoft.Xna.Framework.Content.Pipeline.Graphics; 7 | using Microsoft.Xna.Framework.Content.Pipeline.Processors; 8 | using Microsoft.Xna.Framework.Graphics; 9 | 10 | namespace TiledContentPipeline 11 | { 12 | [ContentProcessor(DisplayName = "TMX Processor")] 13 | public class TmxProcessor : ContentProcessor 14 | { 15 | [DisplayName("TileSet Directory")] 16 | [Description("The directory (relative to the content root) in which the processor will find the tile sheet images.")] 17 | public string TileSetDirectory { get; set; } 18 | 19 | public override MapContent Process(XmlDocument input, ContentProcessorContext context) 20 | { 21 | // get our MapContent which does all the parsing of the XmlDocument we need 22 | MapContent content = new MapContent(input); 23 | 24 | // now we do some processing on tile sets to load external textures and figure out tile regions 25 | foreach (var tileSet in content.TileSets) 26 | { 27 | // get the full path to the file 28 | string path = string.IsNullOrEmpty(TileSetDirectory) ? tileSet.Image : Path.Combine(TileSetDirectory, tileSet.Image); 29 | string asset = path.Remove(path.LastIndexOf('.')); 30 | path = Path.Combine(Directory.GetCurrentDirectory(), path); 31 | 32 | //if (path.StartsWith("\\")) path = path.Substring(1); 33 | //if (asset.StartsWith("\\")) asset = asset.Substring(1); 34 | 35 | 36 | // build the asset as an external reference 37 | OpaqueDataDictionary data = new OpaqueDataDictionary(); 38 | data.Add("GenerateMipmaps", false); 39 | data.Add("ResizeToPowerOfTwo", false); 40 | data.Add("TextureFormat", TextureProcessorOutputFormat.Color); 41 | data.Add("ColorKeyEnabled", tileSet.ColorKey.HasValue); 42 | data.Add("ColorKeyColor", tileSet.ColorKey.HasValue ? tileSet.ColorKey.Value : Microsoft.Xna.Framework.Color.Magenta); 43 | tileSet.Texture = context.BuildAsset( 44 | new ExternalReference(path), 45 | "TextureProcessor", 46 | data, 47 | "TextureImporter", 48 | asset); 49 | 50 | // load the image so we can compute the individual tile source rectangles 51 | int imageWidth = 0; 52 | int imageHeight = 0; 53 | using (Image image = Image.FromFile(path)) 54 | { 55 | imageWidth = image.Width; 56 | imageHeight = image.Height; 57 | } 58 | 59 | // remove the margins from our calculations 60 | imageWidth -= tileSet.Margin * 2; 61 | imageHeight -= tileSet.Margin * 2; 62 | 63 | // figure out how many frames fit on the X axis 64 | int frameCountX = 1; 65 | while (frameCountX * tileSet.TileWidth < imageWidth) 66 | { 67 | frameCountX++; 68 | imageWidth -= tileSet.Spacing; 69 | } 70 | 71 | // figure out how many frames fit on the Y axis 72 | int frameCountY = 1; 73 | while (frameCountY * tileSet.TileHeight < imageHeight) 74 | { 75 | frameCountY++; 76 | imageHeight -= tileSet.Spacing; 77 | } 78 | 79 | // make our tiles. tiles are numbered by row, left to right. 80 | for (int y = 0; y < frameCountY; y++) 81 | { 82 | for (int x = 0; x < frameCountX; x++) 83 | { 84 | Tile tile = new Tile(); 85 | 86 | // calculate the source rectangle 87 | int rx = tileSet.Margin + x * (tileSet.TileWidth + tileSet.Spacing); 88 | int ry = tileSet.Margin + y * (tileSet.TileHeight + tileSet.Spacing); 89 | tile.Source = new Microsoft.Xna.Framework.Rectangle(rx, ry, tileSet.TileWidth, tileSet.TileHeight); 90 | 91 | // get any properties from the tile set 92 | if (tileSet.TileProperties.ContainsKey(y + x)) 93 | { 94 | tile.Properties = tileSet.TileProperties[y + x]; 95 | } 96 | 97 | // save the tile 98 | tileSet.Tiles.Add(tile); 99 | } 100 | } 101 | } 102 | 103 | return content; 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /LDEngine/TiledContentPipeline/TiledContentPipeline.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {84C8D1CA-634D-4977-ADD3-23CC6CB36F5A} 5 | Debug 6 | x86 7 | Library 8 | Properties 9 | TiledContentPipeline 10 | TiledContentPipeline 11 | v4.0 12 | Windows 13 | v4.0 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\x86\Debug 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | x86 25 | 26 | 27 | pdbonly 28 | true 29 | bin\x86\Release 30 | TRACE 31 | prompt 32 | 4 33 | x86 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 4.0 45 | 46 | 47 | 4.0 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | {43e57147-8c31-48f8-8c54-f090bf9d715b} 66 | TiledLib %28TiledLib\TiledLib%29 67 | 68 | 69 | 70 | 71 | 78 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/AudioController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Content; 6 | using Microsoft.Xna.Framework.Graphics; 7 | using Microsoft.Xna.Framework.Input; 8 | using System.IO; 9 | using System.Diagnostics; 10 | using Microsoft.Xna.Framework.Audio; 11 | using Microsoft.Xna.Framework.Media; 12 | using TiledLib; 13 | 14 | 15 | namespace LDEngine 16 | { 17 | public static class AudioController 18 | { 19 | private static float _sfxVolume = 1f; 20 | public static float SFXVolume 21 | { 22 | get { return _sfxVolume; } 23 | set { _sfxVolume = MathHelper.Clamp(value, 0f, 1f); } 24 | } 25 | 26 | private static float _musicVolume = 1f; 27 | public static float MusicVolume 28 | { 29 | get { return _musicVolume; } 30 | set { _musicVolume = MathHelper.Clamp(value, 0f, 1f); } 31 | } 32 | 33 | private static Dictionary _effects; 34 | 35 | private static Dictionary _songs; 36 | 37 | private static string _playingTrack = ""; 38 | private static bool _isPlaying; 39 | 40 | public static void LoadContent(ContentManager content) 41 | { 42 | _effects = new Dictionary(); 43 | 44 | //_effects.Add("explode", content.Load("sfx/explode")); 45 | 46 | 47 | _songs = new Dictionary(); 48 | 49 | //_songs.Add("theme", content.Load("music").CreateInstance()); 50 | 51 | foreach (SoundEffectInstance s in _songs.Values) 52 | { 53 | s.IsLooped = true; 54 | s.Volume = _musicVolume; 55 | } 56 | } 57 | 58 | public static void PlayMusic(string track) 59 | { 60 | if (!_songs.ContainsKey(track.ToLower())) return; 61 | 62 | StopMusic(); 63 | 64 | _playingTrack = track.ToLower(); 65 | _isPlaying = true; 66 | _songs[track].Play(); 67 | } 68 | 69 | public static void StopMusic() 70 | { 71 | if (!_isPlaying) return; 72 | 73 | _isPlaying = false; 74 | _songs[_playingTrack].Stop(); 75 | } 76 | 77 | public static void PlaySFX(string name) 78 | { 79 | _effects[name].Play(_sfxVolume, 0f, 0f); 80 | } 81 | public static void PlaySFX(string name, float pitch) 82 | { 83 | _effects[name].Play(_sfxVolume, pitch, 0f); 84 | } 85 | public static void PlaySFX(string name, float volume, float pitch, float pan) 86 | { 87 | if (pan < -1f || pan > 1f) return; 88 | 89 | pitch = MathHelper.Clamp(pitch, -1.00f, 1.00f); 90 | volume = MathHelper.Clamp(volume, 0f, 1f); 91 | 92 | _effects[name].Play(volume * _sfxVolume, pitch, pan); 93 | } 94 | public static void PlaySFX(string name, float minpitch, float maxpitch) 95 | { 96 | _effects[name].Play(_sfxVolume, minpitch + (Helper.RandomFloat(1f) * (maxpitch - minpitch)), 0f); 97 | } 98 | 99 | internal static void PlaySFX(string name, float volume, float minpitch, float maxpitch, Camera gameCamera, Vector2 position) 100 | { 101 | Vector2 screenPos = Vector2.Transform(position, gameCamera.CameraMatrix); 102 | 103 | float pan = (screenPos.X - (gameCamera.Width / 2f)) / (gameCamera.Width / 2f); 104 | if(pan>-1f && pan<1f) 105 | _effects[name].Play(volume * _sfxVolume, minpitch + (Helper.RandomFloat(1f) * (maxpitch - minpitch)), pan); 106 | } 107 | 108 | public static void Update(GameTime gameTime) 109 | { 110 | if (_playingTrack == "") return; 111 | 112 | foreach (SoundEffectInstance s in _songs.Values) 113 | s.Volume = _musicVolume; 114 | } 115 | 116 | 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /LDEngine/LDEngineContent/LDEngineContent.contentproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {F4E79BFE-6F76-49C2-B252-708394435130} 5 | {96E2B04D-8817-42c6-938A-82C39BA4D311};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | v4.0 11 | v4.0 12 | bin\$(Platform)\$(Configuration) 13 | Content 14 | 15 | 16 | x86 17 | 18 | 19 | x86 20 | 21 | 22 | LDEngineContent 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | font 35 | FontDescriptionImporter 36 | FontDescriptionProcessor 37 | 38 | 39 | 40 | 41 | blank 42 | TextureImporter 43 | TextureProcessor 44 | 45 | 46 | 47 | 48 | map 49 | TmxImporter 50 | TmxProcessor 51 | 52 | 53 | 54 | 55 | {84c8d1ca-634d-4977-add3-23cc6cb36f5a} 56 | TiledContentPipeline 57 | 58 | 59 | 60 | 61 | testhero 62 | TextureImporter 63 | TextureProcessor 64 | 65 | 66 | 67 | 68 | particles 69 | TextureImporter 70 | TextureProcessor 71 | 72 | 73 | 74 | 81 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/Bone.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Esoteric Software 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | ******************************************************************************/ 25 | 26 | using System; 27 | 28 | namespace Spine { 29 | public class Bone { 30 | static public bool yDown; 31 | 32 | public BoneData Data { get; private set; } 33 | public Bone Parent { get; private set; } 34 | public float X { get; set; } 35 | public float Y { get; set; } 36 | public float Rotation { get; set; } 37 | public float ScaleX { get; set; } 38 | public float ScaleY { get; set; } 39 | 40 | public float M00 { get; private set; } 41 | public float M01 { get; private set; } 42 | public float M10 { get; private set; } 43 | public float M11 { get; private set; } 44 | public float WorldX { get; private set; } 45 | public float WorldY { get; private set; } 46 | public float WorldRotation { get; private set; } 47 | public float WorldScaleX { get; private set; } 48 | public float WorldScaleY { get; private set; } 49 | 50 | /** @param parent May be null. */ 51 | public Bone (BoneData data, Bone parent) { 52 | if (data == null) throw new ArgumentNullException("data cannot be null."); 53 | Data = data; 54 | Parent = parent; 55 | SetToBindPose(); 56 | } 57 | 58 | /** Computes the world SRT using the parent bone and the local SRT. */ 59 | public void UpdateWorldTransform (bool flipX, bool flipY) { 60 | Bone parent = Parent; 61 | if (parent != null) { 62 | WorldX = X * parent.M00 + Y * parent.M01 + parent.WorldX; 63 | WorldY = X * parent.M10 + Y * parent.M11 + parent.WorldY; 64 | WorldScaleX = parent.WorldScaleX * ScaleX; 65 | WorldScaleY = parent.WorldScaleY * ScaleY; 66 | WorldRotation = parent.WorldRotation + Rotation; 67 | } else { 68 | WorldX = X; 69 | WorldY = Y; 70 | WorldScaleX = ScaleX; 71 | WorldScaleY = ScaleY; 72 | WorldRotation = Rotation; 73 | } 74 | float radians = WorldRotation * (float)Math.PI / 180; 75 | float cos = (float)Math.Cos(radians); 76 | float sin = (float)Math.Sin(radians); 77 | M00 = cos * WorldScaleX; 78 | M10 = sin * WorldScaleX; 79 | M01 = -sin * WorldScaleY; 80 | M11 = cos * WorldScaleY; 81 | if (flipX) { 82 | M00 = -M00; 83 | M01 = -M01; 84 | } 85 | if (flipY) { 86 | M10 = -M10; 87 | M11 = -M11; 88 | } 89 | if (yDown) { 90 | M10 = -M10; 91 | M11 = -M11; 92 | } 93 | } 94 | 95 | public void SetToBindPose () { 96 | BoneData data = Data; 97 | X = data.X; 98 | Y = data.Y; 99 | Rotation = data.Rotation; 100 | ScaleX = data.ScaleX; 101 | ScaleY = data.ScaleY; 102 | } 103 | 104 | override public String ToString () { 105 | return Data.Name; 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /LDEngine/TiledLib/TiledLib.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {43E57147-8C31-48F8-8C54-F090BF9D715B} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | TiledLib 11 | TiledLib 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | 1f209637-3e12-47a8-95a3-b1b4d9c71c2f 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 4.0 54 | 55 | 56 | 4.0 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 84 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/Atlas.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Esoteric Software 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | ******************************************************************************/ 25 | 26 | using System; 27 | using System.IO; 28 | using System.Collections.Generic; 29 | using System.Linq; 30 | using Microsoft.Xna.Framework; 31 | using Microsoft.Xna.Framework.Audio; 32 | using Microsoft.Xna.Framework.Content; 33 | using Microsoft.Xna.Framework.GamerServices; 34 | using Microsoft.Xna.Framework.Graphics; 35 | using Microsoft.Xna.Framework.Input; 36 | using Microsoft.Xna.Framework.Media; 37 | 38 | namespace Spine { 39 | public class Atlas : BaseAtlas { 40 | private GraphicsDevice device; 41 | 42 | public Atlas (GraphicsDevice device, String atlasFile, ContentManager content) { 43 | this.device = device; 44 | using (StreamReader reader = new StreamReader(Path.Combine(content.RootDirectory, atlasFile))) { 45 | load(reader, Path.GetDirectoryName(atlasFile), content); 46 | } 47 | } 48 | 49 | override protected AtlasPage NewAtlasPage (String path, ContentManager content) { 50 | XnaAtlasPage page = new XnaAtlasPage(); 51 | page.Texture = content.Load(path); 52 | return page; 53 | } 54 | 55 | private Texture2D loadTexture (string path) { 56 | Texture2D file; 57 | using (Stream fileStream = new FileStream(path, FileMode.Open)) { 58 | file = Texture2D.FromStream(device, fileStream); 59 | } 60 | 61 | // Setup a render target to hold our final texture which will have premulitplied alpha values 62 | RenderTarget2D result = new RenderTarget2D(device, file.Width, file.Height); 63 | device.SetRenderTarget(result); 64 | device.Clear(Color.Black); 65 | 66 | // Multiply each color by the source alpha, and write in just the color values into the final texture 67 | BlendState blendColor = new BlendState(); 68 | blendColor.ColorWriteChannels = ColorWriteChannels.Red | ColorWriteChannels.Green | ColorWriteChannels.Blue; 69 | blendColor.AlphaDestinationBlend = Blend.Zero; 70 | blendColor.ColorDestinationBlend = Blend.Zero; 71 | blendColor.AlphaSourceBlend = Blend.SourceAlpha; 72 | blendColor.ColorSourceBlend = Blend.SourceAlpha; 73 | 74 | SpriteBatch spriteBatch = new SpriteBatch(device); 75 | spriteBatch.Begin(SpriteSortMode.Immediate, blendColor); 76 | spriteBatch.Draw(file, file.Bounds, Color.White); 77 | spriteBatch.End(); 78 | 79 | // Now copy over the alpha values from the PNG source texture to the final one, without multiplying them 80 | BlendState blendAlpha = new BlendState(); 81 | blendAlpha.ColorWriteChannels = ColorWriteChannels.Alpha; 82 | blendAlpha.AlphaDestinationBlend = Blend.Zero; 83 | blendAlpha.ColorDestinationBlend = Blend.Zero; 84 | blendAlpha.AlphaSourceBlend = Blend.One; 85 | blendAlpha.ColorSourceBlend = Blend.One; 86 | 87 | spriteBatch.Begin(SpriteSortMode.Immediate, blendAlpha); 88 | spriteBatch.Draw(file, file.Bounds, Color.White); 89 | spriteBatch.End(); 90 | 91 | // Release the GPU back to drawing to the screen 92 | device.SetRenderTarget(null); 93 | 94 | return result as Texture2D; 95 | } 96 | } 97 | 98 | public class XnaAtlasPage : AtlasPage { 99 | public Texture2D Texture { get; set; } 100 | 101 | override public int GetTextureWidth () { 102 | return Texture.Width; 103 | } 104 | 105 | override public int GetTextureHeight () { 106 | return Texture.Height; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Tween.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Policy; 5 | using System.Text; 6 | using Microsoft.Xna.Framework; 7 | 8 | namespace TimersAndTweens 9 | { 10 | public delegate float TweenFunc(float progress); 11 | 12 | enum TweenState 13 | { 14 | Running, 15 | Paused, 16 | Finished 17 | } 18 | 19 | enum TweenDirection 20 | { 21 | Forward, 22 | Reverse 23 | } 24 | 25 | class Tween 26 | { 27 | public double CurrentTime; 28 | public double TargetTime; 29 | public bool Looping; 30 | public bool PingPong; 31 | public TweenDirection CurrentDirection; 32 | public TweenDirection InitialDirection; 33 | public string Name; 34 | 35 | public TweenState State; 36 | 37 | public float Value; 38 | 39 | private readonly Action _callback; 40 | private readonly TweenFunc _tweenFunc; 41 | 42 | public Tween(string name, TweenFunc func, Action callback, double time, bool pingpong, bool loop) 43 | { 44 | Name = name; 45 | _callback = callback; 46 | _tweenFunc = func; 47 | TargetTime = time; 48 | Looping = loop; 49 | PingPong = pingpong; 50 | 51 | CurrentTime = 0; 52 | CurrentDirection = TweenDirection.Forward; 53 | InitialDirection = TweenDirection.Forward; 54 | Value = 0f; 55 | 56 | if (PingPong) TargetTime /= 2; // If we're pingponging, halve the time so that TargetTime is one complete cycle 57 | } 58 | 59 | public Tween(string name, TweenFunc func, Action callback, double time, bool pingpong, bool loop, TweenDirection initialDirection) 60 | : this(name, func, callback, time, pingpong, loop) 61 | { 62 | CurrentDirection = initialDirection; 63 | InitialDirection = initialDirection; 64 | if (initialDirection == TweenDirection.Reverse) CurrentTime = TargetTime; 65 | } 66 | 67 | public void Update(GameTime gameTime) 68 | { 69 | if(State!=TweenState.Running) return; 70 | 71 | switch (CurrentDirection) 72 | { 73 | case TweenDirection.Forward: 74 | CurrentTime += gameTime.ElapsedGameTime.TotalMilliseconds; 75 | if (CurrentTime >= TargetTime) 76 | { 77 | if (PingPong) 78 | { 79 | if (InitialDirection == TweenDirection.Reverse) 80 | { 81 | if(Looping) CurrentDirection = TweenDirection.Reverse; 82 | else State = TweenState.Finished; 83 | } 84 | else CurrentDirection = TweenDirection.Reverse; 85 | CurrentTime -= (CurrentTime - TargetTime); 86 | } 87 | else 88 | { 89 | if (Looping) CurrentTime = (CurrentTime-TargetTime); 90 | else State = TweenState.Finished; 91 | } 92 | } 93 | break; 94 | case TweenDirection.Reverse: 95 | CurrentTime -= gameTime.ElapsedGameTime.TotalMilliseconds; 96 | if (CurrentTime <= 0) 97 | { 98 | if (PingPong) 99 | { 100 | if (InitialDirection == TweenDirection.Forward) 101 | { 102 | if(Looping) CurrentDirection = TweenDirection.Forward; 103 | else State = TweenState.Finished; 104 | } 105 | else CurrentDirection = TweenDirection.Forward; 106 | CurrentTime = -CurrentTime; 107 | } 108 | else 109 | { 110 | if (Looping) CurrentTime = TargetTime+CurrentTime; 111 | else State = TweenState.Finished; 112 | } 113 | } 114 | break; 115 | default: 116 | throw new ArgumentOutOfRangeException(); 117 | } 118 | 119 | float pos = (1f/(float)TargetTime) * (float)CurrentTime; 120 | Value = _tweenFunc(pos); 121 | _callback(this); 122 | } 123 | 124 | public void Pause() 125 | { 126 | State = TweenState.Paused; 127 | } 128 | 129 | public void Resume() 130 | { 131 | State = TweenState.Running; 132 | } 133 | 134 | public void Kill() 135 | { 136 | State = TweenState.Finished; 137 | } 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /LDEngine/TiledLib/TiledLib.Linux.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {43E57147-8C31-48F8-8C54-F090BF9D715B} 5 | Debug 6 | x86 7 | Library 8 | Properties 9 | TiledLib 10 | TiledLib 11 | v4.0 12 | Client 13 | v4.0 14 | Windows 15 | Reach 16 | 1f209637-3e12-47a8-95a3-b1b4d9c71c2f 17 | Library 18 | 8.0.30703 19 | 2.0 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\x86\Debug 26 | DEBUG;TRACE;LINUX 27 | prompt 28 | 4 29 | true 30 | false 31 | x86 32 | false 33 | 34 | 35 | pdbonly 36 | true 37 | bin\x86\Release 38 | TRACE;WINDOWS 39 | prompt 40 | 4 41 | true 42 | false 43 | x86 44 | true 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 | 78 | 79 | 80 | {E4130F8D-D301-4E0C-916D-489C4A23C9B1} 81 | TiledSharp 82 | 83 | 84 | {35253CE1-C864-4CD3-8249-4D1319748E8F} 85 | MonoGame.Framework.SDL2 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/SkeletonData.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Esoteric Software 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | ******************************************************************************/ 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | 29 | namespace Spine { 30 | public class SkeletonData { 31 | public String Name { get; set; } 32 | public List Bones { get; private set; } // Ordered parents first. 33 | public List Slots { get; private set; } // Bind pose draw order. 34 | public List Skins { get; private set; } 35 | /** May be null. */ 36 | public Skin DefaultSkin; 37 | public List Animations { get; private set; } 38 | 39 | public SkeletonData () { 40 | Bones = new List(); 41 | Slots = new List(); 42 | Skins = new List(); 43 | Animations = new List(); 44 | } 45 | 46 | // --- Bones. 47 | 48 | public void AddBone (BoneData bone) { 49 | if (bone == null) throw new ArgumentNullException("bone cannot be null."); 50 | Bones.Add(bone); 51 | } 52 | 53 | 54 | /** @return May be null. */ 55 | public BoneData FindBone (String boneName) { 56 | if (boneName == null) throw new ArgumentNullException("boneName cannot be null."); 57 | for (int i = 0, n = Bones.Count; i < n; i++) { 58 | BoneData bone = Bones[i]; 59 | if (bone.Name == boneName) return bone; 60 | } 61 | return null; 62 | } 63 | 64 | /** @return -1 if the bone was not found. */ 65 | public int FindBoneIndex (String boneName) { 66 | if (boneName == null) throw new ArgumentNullException("boneName cannot be null."); 67 | for (int i = 0, n = Bones.Count; i < n; i++) 68 | if (Bones[i].Name == boneName) return i; 69 | return -1; 70 | } 71 | 72 | // --- Slots. 73 | 74 | public void AddSlot (SlotData slot) { 75 | if (slot == null) throw new ArgumentNullException("slot cannot be null."); 76 | Slots.Add(slot); 77 | } 78 | 79 | /** @return May be null. */ 80 | public SlotData FindSlot (String slotName) { 81 | if (slotName == null) throw new ArgumentNullException("slotName cannot be null."); 82 | for (int i = 0, n = Slots.Count; i < n; i++) { 83 | SlotData slot = Slots[i]; 84 | if (slot.Name == slotName) return slot; 85 | } 86 | return null; 87 | } 88 | 89 | /** @return -1 if the bone was not found. */ 90 | public int FindSlotIndex (String slotName) { 91 | if (slotName == null) throw new ArgumentNullException("slotName cannot be null."); 92 | for (int i = 0, n = Slots.Count; i < n; i++) 93 | if (Slots[i].Name == slotName) return i; 94 | return -1; 95 | } 96 | 97 | // --- Skins. 98 | 99 | public void AddSkin (Skin skin) { 100 | if (skin == null) throw new ArgumentNullException("skin cannot be null."); 101 | Skins.Add(skin); 102 | } 103 | 104 | /** @return May be null. */ 105 | public Skin FindSkin (String skinName) { 106 | if (skinName == null) throw new ArgumentNullException("skinName cannot be null."); 107 | foreach (Skin skin in Skins) 108 | if (skin.Name == skinName) return skin; 109 | return null; 110 | } 111 | 112 | // --- Animations. 113 | 114 | public void AddAnimation (Animation animation) { 115 | if (animation == null) throw new ArgumentNullException("animation cannot be null."); 116 | Animations.Add(animation); 117 | } 118 | 119 | /** @return May be null. */ 120 | public Animation FindAnimation (String animationName) { 121 | if (animationName == null) throw new ArgumentNullException("animationName cannot be null."); 122 | for (int i = 0, n = Animations.Count; i < n; i++) { 123 | Animation animation = Animations[i]; 124 | if (animation.Name == animationName) return animation; 125 | } 126 | return null; 127 | } 128 | 129 | // --- 130 | 131 | override public String ToString () { 132 | return Name != null ? Name : base.ToString(); 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /LDEngine.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LDEngine", "LDEngine\LDEngine\LDEngine.csproj", "{ACD38123-2E1B-4A41-BD1C-5BC5F9AE2D74}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LDEngineContent", "LDEngine\LDEngineContent\LDEngineContent.contentproj", "{F4E79BFE-6F76-49C2-B252-708394435130}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TiledLib", "LDEngine\TiledLib\TiledLib.csproj", "{43E57147-8C31-48F8-8C54-F090BF9D715B}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TiledContentPipeline", "LDEngine\TiledContentPipeline\TiledContentPipeline.csproj", "{84C8D1CA-634D-4977-ADD3-23CC6CB36F5A}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TiledLib.Mono.Windows", "LDEngine\TiledLib.Mono.Windows\TiledLib.Mono.Windows.csproj", "{14AE59FB-38B9-4423-A3FF-3521ED686A33}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Debug|Mixed Platforms = Debug|Mixed Platforms 18 | Debug|x86 = Debug|x86 19 | Release|Any CPU = Release|Any CPU 20 | Release|Mixed Platforms = Release|Mixed Platforms 21 | Release|x86 = Release|x86 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {ACD38123-2E1B-4A41-BD1C-5BC5F9AE2D74}.Debug|Any CPU.ActiveCfg = Debug|x86 25 | {ACD38123-2E1B-4A41-BD1C-5BC5F9AE2D74}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 26 | {ACD38123-2E1B-4A41-BD1C-5BC5F9AE2D74}.Debug|Mixed Platforms.Build.0 = Debug|x86 27 | {ACD38123-2E1B-4A41-BD1C-5BC5F9AE2D74}.Debug|x86.ActiveCfg = Debug|x86 28 | {ACD38123-2E1B-4A41-BD1C-5BC5F9AE2D74}.Debug|x86.Build.0 = Debug|x86 29 | {ACD38123-2E1B-4A41-BD1C-5BC5F9AE2D74}.Release|Any CPU.ActiveCfg = Release|x86 30 | {ACD38123-2E1B-4A41-BD1C-5BC5F9AE2D74}.Release|Mixed Platforms.ActiveCfg = Release|x86 31 | {ACD38123-2E1B-4A41-BD1C-5BC5F9AE2D74}.Release|Mixed Platforms.Build.0 = Release|x86 32 | {ACD38123-2E1B-4A41-BD1C-5BC5F9AE2D74}.Release|x86.ActiveCfg = Release|x86 33 | {ACD38123-2E1B-4A41-BD1C-5BC5F9AE2D74}.Release|x86.Build.0 = Release|x86 34 | {F4E79BFE-6F76-49C2-B252-708394435130}.Debug|Any CPU.ActiveCfg = Debug|x86 35 | {F4E79BFE-6F76-49C2-B252-708394435130}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 36 | {F4E79BFE-6F76-49C2-B252-708394435130}.Debug|x86.ActiveCfg = Debug|x86 37 | {F4E79BFE-6F76-49C2-B252-708394435130}.Release|Any CPU.ActiveCfg = Release|x86 38 | {F4E79BFE-6F76-49C2-B252-708394435130}.Release|Mixed Platforms.ActiveCfg = Release|x86 39 | {F4E79BFE-6F76-49C2-B252-708394435130}.Release|x86.ActiveCfg = Release|x86 40 | {43E57147-8C31-48F8-8C54-F090BF9D715B}.Debug|Any CPU.ActiveCfg = Debug|x86 41 | {43E57147-8C31-48F8-8C54-F090BF9D715B}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 42 | {43E57147-8C31-48F8-8C54-F090BF9D715B}.Debug|Mixed Platforms.Build.0 = Debug|x86 43 | {43E57147-8C31-48F8-8C54-F090BF9D715B}.Debug|x86.ActiveCfg = Debug|x86 44 | {43E57147-8C31-48F8-8C54-F090BF9D715B}.Debug|x86.Build.0 = Debug|x86 45 | {43E57147-8C31-48F8-8C54-F090BF9D715B}.Release|Any CPU.ActiveCfg = Release|x86 46 | {43E57147-8C31-48F8-8C54-F090BF9D715B}.Release|Mixed Platforms.ActiveCfg = Release|x86 47 | {43E57147-8C31-48F8-8C54-F090BF9D715B}.Release|Mixed Platforms.Build.0 = Release|x86 48 | {43E57147-8C31-48F8-8C54-F090BF9D715B}.Release|x86.ActiveCfg = Release|x86 49 | {43E57147-8C31-48F8-8C54-F090BF9D715B}.Release|x86.Build.0 = Release|x86 50 | {84C8D1CA-634D-4977-ADD3-23CC6CB36F5A}.Debug|Any CPU.ActiveCfg = Debug|x86 51 | {84C8D1CA-634D-4977-ADD3-23CC6CB36F5A}.Debug|Any CPU.Build.0 = Debug|x86 52 | {84C8D1CA-634D-4977-ADD3-23CC6CB36F5A}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 53 | {84C8D1CA-634D-4977-ADD3-23CC6CB36F5A}.Debug|Mixed Platforms.Build.0 = Debug|x86 54 | {84C8D1CA-634D-4977-ADD3-23CC6CB36F5A}.Debug|x86.ActiveCfg = Debug|x86 55 | {84C8D1CA-634D-4977-ADD3-23CC6CB36F5A}.Debug|x86.Build.0 = Debug|x86 56 | {84C8D1CA-634D-4977-ADD3-23CC6CB36F5A}.Release|Any CPU.ActiveCfg = Release|x86 57 | {84C8D1CA-634D-4977-ADD3-23CC6CB36F5A}.Release|Any CPU.Build.0 = Release|x86 58 | {84C8D1CA-634D-4977-ADD3-23CC6CB36F5A}.Release|Mixed Platforms.ActiveCfg = Release|x86 59 | {84C8D1CA-634D-4977-ADD3-23CC6CB36F5A}.Release|Mixed Platforms.Build.0 = Release|x86 60 | {84C8D1CA-634D-4977-ADD3-23CC6CB36F5A}.Release|x86.ActiveCfg = Release|x86 61 | {84C8D1CA-634D-4977-ADD3-23CC6CB36F5A}.Release|x86.Build.0 = Release|x86 62 | {14AE59FB-38B9-4423-A3FF-3521ED686A33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 63 | {14AE59FB-38B9-4423-A3FF-3521ED686A33}.Debug|Any CPU.Build.0 = Debug|Any CPU 64 | {14AE59FB-38B9-4423-A3FF-3521ED686A33}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 65 | {14AE59FB-38B9-4423-A3FF-3521ED686A33}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 66 | {14AE59FB-38B9-4423-A3FF-3521ED686A33}.Debug|x86.ActiveCfg = Debug|Any CPU 67 | {14AE59FB-38B9-4423-A3FF-3521ED686A33}.Release|Any CPU.ActiveCfg = Release|Any CPU 68 | {14AE59FB-38B9-4423-A3FF-3521ED686A33}.Release|Any CPU.Build.0 = Release|Any CPU 69 | {14AE59FB-38B9-4423-A3FF-3521ED686A33}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 70 | {14AE59FB-38B9-4423-A3FF-3521ED686A33}.Release|Mixed Platforms.Build.0 = Release|Any CPU 71 | {14AE59FB-38B9-4423-A3FF-3521ED686A33}.Release|x86.ActiveCfg = Release|Any CPU 72 | EndGlobalSection 73 | GlobalSection(SolutionProperties) = preSolution 74 | HideSolutionNode = FALSE 75 | EndGlobalSection 76 | EndGlobal 77 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/SkeletonRenderer.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Esoteric Software 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | ******************************************************************************/ 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | using Microsoft.Xna.Framework.Graphics; 29 | using Microsoft.Xna.Framework; 30 | 31 | namespace Spine { 32 | public class SkeletonRenderer { 33 | GraphicsDevice device; 34 | SpriteBatcher batcher; 35 | BasicEffect effect; 36 | RasterizerState rasterizerState; 37 | 38 | public SkeletonRenderer (GraphicsDevice device) { 39 | this.device = device; 40 | 41 | batcher = new SpriteBatcher(); 42 | 43 | effect = new BasicEffect(device); 44 | effect.World = Matrix.Identity; 45 | effect.View = Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up); 46 | effect.TextureEnabled = true; 47 | effect.VertexColorEnabled = true; 48 | 49 | rasterizerState = new RasterizerState(); 50 | rasterizerState.CullMode = CullMode.None; 51 | 52 | Bone.yDown = true; 53 | } 54 | 55 | public void Begin (GraphicsDevice gd, Matrix cameraMatrix) { 56 | device.RasterizerState = rasterizerState; 57 | //device.BlendState = BlendState.AlphaBlend; 58 | 59 | effect.Projection = Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 1, 0); 60 | effect.View = Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up) * cameraMatrix; 61 | } 62 | 63 | public void End () { 64 | 65 | foreach (EffectPass pass in effect.CurrentTechnique.Passes) { 66 | pass.Apply(); 67 | batcher.Draw(device); 68 | } 69 | } 70 | 71 | public void Draw (Skeleton skeleton) { 72 | List drawOrder = skeleton.DrawOrder; 73 | for (int i = 0, n = drawOrder.Count; i < n; i++) { 74 | Slot slot = drawOrder[i]; 75 | Attachment attachment = slot.Attachment; 76 | if (attachment == null) 77 | continue; 78 | if (attachment is RegionAttachment) { 79 | RegionAttachment regionAttachment = (RegionAttachment)attachment; 80 | 81 | SpriteBatchItem item = batcher.CreateBatchItem(); 82 | item.Texture = ((XnaAtlasPage)regionAttachment.Region.Page).Texture; 83 | 84 | 85 | item.vertexTL.Color = new Color(slot.R, slot.G, slot.B, slot.A); 86 | 87 | item.vertexBL.Color = new Color(slot.R, slot.G, slot.B, slot.A); 88 | 89 | item.vertexBR.Color = new Color(slot.R, slot.G, slot.B, slot.A); 90 | 91 | item.vertexTR.Color = new Color(slot.R, slot.G, slot.B, slot.A); 92 | 93 | 94 | regionAttachment.UpdateVertices(slot.Bone); 95 | float[] vertices = regionAttachment.Vertices; 96 | item.vertexTL.Position.X = vertices[RegionAttachment.X1]; 97 | item.vertexTL.Position.Y = vertices[RegionAttachment.Y1]; 98 | item.vertexTL.Position.Z = 0; 99 | item.vertexBL.Position.X = vertices[RegionAttachment.X2]; 100 | item.vertexBL.Position.Y = vertices[RegionAttachment.Y2]; 101 | item.vertexBL.Position.Z = 0; 102 | item.vertexBR.Position.X = vertices[RegionAttachment.X3]; 103 | item.vertexBR.Position.Y = vertices[RegionAttachment.Y3]; 104 | item.vertexBR.Position.Z = 0; 105 | item.vertexTR.Position.X = vertices[RegionAttachment.X4]; 106 | item.vertexTR.Position.Y = vertices[RegionAttachment.Y4]; 107 | item.vertexTR.Position.Z = 0; 108 | 109 | float[] uvs = regionAttachment.UVs; 110 | item.vertexTL.TextureCoordinate.X = uvs[RegionAttachment.X1]; 111 | item.vertexTL.TextureCoordinate.Y = uvs[RegionAttachment.Y1]; 112 | item.vertexBL.TextureCoordinate.X = uvs[RegionAttachment.X2]; 113 | item.vertexBL.TextureCoordinate.Y = uvs[RegionAttachment.Y2]; 114 | item.vertexBR.TextureCoordinate.X = uvs[RegionAttachment.X3]; 115 | item.vertexBR.TextureCoordinate.Y = uvs[RegionAttachment.Y3]; 116 | item.vertexTR.TextureCoordinate.X = uvs[RegionAttachment.X4]; 117 | item.vertexTR.TextureCoordinate.Y = uvs[RegionAttachment.Y4]; 118 | } 119 | } 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/ScreenManager/InputState.cs: -------------------------------------------------------------------------------- 1 | #region File Description 2 | //----------------------------------------------------------------------------- 3 | // InputState.cs 4 | // 5 | // Microsoft XNA Community Game Platform 6 | // Copyright (C) Microsoft Corporation. All rights reserved. 7 | //----------------------------------------------------------------------------- 8 | #endregion 9 | 10 | #region Using Statements 11 | using Microsoft.Xna.Framework; 12 | using Microsoft.Xna.Framework.Input; 13 | using System.Collections.Generic; 14 | #endregion 15 | 16 | namespace GameStateManagement 17 | { 18 | /// 19 | /// Helper for reading input from keyboard, gamepad, and touch input. This class 20 | /// tracks both the current and previous state of the input devices, and implements 21 | /// query methods for high level input actions such as "move up through the menu" 22 | /// or "pause the game". 23 | /// 24 | public class InputState 25 | { 26 | #region Fields 27 | 28 | 29 | public KeyboardState CurrentKeyboardState; 30 | public KeyboardState LastKeyboardState; 31 | public MouseState CurrentMouseState; 32 | public MouseState LastMouseState; 33 | 34 | 35 | 36 | #endregion 37 | 38 | #region Initialization 39 | 40 | 41 | /// 42 | /// Constructs a new input state. 43 | /// 44 | public InputState() 45 | { 46 | 47 | } 48 | 49 | 50 | #endregion 51 | 52 | #region Public Methods 53 | 54 | 55 | /// 56 | /// Reads the latest state of the keyboard and gamepad. 57 | /// 58 | public void Update() 59 | { 60 | LastKeyboardState = CurrentKeyboardState; 61 | LastMouseState = CurrentMouseState; 62 | 63 | CurrentKeyboardState = Keyboard.GetState(); 64 | CurrentMouseState = Mouse.GetState(); 65 | 66 | 67 | } 68 | 69 | 70 | /// 71 | /// Helper for checking if a key was newly pressed during this update. The 72 | /// controllingPlayer parameter specifies which player to read input for. 73 | /// If this is null, it will accept input from any player. When a keypress 74 | /// is detected, the output playerIndex reports which player pressed it. 75 | /// 76 | public bool IsNewKeyPress(Keys key) 77 | { 78 | 79 | return (CurrentKeyboardState.IsKeyDown(key) && 80 | LastKeyboardState.IsKeyUp(key)); 81 | 82 | } 83 | 84 | 85 | 86 | 87 | 88 | /// 89 | /// Checks for a "menu select" input action. 90 | /// The controllingPlayer parameter specifies which player to read input for. 91 | /// If this is null, it will accept input from any player. When the action 92 | /// is detected, the output playerIndex reports which player pressed it. 93 | /// 94 | public bool IsMenuSelect() 95 | { 96 | return IsNewKeyPress(Keys.Space) || 97 | IsNewKeyPress(Keys.Enter); 98 | 99 | } 100 | 101 | 102 | /// 103 | /// Checks for a "menu cancel" input action. 104 | /// The controllingPlayer parameter specifies which player to read input for. 105 | /// If this is null, it will accept input from any player. When the action 106 | /// is detected, the output playerIndex reports which player pressed it. 107 | /// 108 | public bool IsMenuCancel() 109 | { 110 | return IsNewKeyPress(Keys.Escape); 111 | } 112 | 113 | 114 | /// 115 | /// Checks for a "menu up" input action. 116 | /// The controllingPlayer parameter specifies which player to read 117 | /// input for. If this is null, it will accept input from any player. 118 | /// 119 | public bool IsMenuUp() 120 | { 121 | return IsNewKeyPress(Keys.Up); 122 | } 123 | 124 | 125 | /// 126 | /// Checks for a "menu down" input action. 127 | /// The controllingPlayer parameter specifies which player to read 128 | /// input for. If this is null, it will accept input from any player. 129 | /// 130 | public bool IsMenuDown() 131 | { 132 | return IsNewKeyPress(Keys.Down); 133 | } 134 | 135 | public bool IsMenuLeft() 136 | { 137 | return IsNewKeyPress(Keys.Left); 138 | } 139 | 140 | 141 | /// 142 | /// Checks for a "menu down" input action. 143 | /// The controllingPlayer parameter specifies which player to read 144 | /// input for. If this is null, it will accept input from any player. 145 | /// 146 | public bool IsMenuRight() 147 | { 148 | return IsNewKeyPress(Keys.Right); 149 | } 150 | 151 | 152 | /// 153 | /// Checks for a "pause the game" input action. 154 | /// The controllingPlayer parameter specifies which player to read 155 | /// input for. If this is null, it will accept input from any player. 156 | /// 157 | public bool IsPauseGame() 158 | { 159 | return IsNewKeyPress(Keys.Escape); 160 | } 161 | 162 | 163 | #endregion 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Entities/EntityPool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using GameStateManagement; 6 | using LDEngine.Entities; 7 | using Microsoft.Xna.Framework; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using TiledLib; 10 | 11 | namespace LDEngine.EntityPools 12 | { 13 | class EntityPool 14 | { 15 | public static EntityPool Instance; 16 | 17 | public List Entities; 18 | public List BoxCollidesWith; 19 | public List PolyCollidesWith; 20 | 21 | 22 | private int _maxEntities; 23 | 24 | public EntityPool(int maxEntities, Func createFunc, Texture2D spriteSheet) 25 | { 26 | Instance = this; 27 | 28 | _maxEntities = maxEntities; 29 | 30 | Entities = new List(); 31 | for(int i=0;i(); 34 | PolyCollidesWith = new List(); 35 | } 36 | 37 | public virtual void Update(GameTime gameTime) 38 | { 39 | foreach (Entity e in Entities.Where(ent => ent.Active)) 40 | { 41 | e.Update(gameTime); 42 | CheckCollisions(e); 43 | } 44 | } 45 | public virtual void Update(GameTime gameTime, Map gameMap) 46 | { 47 | foreach (Entity e in Entities.Where(ent => ent.Active)) 48 | { 49 | e.Update(gameTime, gameMap); 50 | CheckCollisions(e); 51 | } 52 | } 53 | 54 | public virtual void HandleInput(InputState input) 55 | { 56 | foreach (Entity e in Entities.Where(ent => ent.Active)) e.HandleInput(input); 57 | } 58 | 59 | public virtual void Draw(SpriteBatch sb, Camera camera) 60 | { 61 | sb.Begin(SpriteSortMode.Deferred, null,SamplerState.PointClamp,null,null,null,camera.CameraMatrix); 62 | foreach (Entity e in Entities.Where(ent=>ent.Active)) e.Draw(sb); 63 | sb.End(); 64 | } 65 | 66 | public Entity Spawn(Action spawnFunc) 67 | { 68 | // Find an entity in our pool that isn't active 69 | Entity retEntity = Entities.FirstOrDefault(ent => !ent.Active); 70 | 71 | // If we don't have a spare entitiy, return null 72 | if (retEntity == null) return null; 73 | 74 | // First, run our reset function to reset required default values (might be speed or life etc.) 75 | retEntity.Reset(); 76 | 77 | // Then, run the spawn function to set new values (position, etc) 78 | spawnFunc(retEntity); 79 | 80 | // Make it alive! 81 | retEntity.Active = true; 82 | 83 | return retEntity; 84 | } 85 | 86 | 87 | 88 | private void CheckCollisions(Entity e) 89 | { 90 | foreach (object o in BoxCollidesWith) 91 | { 92 | if (o is EntityPool) 93 | { 94 | foreach (Entity collEnt in ((EntityPool)o).Entities) 95 | { 96 | if (!collEnt.Active) continue; 97 | if (collEnt == e) continue; 98 | 99 | Rectangle intersect = Rectangle.Intersect(e.HitBox, collEnt.HitBox); 100 | if (intersect.IsEmpty) continue; 101 | 102 | e.OnBoxCollision(collEnt, intersect); 103 | } 104 | } 105 | 106 | if (o is Entity) 107 | { 108 | Entity collEnt = (Entity)o; 109 | 110 | if (!collEnt.Active) continue; 111 | if (collEnt == e) continue; 112 | 113 | Rectangle intersect = Rectangle.Intersect(e.HitBox, collEnt.HitBox); 114 | if (intersect.IsEmpty) continue; 115 | 116 | e.OnBoxCollision(collEnt, intersect); 117 | collEnt.OnBoxCollision(e, intersect); 118 | } 119 | } 120 | 121 | foreach (object o in PolyCollidesWith) 122 | { 123 | if (o is EntityPool) 124 | { 125 | foreach (Entity collEnt in ((EntityPool)o).Entities) 126 | { 127 | if (!collEnt.Active) continue; 128 | if (collEnt == e) continue; 129 | 130 | bool collides = false; 131 | foreach (Vector2 vector2 in e.HitPolyPoints) 132 | if (Helper.IsPointInShape(vector2, collEnt.HitPolyPoints)) collides = true; 133 | if (!collides) continue; 134 | 135 | e.OnPolyCollision(collEnt); 136 | } 137 | } 138 | 139 | if (o is Entity) 140 | { 141 | Entity collEnt = (Entity)o; 142 | 143 | if (!collEnt.Active) continue; 144 | if (collEnt == e) continue; 145 | 146 | bool collides = false; 147 | foreach (Vector2 vector2 in e.HitPolyPoints) 148 | if (Helper.IsPointInShape(vector2, collEnt.HitPolyPoints)) collides = true; 149 | if (!collides) continue; 150 | 151 | e.OnPolyCollision(collEnt); 152 | collEnt.OnPolyCollision(e); 153 | } 154 | } 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Game.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using GameStateManagement; 5 | using LDEngine.Screens; 6 | using Microsoft.Xna.Framework; 7 | using Microsoft.Xna.Framework.Audio; 8 | using Microsoft.Xna.Framework.Content; 9 | using Microsoft.Xna.Framework.GamerServices; 10 | using Microsoft.Xna.Framework.Graphics; 11 | using Microsoft.Xna.Framework.Input; 12 | using Microsoft.Xna.Framework.Media; 13 | using TimersAndTweens; 14 | 15 | namespace LDEngine 16 | { 17 | /// 18 | /// This is the main type for your game 19 | /// 20 | public class Game : Microsoft.Xna.Framework.Game 21 | { 22 | private const int MAX_SCALE = 5; 23 | private const int MIN_SCALE = 1; 24 | 25 | GraphicsDeviceManager graphics; 26 | SpriteBatch spriteBatch; 27 | private ScreenManager screenManager; 28 | 29 | private TimerController timerController = new TimerController(); 30 | private TweenController tweenController = new TweenController(); 31 | 32 | public int RenderWidth = 320; 33 | public int RenderHeight = 180; 34 | public int DisplayScale = 5; 35 | 36 | private RenderTarget2D renderTarget; 37 | 38 | public Game() 39 | { 40 | graphics = new GraphicsDeviceManager(this); 41 | Content.RootDirectory = "Content"; 42 | } 43 | 44 | protected override void Initialize() 45 | { 46 | graphics.PreferredBackBufferWidth = RenderWidth * DisplayScale; 47 | graphics.PreferredBackBufferHeight = RenderHeight * DisplayScale; 48 | graphics.ApplyChanges(); 49 | 50 | screenManager = new ScreenManager(this); 51 | screenManager.Initialize(); 52 | 53 | IsMouseVisible = true; 54 | 55 | base.Initialize(); 56 | } 57 | 58 | protected override void LoadContent() 59 | { 60 | screenManager.LoadContent(); 61 | renderTarget = new RenderTarget2D(GraphicsDevice, RenderWidth, RenderHeight, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); 62 | 63 | spriteBatch = new SpriteBatch(GraphicsDevice); 64 | 65 | AudioController.LoadContent(Content); 66 | 67 | // Add the first screen here, usually either MainMenuScreen or GameplayScreen if you just want to go straight to gameplay 68 | screenManager.AddScreen(new ExampleGameplayScreen()); 69 | //screenManager.AddScreen(new GameplayScreen()); 70 | //screenManager.AddScreen(new MainMenuScreen()); 71 | } 72 | 73 | protected override void Update(GameTime gameTime) 74 | { 75 | if (!IsActive) return; 76 | 77 | AudioController.Update(gameTime); 78 | 79 | screenManager.Update(gameTime); 80 | 81 | timerController.Update(gameTime); 82 | tweenController.Update(gameTime); 83 | 84 | // Allows the game to exit 85 | if (screenManager.Input.CurrentKeyboardState.IsKeyDown(Keys.F12)) this.Exit(); 86 | 87 | // PgUp/PgDn change the display scaling 88 | if (screenManager.Input.CurrentKeyboardState.IsKeyDown(Keys.PageDown) && !screenManager.Input.LastKeyboardState.IsKeyDown(Keys.PageDown) && DisplayScale > MIN_SCALE) 89 | { 90 | DisplayScale--; 91 | ChangeDisplayScale(); 92 | } 93 | if (screenManager.Input.CurrentKeyboardState.IsKeyDown(Keys.PageUp) && !screenManager.Input.LastKeyboardState.IsKeyDown(Keys.PageUp) && DisplayScale < MAX_SCALE) 94 | { 95 | DisplayScale++; 96 | ChangeDisplayScale(); 97 | } 98 | 99 | base.Update(gameTime); 100 | } 101 | 102 | /// 103 | /// This is called when the game should draw itself. 104 | /// 105 | /// Provides a snapshot of timing values. 106 | protected override void Draw(GameTime gameTime) 107 | { 108 | // First, draw our game to the 1:1 rendertarget 109 | GraphicsDevice.SetRenderTarget(renderTarget); 110 | GraphicsDevice.Clear(Color.Black); 111 | screenManager.Draw(gameTime); 112 | 113 | // Then, draw the 1:1 rendertarget upscaled to our display resolution 114 | GraphicsDevice.SetRenderTarget(null); 115 | GraphicsDevice.Clear(Color.Black); 116 | // We use PointClamp sampling throughout for nearest-neighbour scaling 117 | spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise); 118 | spriteBatch.Draw(renderTarget, 119 | new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height)/2, null, 120 | Color.White, 0f, 121 | new Vector2(renderTarget.Width,renderTarget.Height)/2, 122 | DisplayScale, 123 | SpriteEffects.None, 1); 124 | spriteBatch.End(); 125 | 126 | base.Draw(gameTime); 127 | } 128 | 129 | public void ToggleFullScreen() 130 | { 131 | graphics.IsFullScreen = !graphics.IsFullScreen; 132 | ChangeDisplayScale(); 133 | } 134 | 135 | void ChangeDisplayScale() 136 | { 137 | graphics.PreferredBackBufferWidth = RenderWidth * DisplayScale; 138 | graphics.PreferredBackBufferHeight = RenderHeight * DisplayScale; 139 | graphics.ApplyChanges(); 140 | } 141 | 142 | 143 | } 144 | } 145 | 146 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Screens/MessageBoxScreen.cs: -------------------------------------------------------------------------------- 1 | #region File Description 2 | //----------------------------------------------------------------------------- 3 | // MessageBoxScreen.cs 4 | // 5 | // Microsoft XNA Community Game Platform 6 | // Copyright (C) Microsoft Corporation. All rights reserved. 7 | //----------------------------------------------------------------------------- 8 | #endregion 9 | 10 | #region Using Statements 11 | using System; 12 | using Microsoft.Xna.Framework; 13 | using Microsoft.Xna.Framework.Input; 14 | using Microsoft.Xna.Framework.Content; 15 | using Microsoft.Xna.Framework.Graphics; 16 | 17 | #endregion 18 | 19 | namespace GameStateManagement 20 | { 21 | /// 22 | /// A popup message box screen, used to display "are you sure?" 23 | /// confirmation messages. 24 | /// 25 | class MessageBoxScreen : GameScreen 26 | { 27 | #region Fields 28 | 29 | string message; 30 | Texture2D texBG; 31 | 32 | #endregion 33 | 34 | #region Events 35 | 36 | public event EventHandler Accepted; 37 | public event EventHandler Cancelled; 38 | 39 | #endregion 40 | 41 | #region Initialization 42 | 43 | 44 | /// 45 | /// Constructor lets the caller specify whether to include the standard 46 | /// "A=ok, B=cancel" usage text prompt. 47 | /// 48 | public MessageBoxScreen(string message) 49 | { 50 | this.message = message; 51 | 52 | IsPopup = true; 53 | 54 | TransitionOnTime = TimeSpan.FromSeconds(0.2); 55 | TransitionOffTime = TimeSpan.FromSeconds(0.2); 56 | } 57 | 58 | 59 | /// 60 | /// Loads graphics content for this screen. This uses the shared ContentManager 61 | /// provided by the Game class, so the content will remain loaded forever. 62 | /// Whenever a subsequent MessageBoxScreen tries to load this same content, 63 | /// it will just get back another reference to the already loaded data. 64 | /// 65 | public override void LoadContent() 66 | { 67 | ContentManager content = ScreenManager.Game.Content; 68 | 69 | texBG = content.Load("ui/messagebg"); 70 | } 71 | 72 | 73 | #endregion 74 | 75 | #region Handle Input 76 | 77 | 78 | /// 79 | /// Responds to user input, accepting or cancelling the message box. 80 | /// 81 | public override void HandleInput(InputState input) 82 | { 83 | PlayerIndex playerIndex; 84 | Viewport viewport = ScreenManager.Game.GraphicsDevice.Viewport; 85 | Vector2 halfSize = new Vector2(viewport.Width, viewport.Height)/2; 86 | // We pass in our ControllingPlayer, which may either be null (to 87 | // accept input from any player) or a specific index. If we pass a null 88 | // controlling player, the InputState helper returns to us which player 89 | // actually provided the input. We pass that through to our Accepted and 90 | // Cancelled events, so they can tell which player triggered them. 91 | if (input.IsMenuSelect()) 92 | { 93 | // Raise the accepted event, then exit the message box. 94 | if (Accepted != null) 95 | Accepted(this, new EventArgs()); 96 | 97 | ExitScreen(); 98 | } 99 | else if (input.IsMenuCancel()) 100 | { 101 | // Raise the cancelled event, then exit the message box. 102 | if (Cancelled != null) 103 | Cancelled(this, new EventArgs()); 104 | 105 | ExitScreen(); 106 | } 107 | 108 | Point mouseLoc = new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y); 109 | 110 | Rectangle okRect = new Rectangle((int)halfSize.X - 25, (int)halfSize.Y + 25, 50, 50); 111 | if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.LastMouseState.LeftButton == ButtonState.Released) 112 | { 113 | if (okRect.Contains(mouseLoc)) ExitScreen(); 114 | } 115 | } 116 | 117 | 118 | #endregion 119 | 120 | #region Draw 121 | 122 | 123 | /// 124 | /// Draws the message box. 125 | /// 126 | public override void Draw(GameTime gameTime) 127 | { 128 | SpriteBatch spriteBatch = ScreenManager.SpriteBatch; 129 | SpriteFont font = ScreenManager.Font; 130 | 131 | // Darken down any other screens that were drawn beneath the popup. 132 | //ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3); 133 | 134 | // Center the message text in the viewport. 135 | Viewport viewport = ScreenManager.Game.GraphicsDevice.Viewport; 136 | Vector2 halfSize = new Vector2(viewport.Width, viewport.Height)/2; 137 | 138 | 139 | // Fade the popup alpha during transitions. 140 | Color color = Color.White * TransitionAlpha; 141 | 142 | spriteBatch.Begin(); 143 | 144 | // Draw the background rectangle. 145 | spriteBatch.Draw(texBG, halfSize, null, color, 0f, new Vector2(texBG.Width,texBG.Height)/2,1f,SpriteEffects.None,1); 146 | 147 | // Draw the message box text. 148 | spriteBatch.DrawString(font, message, halfSize+new Vector2(0,-50f), new Color(128,128,128)*TransitionAlpha,0f,font.MeasureString(message)/2f,1f, SpriteEffects.None,1); 149 | 150 | spriteBatch.DrawString(font, "OK", halfSize + new Vector2(0, 50f), new Color(128, 128, 128) * TransitionAlpha, 0f, font.MeasureString("OK") / 2f, 1f, SpriteEffects.None, 1); 151 | 152 | 153 | spriteBatch.End(); 154 | } 155 | 156 | 157 | #endregion 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Spine/Attachments/RegionAttachment.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Esoteric Software 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | ******************************************************************************/ 25 | 26 | using System; 27 | 28 | namespace Spine { 29 | /** Attachment that displays a texture region. */ 30 | public class RegionAttachment : Attachment { 31 | public const int X1 = 0; 32 | public const int Y1 = 1; 33 | public const int X2 = 2; 34 | public const int Y2 = 3; 35 | public const int X3 = 4; 36 | public const int Y3 = 5; 37 | public const int X4 = 6; 38 | public const int Y4 = 7; 39 | 40 | public float X { get; set; } 41 | public float Y { get; set; } 42 | public float ScaleX { get; set; } 43 | public float ScaleY { get; set; } 44 | public float Rotation { get; set; } 45 | public float Width { get; set; } 46 | public float Height { get; set; } 47 | 48 | public float[] Offset { get; private set; } 49 | public float[] Vertices { get; private set; } 50 | public float[] UVs { get; private set; } 51 | 52 | private AtlasRegion region; 53 | public AtlasRegion Region { 54 | get { 55 | return region; 56 | } 57 | set { 58 | region = value; 59 | float[] uvs = UVs; 60 | if (value.Rotate) { 61 | uvs[X2] = value.U; 62 | uvs[Y2] = value.V2; 63 | uvs[X3] = value.U; 64 | uvs[Y3] = value.V; 65 | uvs[X4] = value.U2; 66 | uvs[Y4] = value.V; 67 | uvs[X1] = value.U2; 68 | uvs[Y1] = value.V2; 69 | } else { 70 | uvs[X1] = value.U; 71 | uvs[Y1] = value.V2; 72 | uvs[X2] = value.U; 73 | uvs[Y2] = value.V; 74 | uvs[X3] = value.U2; 75 | uvs[Y3] = value.V; 76 | uvs[X4] = value.U2; 77 | uvs[Y4] = value.V2; 78 | } 79 | } 80 | } 81 | 82 | public RegionAttachment (string name) 83 | : base(name) { 84 | Offset = new float[8]; 85 | Vertices = new float[8]; 86 | UVs = new float[8]; 87 | ScaleX = 1; 88 | ScaleY = 1; 89 | } 90 | 91 | public void UpdateOffset () { 92 | float width = Width; 93 | float height = Height; 94 | float localX2 = width / 2; 95 | float localY2 = height / 2; 96 | float localX = -localX2; 97 | float localY = -localY2; 98 | AtlasRegion region = Region; 99 | if (region.Rotate) { 100 | localX += region.OffsetX / region.OriginalWidth * height; 101 | localY += region.OffsetY / region.OriginalHeight * width; 102 | localX2 -= (region.OriginalWidth - region.OffsetX - region.Height) / region.OriginalWidth * width; 103 | localY2 -= (region.OriginalHeight - region.OffsetY - region.Width) / region.OriginalHeight * height; 104 | } else { 105 | localX += region.OffsetX / region.OriginalWidth * width; 106 | localY += region.OffsetY / region.OriginalHeight * height; 107 | localX2 -= (region.OriginalWidth - region.OffsetX - region.Width) / region.OriginalWidth * width; 108 | localY2 -= (region.OriginalHeight - region.OffsetY - region.Height) / region.OriginalHeight * height; 109 | } 110 | float scaleX = ScaleX; 111 | float scaleY = ScaleY; 112 | localX *= scaleX; 113 | localY *= scaleY; 114 | localX2 *= scaleX; 115 | localY2 *= scaleY; 116 | float radians = Rotation * (float)Math.PI / 180; 117 | float cos = (float)Math.Cos(radians); 118 | float sin = (float)Math.Sin(radians); 119 | float x = X; 120 | float y = Y; 121 | float localXCos = localX * cos + x; 122 | float localXSin = localX * sin; 123 | float localYCos = localY * cos + y; 124 | float localYSin = localY * sin; 125 | float localX2Cos = localX2 * cos + x; 126 | float localX2Sin = localX2 * sin; 127 | float localY2Cos = localY2 * cos + y; 128 | float localY2Sin = localY2 * sin; 129 | float[] offset = Offset; 130 | offset[X1] = localXCos - localYSin; 131 | offset[Y1] = localYCos + localXSin; 132 | offset[X2] = localXCos - localY2Sin; 133 | offset[Y2] = localY2Cos + localXSin; 134 | offset[X3] = localX2Cos - localY2Sin; 135 | offset[Y3] = localY2Cos + localX2Sin; 136 | offset[X4] = localX2Cos - localYSin; 137 | offset[Y4] = localYCos + localX2Sin; 138 | } 139 | 140 | public void UpdateVertices (Bone bone) { 141 | float x = bone.WorldX; 142 | float y = bone.WorldY; 143 | float m00 = bone.M00; 144 | float m01 = bone.M01; 145 | float m10 = bone.M10; 146 | float m11 = bone.M11; 147 | float[] vertices = Vertices; 148 | float[] offset = Offset; 149 | vertices[X1] = offset[X1] * m00 + offset[Y1] * m01 + x; 150 | vertices[Y1] = offset[X1] * m10 + offset[Y1] * m11 + y; 151 | vertices[X2] = offset[X2] * m00 + offset[Y2] * m01 + x; 152 | vertices[Y2] = offset[X2] * m10 + offset[Y2] * m11 + y; 153 | vertices[X3] = offset[X3] * m00 + offset[Y3] * m01 + x; 154 | vertices[Y3] = offset[X3] * m10 + offset[Y3] * m11 + y; 155 | vertices[X4] = offset[X4] * m00 + offset[Y4] * m01 + x; 156 | vertices[Y4] = offset[X4] * m10 + offset[Y4] * m11 + y; 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /LDEngine/TiledLib/Helper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Xna.Framework; 6 | 7 | namespace TiledLib 8 | { 9 | public static class Helper 10 | { 11 | public static Random Random = new Random(); 12 | 13 | public static float AngleBetween(Vector2 v1, Vector2 v2) 14 | { 15 | v1.Normalize(); 16 | v2.Normalize(); 17 | float Angle = (float)Math.Acos(Vector2.Dot(v1, v2)); 18 | return Angle; 19 | } 20 | 21 | public static float TurnToFace(Vector2 position, Vector2 faceThis, 22 | float currentAngle, float direction, float turnSpeed) 23 | { 24 | // consider this diagram: 25 | // C 26 | // /| 27 | // / | 28 | // / | y 29 | // / o | 30 | // S-------- 31 | // x 32 | // 33 | // where S is the position of the spot light, C is the position of the cat, 34 | // and "o" is the angle that the spot light should be facing in order to 35 | // point at the cat. we need to know what o is. using trig, we know that 36 | // tan(theta) = opposite / adjacent 37 | // tan(o) = y / x 38 | // if we take the arctan of both sides of this equation... 39 | // arctan( tan(o) ) = arctan( y / x ) 40 | // o = arctan( y / x ) 41 | // so, we can use x and y to find o, our "desiredAngle." 42 | // x and y are just the differences in position between the two objects. 43 | float x = (faceThis.X - position.X) * direction; 44 | float y = (faceThis.Y - position.Y) * direction; 45 | 46 | // we'll use the Atan2 function. Atan will calculates the arc tangent of 47 | // y / x for us, and has the added benefit that it will use the signs of x 48 | // and y to determine what cartesian quadrant to put the result in. 49 | // http://msdn2.microsoft.com/en-us/library/system.math.atan2.aspx 50 | float desiredAngle = (float)Math.Atan2(y, x) + MathHelper.PiOver2; 51 | 52 | // so now we know where we WANT to be facing, and where we ARE facing... 53 | // if we weren't constrained by turnSpeed, this would be easy: we'd just 54 | // return desiredAngle. 55 | // instead, we have to calculate how much we WANT to turn, and then make 56 | // sure that's not more than turnSpeed. 57 | 58 | // first, figure out how much we want to turn, using WrapAngle to get our 59 | // result from -Pi to Pi ( -180 degrees to 180 degrees ) 60 | float difference = WrapAngle(desiredAngle - currentAngle); 61 | 62 | // clamp that between -turnSpeed and turnSpeed. 63 | difference = MathHelper.Clamp(difference, -turnSpeed, turnSpeed); 64 | 65 | // so, the closest we can get to our target is currentAngle + difference. 66 | // return that, using WrapAngle again. 67 | return WrapAngle(currentAngle + difference); 68 | } 69 | 70 | /// 71 | /// Returns the angle expressed in radians between -Pi and Pi. 72 | /// 73 | public static float WrapAngle(float radians) 74 | { 75 | while (radians < -MathHelper.Pi) 76 | { 77 | radians += MathHelper.TwoPi; 78 | } 79 | while (radians > MathHelper.Pi) 80 | { 81 | radians -= MathHelper.TwoPi; 82 | } 83 | return radians; 84 | } 85 | 86 | public static Vector2 PointOnCircle(ref Vector2 C, int R, float A) 87 | { 88 | //A = A - 90; 89 | float endX = (C.X + (R * ((float)Math.Cos((float)A)))); 90 | float endY = (C.Y + (R * ((float)Math.Sin((float)A)))); 91 | return new Vector2(endX, endY); 92 | } 93 | 94 | public static Vector2 RandomPointInCircle(Vector2 position, float minradius, float maxradius) 95 | { 96 | float randomRadius = minradius + ((maxradius-minradius) * (float)Math.Sqrt(Random.NextDouble())); 97 | 98 | double randomAngle = Random.NextDouble() * MathHelper.TwoPi; 99 | 100 | float x = randomRadius * (float)Math.Cos(randomAngle); 101 | float y = randomRadius * (float)Math.Sin(randomAngle); 102 | 103 | return new Vector2(position.X + x, position.Y + y); 104 | } 105 | 106 | public static Vector2 AngleToVector(float angle, float length) 107 | { 108 | Vector2 direction = Vector2.Zero; 109 | direction.X = (float)Math.Cos(angle) * length; 110 | direction.Y = (float)Math.Sin(angle) * length; 111 | return direction; 112 | } 113 | 114 | public static float V2ToAngle(Vector2 direction) 115 | { 116 | return (float)Math.Atan2(direction.Y, direction.X); 117 | } 118 | 119 | public static Vector2 PtoV(Point p) 120 | { 121 | return new Vector2(p.X, p.Y); 122 | } 123 | 124 | public static Point VtoP(Vector2 v) 125 | { 126 | return new Point((int)v.X, (int)v.Y); 127 | } 128 | 129 | public static bool IsPointInShape(Vector2 point, List verts) 130 | { 131 | bool oddNodes = false; 132 | 133 | int j = verts.Count - 1; 134 | float x = point.X; 135 | float y = point.Y; 136 | 137 | for (int i = 0; i < verts.Count; i++) 138 | { 139 | Vector2 tpi = verts[i]; 140 | Vector2 tpj = verts[j]; 141 | 142 | if (tpi.Y < y && tpj.Y >= y || tpj.Y < y && tpi.Y >= y) 143 | if (tpi.X + (y - tpi.Y) / (tpj.Y - tpi.Y) * (tpj.X - tpi.X) < x) 144 | oddNodes = !oddNodes; 145 | 146 | j = i; 147 | } 148 | 149 | return oddNodes; 150 | } 151 | 152 | public static float RandomFloat(float max) 153 | { 154 | return RandomFloat(0f, max); 155 | } 156 | public static float RandomFloat(float min, float max) 157 | { 158 | return (float)(min + (Random.NextDouble() * (max-min))); 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Screens/MenuEntry.cs: -------------------------------------------------------------------------------- 1 | #region File Description 2 | //----------------------------------------------------------------------------- 3 | // MenuEntry.cs 4 | // 5 | // XNA Community Game Platform 6 | // Copyright (C) Microsoft Corporation. All rights reserved. 7 | //----------------------------------------------------------------------------- 8 | #endregion 9 | 10 | #region Using Statements 11 | using System; 12 | using Microsoft.Xna.Framework; 13 | using Microsoft.Xna.Framework.Graphics; 14 | #endregion 15 | 16 | namespace GameStateManagement 17 | { 18 | /// 19 | /// Helper class represents a single entry in a MenuScreen. By default this 20 | /// just draws the entry text string, but it can be customized to display menu 21 | /// entries in different ways. This also provides an event that will be raised 22 | /// when the menu entry is selected. 23 | /// 24 | public class MenuEntry 25 | { 26 | #region Fields 27 | 28 | /// 29 | /// The text rendered for this entry. 30 | /// 31 | string text; 32 | 33 | bool enabled; 34 | int option; 35 | 36 | /// 37 | /// Tracks a fading selection effect on the entry. 38 | /// 39 | /// 40 | /// The entries transition out of the selection effect when they are deselected. 41 | /// 42 | public float selectionFade; 43 | 44 | public Rectangle bounds; 45 | 46 | public Vector2 Position; 47 | 48 | #endregion 49 | 50 | #region Properties 51 | 52 | 53 | /// 54 | /// Gets or sets the text of this menu entry. 55 | /// 56 | public string Text 57 | { 58 | get { return text; } 59 | set { text = value; } 60 | } 61 | 62 | 63 | public bool Enabled 64 | { 65 | get { return enabled; } 66 | set { enabled = value; } 67 | } 68 | 69 | #endregion 70 | 71 | #region Events 72 | 73 | 74 | /// 75 | /// Event raised when the menu entry is selected. 76 | /// 77 | public event EventHandler Selected; 78 | 79 | 80 | /// 81 | /// Method for raising the Selected event. 82 | /// 83 | protected internal virtual void OnSelectEntry() 84 | { 85 | if (Selected != null) 86 | Selected(this, new EventArgs()); 87 | } 88 | 89 | 90 | public virtual void Left() 91 | { 92 | 93 | } 94 | 95 | public virtual void Right() 96 | { 97 | 98 | } 99 | #endregion 100 | 101 | #region Initialization 102 | 103 | 104 | /// 105 | /// Constructs a new menu entry with the specified text. 106 | /// 107 | public MenuEntry(string text, bool isEnabled) 108 | { 109 | this.text = text; 110 | enabled = isEnabled; 111 | } 112 | //public MenuEntry(string text, bool isEnabled, int numOptions, int startOption) 113 | //{ 114 | // this.text = text; 115 | // enabled = isEnabled; 116 | // option = startOption; 117 | //} 118 | 119 | #endregion 120 | 121 | #region Update and Draw 122 | 123 | 124 | /// 125 | /// Updates the menu entry. 126 | /// 127 | public virtual void Update(MenuScreen screen, bool isSelected, 128 | GameTime gameTime) 129 | { 130 | // When the menu selection changes, entries gradually fade between 131 | // their selected and deselected appearance, rather than instantly 132 | // popping to the new state. 133 | float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4; 134 | 135 | if (isSelected) 136 | selectionFade = Math.Min(selectionFade + fadeSpeed, 1f); 137 | else 138 | selectionFade = Math.Max(selectionFade - fadeSpeed, 0f); 139 | 140 | 141 | } 142 | 143 | 144 | /// 145 | /// Draws the menu entry. This can be overridden to customize the appearance. 146 | /// 147 | public virtual void Draw(MenuScreen screen, bool isSelected, GameTime gameTime) 148 | { 149 | // Draw the selected entry in yellow, otherwise white. 150 | Color color = Color.White; 151 | 152 | // Pulsate the size of the selected menu entry. 153 | double time = gameTime.TotalGameTime.TotalSeconds; 154 | 155 | float pulsate = (float)Math.Sin(time * 6) + 1; 156 | 157 | float scale = 1; 158 | 159 | // Modify the alpha to fade text out during transitions. 160 | if (enabled) 161 | color = Color.Lerp(Color.White, new Color(10,68,123),selectionFade) * screen.TransitionAlpha;//Math.Min(screen.TransitionAlpha, Convert.ToByte(selectionFade))); 162 | else 163 | color = new Color(color.R, color.G, color.B) * screen.TransitionAlpha * 0.3f; 164 | 165 | // Draw text, centered on the middle of each line. 166 | ScreenManager screenManager = screen.ScreenManager; 167 | SpriteBatch spriteBatch = screenManager.SpriteBatch; 168 | SpriteFont font = screenManager.Font; 169 | font.LineSpacing = 25; 170 | 171 | Vector2 origin = new Vector2(0, font.LineSpacing / 2); 172 | 173 | spriteBatch.DrawString(font, text, Position+Vector2.One, Color.Black*0.2f, 0, 174 | origin, scale, SpriteEffects.None, 0); 175 | spriteBatch.DrawString(font, text, Position, color, 0, 176 | origin, scale, SpriteEffects.None, 0); 177 | 178 | bounds = new Rectangle((int)Position.X, (int)Position.Y - 10, 300, 25); 179 | } 180 | 181 | 182 | /// 183 | /// Queries how much space this menu entry requires. 184 | /// 185 | public virtual int GetHeight(MenuScreen screen) 186 | { 187 | return screen.ScreenManager.Font.LineSpacing; 188 | } 189 | 190 | 191 | #endregion 192 | 193 | public virtual void Click(int x, int y) 194 | { 195 | OnSelectEntry(); 196 | } 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/TweenController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using Microsoft.Xna.Framework; 7 | 8 | namespace TimersAndTweens 9 | { 10 | class TweenController 11 | { 12 | public static TweenController Instance; 13 | 14 | public List Tweens = new List(); 15 | 16 | public TweenController() 17 | { 18 | Instance = this; 19 | } 20 | 21 | public void Update(GameTime gameTime) 22 | { 23 | foreach(Tween t in Tweens) t.Update(gameTime); 24 | 25 | Tweens.RemoveAll(t => t.State == TweenState.Finished); 26 | } 27 | 28 | public Tween Create(string name, TweenFunc func, Action callback, double time, bool pingpong, bool loop) 29 | { 30 | return Create(name, func, callback, time, pingpong, loop, TweenDirection.Forward); 31 | } 32 | public Tween Create(string name, TweenFunc func, Action callback, double time, bool pingpong, bool loop, TweenDirection initialDirection) 33 | { 34 | Tween t = new Tween(name, func, callback, time, pingpong, loop, initialDirection); 35 | Tweens.Add(t); 36 | 37 | return t; 38 | } 39 | 40 | public Tween Get(string name) 41 | { 42 | return Tweens.FirstOrDefault(t => t.Name == name); 43 | } 44 | } 45 | 46 | public static class TweenFuncs 47 | { 48 | public static readonly TweenFunc Linear = DoLinear; 49 | public static readonly TweenFunc QuadraticEaseIn = DoQuadraticEaseIn; 50 | public static readonly TweenFunc QuadraticEaseOut = DoQuadraticEaseOut; 51 | public static readonly TweenFunc QuadraticEaseInOut = DoQuadraticEaseInOut; 52 | public static readonly TweenFunc CubicEaseIn = DoCubicEaseIn; 53 | public static readonly TweenFunc CubicEaseOut = DoCubicEaseOut; 54 | public static readonly TweenFunc CubicEaseInOut = DoCubicEaseInOut; 55 | public static readonly TweenFunc QuarticEaseIn = DoQuarticEaseIn; 56 | public static readonly TweenFunc QuarticEaseOut = DoQuarticEaseOut; 57 | public static readonly TweenFunc QuarticEaseInOut = DoQuarticEaseInOut; 58 | public static readonly TweenFunc QuinticEaseIn = DoQuinticEaseIn; 59 | public static readonly TweenFunc QuinticEaseOut = DoQuinticEaseOut; 60 | public static readonly TweenFunc QuinticEaseInOut = DoQuinticEaseInOut; 61 | public static readonly TweenFunc SineEaseIn = DoSineEaseIn; 62 | public static readonly TweenFunc SineEaseOut = DoSineEaseOut; 63 | public static readonly TweenFunc SineEaseInOut = DoSineEaseInOut; 64 | public static readonly TweenFunc Bounce = DoBounce; 65 | public static readonly TweenFunc Elastic = DoElastic; 66 | 67 | private static float DoLinear(float progress) { return progress; } 68 | private static float DoQuadraticEaseIn(float progress) { return EaseInPower(progress, 2); } 69 | private static float DoQuadraticEaseOut(float progress) { return EaseOutPower(progress, 2); } 70 | private static float DoQuadraticEaseInOut(float progress) { return EaseInOutPower(progress, 2); } 71 | private static float DoCubicEaseIn(float progress) { return EaseInPower(progress, 3); } 72 | private static float DoCubicEaseOut(float progress) { return EaseOutPower(progress, 3); } 73 | private static float DoCubicEaseInOut(float progress) { return EaseInOutPower(progress, 3); } 74 | private static float DoQuarticEaseIn(float progress) { return EaseInPower(progress, 4); } 75 | private static float DoQuarticEaseOut(float progress) { return EaseOutPower(progress, 4); } 76 | private static float DoQuarticEaseInOut(float progress) { return EaseInOutPower(progress, 4); } 77 | private static float DoQuinticEaseIn(float progress) { return EaseInPower(progress, 5); } 78 | private static float DoQuinticEaseOut(float progress) { return EaseOutPower(progress, 5); } 79 | private static float DoQuinticEaseInOut(float progress) { return EaseInOutPower(progress, 5); } 80 | 81 | private static float DoSineEaseIn(float progress) 82 | { 83 | return (float)Math.Sin(progress * MathHelper.PiOver2 - MathHelper.PiOver2) + 1; 84 | } 85 | 86 | private static float DoSineEaseOut(float progress) 87 | { 88 | return (float)Math.Sin(progress * MathHelper.PiOver2); 89 | } 90 | 91 | private static float DoSineEaseInOut(float progress) 92 | { 93 | return (float)(Math.Sin(progress * MathHelper.Pi - MathHelper.PiOver2) + 1) / 2; 94 | } 95 | 96 | private static float DoBounce(float progress) 97 | { 98 | if ((progress /= 1f) < (1f / 2.75f)) 99 | return (7.5625f * progress * progress); 100 | else if (progress < (2f / 2.75f)) 101 | return (7.5625f * (progress -= (1.5f / 2.75f)) * progress + .75f); 102 | else if (progress < (2.5f / 2.75)) 103 | return (7.5625f * (progress -= (2.25f / 2.75f)) * progress + .9375f); 104 | else 105 | return (7.5625f * (progress -= (2.625f / 2.75f)) * progress + .984375f); 106 | } 107 | 108 | public static float DoElastic(float progress) 109 | { 110 | if ((progress /= 1f) == 1) 111 | return 1f; 112 | 113 | float p = 0.3f; 114 | float s = p / 4f; 115 | 116 | return (1f * (float)Math.Pow(2f, -10f * progress) * (float)Math.Sin((progress * 1f - s) * (2f * (float)Math.PI) / p) + 1f); 117 | } 118 | 119 | private static float EaseInPower(float progress, int power) 120 | { 121 | return (float)Math.Pow(progress, power); 122 | } 123 | 124 | private static float EaseOutPower(float progress, int power) 125 | { 126 | int sign = power % 2 == 0 ? -1 : 1; 127 | return (float)(sign * (Math.Pow(progress - 1, power) + sign)); 128 | } 129 | 130 | private static float EaseInOutPower(float progress, int power) 131 | { 132 | progress *= 2; 133 | if (progress < 1) 134 | { 135 | return (float)Math.Pow(progress, power) / 2f; 136 | } 137 | else 138 | { 139 | int sign = power % 2 == 0 ? -1 : 1; 140 | return (float)(sign / 2.0 * (Math.Pow(progress - 2, power) + sign * 2)); 141 | } 142 | } 143 | 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/SpriteAnim.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Xna.Framework; 6 | using Microsoft.Xna.Framework.Graphics; 7 | 8 | namespace LDEngine 9 | { 10 | enum SpriteAnimState 11 | { 12 | Playing, 13 | Paused 14 | } 15 | 16 | enum SpriteAnimDirection 17 | { 18 | Forward, 19 | Reverse 20 | } 21 | 22 | class SpriteAnim 23 | { 24 | public Texture2D SpriteSheet; 25 | public Vector2 Offset; 26 | public int NumFrames; 27 | public int SheetRow; 28 | public int CellWidth; 29 | public int CellHeight; 30 | public int CurrentFrame; 31 | public double CurrentFrameTime; 32 | public double TargetFrameTime; 33 | public bool Loop; 34 | public bool PingPong; 35 | public SpriteAnimDirection CurrentDirection; 36 | public SpriteAnimState State; 37 | 38 | public SpriteAnim(Texture2D sheet, int row, int numframes, int width, int height, double frametime) 39 | { 40 | SpriteSheet = sheet; 41 | Offset = new Vector2(sheet.Width,sheet.Height)/2f; 42 | NumFrames = numframes; 43 | SheetRow = row; 44 | CellWidth = width; 45 | CellHeight = height; 46 | CurrentFrame = 0; 47 | CurrentFrameTime = 0; 48 | TargetFrameTime = frametime; 49 | Loop = true; 50 | PingPong = false; 51 | CurrentDirection = SpriteAnimDirection.Forward; 52 | State = SpriteAnimState.Paused; 53 | } 54 | public SpriteAnim(Texture2D sheet, int row, int numframes, int width, int height, double frametime, Vector2 offset) 55 | :this(sheet, row, numframes, width, height, frametime) 56 | { 57 | Offset = offset; 58 | } 59 | public SpriteAnim(Texture2D sheet, int row, int numframes, int width, int height, double frametime, Vector2 offset, bool loop, bool pingpong, int startframe) 60 | : this(sheet, row, numframes, width, height, frametime, offset) 61 | { 62 | CurrentFrame = startframe; 63 | Loop = loop; 64 | PingPong = pingpong; 65 | } 66 | 67 | public void Update(GameTime gameTime) 68 | { 69 | if (State != SpriteAnimState.Playing) return; 70 | 71 | CurrentFrameTime += gameTime.ElapsedGameTime.TotalMilliseconds; 72 | if (CurrentFrameTime < TargetFrameTime) return; 73 | 74 | CurrentFrameTime = 0; 75 | 76 | switch(CurrentDirection) 77 | { 78 | case SpriteAnimDirection.Forward: 79 | CurrentFrame++; 80 | if (CurrentFrame == NumFrames) 81 | { 82 | if (PingPong && NumFrames > 1) 83 | { 84 | CurrentDirection = SpriteAnimDirection.Reverse; 85 | CurrentFrame -= 2; 86 | } 87 | else CurrentFrame = 0; 88 | } 89 | break; 90 | case SpriteAnimDirection.Reverse: 91 | CurrentFrame--; 92 | if (CurrentFrame == -1) 93 | { 94 | if (PingPong && NumFrames > 1) 95 | { 96 | CurrentDirection = SpriteAnimDirection.Forward; 97 | CurrentFrame = 1; 98 | } 99 | else CurrentFrame = NumFrames-1; 100 | } 101 | break; 102 | default: 103 | throw new ArgumentOutOfRangeException(); 104 | } 105 | } 106 | 107 | public void Play() { State = SpriteAnimState.Playing; } 108 | public void Pause() { State = SpriteAnimState.Paused; } 109 | public void Reset() 110 | { 111 | CurrentDirection = SpriteAnimDirection.Forward; 112 | CurrentFrame = 0; 113 | CurrentFrameTime = 0; 114 | } 115 | 116 | public void Draw(SpriteBatch sb, Vector2 pos) 117 | { 118 | sb.Draw(SpriteSheet, 119 | pos, 120 | new Rectangle(CurrentFrame * CellWidth, SheetRow * CellHeight, CellWidth, CellHeight), 121 | Color.White, 122 | 0f, 123 | Offset, 124 | 1f, 125 | SpriteEffects.None, 126 | 0); 127 | } 128 | public void Draw(SpriteBatch sb, Vector2 pos, SpriteEffects effects) 129 | { 130 | sb.Draw(SpriteSheet, 131 | pos, 132 | new Rectangle(CurrentFrame * CellWidth, SheetRow * CellHeight, CellWidth, CellHeight), 133 | Color.White, 134 | 0f, 135 | Offset, 136 | 1f, 137 | effects, 138 | 0); 139 | } 140 | public void Draw(SpriteBatch sb, Vector2 pos, SpriteEffects effects, float scale) 141 | { 142 | sb.Draw(SpriteSheet, 143 | pos, 144 | new Rectangle(CurrentFrame * CellWidth, SheetRow * CellHeight, CellWidth, CellHeight), 145 | Color.White, 146 | 0f, 147 | Offset, 148 | scale, 149 | effects, 150 | 0); 151 | } 152 | public void Draw(SpriteBatch sb, Vector2 pos, SpriteEffects effects, float scale, float rotation) 153 | { 154 | sb.Draw(SpriteSheet, 155 | pos, 156 | new Rectangle(CurrentFrame * CellWidth, SheetRow * CellHeight, CellWidth, CellHeight), 157 | Color.White, 158 | rotation, 159 | Offset, 160 | scale, 161 | effects, 162 | 0); 163 | } 164 | public void Draw(SpriteBatch sb, Vector2 pos, SpriteEffects effects, float scale, float rotation, Color tint) 165 | { 166 | sb.Draw(SpriteSheet, 167 | pos, 168 | new Rectangle(CurrentFrame * CellWidth, SheetRow * CellHeight, CellWidth, CellHeight), 169 | tint, 170 | rotation, 171 | Offset, 172 | scale, 173 | effects, 174 | 0); 175 | } 176 | 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /LDEngine/LDEngine/Screens/LoadingScreen.cs: -------------------------------------------------------------------------------- 1 | #region File Description 2 | //----------------------------------------------------------------------------- 3 | // LoadingScreen.cs 4 | // 5 | // Microsoft XNA Community Game Platform 6 | // Copyright (C) Microsoft Corporation. All rights reserved. 7 | //----------------------------------------------------------------------------- 8 | #endregion 9 | 10 | #region Using Statements 11 | using System; 12 | using Microsoft.Xna.Framework; 13 | using Microsoft.Xna.Framework.Graphics; 14 | #endregion 15 | 16 | namespace GameStateManagement 17 | { 18 | /// 19 | /// The loading screen coordinates transitions between the menu system and the 20 | /// game itself. Normally one screen will transition off at the same time as 21 | /// the next screen is transitioning on, but for larger transitions that can 22 | /// take a longer time to load their data, we want the menu system to be entirely 23 | /// gone before we start loading the game. This is done as follows: 24 | /// 25 | /// - Tell all the existing screens to transition off. 26 | /// - Activate a loading screen, which will transition on at the same time. 27 | /// - The loading screen watches the state of the previous screens. 28 | /// - When it sees they have finished transitioning off, it activates the real 29 | /// next screen, which may take a long time to load its data. The loading 30 | /// screen will be the only thing displayed while this load is taking place. 31 | /// 32 | class LoadingScreen : GameScreen 33 | { 34 | #region Fields 35 | 36 | bool loadingIsSlow; 37 | bool otherScreensAreGone; 38 | 39 | GameScreen[] screensToLoad; 40 | 41 | #endregion 42 | 43 | #region Initialization 44 | 45 | 46 | /// 47 | /// The constructor is private: loading screens should 48 | /// be activated via the static Load method instead. 49 | /// 50 | private LoadingScreen(ScreenManager screenManager, bool loadingIsSlow, 51 | GameScreen[] screensToLoad) 52 | { 53 | this.loadingIsSlow = loadingIsSlow; 54 | this.screensToLoad = screensToLoad; 55 | 56 | TransitionOnTime = TimeSpan.FromSeconds(0.5); 57 | } 58 | 59 | 60 | /// 61 | /// Activates the loading screen. 62 | /// 63 | public static void Load(ScreenManager screenManager, bool loadingIsSlow, params GameScreen[] screensToLoad) 64 | { 65 | // Tell all the current screens to transition off. 66 | foreach (GameScreen screen in screenManager.GetScreens()) 67 | screen.ExitScreen(); 68 | 69 | // Create and activate the loading screen. 70 | LoadingScreen loadingScreen = new LoadingScreen(screenManager, 71 | loadingIsSlow, 72 | screensToLoad); 73 | 74 | screenManager.AddScreen(loadingScreen); 75 | } 76 | 77 | 78 | #endregion 79 | 80 | #region Update and Draw 81 | 82 | 83 | /// 84 | /// Updates the loading screen. 85 | /// 86 | public override void Update(GameTime gameTime, bool otherScreenHasFocus, 87 | bool coveredByOtherScreen) 88 | { 89 | base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); 90 | 91 | // If all the previous screens have finished transitioning 92 | // off, it is time to actually perform the load. 93 | if (otherScreensAreGone) 94 | { 95 | ScreenManager.RemoveScreen(this); 96 | 97 | foreach (GameScreen screen in screensToLoad) 98 | { 99 | if (screen != null) 100 | { 101 | ScreenManager.AddScreen(screen); 102 | } 103 | } 104 | 105 | // Once the load has finished, we use ResetElapsedTime to tell 106 | // the game timing mechanism that we have just finished a very 107 | // long frame, and that it should not try to catch up. 108 | ScreenManager.Game.ResetElapsedTime(); 109 | } 110 | } 111 | 112 | 113 | /// 114 | /// Draws the loading screen. 115 | /// 116 | public override void Draw(GameTime gameTime) 117 | { 118 | // If we are the only active screen, that means all the previous screens 119 | // must have finished transitioning off. We check for this in the Draw 120 | // method, rather than in Update, because it isn't enough just for the 121 | // screens to be gone: in order for the transition to look good we must 122 | // have actually drawn a frame without them before we perform the load. 123 | if ((ScreenState == ScreenState.Active) && 124 | (ScreenManager.GetScreens().Length == 1)) 125 | { 126 | otherScreensAreGone = true; 127 | } 128 | 129 | // The gameplay screen takes a while to load, so we display a loading 130 | // message while that is going on, but the menus load very quickly, and 131 | // it would look silly if we flashed this up for just a fraction of a 132 | // second while returning from the game to the menus. This parameter 133 | // tells us how long the loading is going to take, so we know whether 134 | // to bother drawing the message. 135 | if (loadingIsSlow) 136 | { 137 | SpriteBatch spriteBatch = ScreenManager.SpriteBatch; 138 | SpriteFont font = ScreenManager.Font; 139 | 140 | const string message = "Loading..."; 141 | 142 | // Center the text in the viewport. 143 | Viewport viewport = ScreenManager.Game.GraphicsDevice.Viewport; 144 | Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height); 145 | Vector2 textSize = font.MeasureString(message); 146 | Vector2 textPosition = (viewportSize - textSize) / 2; 147 | 148 | Color color = Color.White * TransitionAlpha; 149 | 150 | // Draw the text. 151 | spriteBatch.Begin(); 152 | spriteBatch.DrawString(font, message, textPosition, color); 153 | spriteBatch.End(); 154 | } 155 | } 156 | 157 | 158 | #endregion 159 | } 160 | } 161 | --------------------------------------------------------------------------------