public override void EndContact(Contact contact) { V2DSprite objA = (V2DSprite)contact.GetFixtureA().GetBody().GetUserData(); V2DSprite objB = (V2DSprite)contact.GetFixtureB().GetBody().GetUserData(); SmuckPlayer p = objA is SmuckPlayer ? (SmuckPlayer)objA : objB is SmuckPlayer ? (SmuckPlayer)objB : null; LaneVehicle v = objA is LaneVehicle ? (LaneVehicle)objA : objB is LaneVehicle ? (LaneVehicle)objB : null; V2DSprite w = objA.InstanceName.StartsWith("water") ? objA : objB.InstanceName.StartsWith("water") ? objB : null; if (p != null) { if (w != null) { p.IsOnWater = false; } else if (v != null) { if (v.Lane.LaneKind == LaneKind.DrownWater) { p.aboardVehicle = null; if (p.IsOnWater) { p.LivingState = LivingState.Dying; stage.audio.PlaySound(Sfx.bigSplash); } } else { this.KillPlayer(p); } } } }
protected override void OnPlayerContact(object player, object objB, Fixture fixtureA, Fixture fixtureB) { base.OnPlayerContact(player, objB, fixtureA, fixtureB); if (!roundOver && objB is Target) { V2DSprite p = (V2DSprite)player; int scoredOnPlayer = p.Parent.Index == 0 ? 1 : 0; AddPoint(scoredOnPlayer); } }
public void EndContact(V2DSprite objB) { if (objB.Parent != this.Parent) { contactCount--; if (objB is Target) { targetContactIndex = -1; } } }
public void BeginContact(V2DSprite objB) { if (objB.Parent != this.Parent) { contactCount++; airTime = 0; if (objB is Target) { targetContactIndex = objB.Index; } } }
protected override void OnPlayerContact(object player, object objB, Fixture fixtureA, Fixture fixtureB) { base.OnPlayerContact(player, objB, fixtureA, fixtureB); if (!roundOver && objB is Target) { PlayerFeet pf = (PlayerFeet)player; int scoredOnPlayer = pf.Parent.Index == 0 ? 1 : 0; V2DSprite head = ((HeadPlayer)pf.Parent).head; int pt = thrust[scoredOnPlayer]; Vector2 impulse = new Vector2(rnd.Next(-pt, pt), -pt); head.body.ApplyLinearImpulse(impulse, head.body.GetWorldCenter()); } }
public virtual DisplayObject SetFieldWithReflection(Texture2D texture, V2DInstance inst) { DisplayObject result = null; Type t = this.GetType(); string instName = inst.InstanceName; int index = -1; Match m = lastDigits.Match(instName); if (m.Groups.Count > 2 && t.GetField(instName) == null) { instName = m.Groups[1].Value; index = int.Parse(m.Groups[2].Value, System.Globalization.NumberStyles.None); } FieldInfo fi = t.GetField(instName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy); if (fi != null) { Type ft = fi.FieldType; if (ft.BaseType.Name == typeof(V2DRuntime.Components.Group <>).Name && // IsSubclassOf etc doesn't work on generics? ft.BaseType.Namespace == typeof(V2DRuntime.Components.Group <>).Namespace) { // eg ButtonTabGroup if (fi.GetValue(this) == null) { ConstructorInfo ci = ft.GetConstructor(new Type[] { typeof(Texture2D), typeof(V2DInstance) }); result = (DisplayObject)ci.Invoke(new object[] { texture, inst }); fi.SetValue(this, result); } } else if (ft.IsArray) { object array = fi.GetValue(this); Type elementType = ft.GetElementType(); if (array == null) { int arrayLength = GetArrayLength(instName); array = Array.CreateInstance(elementType, arrayLength); fi.SetValue(this, array); } // add element ConstructorInfo elementCtor = elementType.GetConstructor(new Type[] { typeof(Texture2D), typeof(V2DInstance) }); result = (DisplayObject)elementCtor.Invoke(new object[] { texture, inst }); MethodInfo mi = array.GetType().GetMethod("SetValue", new Type[] { elementType, index.GetType() }); mi.Invoke(array, new object[] { result, index }); } else if (typeof(System.Collections.ICollection).IsAssignableFrom(ft)) { Type[] genTypes = ft.GetGenericArguments(); if (genTypes.Length == 1) // only support single type generics (eg List<>) for now { Type gt = genTypes[0]; object collection = fi.GetValue(this); if (collection == null) // ensure list created { ConstructorInfo ci = ft.GetConstructor(new Type[] { }); collection = ci.Invoke(new object[] { }); fi.SetValue(this, collection); } // add element ConstructorInfo elementCtor = gt.GetConstructor(new Type[] { typeof(Texture2D), typeof(V2DInstance) }); result = (DisplayObject)elementCtor.Invoke(new object[] { texture, inst }); PropertyInfo cm = collection.GetType().GetProperty("Count"); int cnt = (int)cm.GetValue(collection, new object[] { }); // pad with nulls if needs to skip indexes (order is based on flash depth, not index) while (index > cnt) { MethodInfo mia = collection.GetType().GetMethod("Add"); mia.Invoke(collection, new object[] { null }); cnt = (int)cm.GetValue(collection, new object[] { }); } if (index < cnt) { MethodInfo mia = collection.GetType().GetMethod("RemoveAt"); mia.Invoke(collection, new object[] { index }); } MethodInfo mi = collection.GetType().GetMethod("Insert"); mi.Invoke(collection, new object[] { index, result }); } } //else if (ft.Equals(typeof(TextBox)) || ft.IsSubclassOf(typeof(TextBox))) //{ // ConstructorInfo ci = ft.GetConstructor(new Type[] { }); // result = (DisplayObject)ci.Invoke(new object[] { }); // fi.SetValue(this, result); //} else if (ft.Equals(typeof(DisplayObject)) || ft.IsSubclassOf(typeof(DisplayObject))) { ConstructorInfo ci = ft.GetConstructor(new Type[] { typeof(Texture2D), typeof(V2DInstance) }); result = (DisplayObject)ci.Invoke(new object[] { texture, inst }); fi.SetValue(this, result); } else { throw new ArgumentException("Not supported field type. " + ft.ToString() + " " + instName); } } if (result != null) { result.Index = index; // set for all object, -1 if not in collection result.RootName = instName; // apply attributes System.Attribute[] attrs = System.Attribute.GetCustomAttributes(fi); // reflection foreach (System.Attribute attr in attrs) { if (attr is SpriteAttribute) { SpriteAttribute a = (SpriteAttribute)attr; result.DepthGroup = a.depthGroup; } if (attr is V2DSpriteAttribute) { if (result is V2DSprite) { V2DSpriteAttribute a = (V2DSpriteAttribute)attr; V2DSprite sp = (V2DSprite)result; sp.attributeProperties = a; sp.SetGroupIndex(a.groupIndex); sp.IsStatic = a.isStatic; } } } // need to do this separately to ensure the depth group is set in previous step if (this is Screen) { Screen scr = (Screen)this; // field attirbutes foreach (System.Attribute attr in attrs) { if (attr is V2DShaderAttribute && !scr.shaderMap.ContainsKey(result.DepthGroup)) { V2DShaderAttribute vsa = (V2DShaderAttribute)attr; float[] parameters = new float[] { }; ConstructorInfo ci = vsa.shaderType.GetConstructor(new Type[] { parameters.GetType() }); scr.shaderMap.Add( result.DepthGroup, (V2DShader)ci.Invoke(new object[] { new float[] { vsa.param0, vsa.param1, vsa.param2, vsa.param3, vsa.param4 } }) ); } } } } return(result); }
public override void BeginContact(Contact contact) { collisionObjA = (V2DSprite)contact.GetFixtureA().GetBody().GetUserData(); collisionObjB = (V2DSprite)contact.GetFixtureB().GetBody().GetUserData(); SmuckPlayer p = null; V2DSprite nonPlayerObj = null; if (collisionObjA is SmuckPlayer) { p = (SmuckPlayer)collisionObjA; nonPlayerObj = collisionObjB; } else if (collisionObjB is SmuckPlayer) { p = (SmuckPlayer)collisionObjB; nonPlayerObj = collisionObjA; } if (p != null) { LaneVehicle v = nonPlayerObj is LaneVehicle ? (LaneVehicle)nonPlayerObj : null; if (v != null) { if (v.Lane.LaneKind == LaneKind.DrownWater && !collideWithBoats) { if (p.LivingState == LivingState.Alive) { p.aboardVehicle = v; } else { p.DestroyAfterUpdate(); // dont want drowning amin over boats } } else { Manifold m; contact.GetManifold(out m); Vector2 dir = m._localNormal * (p == collisionObjA ? 20 : -20) + v.body.GetLinearVelocity() * 10; if (Math.Abs(dir.Y) < 60) { dir.Y += rnd.Next(-400, 400); } p.isExploding = false; p.body.ApplyLinearImpulse(dir, p.body.GetPosition()); float torque = dir.Y > 0 ? 1 : -1; p.body.ApplyTorque(torque); p.body.SetAngularVelocity(rnd.Next(15) * torque); if (p.LivingState == LivingState.Alive) // first hit a whack { stage.audio.PlaySound(Sfx.whack); } stage.audio.PlaySound(Sfx.secondWhack); this.KillPlayer(p); } } else { if (nonPlayerObj.InstanceName.StartsWith("water")) { p.IsOnWater = true; if (p.aboardVehicle == null) { p.Lane = lanes[GetLaneFromY((int)nonPlayerObj.Y)]; p.LivingState = LivingState.Dying; stage.audio.PlaySound(Sfx.bigSplash); } } else if (p.LivingState == LivingState.Dying && nonPlayerObj.InstanceName.StartsWith("border")) { // no death icon when flying off left or right side of highway if (nonPlayerObj.Index == 0 || nonPlayerObj.Index == 2) { p.skipDeathMarker = true; } p.DestroyAfterUpdate(); } } } else if (collisionObjA is LaneVehicle && collisionObjB is LaneVehicle) { LaneVehicle vA = (LaneVehicle)collisionObjA; LaneVehicle vB = (LaneVehicle)collisionObjB; const float boost = 15; if (vA.Lane.movesRight && vB.Lane.movesRight) { if (vA.Position.X > vB.Position.X) { vA.MaxSpeed = vA.Lane.vehicleSpeed + boost; vB.MaxSpeed = vA.MaxSpeed - boost; } else { vB.MaxSpeed = vB.Lane.vehicleSpeed + boost; vA.MaxSpeed = vB.MaxSpeed - boost; } } else if (!vA.Lane.movesRight && !vB.Lane.movesRight) { if (vA.Position.X > vB.Position.X) { vB.MaxSpeed = vB.Lane.vehicleSpeed + boost; vA.MaxSpeed = vB.MaxSpeed - boost; } else { vA.MaxSpeed = vA.Lane.vehicleSpeed + boost; vB.MaxSpeed = vA.MaxSpeed - boost; } } } }