コード例 #1
0
 public override void TryDoingSomething(Sprite me, Map map)
 {
     if (me.IsMoving) return;
     script.Owner = me;
     object result = script.Run();
     if (result != null && result.GetType() == typeof(string)) {
         string res = (string)result;
         switch (res.ToLower()) {
             case "up": me.PlanMove(Sprite.Dir.Up, map); break;
             case "down": me.PlanMove(Sprite.Dir.Down, map); break;
             case "left": me.PlanMove(Sprite.Dir.Left, map); break;
             case "right": me.PlanMove(Sprite.Dir.Right, map); break;
             default: me.PlanMove(Sprite.Dir.None, map); break;
         }
     }
 }
コード例 #2
0
 public override void TryDoingSomething(Sprite me, Map map)
 {
     if (game.Input.IsPressed(UserInput.Buttons.Up)) {
         me.PlanMove(Sprite.Dir.Up, map);
     }
     else if (game.Input.IsPressed(UserInput.Buttons.Down)) {
         me.PlanMove(Sprite.Dir.Down, map);
     }
     else if (game.Input.IsPressed(UserInput.Buttons.Left)) {
         me.PlanMove(Sprite.Dir.Left, map);
     }
     else if (game.Input.IsPressed(UserInput.Buttons.Right)) {
         me.PlanMove(Sprite.Dir.Right, map);
     }
     if (game.Input.IsPressed(UserInput.Buttons.Action)) {
         me.PlanAction(map);
     }
 }
コード例 #3
0
ファイル: Party.cs プロジェクト: hgabor/kfirpgcreator
 public void Add(Sprite member)
 {
     if (Leader == null) Leader = member;
     this.members.Add(member);
 }
コード例 #4
0
ファイル: NotMovingAI.cs プロジェクト: hgabor/kfirpgcreator
 public override void TryDoingSomething(Sprite me, Map map)
 {
 }
コード例 #5
0
 public AnimationType(string type, Sprite.Dir dir)
 {
     this.type = type;
     this.dir = dir;
 }
コード例 #6
0
 /// <summary>
 /// Selects the direction for the animation.
 /// </summary>
 /// <param name="dir">The new direction.</param>
 public void SetDirection(Sprite.Dir dir)
 {
     currentType.dir = dir;
     currentAnimation = animations[currentType];
     CalculateRows();
 }
コード例 #7
0
ファイル: Map.cs プロジェクト: hgabor/kfirpgcreator
        private Map(string mapName, Game game, PropertyReader objectList)
        {
            this.mapName = mapName;
            PropertyReader baseReader = game.loader.GetPropertyReader();
            PropertyReader info = baseReader.Select("maps/" + mapName + "/info.xml");
            cols = info.GetInt("width");
            rows = info.GetInt("height");
            int numLayers = info.GetInt("layers");
            tileSize = game.TileSize;

            layers = new Layer[numLayers];
            for (int i = 0; i < numLayers; ++i) {
                layers[i] = new Layer(cols, rows, "maps/" + mapName + "/layers/{0}." + i.ToString(), game);
            }

            PropertyReader objects;
            if (objectList == null) {
                objects = baseReader.Select("maps/" + mapName + "/objects.xml");
                foreach (PropertyReader obj in objects.SelectAll("object")) {
                    string name = obj.GetString("sprite");
                    int x = obj.GetInt("x");
                    int y = obj.GetInt("y");
                    int l = obj.GetInt("layer");
                    string action = obj.GetString("action");
                    string movement = obj.GetString("movement");
                    string collide = obj.GetString("collide");
                    Sprite sp = new Sprite(name, game);
                    this.Place(sp, x, y, l);
                    if (action != "") {
                        Script script = game.vm.LoadResumableScript(game.loader.LoadText("scripts/" + action));
                        script.Owner = sp;
                        sp.Action = script;
                    }
                    if (movement != "") {
                        MovementAI ai = new ScriptedMovementAI(game.loader.LoadText("scripts/" + movement), game);
                        sp.MovementAI = ai;
                    }
                    if (collide != "") {
                        Script script = game.vm.LoadResumableScript(game.loader.LoadText("scripts/" + collide));
                        script.Owner = sp;
                        sp.Collide = script;
                    }
                }
            }
            else {
                objects = objectList;
                foreach (PropertyReader obj in objects.SelectAll("object")) {
                    if (obj.GetBool("player")) continue;
                    int x = obj.GetInt("x");
                    int y = obj.GetInt("y");
                    int l = obj.GetInt("layer");
                    Sprite sp = Sprite.LoadFromSaveFile(obj, game);
                    this.Place(sp, x, y, l);
                }
            }

            PropertyReader onstep = baseReader.Select("maps/" + mapName + "/onstep.xml");
            foreach (PropertyReader stepEvent in onstep.SelectAll("event")) {
                int x = stepEvent.GetInt("x");
                int y = stepEvent.GetInt("y");
                int l = stepEvent.GetInt("layer");
                string name = stepEvent.GetString("script");
                Script script = game.vm.LoadResumableScript(game.loader.LoadText("scripts/" + name));
                layers[l].onStep[x, y].Add(script);
            }

            PropertyReader ladders = baseReader.Select("maps/" + mapName + "/ladders.xml");
            foreach (PropertyReader ladder in ladders.SelectAll("ladder")) {
                int x = ladder.GetInt("x");
                int y = ladder.GetInt("y");
                int baseLayer = ladder.GetInt("base");
                int topLayer = ladder.GetInt("top");
                layers[baseLayer].ladderMove[x, y - 1] = layers[topLayer];
                layers[topLayer].ladderMove[x, y] = layers[baseLayer];
            }
        }
コード例 #8
0
ファイル: Map.cs プロジェクト: hgabor/kfirpgcreator
 private static bool ObjectPassable(Sprite obj)
 {
     return obj.Noclip;
 }
コード例 #9
0
ファイル: Map.cs プロジェクト: hgabor/kfirpgcreator
 //TODO: Might be the cause of yet unknown bugs.
 /// <summary>
 /// Removes a sprite from the map with specified coordinates. The sprite's Advance() method
 /// is still executed this frame.
 /// </summary>
 /// <param name="sprite"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="layer"></param>
 internal void Remove(Sprite sprite, int x, int y, int layer)
 {
     layers[layer].objects[x, y].Remove(sprite);
     removeList.Add(sprite);
 }
コード例 #10
0
ファイル: Map.cs プロジェクト: hgabor/kfirpgcreator
 /// <summary>
 /// Places a new sprite on the map. The sprite's Advance() method is not executed
 /// until next frame.
 /// </summary>
 /// <param name="sprite"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="layer"></param>
 internal void Place(Sprite sprite, int x, int y, int layer)
 {
     layers[layer].objects[x, y].Add(sprite);
     addList.Add(sprite);
     sprite.UpdateCoords(x, y, layer);
 }
コード例 #11
0
ファイル: Map.cs プロジェクト: hgabor/kfirpgcreator
 internal void OnCollide(int x, int y, int layer, Sprite asker)
 {
     if (asker.Noclip || x < 0 || y < 0 || x >= cols || y >= rows) return;
     if (layers[layer].ladderMove[x, y] == null) {
         if (asker is PlayerSprite) {
             layers[layer].objects[x, y].ForEach(o => {
                 if (!o.Noclip) o.OnCollide();
             });
         }
         else {
             Sprite s = layers[layer].objects[x, y].Find(o => o is PlayerSprite);
             if (s != null) asker.OnCollide();
         }
     }
     else {
         if (asker is PlayerSprite) {
             layers[layer].ladderMove[x, y].objects[x, y].ForEach(o => {
                 if (!o.Noclip) o.OnCollide();
             });
         }
         else {
             Sprite s = layers[layer].ladderMove[x, y].objects[x, y].Find(o => o is PlayerSprite);
             if (s != null) s.OnCollide();
         }
     }
 }
コード例 #12
0
ファイル: Map.cs プロジェクト: hgabor/kfirpgcreator
 /// <summary>
 /// Moves a sprite from one place to another.
 /// </summary>
 /// <param name="sprite"></param>
 /// <param name="fromX"></param>
 /// <param name="fromY"></param>
 /// <param name="fromLayer"></param>
 /// <param name="toX"></param>
 /// <param name="toY"></param>
 /// <param name="toLayer"></param>
 internal void Move(Sprite sprite, int fromX, int fromY, int fromLayer, int toX, int toY, int toLayer)
 {
     layers[fromLayer].objects[fromX, fromY].Remove(sprite);
     if (layers[toLayer].ladderMove[toX, toY] != null) {
         layers[toLayer].ladderMove[toX, toY].objects[toX, toY].Add(sprite);
         sprite.UpdateCoords(toX, toY, Array.IndexOf(layers, layers[toLayer].ladderMove[toX, toY]));
     }
     else {
         layers[toLayer].objects[toX, toY].Add(sprite);
         sprite.UpdateCoords(toX, toY, toLayer);
     }
 }
コード例 #13
0
ファイル: Sprite.cs プロジェクト: hgabor/kfirpgcreator
 public static Sprite LoadFromSaveFile(PropertyReader r, Game game)
 {
     Sprite sp = new Sprite(r.GetString("sprite"), game);
     sp.Load_FillInDetails(r, game);
     return sp;
 }
コード例 #14
0
ファイル: MovementAI.cs プロジェクト: hgabor/kfirpgcreator
 /// <summary>
 /// Decides the next action of the sprite.
 /// </summary>
 /// <param name="me">The sprite whose action is to be decided.</param>
 /// <param name="map">The map the sprite is on.</param>
 public abstract void TryDoingSomething(Sprite me, Map map);
コード例 #15
0
ファイル: ScriptLib.cs プロジェクト: hgabor/kfirpgcreator
 public void Turn(Sprite her, Sprite to)
 {
     int x = to.X - her.X;
     int y = to.Y - her.Y;
     if (x + y > 0) {
         if (y - x > 0) her.Turn(Sprite.Dir.Down);
         else her.Turn(Sprite.Dir.Right);
     }
     else {
         if (y - x > 0) her.Turn(Sprite.Dir.Left);
         else her.Turn(Sprite.Dir.Up);
     }
 }
コード例 #16
0
ファイル: ScriptLib.cs プロジェクト: hgabor/kfirpgcreator
 public void SetAnimation(Sprite sprite, string animation)
 {
     sprite.SetAnimation(animation.ToLower().Trim());
 }