Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions Objects/Dynamics/Player.cs → Objects/Dynamics/PlayerObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public enum Direction
Up=0, Down=1, Left=2, Right=3
};

public class Player : DynamicRectObject
public class PlayerObject : DynamicRectObject
{
protected Point SightAreaSize;
public Direction SightDirection;
Expand All @@ -19,14 +19,15 @@ public virtual Rectangle SightArea
{
get
{
Rectangle c = Collider;
switch (SightDirection)
{
case Direction.Up:
{
return new Rectangle
(
Collider.X + Collider.Width / 2 - SightAreaSize.X,
Collider.Y - SightAreaSize.Y,
c.X + c.Width / 2 - SightAreaSize.X,
c.Y - SightAreaSize.Y,
SightAreaSize.X,
SightAreaSize.Y
);
Expand All @@ -35,8 +36,8 @@ public virtual Rectangle SightArea
{
return new Rectangle
(
Collider.X + Collider.Width / 2 - SightAreaSize.X,
Collider.Y + Collider.Height + SightAreaSize.Y,
c.X + c.Width / 2 - SightAreaSize.X,
c.Y + c.Height + SightAreaSize.Y,
SightAreaSize.X,
SightAreaSize.Y
);
Expand All @@ -45,28 +46,28 @@ public virtual Rectangle SightArea
{
return new Rectangle
(
Collider.X - SightArea.X,
Collider.Y + Collider.Height / 2 - SightAreaSize.Y,
SightAreaSize.X,
SightAreaSize.Y
c.X - SightAreaSize.X,
c.Y + c.Height / 2 - SightAreaSize.Y,
SightAreaSize.Y,
SightAreaSize.X
);
}
case Direction.Right:
{
return new Rectangle
(
Collider.X + Collider.Width + SightArea.X,
Collider.Y + Collider.Height / 2 - SightAreaSize.Y,
SightAreaSize.X,
SightAreaSize.Y
c.X + c.Width + SightAreaSize.X,
c.Y + c.Height / 2 - SightAreaSize.Y,
SightAreaSize.Y,
SightAreaSize.X
);
}
default:
{
return new Rectangle
(
Collider.X + Collider.Width / 2 - SightAreaSize.X / 2,
Collider.Y + Collider.Height / 2 - SightAreaSize.Y / 2,
c.X + c.Width / 2 - SightAreaSize.X / 2,
c.Y + c.Height / 2 - SightAreaSize.Y / 2,
SightAreaSize.X,
SightAreaSize.Y
);
Expand All @@ -75,7 +76,7 @@ public virtual Rectangle SightArea
}
}

public Player(Point StartLocation, Point colliderSize, Single mass, Point sightAreaSize) : base(StartLocation, colliderSize, mass, false)
public PlayerObject(Point StartLocation, Point colliderSize, Single mass, Point sightAreaSize) : base(StartLocation, colliderSize, mass, false)
{
SightAreaSize = sightAreaSize;
}
Expand Down
4 changes: 2 additions & 2 deletions Scripting/LuaModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class LuaModule
public Lua Runtime;
public Boolean IsUp = true;
public Int32 EventID;
public readonly Int32 EventAmount;
public readonly Double EventAmount;

public LuaModule(String initFile, Int32 eventAmount)
{
Expand All @@ -26,7 +26,7 @@ public LuaModule(String initFile)
Runtime = new Lua();
Runtime.LoadCLRPackage();
Runtime.DoString(initFile);
EventAmount = (Int32) Runtime["event_count"];
EventAmount = (Double) Runtime["event_count"];
}

public void Update(Single elapsedTime, Single totalTime)
Expand Down
8 changes: 3 additions & 5 deletions Scripting/Pipeline/ScriptImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
using Scripting = DotRPG.Scripting;
using System.IO;

using TImport = System.String;

namespace DotRPG.Scripting.Pipeline
{
[ContentImporter(".lua", DisplayName = "DotRPG embeddable script handler", DefaultProcessor = "ScriptProcessor")]
public class ScriptImporter : ContentImporter<TImport>
public class ScriptImporter : ContentImporter<LuaModule>
{
public override TImport Import(string filename, ContentImporterContext context)
public override LuaModule Import(string filename, ContentImporterContext context)
{
return File.ReadAllText(filename);
return new Scripting::LuaModule(File.ReadAllText(filename));
}
}
}
4 changes: 2 additions & 2 deletions Scripting/Pipeline/ScriptProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Xna.Framework.Content.Pipeline;

using TInput = System.String;
using TInput = DotRPG.Scripting.LuaModule;
using TOutput = DotRPG.Scripting.LuaModule;

namespace ScriptImporter
Expand All @@ -10,7 +10,7 @@ class ScriptProcessor : ContentProcessor<TInput, TOutput>
{
public override TOutput Process(TInput input, ContentProcessorContext context)
{
return new TOutput(input);
return input;
}
}
}
12 changes: 12 additions & 0 deletions Scripting/SceneSwitchSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace DotRPG.Scripting
{
public class SceneSwitchSet
{
public Boolean AutoScroll = false;
public Boolean ExitDialog = false;
}
}
1 change: 1 addition & 0 deletions _Example/DotRPG.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
<ItemGroup>
<ProjectReference Include="..\Objects\DotRPG.Objects.csproj" />
<ProjectReference Include="..\Objects\Dynamics\DotRPG.Objects.Dynamics.csproj" />
<ProjectReference Include="..\Scripting\DotRPG.Scripting.csproj" />
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletion _Example/Game1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void SetFrameNumber(Object sender, EventArgs e, GameTime gameTime)

private void StartScroll(Object sender, EventArgs e, GameTime gameTime)
{
ActiveFrame = Frames[1];
ActiveFrame = Frames[2];
ActiveFrame.LoadContent();
}

Expand All @@ -104,6 +104,8 @@ protected override void Initialize()
Frames[0].Initialize();
Frames.Add(new DynamicsTestFrame(this, ResourceHGlobal, LogicEventSet));
Frames[1].Initialize();
Frames.Add(new ScriptTest(this, ResourceHGlobal, LogicEventSet));
Frames[2].Initialize();
base.Initialize();
}

Expand Down
3 changes: 3 additions & 0 deletions _Example/GameData/DotRPG.Example_data.mgcb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
/processorParam:TextureFormat=Compressed
/build:Fonts/MainFont_Large.spritefont

#begin Scripts/dialog.lua
/copy:Scripts/dialog.lua

#begin Sounds/clickText.wav
/importer:WavImporter
/processor:SoundEffectProcessor
Expand Down
27 changes: 27 additions & 0 deletions _Example/GameData/Scripts/dialog.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import ('DotRPG.Scripting', 'DotRPG.Objects')

event_count = 7

function loop(eventID, frameTime, totalTime)
if eventID == 0 then
dialog.Text = "You ran across white rectangular object.\nSo what?"
elseif eventID == 1 then
dialog.Text = "You should better go elsewhere."
scene.ExitDialog = true
elseif eventID == 2 then
dialog.Text = "A white rectangular object."
scene.ExitDialog = true
elseif eventID == 3 then
dialog.Text = "You've never seen object that is more white\nand rectangular than this one."
scene.ExitDialog = true
elseif eventID == 4 then
dialog.Text = "Don't you have better things to do?"
scene.ExitDialog = true
elseif eventID == 5 then
dialog.Text = "You ran across white rect"
scene.AutoScroll = true
elseif eventID == 6 then
dialog.Text = "COME ON, QUIT IT ALREADY!"
scene.ExitDialog = true
end
end
148 changes: 148 additions & 0 deletions _Example/ScriptTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using DotRPG.Objects;
using DotRPG.Objects.Dynamics;
using DotRPG.Scripting;
using Microsoft.Xna.Framework.Graphics;

namespace DotRPG._Example
{
class ScriptTest : Frame
{
LuaModule DialogTest1;
TextObject DialogForm;
SceneSwitchSet SceneSwitches = new SceneSwitchSet();
PlayerObject Player;
DynamicRectObject dro;
Boolean[] lastInputCollection = new bool[8];
Boolean ShowingText;

public override int FrameID
{
get
{
return 2;
}
}

public ScriptTest(Game owner, ResourceHeap globalGameResources, HashSet<TimedEvent> globalEventSet) : base(owner, globalGameResources, globalEventSet)
{

}

public override void Initialize()
{

}

public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, Rectangle drawZone)
{
Player.Draw(spriteBatch, gameTime, 540, new Point(0, 0), new Point(drawZone.Width, drawZone.Height));
dro.Draw(spriteBatch, gameTime, 540, new Point(0, 0), new Point(drawZone.Width, drawZone.Height));
if (ShowingText)
{
DialogForm.Draw(spriteBatch, Owner.Window);
}
#if DEBUG
spriteBatch.DrawString(FrameResources.Global.Fonts["vcr"], String.Format("Sight: {0}, Z key: {1}", Player.SightArea, lastInputCollection[4]), new Vector2(0, 12), Color.White);
#endif
}

public override void Update(GameTime gameTime, bool[] controls)
{
Single loco_x = 0.0f; Single loco_y = 0.0f;
if (controls[0]) { loco_y -= 1.0f; }
if (controls[1]) { loco_y += 1.0f; }
if (controls[2]) { loco_x -= 1.0f; }
if (controls[3]) { loco_x += 1.0f; }
Vector2 Locomotion = new Vector2(loco_x, loco_y);
if (controls[0] && !(controls[1] || controls[2] || controls[3]))
{
Player.SightDirection = Direction.Up;
}
if (controls[1] && !(controls[0] || controls[2] || controls[3]))
{
Player.SightDirection = Direction.Down;
}
if (controls[2] && !(controls[1] || controls[0] || controls[3]))
{
Player.SightDirection = Direction.Left;
}
if (controls[3] && !(controls[1] || controls[0] || controls[2]))
{
Player.SightDirection = Direction.Right;
}
Locomotion /= (Locomotion.Length() != 0 ? Locomotion.Length() : 1.0f);
Locomotion *= 0.1f;
if (ShowingText)
{
Locomotion = Vector2.Zero;
}
Player.Velocity = Locomotion;
Player.TryCollideWith(dro);
if (controls[4] && !lastInputCollection[4] || (ShowingText && DialogForm.ReachedEnd && SceneSwitches.AutoScroll))
{
if (Player.SightArea.Intersects(dro.Collider) && !ShowingText)
{
SceneSwitches.AutoScroll = false;
SceneSwitches.ExitDialog = false;
ShowingText = true;
DialogTest1.Update((float)gameTime.ElapsedGameTime.TotalMilliseconds, (float)gameTime.TotalGameTime.TotalMilliseconds);
DialogForm.ResetToStart();
}
else if (DialogForm.ReachedEnd)
{
if (SceneSwitches.ExitDialog)
{
ShowingText = false;
}
else
{
SceneSwitches.AutoScroll = false;
SceneSwitches.ExitDialog = false;
DialogTest1.Update((float)gameTime.ElapsedGameTime.TotalMilliseconds, (float)gameTime.TotalGameTime.TotalMilliseconds);
DialogForm.ResetToStart();
}
}

}
if (ShowingText)
{
DialogForm.Update(gameTime);
}
Player.Update(gameTime);
base.Update(gameTime, controls);
for (int i = 0; i < Math.Min(lastInputCollection.Length, controls.Length); i++)
{
lastInputCollection[i] = controls[i];
}
}

public override void SetPlayerPosition(object sender, EventArgs e, GameTime gameTime)
{
throw new NotImplementedException();
}

public override void LoadContent()
{
DialogForm = new TextObject(FrameResources.Global.Fonts["vcr_large"], "...", 0.01f, 0.80f, Color.White, AlignMode.TopLeft, 1080, scrollPerTick: 1, scrollDelay: 0.04f);
DialogTest1 = new LuaModule(System.IO.File.ReadAllText(System.IO.Path.Join(Owner.Content.RootDirectory, "Scripts/dialog.lua")));
DialogTest1.Runtime["dialog"] = DialogForm;
DialogTest1.Runtime["scene"] = SceneSwitches;
Player = new PlayerObject(new Point(32, 32), new Point(32, 32), 20.0f, new Point(32, 8));
dro = new DynamicRectObject(new Point(32, 128), new Point(32, 32), 30.0f, true);
FrameResources.Textures.Add("cube-p", Owner.Content.Load<Texture2D>("Texture2D/cube-p"));
Player.Sprite = new SpriteController(1000 / 60.0f, FrameResources.Textures["cube-p"]);
FrameResources.Textures.Add("cube-o", Owner.Content.Load<Texture2D>("Texture2D/cube-o"));
dro.Sprite = new SpriteController(1000 / 60.0f, FrameResources.Textures["cube-o"]);
}

public override void UnloadContent()
{
DialogForm = null;
FrameResources.Dispose();
}
}
}