Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kiznore

need help with moving ship

This topic is 5182 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi ya. I m pretty new to programming and i need help with my asteriods game. Im having trouble with moving my ship in a straight line in the direction the ship is facing and i would like to know how to do some sort of acceration. I can move it in the different directions but its not always in a stright line and the speed of the ship varies. Below are the functions for move and rotating the ship. Any help at all would be brill thanks.Please try and keep it simple int cShip::TurnShipLeft() { if(ShipAngle == 0) { ShipAngle = ShipAngle + 360; } //Change Ship angle to reflect the turn ShipAngle -= 10; //the amount of degrees we have turned return 10; } int cShip::TurnShipRight() { //Change Ship angle to reflect the turn ShipAngle += 10; //the amount of degrees we have turned return 10; } void cShip::DrawShip() { int iX, iY; int ClipX = 0; int ClipY = 0; switch(ShipAngle) { case 0: case 10: case 20: case 30: case 40: case 50: case 60: case 70: case 80: case 360: if(ShipAngle == 360) ShipAngle = 0; ClipX = ((ShipAngle)/10) * 80; ClipY = 0; break; case 90: case 100: case 110: case 120: case 130: case 140: case 150: case 160: case 170: ClipX = ((ShipAngle-90)/10) * 80; ClipY = 80; break; case 180: case 190: case 200: case 210: case 220: case 230: case 240: case 250: case 260: ClipX = ((ShipAngle-180)/10) * 80; ClipY = 160; break; case 270: case 280: case 290: case 300: case 310: case 320: case 330: case 340: case 350: ClipX = ((ShipAngle-270)/10) * 80; ClipY = 240; break; } m_ship.Draw(GetMainApp()->m_pBackBuffer,XPos,XPos,ClipX,ClipY,80,80); } void cShip::MoveShip() { //Dont have them all dont. There must be a far more efficent way switch(ShipAngle) { case 10: case 20: case 30: YPos = YPos - 5; XPos = XPos + (ShipAngle/10); break; case 40: case 50: YPos = YPos - 4; XPos = XPos + (ShipAngle/10); break; case 60: case 70: case 80: YPos = YPos - 3; XPos = XPos + (ShipAngle/10); break; case 90: XPos = XPos + 5; break; case 100: YPos = YPos + ((ShipAngle/10)/10); //YPos = YPos + 1; XPos = XPos + 5; break; case 110: YPos = YPos + 1; XPos = XPos + 5; break; case 120: YPos = YPos + 2; XPos = XPos + 5; break; case 130: YPos = YPos + 3; XPos = XPos + 6; break; case 140: YPos = YPos + 4; XPos = XPos + 6; break; case 180: YPos = YPos + 5; break; case 270: XPos = XPos - 5; break; case 280: YPos = YPos - 3; XPos = XPos - 8; break; case 290: YPos = YPos - 3; XPos = XPos - 7; break; case 300: YPos = YPos - 3; XPos = XPos - 6; break; case 310: YPos = YPos - 4; XPos = XPos - 5; break; case 320: YPos = YPos - 4; XPos = XPos - 4; break; case 330: YPos = YPos - 5; XPos = XPos - 3; break; case 340: YPos = YPos - 5; XPos = XPos - 2; break; case 350: YPos = YPos - 5; XPos = XPos - 1; break; case 0: case 360: YPos = YPos - 5; break; } }

Share this post


Link to post
Share on other sites
Advertisement
I would say that the problem is that you need to handle the acceleration and rotation algorithmically rather than using all those switch cases. Try sine and cosine.

Here's an example of a 2D rotation. That should help you understand what I'm talking about.

[edited by - tiffany_smith on April 13, 2004 10:29:49 PM]

Share this post


Link to post
Share on other sites

This topic is 5182 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!