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 } }
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 { } }
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(); } }