Example #1
0
        public ControlPanel()
        {
            InitializeComponent();
            this.boardStatePanel.DataContext = GameInstance.Inst;

            List<Sprite> allSprites = new List<Sprite>();
            var state1 = new Position() { Ay = 0, Ax = 0};
            var s1 = new Sprite(state1) {
                Name = "Red Brick",
                Brush = Brushes.Red,
                IsSolid = true
            };

            var state2 = new Position() { Ay = .0001, Ax = .000012 };
            var s2 = new Sprite(state2) {
                Name = "Wall",
                Brush = Brushes.Black
            };

            var state3 = new Position() { Ay = .0001, Ax = .000012 };
            var s3 = new Sprite(state3) {
                Name = "Avatar",
                Brush = Brushes.Green,
                Width = 10,
                Height = 30
            };

            //var s3 = new Sprite();

            allSprites.Add(s1);
            allSprites.Add(s2);
            allSprites.Add(s3);
            this.allSprites.ItemsSource = allSprites;
            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.LastFilepath)) {
                ///openFile(Properties.Settings.Default.LastFilepath);
            }
            ///Create a list of sprites, bind these sprites to the control panel
            ///Allow point and click addition to the window
        }
Example #2
0
 internal bool IsOffTheBoard(Sprite s)
 {
     return (s.Right < 0 || s.Top > UniverseHeight || s.Left > UniverseWidth || s.Bottom < 0);
 }
Example #3
0
 private void spriteEvents(Sprite s)
 {
     if (isOffTheBoard(s)) {
         s.RaiseOffTheBoard();
     }
     ///We want to get rid of this element wise test
     ///Test for collision
     if (s.IsSolid) {
         var obst = collisionDetector.Update_Slow(s.CreationIndex, s.Left, s.Top, s.Right, s.Bottom);
         switch (obst) {
             case CollisionType.none:
                 s.State.ClearObstructions();
                 break;
             case CollisionType.overlap:
                 s.State.Freeze();
                 //s2.State.Freeze();
                 break;
             default:
                 s.State.AddObstruction(obst);
                 break;
         }
     }
 }
Example #4
0
 //public double BoardWidth { get; set; }
 //public double BoardHeight { get; set; }
 private bool isOffTheBoard(Sprite s)
 {
     return GamePerspective.IsOffTheBoard(s);
 }
Example #5
0
        private CollisionType collision(Sprite s1, Sprite s2)
        {
            ///Sort four edges and test for arrangement
            var horizCollision = collionIn1D(s1.Left, s1.Right, s2.Left, s2.Right);
            var vertCollision = collionIn1D(s1.Top, s1.Bottom, s2.Top, s2.Bottom);

            if (horizCollision == 0 || vertCollision == 0) {
                return CollisionType.none;
            }

            if (vertCollision < horizCollision) {
                //vert collision
                if (s1.Top < s2.Top) {
                    return CollisionType.bottom;
                } else {
                    return CollisionType.top;
                }

            }
            if (horizCollision < vertCollision) {
                //horiz collision
                if (s1.Left < s2.Left) {
                    return CollisionType.right;
                } else {
                    return CollisionType.left;
                }
            }
            throw new Exception();
        }
Example #6
0
 public void AddNewSprite(Sprite s, bool initialSprite = false)
 {
     if (initialSprite) {
         this.initialSprites.Add(s.Clone());
     }
     lock (this.allSprites) {
         this.allSprites.Add(s);
         if (s.Name == "Avatar") {
             this.mainCharacter = s;
         }
     }
 }
Example #7
0
 public static Sprite Deserialize(XElement root)
 {
     var state = Position.Deserialize(root.Elements().First());
     Sprite spr = new Sprite(state);
     spr.Name = (string)root.Attribute("Name");
     spr.Width = double.Parse((string)root.Attribute("Width"));
     spr.Height = double.Parse((string)root.Attribute("Height"));
     spr.Brush = new BrushConverter().ConvertFromString((string)root.Attribute("Brush")) as Brush;
     spr.DestroyOffscreen = bool.Parse((string)root.Attribute("DestroyOffScreen"));
     spr.IsSolid = bool.Parse((string)root.Attribute("IsSolid"));
     spr.CreationIndex = indexCounter++;
     return spr;
 }