public void WalkRight() { Direction = 1; Box.X += (int)vx; if (Globals.Map.Collide(this).Any()) { Box.X = (Box.X / Globals.TileWidth) * Globals.TileWidth + (Globals.TileWidth - Box.Width); } Box.X = Globals.WrappedX(Box.X); }
public void WalkLeft() { Direction = -1; Box.X -= (int)vx; if (Globals.Map.Collide(this).Any()) { Box.X = ((Globals.WrappedX(Box.X) / Globals.TileWidth) + 1) * Globals.TileWidth; } Box.X = Globals.WrappedX(Box.X); }
public List <Tile> Collide(Sprite sprite) { int top = Globals.WrappedY(sprite.Box.Top) / Globals.TileHeight; int bottom = Globals.WrappedY(sprite.Box.Bottom - 1) / Globals.TileHeight; int left = Globals.WrappedX(sprite.Box.Left) / Globals.TileWidth; int right = Globals.WrappedX(sprite.Box.Right - 1) / Globals.TileWidth; List <Tile> tilesToCheck = new List <Tile>(); for (int i = left; i != (right + 1) % Width; i = (i + 1) % Width) { for (int j = top; j != (bottom + 1) % Height; j = (j + 1) % Height) { if (Tiles[i, j] != null && Tiles[i, j].Solid) { tilesToCheck.Add(Tiles[i, j]); } } } return(tilesToCheck); }
protected void handleXCollision() { if (Math.Abs(vx) > 2) { SoundEffectInstance b = bounceSound.CreateInstance(); b.Volume = Math.Abs(vx) / (maxV / 2); b.Play(); } if (vx > 0) { Box.X = (Box.X / Globals.TileWidth) * Globals.TileWidth + (Globals.TileWidth - Box.Width); } else { Box.X = ((Globals.WrappedX(Box.X) / Globals.TileWidth) + 1) * Globals.TileWidth; } Box.X = Globals.WrappedX(Box.X); vx = -vx * restitution; vy = vy * friction; //vy = vy * restitution; }
protected void moveX() { Box.X = Globals.WrappedX(Box.X + (int)vx); }