Пример #1
0
 private void RemoveGameObject(GameObject go)
 {
     lock (locker)
     {
         //gameObjects.Remove(go); //modifies the gameobjects list ! breaks the foreach statement
         go.Sprite.Bounds = new Rectangle(); //avoid intersecting in location where destroyed object stood
         go.DestroyObject(); //polymorphism
     }
 }
Пример #2
0
 private void UpdateGameObjectLocation(GameObject go, Point location)
 {
     try
     {
         lock (locker)
         {
             go.Sprite.Location = location;
             if (go is Character)
             {
                 Character c = (Character)go;
                 Point point = new Point(location.X - 5, location.Y - c.CharacterLabel.Height);
                 c.CharacterLabel.Location = point;
             }
         }
     }
     catch { }
 }
Пример #3
0
        private void AddGameObject(GameObject go)
        {
            lock (locker)
            {
                if (go is Character)
                {
                    Character c = (Character)go;
                    GamePanel.Controls.Add(c.CharacterLabel);
                    Point s = new Point(c.Location.X - 5, c.Location.Y - c.CharacterLabel.Height);
                    c.CharacterLabel.Location = s;
                    characters.Add(c);
                }
                go.GameObjectMoved += new GameObject.MovedEventHandler(UpdateGameObjectLocation);
                go.DisposeComponentEvent += new GameObject.DisposeComponentDelegate(DisposeComponent);
                gameObjects.Add(go);
                go.SetController(this);
                GamePanel.Controls.Add(go.Sprite);

                go.StartMoving();
            }
        }