protected override void OnCollision(GameSession gameSession, ColliderInfo collidedInfo, ColliderInfo colliderInfo, Vector2 collisionPosition, bool amCollided) { if (amCollided) { //Knockback float angleOfCollision = (float)Math.Atan2(colliderInfo.colliderPosition.Y - rigidBody.CollisionPolygon.CenterPoint.Y, colliderInfo.colliderPosition.X - rigidBody.CollisionPolygon.CenterPoint.X); Vector2 velocityVector = new Vector2(-(float)Math.Cos(angleOfCollision), -(float)Math.Sin(angleOfCollision) - .5F); rigidBody.AddTranslationalVelocity(velocityVector); if (colliderInfo.colliderPosition.X < rigidBody.CollisionPolygon.CenterPoint.X) { SpriteManager.FacingState = SpriteManager.FacingStates.Left; } else { SpriteManager.FacingState = SpriteManager.FacingStates.Right; } //Damage //rigidBody.Mass = (CurrentHealth / 200) + .5F; //Spawn blood playerParticleManager.SpawnBlood(gameSession.gameMap); //Spawn damage indicator playerParticleManager.SpawnDamageNotifier(-colliderInfo.CollisionDamage, gameSession.gameMap); } else { RectangleF boundaryRectangle = rigidBody.CollisionPolygon.BoundaryRectangle; PlayerParticleManager PPM = new PlayerParticleManager(PlayerTexturePack, new RotationRectangle(new RectangleF(collidedInfo.colliderPosition.X - (boundaryRectangle.Width / 2), collidedInfo.colliderPosition.Y - (boundaryRectangle.Height / 2), boundaryRectangle.Width, boundaryRectangle.Height)), drawDimensions); PPM.SpawnBlood(gameMap); PPM.SpawnDamageNotifier(colliderInfo.CollisionDamage, gameMap); } }
protected override void Update(GameTime gameTime, KeyboardState keyboardState, KeyboardState pastKeyboardState, MouseState mouseState, MouseState pastMouseState, GameMap map) { //Apply gravity float frameTimePortion = (float)gameTime.ElapsedGameTime.TotalMilliseconds / RigidBody.TARGET_FRAME_TIME; rigidBody.AddTranslationalVelocity(new Vector2(0, MapStandards.GRAVITY_ACCELERATION * frameTimePortion), isGlobal: false); rigidBody.Update(gameTime); //Check expiration if (gameTime.TotalGameTime.TotalMilliseconds - timeOfCreation >= lifetime || (strictBounds && !rigidBody.ReferenceMap.InBounds(rigidBody.CollisionPolygon.BoundaryRectangle))) { Dispose(map); } }
private void Form1_Load(object sender, EventArgs e) { wheel1 = new RigidBody(new RegularPolygon(new Vector2((Width - 100) / 2, Height / 2 - 50), 15, 8), DefinedMaterials.Rubber, 1); wheel2 = new RigidBody(new RegularPolygon(new Vector2((Width + 100) / 2, Height / 2 - 50), 15, 8), DefinedMaterials.Rubber, 1); RigidBody bridge = new RigidBody(new RotationRectangle(new ImpulseEngine2.RectangleF((Width - 100) / 2, Height / 2 - 100, 100, 50)), DefinedMaterials.Rubber, 1); bridge.AddTranslationalVelocity(new Vector2(0, .1F), isMomentum: false); //bridge.AddAngularVelocity(.1F, isMomentum: false); //wheel2.AddTranslationalVelocity(new Vector2(0, 3), isMomentum: false); //RigidBody tankBody = new RigidBody(new RotationRectangle(new ImpulseEngine2.RectangleF((Width - 100) / 2, Height / 2 - 200, 100, 150)), DefinedMaterials.Wood, 1); ElasticJoint elasticJoint1 = new ElasticJoint(.5F, bridge, new Vector2((Width - 100) / 2, Height / 2 - 50), wheel1, new Vector2((Width - 100) / 2, Height / 2 - 50)); ElasticJoint elasticJoint2 = new ElasticJoint(.5F, bridge, new Vector2((Width + 100) / 2, Height / 2 - 50), wheel2, new Vector2((Width + 100) / 2, Height / 2 - 50)); //ElasticJoint elasticJoint3 = new ElasticJoint(.5F, bridge, new Vector2((Width - 100) / 2, Height / 2 - 50), tankBody, new Vector2((Width - 100) / 2, Height / 2 - 50)); RigidBody bound = new RigidBody(new RotationRectangle(new ImpulseEngine2.RectangleF(0, Height * (2F / 3), Width, Height / 3)), DefinedMaterials.Static); handler.AddMetaElement(new GravityMeta()); handler.AddMetaElement(elasticJoint1); handler.AddMetaElement(elasticJoint2); handler.AddBody(wheel1); handler.AddBody(wheel2); handler.AddBody(bridge); handler.AddBody(bound); //RigidBody body1 = new RigidBody(new RotationRectangle(new ImpulseEngine2.RectangleF(0, 0, 200, 100)), DefinedMaterials.Wood); //RigidBody body2 = new RigidBody(new RotationRectangle(new ImpulseEngine2.RectangleF(0, 200, 200, 100)), DefinedMaterials.Wood); //body1.AddTranslationalVelocity(new Vector2(.1F, 0), isMomentum: false); //handler.AddBody(body1); //handler.AddBody(body2); //ElasticJoint joint = new ElasticJoint(.5F, body1, body1.CollisionPolygon.CenterPoint, body2, body2.CollisionPolygon.CenterPoint); //handler.AddMetaElement(joint); }