Beispiel #1
0
        public bool Conflicts(Movement other)
        {
            // if the objects are moving into eachother, cancel both
            if (this.NewX () == other.NewX () && this.NewY () == other.NewY ())
                return true;

            // if the two objects swapped places, cancel both
            if (this.NewX () == other.OldX () && other.NewX () == this.OldX ()
                && this.NewY () == other.OldY () && other.NewY () == this.OldY ())
                return true;

            return false;
        }
Beispiel #2
0
        public void StartMovement(Direction playerDirection)
        {
            // the player movement is special; if it fails, everything fails.
            Movement playerMovement;

            List<Movement> movements = new List<Movement> ();
            foreach (Tile t in this.occupiedTiles) {
                Movement m = new Movement (t.contains, t.x, t.y, t.contains.Move (playerDirection));
                movements.Add (m);

                if (m.ParentObject ().IsCharacter ())
                    playerMovement = m;
            }

            foreach (Movement m1 in movements) {
                // if we already marked it invalid, skip
                if (m1.Invalid ())
                    continue;

                if (m1.NewX () < 0 || m1.NewX () >= this.width
                    || m1.NewY () < 0 || m1.NewY () >= this.height) {
                    m1.SetInvalid ();
                    continue;
                }

                foreach (Movement m2 in movements) {
                    if (m1 == m2)
                        continue;
                    if (m1.Conflicts (m2)) {
                        m1.SetInvalid ();
                        m2.SetInvalid ();
                        break;
                    }
                }
            }

            this.currentMovements = movements;
        }