public virtual void Update() { // update my position _position = SwinGame.AddVectors(_position, _velocity); _velocity = SwinGame.AddVectors(_velocity, SwinGame.VectorTo(0, 0.05f)); // update hitbox Point2D hitboxposition = new Point2D(); hitboxposition.X = _position.X + MyBitmap().Width / 2; hitboxposition.Y = _position.Y + MyBitmap().Height / 2; _hitBox = SwinGame.BitmapCircle(MyBitmap(), hitboxposition); }
private SwinGameSDK.Vector GetPathVector(SwinGameSDK.Point2D playerPos, Tile[,] tileSet, Point2D destination, bool selected) { SwinGameSDK.Vector pathVector = new SwinGameSDK.Vector(); if (_inControl) { ///////////////////////ALLOWS CONTROL OF PLAYERS//////////////////////////////// if (SwinGame.KeyDown(KeyCode.vk_RIGHT) && selected) { pathVector = SwinGame.AddVectors(pathVector, SwinGame.CreateVectorFromAngle(0, 8)); } if (SwinGame.KeyDown(KeyCode.vk_DOWN) && selected) { pathVector = SwinGame.AddVectors(pathVector, SwinGame.CreateVectorFromAngle(90, 8)); } if (SwinGame.KeyDown(KeyCode.vk_LEFT) && selected) { pathVector = SwinGame.AddVectors(pathVector, SwinGame.CreateVectorFromAngle(180, 8)); } if (SwinGame.KeyDown(KeyCode.vk_UP) && selected) { pathVector = SwinGame.AddVectors(pathVector, SwinGame.CreateVectorFromAngle(-90, 8)); } ///////////////////////ALLOWS CONTROL OF PLAYERS//////////////////////////////// } else { if (_toUpdate) { _forces = AStarPathfinder.CalculateForces(playerPos, tileSet, destination); _toUpdate = false; pathVector = CurrentForce(playerPos, tileSet); } else { pathVector = CurrentForce(playerPos, tileSet); } } if (pathVector.Magnitude > 3) { pathVector = SwinGame.LimitVector(pathVector, 3); } return(pathVector); }
public SwinGameSDK.Vector GetMovementVector(SwinGameSDK.Point2D playerPos, Tile[,] tileSet, SwinGameSDK.Vector currentMoveVector, Point2D destination, bool selected) { if (currentMoveVector.Magnitude > 8) { currentMoveVector = SwinGame.LimitVector(currentMoveVector, 8); } if (!_velocity) { currentMoveVector = new SwinGameSDK.Vector(); } currentMoveVector = SwinGame.AddVectors(currentMoveVector, GetPathVector(playerPos, tileSet, destination, selected)); currentMoveVector = SwinGame.AddVectors(currentMoveVector, GetDistractionVector(playerPos, tileSet, currentMoveVector)); if (SwinGame.PointPointDistance(playerPos, destination) < 120) { if (SwinGame.PointPointDistance(playerPos, destination) < 60) { if (currentMoveVector.Magnitude < 2) { return(SwinGame.VectorFromAngle(currentMoveVector.Angle, 0)); } else { return(SwinGame.LimitVector(currentMoveVector, (float)(currentMoveVector.Magnitude * 0.7))); //////////////////////////FIIIIIIIIIIIIIIIIX /// } } // FIX FIX FIX FIX FIX return(SwinGame.LimitVector(currentMoveVector, (float)(currentMoveVector.Magnitude * 0.9))); } return(currentMoveVector); }
private SwinGameSDK.Vector GetDistractionVector(SwinGameSDK.Point2D playerPos, Tile[,] tileSet, SwinGameSDK.Vector currentMoveVector) { SwinGameSDK.Vector distractionVector = new SwinGameSDK.Vector(); SwinGameSDK.Point2D max = new Point2D(); SwinGameSDK.Point2D min = new Point2D(); if (currentMoveVector.Angle <= 0) { min.Y = playerPos.Y + (currentMoveVector.Y * 7); max.Y = playerPos.Y; } else { max.Y = playerPos.Y - (currentMoveVector.Y * 7); min.Y = playerPos.Y; } if (currentMoveVector.Angle < 90 && currentMoveVector.Angle > -90) { max.X = playerPos.X + (currentMoveVector.X * 7); min.X = playerPos.X; } else { min.X = playerPos.X - (currentMoveVector.X * 7); max.X = playerPos.X; } float normalX = SwinGame.VectorNormal(currentMoveVector).X *(12); float normalY = SwinGame.VectorNormal(currentMoveVector).Y *(12); int iMax = (int)(Math.Ceiling(max.X / 60) + 1); int iMin = (int)(Math.Floor(min.X / 60) - 1); int jMax = (int)(Math.Ceiling(max.Y / 60) + 1); int jMin = (int)(Math.Floor(min.Y / 60) - 1); if (iMax > Game.x_width - 1) { iMax = Game.x_width - 1; } if (iMin < 0) { iMin = 0; } if (jMax > Game.y_height - 1) { jMax = Game.y_height - 1; } if (jMin < 0) { jMin = 0; } //loops through each square in the min/max of the rect fov. for (int i = iMin; i < iMax; i++) { for (int j = jMin; j < jMax; j++) { if (tileSet[i, j].GetTileType() == TileType.WALL) { // I'm so sorry. It's so ugly. if ( SwinGame.LineIntersectsRect(SwinGame.LineFrom(playerPos.X + normalX, playerPos.Y + normalY, playerPos.X + (currentMoveVector.X * 7) + normalX, playerPos.Y + (currentMoveVector.Y * 7) + normalY), tileSet[i, j].GetHitBox()) || SwinGame.LineIntersectsRect(SwinGame.LineFrom(playerPos.X - normalX, playerPos.Y - normalY, playerPos.X + (currentMoveVector.X * 7) - normalX, playerPos.Y + (currentMoveVector.Y * 7) - normalY), tileSet[i, j].GetHitBox()) ) { SwinGameSDK.Vector thisDistraction = new SwinGameSDK.Vector(); float distance = SwinGame.PointPointDistance(playerPos, tileSet[i, j].GetPos()); if (distance < 0) { distance = 0; } thisDistraction = SwinGame.VectorFromAngle(SwinGame.CalculateAngleBetween(playerPos, tileSet[i, j].GetPos()), distance); distractionVector = SwinGame.AddVectors(distractionVector, SwinGame.InvertVector(thisDistraction)); } } } } if (distractionVector.Magnitude > 3) { distractionVector = SwinGame.LimitVector(distractionVector, 3); } return(distractionVector); }