Lua stuffs is working :D
This commit is contained in:
+210
-201
@@ -1,201 +1,210 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using DepthsBelow.GUI;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Audio;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.GamerServices;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Microsoft.Xna.Framework.Media;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the main type for your game
|
||||
/// </summary>
|
||||
public class Core : Microsoft.Xna.Framework.Game
|
||||
{
|
||||
public static GraphicsDeviceManager GraphicsDeviceManager;
|
||||
SpriteBatch spriteBatch;
|
||||
|
||||
public Camera Camera;
|
||||
|
||||
public bool PlayerTurn = true;
|
||||
public static MouseInput MouseInput;
|
||||
public static KeyboardInput KeyboardInput;
|
||||
public List<Soldier> Squad;
|
||||
public List<SmallEnemy> Swarm;
|
||||
public List<Shot> Volley;
|
||||
public static Map Map;
|
||||
|
||||
public SmallEnemy TestMonster;
|
||||
|
||||
public Core()
|
||||
{
|
||||
GraphicsDeviceManager = new GraphicsDeviceManager(this);
|
||||
Content.RootDirectory = "Content";
|
||||
|
||||
GraphicsDeviceManager.PreferredBackBufferWidth = 1280;
|
||||
GraphicsDeviceManager.PreferredBackBufferHeight = 720;
|
||||
GraphicsDeviceManager.IsFullScreen = false;
|
||||
|
||||
//graphics.SynchronizeWithVerticalRetrace = false;
|
||||
this.IsFixedTimeStep = false;
|
||||
GraphicsDeviceManager.ApplyChanges();
|
||||
|
||||
this.IsMouseVisible = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows the game to perform any initialization it needs to before starting to run.
|
||||
/// This is where it can query for any required services and load any non-graphic
|
||||
/// related content. Calling base.Initialize will enumerate through any components
|
||||
/// and initialize them as well.
|
||||
/// </summary>
|
||||
protected override void Initialize()
|
||||
{
|
||||
// TEST LUA
|
||||
new Lua();
|
||||
|
||||
// TODO: Add your initialization logic here
|
||||
Camera = new Camera(this);
|
||||
Squad = new List<Soldier>();
|
||||
Swarm = new List<SmallEnemy>();
|
||||
Volley = new List<Shot>();
|
||||
|
||||
TestMonster = new SmallEnemy(this, ref Swarm);
|
||||
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LoadContent will be called once per game and is the place to load
|
||||
/// all of your content.
|
||||
/// </summary>
|
||||
protected override void LoadContent()
|
||||
{
|
||||
// Create a new SpriteBatch, which can be used to draw textures.
|
||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
|
||||
Map = Content.Load<Map>("maps/Cave.Level1");
|
||||
// Load map objects
|
||||
Map.ParseObjects(this);
|
||||
|
||||
// TODO: use this.Content to load your game content here
|
||||
Soldier.LoadContent(this);
|
||||
SmallEnemy.LoadContent(this);
|
||||
Shot.LoadContent(this);
|
||||
|
||||
MouseInput = new MouseInput(this);
|
||||
MouseInput.LoadContent();
|
||||
KeyboardInput = new KeyboardInput(this);
|
||||
|
||||
TestMonster.X = 12;
|
||||
TestMonster.Y = 4;
|
||||
|
||||
//frame.Add(text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UnloadContent will be called once per game and is the place to unload
|
||||
/// all content.
|
||||
/// </summary>
|
||||
protected override void UnloadContent()
|
||||
{
|
||||
// TODO: Unload any non ContentManager content here
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows the game to run logic such as updating the world,
|
||||
/// checking for collisions, gathering input, and playing audio.
|
||||
/// </summary>
|
||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
// Allows the game to exit
|
||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
|
||||
this.Exit();
|
||||
|
||||
Camera.Update(gameTime);
|
||||
MouseInput.Update(gameTime);
|
||||
KeyboardInput.Update(gameTime);
|
||||
|
||||
// Update soldiers in squad
|
||||
foreach (var soldier in Squad)
|
||||
soldier.Update(gameTime);
|
||||
|
||||
foreach (var body in Swarm)
|
||||
body.Update(gameTime);
|
||||
|
||||
TestMonster.Update(gameTime);
|
||||
GUIManager.Update(gameTime);
|
||||
|
||||
base.Update(gameTime);
|
||||
}
|
||||
|
||||
public int FindDistance(Vector2 target, Vector2 start)
|
||||
{
|
||||
Vector2 combine = new Vector2(target.X - start.X, target.Y - start.Y);
|
||||
|
||||
int result = 0;
|
||||
int firstRestult = (int)Math.Sqrt((int)combine.X^2 + (int)combine.Y^2);
|
||||
|
||||
result = (int)Vector2.Distance(target, start);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is called when the game should draw itself.
|
||||
/// </summary>
|
||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||
protected override void Draw(GameTime gameTime)
|
||||
{
|
||||
GraphicsDevice.Clear(Color.Black);
|
||||
|
||||
// Start drawing using the Camera transform
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null,
|
||||
Camera.Transform);
|
||||
|
||||
// Draw the level
|
||||
Map.Draw(spriteBatch);
|
||||
|
||||
// Draw units
|
||||
foreach (var soldier in Squad)
|
||||
{
|
||||
var sr = soldier.GetComponent<Component.SpriteRenderer>();
|
||||
if (sr != null)
|
||||
sr.Draw(spriteBatch);
|
||||
}
|
||||
foreach (var body in Swarm)
|
||||
{
|
||||
var sr = body.GetComponent<Component.SpriteRenderer>();
|
||||
if (sr != null)
|
||||
sr.Draw(spriteBatch);
|
||||
}
|
||||
foreach (var bullet in Volley)
|
||||
{
|
||||
var sr = bullet.GetComponent<Component.SpriteRenderer>();
|
||||
if (sr != null)
|
||||
sr.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
// Draw mouse input visuals
|
||||
MouseInput.Draw(spriteBatch);
|
||||
|
||||
TestMonster.GetComponent<Component.SpriteRenderer>().Draw(spriteBatch);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
// Start drawing GUI components
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, null, null, null, Matrix.Identity);
|
||||
GUIManager.Draw(spriteBatch);
|
||||
spriteBatch.End();
|
||||
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using DepthsBelow.GUI;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Audio;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.GamerServices;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Microsoft.Xna.Framework.Media;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the main type for your game
|
||||
/// </summary>
|
||||
public class Core : Microsoft.Xna.Framework.Game
|
||||
{
|
||||
public static GraphicsDeviceManager GraphicsDeviceManager;
|
||||
SpriteBatch spriteBatch;
|
||||
|
||||
public Lua Lua;
|
||||
|
||||
public Camera Camera;
|
||||
|
||||
public bool PlayerTurn = true;
|
||||
public static MouseInput MouseInput;
|
||||
public static KeyboardInput KeyboardInput;
|
||||
public List<Soldier> Squad;
|
||||
public List<SmallEnemy> Swarm;
|
||||
public List<Shot> Volley;
|
||||
public static Map Map;
|
||||
|
||||
public SmallEnemy TestMonster;
|
||||
|
||||
public Core()
|
||||
{
|
||||
GraphicsDeviceManager = new GraphicsDeviceManager(this);
|
||||
Content.RootDirectory = "Content";
|
||||
|
||||
GraphicsDeviceManager.PreferredBackBufferWidth = 1280;
|
||||
GraphicsDeviceManager.PreferredBackBufferHeight = 720;
|
||||
GraphicsDeviceManager.IsFullScreen = false;
|
||||
|
||||
//graphics.SynchronizeWithVerticalRetrace = false;
|
||||
this.IsFixedTimeStep = false;
|
||||
GraphicsDeviceManager.ApplyChanges();
|
||||
|
||||
this.IsMouseVisible = true;
|
||||
|
||||
GameServices.AddService<GraphicsDevice>(GraphicsDevice);
|
||||
GameServices.AddService<ContentManager>(Content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows the game to perform any initialization it needs to before starting to run.
|
||||
/// This is where it can query for any required services and load any non-graphic
|
||||
/// related content. Calling base.Initialize will enumerate through any components
|
||||
/// and initialize them as well.
|
||||
/// </summary>
|
||||
protected override void Initialize()
|
||||
{
|
||||
// TODO: Add your initialization logic here
|
||||
Camera = new Camera(this);
|
||||
Squad = new List<Soldier>();
|
||||
Swarm = new List<SmallEnemy>();
|
||||
Volley = new List<Shot>();
|
||||
|
||||
TestMonster = new SmallEnemy(this, ref Swarm);
|
||||
|
||||
// Run scripts after everything is initialized
|
||||
Lua = new Lua();
|
||||
Lua.LoadScripts();
|
||||
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LoadContent will be called once per game and is the place to load
|
||||
/// all of your content.
|
||||
/// </summary>
|
||||
protected override void LoadContent()
|
||||
{
|
||||
// Create a new SpriteBatch, which can be used to draw textures.
|
||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
|
||||
Map = Content.Load<Map>("maps/Cave.Level1");
|
||||
// Load map objects
|
||||
Map.ParseObjects(this);
|
||||
|
||||
// TODO: use this.Content to load your game content here
|
||||
Soldier.LoadContent(this);
|
||||
SmallEnemy.LoadContent(this);
|
||||
Shot.LoadContent(this);
|
||||
|
||||
MouseInput = new MouseInput(this);
|
||||
MouseInput.LoadContent();
|
||||
KeyboardInput = new KeyboardInput(this);
|
||||
|
||||
TestMonster.X = 12;
|
||||
TestMonster.Y = 4;
|
||||
|
||||
//frame.Add(text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UnloadContent will be called once per game and is the place to unload
|
||||
/// all content.
|
||||
/// </summary>
|
||||
protected override void UnloadContent()
|
||||
{
|
||||
// TODO: Unload any non ContentManager content here
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows the game to run logic such as updating the world,
|
||||
/// checking for collisions, gathering input, and playing audio.
|
||||
/// </summary>
|
||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
// Allows the game to exit
|
||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
|
||||
this.Exit();
|
||||
|
||||
Camera.Update(gameTime);
|
||||
MouseInput.Update(gameTime);
|
||||
KeyboardInput.Update(gameTime);
|
||||
|
||||
// Update soldiers in squad
|
||||
foreach (var soldier in Squad)
|
||||
soldier.Update(gameTime);
|
||||
|
||||
foreach (var body in Swarm)
|
||||
body.Update(gameTime);
|
||||
|
||||
TestMonster.Update(gameTime);
|
||||
GUIManager.Update(gameTime);
|
||||
|
||||
base.Update(gameTime);
|
||||
}
|
||||
|
||||
public int FindDistance(Vector2 target, Vector2 start)
|
||||
{
|
||||
Vector2 combine = new Vector2(target.X - start.X, target.Y - start.Y);
|
||||
|
||||
int result = 0;
|
||||
int firstRestult = (int)Math.Sqrt((int)combine.X^2 + (int)combine.Y^2);
|
||||
|
||||
result = (int)Vector2.Distance(target, start);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is called when the game should draw itself.
|
||||
/// </summary>
|
||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||
protected override void Draw(GameTime gameTime)
|
||||
{
|
||||
GraphicsDevice.Clear(Color.Black);
|
||||
|
||||
// Start drawing using the Camera transform
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null,
|
||||
Camera.Transform);
|
||||
|
||||
// Draw the level
|
||||
Map.Draw(spriteBatch);
|
||||
|
||||
// Draw units
|
||||
foreach (var soldier in Squad)
|
||||
{
|
||||
var sr = soldier.GetComponent<Component.SpriteRenderer>();
|
||||
if (sr != null)
|
||||
sr.Draw(spriteBatch);
|
||||
}
|
||||
foreach (var body in Swarm)
|
||||
{
|
||||
var sr = body.GetComponent<Component.SpriteRenderer>();
|
||||
if (sr != null)
|
||||
sr.Draw(spriteBatch);
|
||||
}
|
||||
foreach (var bullet in Volley)
|
||||
{
|
||||
var sr = bullet.GetComponent<Component.SpriteRenderer>();
|
||||
if (sr != null)
|
||||
sr.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
// Draw mouse input visuals
|
||||
MouseInput.Draw(spriteBatch);
|
||||
|
||||
TestMonster.GetComponent<Component.SpriteRenderer>().Draw(spriteBatch);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
// Start drawing GUI components
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, null, null, null, Matrix.Identity);
|
||||
GUIManager.Draw(spriteBatch);
|
||||
spriteBatch.End();
|
||||
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
static class CustomExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Load all content within a certain folder. The function
|
||||
/// returns a dictionary where the file name, without type
|
||||
/// extension, is the key and the texture object is the value.
|
||||
///
|
||||
/// The contentFolder parameter has to be relative to the
|
||||
/// game.Content.RootDirectory folder.
|
||||
///
|
||||
/// http://danielsaidi.wordpress.com/2010/01/26/xna-load-all-content-files-in-a-folder/
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The content type.</typeparam>
|
||||
/// <param name="contentManager">The content manager for which content is to be loaded.</param>
|
||||
/// <param name="contentFolder">The game project root folder relative folder path.</param>
|
||||
/// <returns>A list of loaded content objects.</returns>
|
||||
public static Dictionary<String, T> LoadContent<T>(this ContentManager contentManager, string contentFolder)
|
||||
{
|
||||
//Load directory info, abort if none
|
||||
DirectoryInfo dir = new DirectoryInfo(contentManager.RootDirectory + "\\" + contentFolder);
|
||||
if (!dir.Exists)
|
||||
throw new DirectoryNotFoundException();
|
||||
//Init the resulting list
|
||||
Dictionary<String, T> result = new Dictionary<String, T>();
|
||||
|
||||
//Load all files that matches the file filter
|
||||
FileInfo[] files = dir.GetFiles("*.*");
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
string key = Path.GetFileNameWithoutExtension(file.Name);
|
||||
|
||||
result[key] = contentManager.Load<T>(contentFolder + "/" + key);
|
||||
}
|
||||
//Return the result
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
<RootNamespace>DepthsBelow</RootNamespace>
|
||||
<AssemblyName>DepthsBelow</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
|
||||
<XnaPlatform>Windows</XnaPlatform>
|
||||
<XnaProfile>HiDef</XnaProfile>
|
||||
@@ -73,9 +73,6 @@
|
||||
<SignManifests>true</SignManifests>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="lua51">
|
||||
<HintPath>..\..\LuaInterface\lua51.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="LuaInterface, Version=2.0.0.16708, Culture=neutral, processorArchitecture=x86">
|
||||
<HintPath>..\..\LuaInterface\LuaInterface.dll</HintPath>
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
@@ -114,21 +111,17 @@
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Core">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Net">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Camera.cs" />
|
||||
<Compile Include="CustomExtensions.cs" />
|
||||
<Compile Include="GameServices.cs" />
|
||||
<Compile Include="Interface.cs" />
|
||||
<Compile Include="Lua.cs" />
|
||||
<Compile Include="Shot.cs" />
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace DepthsBelow.GUI
|
||||
@@ -86,6 +87,11 @@ namespace DepthsBelow.GUI
|
||||
GUIManager.Remove(this);
|
||||
}
|
||||
|
||||
public void SetTexture(string fileName)
|
||||
{
|
||||
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>(fileName);
|
||||
}
|
||||
|
||||
public virtual void Update(GameTime gameTime)
|
||||
{
|
||||
foreach (var child in Children)
|
||||
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
/*
|
||||
* http://roy-t.nl/index.php/2010/08/25/xna-accessing-contentmanager-and-graphicsdevice-anywhere-anytime-the-gameservicecontainer/
|
||||
*/
|
||||
public static class GameServices
|
||||
{
|
||||
private static GameServiceContainer container;
|
||||
public static GameServiceContainer Instance
|
||||
{
|
||||
get { return container ?? (container = new GameServiceContainer()); }
|
||||
}
|
||||
|
||||
public static T GetService<T>()
|
||||
{
|
||||
return (T)Instance.GetService(typeof(T));
|
||||
}
|
||||
|
||||
public static void AddService<T>(T service)
|
||||
{
|
||||
Instance.AddService(typeof(T), service);
|
||||
}
|
||||
|
||||
public static void RemoveService<T>()
|
||||
{
|
||||
Instance.RemoveService(typeof(T));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,26 +2,110 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DepthsBelow.GUI;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
class Lua
|
||||
// TODO: The frames created here must be disposed correctly when the Lua context is disposed
|
||||
static class LuaGUI
|
||||
{
|
||||
public static GUI.Frame CreateFrame()
|
||||
{
|
||||
return new Frame();
|
||||
}
|
||||
public static GUI.Frame CreateFrame(GUI.Frame parent)
|
||||
{
|
||||
return new GUI.Frame(parent);
|
||||
}
|
||||
|
||||
public static GUI.Button CreateButton()
|
||||
{
|
||||
return new Button();
|
||||
}
|
||||
public static GUI.Button CreateButton(GUI.Frame parent)
|
||||
{
|
||||
return new GUI.Button(parent);
|
||||
}
|
||||
}
|
||||
|
||||
public class Lua
|
||||
{
|
||||
private LuaInterface.Lua lua;
|
||||
|
||||
public Lua()
|
||||
{
|
||||
LuaInterface.Lua lua = new LuaInterface.Lua();
|
||||
ResetContext();
|
||||
ExposeLibraries();
|
||||
|
||||
lua.RegisterFunction("GetKeyboardState", null, typeof(DepthsBelow.Lua).GetMethod("GetKeyboardState"));
|
||||
object[] ret = lua.DoString("return GetKeyboardState()");
|
||||
Console.WriteLine(((KeyboardState)ret[0]).ToString());
|
||||
/*lua.DoString(@"
|
||||
local frame = CreateFrame('Frame');
|
||||
frame.X = 100;
|
||||
local button = CreateFrame('Button', frame);
|
||||
button:SetTexture('images/Enter');
|
||||
button.Width = 100;
|
||||
button.Height = 50;
|
||||
button.OnClick = function(clickPos)
|
||||
Console.WriteLine(clickPos.X .. ' ' .. clickPos.Y);
|
||||
end
|
||||
");*/
|
||||
}
|
||||
|
||||
public KeyboardState GetKeyboardState()
|
||||
public void ExposeLibraries()
|
||||
{
|
||||
return Keyboard.GetState();
|
||||
lua.NewTable("Console");
|
||||
lua.RegisterFunction("Console.Write", null, typeof(System.Console).GetMethod("Write", new Type[] { typeof(string) }));
|
||||
lua.RegisterFunction("Console.WriteLine", null, typeof(System.Console).GetMethod("WriteLine", new Type[] { typeof(string) }));
|
||||
|
||||
// Register GUI creation functions
|
||||
lua.RegisterFunction("_CreateFrame", null, typeof(LuaGUI).GetMethod("CreateFrame", new Type[] { }));
|
||||
lua.RegisterFunction("_CreateFrameAsChild", null, typeof(LuaGUI).GetMethod("CreateFrame", new Type[] { typeof(GUI.Frame) }));
|
||||
lua.RegisterFunction("_CreateButton", null, typeof(LuaGUI).GetMethod("CreateButton", new Type[] { }));
|
||||
lua.RegisterFunction("_CreateButtonAsChild", null, typeof(LuaGUI).GetMethod("CreateButton", new Type[] { typeof(GUI.Frame) }));
|
||||
lua.NewTable("GUI");
|
||||
/*
|
||||
* Because Lua can't dynamically call overloads of registered functions, a generic Lua function needs to do the decision making.
|
||||
* This way we can also dynamically create different frame classes with the same function.
|
||||
*/
|
||||
lua.DoString(@"
|
||||
CreateFrame = function(frameType, parent)
|
||||
frameType = string.lower(frameType):gsub('^%l', string.upper)
|
||||
if (parent == nil) then
|
||||
return _G['_Create' .. frameType]()
|
||||
else
|
||||
return _G['_Create' .. frameType .. 'AsChild'](parent)
|
||||
end
|
||||
end
|
||||
");
|
||||
}
|
||||
|
||||
public void ResetContext()
|
||||
{
|
||||
if (lua != null)
|
||||
lua.Dispose();
|
||||
|
||||
lua = new LuaInterface.Lua();
|
||||
}
|
||||
|
||||
public void LoadScripts()
|
||||
{
|
||||
// Load scripts from script folder
|
||||
// HACK: This needs to load files on the fly instead of loading precompiled files by the content manager.
|
||||
// http://xbox.create.msdn.com/en-US/education/catalog/sample/winforms_series_2 maybe?
|
||||
var scripts = GameServices.GetService<ContentManager>().LoadContent<string>("scripts");
|
||||
foreach (var script in scripts)
|
||||
{
|
||||
try
|
||||
{
|
||||
lua.DoString(script.Value);
|
||||
}
|
||||
catch (LuaInterface.LuaException e)
|
||||
{
|
||||
Console.WriteLine("Lua error: " + e.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,138 +1,149 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{433A77A2-DE52-4875-A4EF-232CF59C2DD3}</ProjectGuid>
|
||||
<ProjectTypeGuids>{96E2B04D-8817-42c6-938A-82C39BA4D311};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
|
||||
<OutputPath>bin\$(Platform)\$(Configuration)</OutputPath>
|
||||
<ContentRootDirectory>Content</ContentRootDirectory>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<RootNamespace>DepthsBelowContent</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.EffectImporter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.FBXImporter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.TextureImporter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.XImporter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.AudioImporters, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.VideoImporters, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="images\soldier.png">
|
||||
<Name>soldier</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
<Compile Include="maps\test.tmx">
|
||||
<Name>test</Name>
|
||||
<Importer>TmxImporter</Importer>
|
||||
<Processor>MapProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\TiledLib\TiledLib\TiledLib.csproj">
|
||||
<Project>{EC3F6988-459C-4783-89E9-F34C0CC731C7}</Project>
|
||||
<Name>TiledLib</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\DepthsBelowContentPipeline\DepthsBelowContentPipeline.csproj">
|
||||
<Project>{D054E3A6-7E05-4255-984F-69FE40D9137F}</Project>
|
||||
<Name>DepthsBelowContentPipeline</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="maps\tilesets\aztek.jpg">
|
||||
<Name>aztek</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="images\soldier2.png">
|
||||
<Name>soldier2</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="maps\tilesets\collision.png">
|
||||
<Name>collision</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="maps\Cave.Level1.tmx">
|
||||
<Name>Cave.Level1</Name>
|
||||
<Processor>MapProcessor</Processor>
|
||||
<Importer>TmxImporter</Importer>
|
||||
<SubType>Designer</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="maps\tilesets\cave.png">
|
||||
<Name>cave</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="images\Monster.png">
|
||||
<Name>Monster</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="images\Enter.bmp">
|
||||
<Name>Enter</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Arial.spritefont">
|
||||
<Name>Arial</Name>
|
||||
<Importer>FontDescriptionImporter</Importer>
|
||||
<Processor>FontDescriptionProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="images\Shot.bmp">
|
||||
<Name>Shot</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{433A77A2-DE52-4875-A4EF-232CF59C2DD3}</ProjectGuid>
|
||||
<ProjectTypeGuids>{96E2B04D-8817-42c6-938A-82C39BA4D311};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
|
||||
<OutputPath>bin\$(Platform)\$(Configuration)</OutputPath>
|
||||
<ContentRootDirectory>Content</ContentRootDirectory>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<RootNamespace>DepthsBelowContent</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.EffectImporter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.FBXImporter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.TextureImporter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.XImporter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.AudioImporters, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.VideoImporters, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="images\soldier.png">
|
||||
<Name>soldier</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
<Compile Include="maps\test.tmx">
|
||||
<Name>test</Name>
|
||||
<Importer>TmxImporter</Importer>
|
||||
<Processor>MapProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\TiledLib\TiledLib\TiledLib.csproj">
|
||||
<Project>{EC3F6988-459C-4783-89E9-F34C0CC731C7}</Project>
|
||||
<Name>TiledLib</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\DepthsBelowContentPipeline\DepthsBelowContentPipeline.csproj">
|
||||
<Project>{D054E3A6-7E05-4255-984F-69FE40D9137F}</Project>
|
||||
<Name>DepthsBelowContentPipeline</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="maps\tilesets\aztek.jpg">
|
||||
<Name>aztek</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="images\soldier2.png">
|
||||
<Name>soldier2</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="maps\tilesets\collision.png">
|
||||
<Name>collision</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="maps\Cave.Level1.tmx">
|
||||
<Name>Cave.Level1</Name>
|
||||
<Processor>MapProcessor</Processor>
|
||||
<Importer>TmxImporter</Importer>
|
||||
<SubType>Designer</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="maps\tilesets\cave.png">
|
||||
<Name>cave</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="images\Monster.png">
|
||||
<Name>Monster</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="images\Enter.bmp">
|
||||
<Name>Enter</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Arial.spritefont">
|
||||
<Name>Arial</Name>
|
||||
<Importer>FontDescriptionImporter</Importer>
|
||||
<Processor>FontDescriptionProcessor</Processor>
|
||||
<SubType>Designer</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="images\Shot.bmp">
|
||||
<Name>Shot</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="scripts\gui.lua">
|
||||
<Name>gui</Name>
|
||||
<Importer>LuaImporter</Importer>
|
||||
</Compile>
|
||||
<Compile Include="scripts\test.lua">
|
||||
<Name>test</Name>
|
||||
<Importer>LuaImporter</Importer>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
-->
|
||||
</Project>
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
local frame = CreateFrame('Frame');
|
||||
frame.X = 100;
|
||||
|
||||
local button = CreateFrame('Button', frame);
|
||||
button:SetTexture('images/Enter');
|
||||
button.Width = 100;
|
||||
button.Height = 50;
|
||||
button.OnClick = function(clickPos)
|
||||
Console.WriteLine(clickPos.X .. ' ' .. clickPos.Y);
|
||||
end
|
||||
+1
@@ -0,0 +1 @@
|
||||
Console.WriteLine("Test.lua loaded");
|
||||
@@ -27,6 +27,7 @@
|
||||
<Private>False</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL" />
|
||||
<Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
|
||||
<Private>False</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
@@ -49,6 +50,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="LuaImporter.cs" />
|
||||
<Compile Include="MapProcessor.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Content.Pipeline;
|
||||
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
|
||||
|
||||
// TODO: replace this with the type you want to import.
|
||||
using TImport = System.String;
|
||||
|
||||
namespace DepthsBelowContentPipeline
|
||||
{
|
||||
/// <summary>
|
||||
/// This class will be instantiated by the XNA Framework Content Pipeline
|
||||
/// to import a file from disk into the specified type, TImport.
|
||||
///
|
||||
/// This should be part of a Content Pipeline Extension Library project.
|
||||
///
|
||||
/// TODO: change the ContentImporter attribute to specify the correct file
|
||||
/// extension, display name, and default processor for this importer.
|
||||
/// </summary>
|
||||
[ContentImporter(".lua", DisplayName = "LUA Importer", DefaultProcessor = "LuaProcessor")]
|
||||
public class LuaImporter : ContentImporter<TImport>
|
||||
{
|
||||
public override TImport Import(string filename, ContentImporterContext context)
|
||||
{
|
||||
return System.IO.File.ReadAllText(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user