private void InitializeCollision() { var decorCollision = Map.Collisions.FirstOrDefault(item => item.Name == "Decor"); if (decorCollision != null) { foreach (var poly in decorCollision.Polygons) { GroundCollision.Polygons.Add(poly); } if (GroundCollision.SortAxis == FlatRedBall.Math.Axis.X) { GroundCollision.Polygons.SortXInsertionAscending(); } else { GroundCollision.Polygons.SortYInsertionAscending(); } } GroundCollision.MergeRectangles(); // We need to do custom logic before/after so we disable it and do manual collisions: ShipListVsGroundCollision.IsActive = false; }
private void ReactToBulletHit(Bullet bullet) { var hitGround = GroundCollision.CollideAgainst(bullet); var shotMissEffect = ShotMissEffectFactory.CreateNew(); shotMissEffect.IsGroundHit = hitGround; shotMissEffect.TriggerEffect(bullet.X, bullet.Y, bullet.RotationZ); bullet.HitSurface(hitGround ? SurfaceType.Ground : SurfaceType.Water); }
public Game1() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 768; graphics.PreferredBackBufferHeight = 576; Content.RootDirectory = "Content"; // The InputHandler class is not part of XNA but has been written by Simon Schofield to help // parse user input. The class casn be found in the Solution Explorer input = new InputHandler(); Knight = new Character(input); groundCollision = new GroundCollision(Knight, myLevel); coin = new CoinCollection(Knight); enemy = new Enemy(Knight); }
// Update is called once per frame void Update() { if (updateBodys) { rigidbodys = this.GetComponentsInChildren <Rigidbody2D> (); updateBodys = false; } if (brokenParts.Count > 0) { for (int i = brokenParts.Count - 1; i >= 0; i--) { for (int j = i - 1; j >= 0; j--) { bool b = CutByPiece(brokenParts[i], brokenParts[j]); if (b) { brokenParts.RemoveAt(i); brokenParts.RemoveAt(j); } } } for (int i = brokenParts.Count - 1; i >= 0; i--) { DestroyByPiece(brokenParts[i]); } } if (alive) { laststate = state; state = GamePad.GetState(Gamepad); GroundCollision gc = rigidbodys [1].transform.GetComponent <GroundCollision> (); if (gc) { onGround = gc.Ground; } if (state.IsConnected) { for (int i = 0; i < rigidbodys.Length; i++) { Rigidbody2D rb = rigidbodys [i]; if (rb) { if (i == 1) { Vector2 f = new Vector2(state.ThumbSticks.Left.X * ForceMultiplier.x, state.ThumbSticks.Left.Y * ForceMultiplier.y); if (!onGround && f.y > 0) { f.y = 0; } rb.AddForce(f); } if (i == topControlIndex) { Vector2 f = new Vector2(state.ThumbSticks.Right.X * ForceMultiplier.x, state.ThumbSticks.Right.Y * ForceMultiplier.y); if (!onGround && f.y > 0) { f.y = 0; } rb.AddForce(f); } if (rb.velocity.x > MaxSpeed) { rb.velocity = new Vector2(MaxSpeed, rb.velocity.y); } if (rb.velocity.x < -MaxSpeed) { rb.velocity = new Vector2(-MaxSpeed, rb.velocity.y); } } } } } }