X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=CarFire%2FCarFire%2FCarFire%2FTrigger.cs;fp=CarFire%2FCarFire%2FCarFire%2FTrigger.cs;h=25cc11efa1ff0ead9f574de5231166729f1ac0a0;hb=d167160264cd2c33de81a71039eddbb959c40bb2;hp=0000000000000000000000000000000000000000;hpb=3ca5852a7df47d4129743ed449816c7c7347b699;p=chaz%2Fcarfire
diff --git a/CarFire/CarFire/CarFire/Trigger.cs b/CarFire/CarFire/CarFire/Trigger.cs
new file mode 100644
index 0000000..25cc11e
--- /dev/null
+++ b/CarFire/CarFire/CarFire/Trigger.cs
@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Content;
+
+namespace CarFire
+{
+ ///
+ /// A trigger is an invisible entity whose only purpose is
+ /// to check a condition and run a script when the condition
+ /// is right.
+ ///
+ public class Trigger : IEntity
+ {
+ #region Public Methods
+
+ public Trigger(char identifier, Point position, Dictionary info, Game game)
+ {
+ mGame = game;
+ mPrevCondition = false;
+ mCoordinates = position;
+
+ string condition;
+ if (info.TryGetValue("condition", out condition))
+ {
+ mCondition = new Script(condition, game);
+ }
+ else throw new Exception("Triggers must define a condition script.");
+
+ string eventt;
+ if (info.TryGetValue("event", out eventt))
+ {
+ mEvent = new Script(eventt, game);
+ }
+ else throw new Exception("Triggers must define an event script.");
+ }
+
+ public void Update(TimeSpan timeSpan)
+ {
+ Player player = mGame.GetPlayerAtCoordinates(mCoordinates);
+ if (player != null)
+ {
+ bool condition = mCondition.Run(player);
+ if (condition && condition != mPrevCondition)
+ {
+ mEvent.Run(player);
+ }
+ mPrevCondition = condition;
+ }
+ else
+ {
+ mPrevCondition = false;
+ }
+ }
+
+ public void LoadContent(ContentManager contentManager)
+ {
+ // No implementation needed.
+ }
+
+ public void Draw(SpriteBatch spriteBatch)
+ {
+ // No implementation needed.
+ }
+
+ public Vector2 Position
+ {
+ get { return Vector2.Zero; }
+ }
+
+ public Point Coordinates
+ {
+ get { return new Point(-1, -1); }
+ }
+
+ #endregion
+
+
+ #region Private Variables
+
+ Script mCondition;
+ Script mEvent;
+ Game mGame;
+ bool mPrevCondition;
+ Point mCoordinates;
+
+ #endregion
+ }
+}