For the Lua level integration:
ATM you can replace default functions with your custom lua functions and be able to receive all sorts of events and stuff.
So basically you can make a level with no code, but only a Init() function that loads the level data.
But you can also override all default functions and do all sorts of things and manipulate the whole environment.
Heres some sample level code I wrote (I originally made this sample for codewalrus, thats why I made the walrii easter egg on pressing W):
Code: -- Main.lua
-- Level file sample
function Init()
-- Create Map object
Map = TwoStep.Game.Map();
-- Load the assets
PortalIn = Engine.TextureManager["Tile::Portal:In"];
PortalOut = Engine.TextureManager["Tile::Portal:Out"];
-- Populate the map
Map.Tiles:Add(TwoStep.Tiles.Void(PortalOut, TwoStep.Game.Position(0, 0)));
Map.Tiles:Add(TwoStep.Tiles.Void(PortalOut, TwoStep.Game.Position(1, 0)));
Map.Tiles:Add(TwoStep.Tiles.Void(PortalIn, TwoStep.Game.Position(0, 1)));
-- Create counter variable
a = 0;
-- Create the two player objects
Girl = TwoStep.GameObjects.Girl(Engine);
Boy = TwoStep.GameObjects.Boy(Engine);
-- Helper vars
Character = "Boy";
ActionPending = true;
WalriiEnable = false;
Random = clr.System.Random();
end
function Update(delta)
-- Update stuff
-- Do some fun with the engine
a = a + 1;
if a == 75 then
Engine:Window:SetTitle("Lua Rulez!");
end
if a == 100 then
Engine:Window:SetTitle("Yeah!");
end
if ActionPending == true then
if Character == "Boy" then
Engine:Screen.Player = Boy;
elseif Character == "Girl" then
Engine:Screen.Player = Girl;
end
ActionPending = false;
end
if WalriiEnable == true then
local newX : float = Random.Next(0, Engine:Window.Size.X);
local newY : float = Random.Next(0, Engine:Window.Size.Y);
WalriiSprite.Position = SFML.Window.Vector2f(newX, newY);
end
end
function Draw(target, delta)
Map:Draw(target);
if WalriiEnable == true then
target:Draw(WalriiSprite);
end
end
function KeyDown(args)
-- Keypress
if args:Code == "Escape" then
TwoStep.Core.Logger.LogInfo("Lua", "Esc pressed :)");
Engine:Shutdown();
end
if args:Code == "Return" then
if Character == "Boy" then
Character = "Girl";
else
Character = "Boy";
end
ActionPending = true;
TwoStep.Core.Logger.LogInfo("Lua", "Changed character to " .. Character);
end
-- Walrii Easter egg
if args:Code == "W" and WalriiEnable == false then
TwoStep.Core.Logger.LogInfo("Lua", "Walrii...");
local wc = clr.System.Net.WebClient();
TwoStep.Core.Logger.LogInfo("Lua", "Downloading walrii...");
local walriibytes : byte[] = wc.DownloadData("http://img.codewalr.us/walrii.png");
TwoStep.Core.Logger.LogInfo("Lua", "Download complete!");
TwoStep.Core.Logger.LogInfo("Lua", "Generating sprite...");
local WalriiTex : SFML.Graphics.Texture = TwoStep.Utils.TextureTools.TextureFromByteArray(walriibytes);
WalriiSprite = SFML.Graphics.Sprite(WalriiTex);
TwoStep.Core.Logger.LogInfo("Lua", "Generation complete!");
WalriiEnable = true;
TwoStep.Core.Logger.LogInfo("Lua", "Walrii done!");
end
end