const double UnitSpeed = 1.0;void ThrustShip(int speed){ int NewAngle; //used for calculating percentages bool XNeg, YNeg; double xdir, ydir; XNeg = YNeg = false; //find out what quad the angle is in if (angle >= 90 && angle < 180) { XNeg = true; NewAngle = 90 - angle; } else if (angle >= 180 && angle < 270) { XNeg = true; YNeg = true; NewAngle = angle - 180; } else if (angle >= 270 && angle < 360) { YNeg = true; NewAngle = 360 - angle; } //calculate the precentages angle will always be in favour of the x direction. xdir = UnitSpeed * (NewAngle / 90); ydir = UnitSpeed * (1 - NewAngle / 90); //check to see if we are negating if (XNeg) xdir = -xdir; if (YNeg) ydir = -ydir; ShipPosX += xdir * speed; ShipPosY += ydir * speed;}
I believe this is correct off the top of my head. Try it out to see if it works and let me know. It also saves you from making calls to sin and cos which can be expensive if called enough times. If you want to have the motion constant then you need to have the unit speed like I want it to move one unit when I thrust then multiply that by the speed. If someone sees a mistake with my logic please point it out.
Thanks,
Richard