private void mapCollision() { Rectangle correctedBox = new Rectangle(spear.Location, spear.Size); correctedBox.X -= 27; Vector2[] verts = VectorMath.rectVerts(correctedBox, orientation); HashSet<int> xVals = new HashSet<int>(); HashSet<int> yVals = new HashSet<int>(); //gather values the spear might be passing through foreach(Vector2 vertex in verts) { xVals.Add((int)Math.Floor(vertex.X)); yVals.Add((int)Math.Floor(vertex.Y)); } //Using the dot product, find collidable rectangles and test. bool colliding = false; foreach(int x in xVals) { foreach(int y in yVals) { int squareData = m.blockInfo(new Vector2(x, y)); if(thrownBy == null && squareData >= 10) { Rectangle r = new Rectangle(x, y, 32, 32); if (VectorMath.rectCollision(correctedBox, orientation, r, 0)) { velocity.X = 0; velocity.Y = 0; atRest = true; throwing = false; Hit_Wall_Sound.Play(); colliding = true; break; if(bomb) { bombExplosion(); bomb = false; } } }//This is messy, I know. else if((squareData >= 10 && !thrownBy.blinked) || (squareData >= 10 && squareData < 20 && thrownBy.blinked)) { Rectangle r = new Rectangle(x, y, 32, 32); if (VectorMath.rectCollision(correctedBox, orientation, r, 0)) { velocity.X = 0; velocity.Y = 0; atRest = true; throwing = false; Hit_Wall_Sound.Play(); colliding = true; break; }
public void blockDataUpdate() { int[] blocks = new int[9]; int x, y; for (x = 0; x < 3; x++) { for (y = 0; y < 3; y++) { blocks[x * 3 + y] = arena.blockInfo(new Vector2(playerRect.X + x * (int)(playerRect.Width / 3) - 1, playerRect.Y + y * (int)(playerRect.Height / 3) - 1)); } } foreach (int block in blocks) { if (block == 5 && !dead) { setDead(true, null, "MAP"); } } }