Quote:Original post by Reegan
Im not sure what you mean by "skewed" so i cant really help with the main problem. However, i do have a few suggestions to clean up your code a little if you dont mind me sharing them with you.
You have made a PI a local variable to a single function, this is generally a global constant, maybe you would like to change it to that?
instead of ...( double *currDX, ... ) perhaps you could make it a referance instead, it looks like your only using the value of what currDX points to and dont actually need the address of what it points to ( then you wont have to keep typing an asterisk each time you want to set the value of whatever currDX/DY points to )
Why are you using fixed angles for your ship? can you not rotate a single image by the current direction? this would reduce code and the amount of assets needed, if you still want a fixed set of angles ( 0, 10, 20, 40, 50,.. n ) i think there is a way to make such a restriction using the modulus operator.
In calcDX( ... ) if you have a restricted angle then you should only need to write:
currDX = (cos(_currAngle*PI/180))*SHIP_SPEED;
currDY = (sin(_currAngle*PI/180))*SHIP_SPEED;
once, eliminating the need for if statements and repetition.
Is SHIP_SPEED a global constant? if so, shouldnt it be a part of the Ship class? and also, why not make it non-constant so you can implement acceleration for the ship which is more natural.
Well, theres a few suggestions there for you. You dont have to take onboard what ive said, but its there if you feel like it.
~Reegan :)
Thanks for the response!
By skewed I mean that with a low SHIP_SPEED, certain angle values seem to behave strangely. For example with a ship speed of 2, when the ship is facing at a 90 degree angle and I move it, it move up and to the right rather than straight up, whereas when I use a ship speed of 10, it moves straight up.
I should indeed make PI a global constant - consider it done.
I wrote my calcDXDY function like that because it allows me to retrieve those values from different objects. For example (I think) in the future should I be writing a different ship's AI and how it behaves is based on my own ship's current trajectory, it can retrieve my current trajectory by doing:
int playerdx, playerdy;
_playerShip->calcDXDY(&playerdx, &playerdy)
---then playerdx and playerdy will contain my ship's dx dy.
Similarly I am currently moving via a main game loop not in the Ship object, and I retrieve my ship's dx and dy that way. I realize my code might not be as optimized as it could be at the moment but I'm just trying to get some of these basics down at the moment.
As far as why I am using fixed angles for my ship, I'm not entirely sure what you mean by "rotating a single image by the current direction." I don't necessarily want to use fixed angles, but I'm not sure how to go about simply rotating an image. I simply pre-generated a number of ship images at rotations of 10 degrees.
Regarding the if statements in calcDX, you are right. I'm not sure why I was having issues before and put them in - but taking them out works fine.
I also plan to implement things like acceleration, different rates of ship rotation, etc. but again I'm just trying to get the basics down for now.
Thanks again for the response.