public Bullet(ContentManager theContent, floatRectangle r, Vector2 v, PlayerIndex player, int team) { m_player = player; m_rect = r; m_vel = v; m_team = team; m_vec = new Vector2(); m_sprite = theContent.Load<Texture2D>("bullet"); }
public Vector2 Collide(ICollidable obj, out bool hit) { hit = false; floatRectangle objInitRect = obj.GetBoundingBox(); Vector2 objVel = obj.GetVelocityVector(); floatRectangle objRect = new floatRectangle(objInitRect.X + objVel.X, objInitRect.Y + objVel.Y, objInitRect.Width, objInitRect.Height); if (objRect.Top() > m_tileHeight * m_height || objRect.Bottom() < 0 || objRect.Left() > m_tileWidth * m_width || objRect.Right() < 0) return objVel; Rectangle tileRect = new Rectangle(); tileRect.X = (int)objRect.X / m_tileWidth; tileRect.Y = (int)objRect.Y / m_tileHeight; tileRect.Width = (int)objRect.Width / m_tileWidth; tileRect.Height = (int)objRect.Height / m_tileHeight; floatRectangle objRectX = new floatRectangle(objInitRect.X + objVel.X, objInitRect.Y + 1, objInitRect.Width, objInitRect.Height - 1); floatRectangle objRectY = new floatRectangle(objInitRect.X + 1, objInitRect.Y + objVel.Y, objInitRect.Width - 1, objInitRect.Height); if (tileRect.X < 0) tileRect.X = 0; if (tileRect.Y < 0) tileRect.Y = 0; if (tileRect.Right >= m_width) tileRect.Width = m_width - tileRect.X - 1; if (tileRect.Bottom >= m_height) tileRect.Height = m_height - tileRect.Y - 1; for (int j = tileRect.Top; j <= tileRect.Bottom; ++j) { for (int i = tileRect.Left; i <= tileRect.Right; ++i) { if (m_tiles[m_map[i, j]].m_type == Tile.TileType.NONE || m_tiles[m_map[i, j]].m_type == Tile.TileType.LADDER) continue; floatRectangle currRect = new floatRectangle(i * m_tileWidth, j * m_tileHeight, m_tileWidth, m_tileHeight); if (objVel.X > 0) { if (objRectX.Right() > currRect.Left() && objRectX.Top() < currRect.Bottom() && objRectX.Bottom() > currRect.Top()) { hit = true; objVel.X = currRect.Left() - objInitRect.Right(); if (objVel.X < 0) objVel.X = 0; } } else { if (objRectX.Left() < currRect.Right() && objRectX.Top() < currRect.Bottom() && objRectX.Bottom() > currRect.Top()) { hit = true; objVel.X = currRect.Right() - objInitRect.Left(); if (objVel.X > 0) objVel.X = 0; } } if (objVel.Y > 0) { if (objRectY.Bottom() > currRect.Top() && objRectY.Left() < currRect.Right() && objRectY.Right() > currRect.Left()) { hit = true; objVel.Y = currRect.Top() - objInitRect.Bottom(); if (objVel.Y < 0) objVel.Y = 0; } } //else //{ // hit = true; // if (objRectY.Top() < currRect.Bottom() // && objRectY.Left() < currRect.Right() && objRectY.Right() > currRect.Left()) // { // objVel.Y = currRect.Bottom() - objInitRect.Top(); // if (objVel.Y > 0) // objVel.Y = 0; // } //} } } return objVel; }
public bool WillCollide(ICollidable other) { floatRectangle theirs = other.GetBoundingBox(); Vector2 vel = other.GetVelocityVector(); floatRectangle mine = new floatRectangle(m_rect.X + m_vec.X, m_rect.Y + m_vec.X, m_rect.Width, m_rect.Height); theirs.X += vel.X; theirs.Y += vel.Y; if (mine.Right() > theirs.Left() && mine.Left() < theirs.Right() && mine.Bottom() > theirs.Top() && mine.Top() < theirs.Bottom()) { return true; } return false; }
public SimpleCollidable(floatRectangle rect, Vector2 vec) { m_rect = rect; m_vec = vec; }
public void LoadContent(ContentManager theContent, string assetName, int squareSize, int pnum, PlayerIndex index) { m_content = theContent; m_sprite.LoadContent(theContent, assetName, squareSize); m_texture = theContent.Load<Texture2D>(assetName); m_rect = new floatRectangle(); m_rect.X = 0; m_rect.Y = 0; m_rect.Width = 16; m_rect.Height = 64; m_xspeed = 240.0f; m_yspeed = 120.0f; m_index = index; m_pos = m_origin[pnum]; switch (m_index) { case PlayerIndex.One: m_sprite.m_color = new Color(176, 59, 205); break; case PlayerIndex.Two: m_sprite.m_color = new Color(180, 180, 180); break; case PlayerIndex.Three: m_sprite.m_color = new Color(247, 213, 23); break; case PlayerIndex.Four: m_sprite.m_color = new Color(238, 16, 16); break; } if(m_team == 0) GamePad.SetVibration(m_index, 0.0f, 0.25f); }