public override void OnCollision(GameObject other) { if (other is Farm) { if (!farmUpgraded) { lock (FarmLock) { gold = 5; Thread.Sleep(3000); } } //The farm can be upgraded to hold two workers at once. if (farmUpgraded) { UpgradeFarm.WaitOne(); Thread.Sleep(0); gold = 5; UpgradeFarm.Release(); } } if (other is Inn) { if (!innUpgraded) { if (gold > 0) { innMutex.WaitOne(); GameWorld.totalGold += gold; gold = 0; deathCount++; Thread.Sleep(3000); innMutex.ReleaseMutex(); } } //The Inn is upgradeable aswell, though this is a bigger upgrade then the Farm, hence why it is more expensive. else { if (gold > 0) { innSpace.WaitOne(); GameWorld.totalGold += gold; gold = 0; deathCount++; Thread.Sleep(0); innSpace.Release(); } } } }
//This is empty, because the individual objects have their own way of reacting to collision. public virtual void OnCollision(GameObject other) { }
public bool IsCollidingWith(GameObject other) { return CollisionBox.IntersectsWith(other.CollisionBox); }