public override bool onHit(ArenaObject other) { if (other != null) { if (!(other is Robot)) return false; owner.parent.spawn(typeof(HellboreExplosion), x, y, owner, other); } destroy(); return true; }
public override bool onHit(ArenaObject other) { if (other != null) { if (!(other is Robot)) return false; if (type == BulletType.Explosive) owner.parent.spawn(typeof(BigExplosion), x, y, owner, energy); else { int damage = energy; if (type == BulletType.Rubber) damage /= 2; owner.parent.spawn(typeof(Explosion), x, y, owner, other, damage); } } destroy(); return true; }
// Instantiate a new ArenaObject subclass internal ArenaObject spawn(Type objtype, double x, double y, params object[] parameters) { if (!objtype.IsSubclassOf(typeof(ArenaObject))) { throw new ArenaObjectExtensionException( "Object type is not an ArenaObject subclass"); } if (objtype == typeof(Robot)) { throw new ArgumentException("I won't allow you to spawn Robots!"); } List <Type> types = new List <Type>(parameters.Length); // Create the ArenaObject. Subclasses should implement // minimal constructors, and instead do most things in onSpawn. ArenaObject retval = Activator.CreateInstance(objtype, this, x, y) as ArenaObject; // Call onSpawn if applicable types.Clear(); foreach (object parameter in parameters) { types.Add(parameter.GetType()); } MethodInfo minfo = objtype.GetMethod("onSpawn", types.ToArray()); if (minfo != null) { minfo.Invoke(retval, parameters); } else if (parameters.Length > 0) { throw new ArenaObjectExtensionException( "Cannot find a suitable onSpawn method for ArenaObject"); } newObjects.Add(retval); return(retval); }
internal void RegisterObject(ArenaObject obj) { newObjects.Add(obj); }
// Other is null if it went off the arena public abstract bool onHit(ArenaObject other);