Oh right, did know that constants like that even had a type but i guess it makes sence, thanks alot for explaining it. and yeah, i used a bullet point i forgot to put it in my example though, sorry.
Oh right, did know that constants like that even had a type but i guess it makes sence, thanks alot for explaining it. and yeah, i used a bullet point i forgot to put it in my example though, sorry.
woo i think ive figured it out:
bullet.Y += (int)(bulletSpeed*Math.Sin(bulletRotation));
bullet.X += (int)(bulletSpeed*Math.Cos(bulletRotation));
it works perfectly,my problem with casts was that i was confusing them with something else, when i made my floats for rotation whenever i added/subtraced from them i had to put and f at the end of the number eg:
float bob=1;
bob+=1f;
why did i have to do that anyway? it woudl be nice to know :D
thanks alot everyone! all i need to do now is add some asteriods and its all done.
EDIT: what the hell it didnt mess up my spacing this time >.<
for some reason all my spacing was deleted and now i cant edit my post >.> how come it didn't do that to my first post but it did to my second?
Thanks allot for the help, and do not worry i think i understand the code that you typed, well heres how i think it works:
bullet.Y += bulletSpeed * sin(bulletRotation);//finds the y-side of the triangle with hypotenuse of length 'bulletRotation'
bullet.X += bulletSpeed * cos(bulletRotation);//same but for the x-side.
is that right? if not tell me but i think that looks about right. i knew there would be a way of doing it i just couldn't think of it.
also, when i try to type it into my compiler i get a few errors, the first was to do with the sin and cos, but changing it to Math.sin/Math.cos solved that the rest is to do with converting from float to int, i know that to add a number to a float i need to put in a cast e.g.:
float floaty=o;
....
floaty+=1f;
...
or something like that.
my problem is that bulletRotation needs to be a float to be passed into the part of the program that draws the bullet but bullet.Y wont let me add a float to it. so i am just asking is there way of converting bulletSpeed * cos(bulletRotation); to a int?
[ Mod note: formatting added. Have a nice day. ]
This year i took up computing at A level and have been learning how to code in C# so im quite new to it.
what im trying to do now is make asteriods, i have a ship that turns at 45 degrees when you press left or right and shoots in the direction its facing. the problem with this is that i would like to make it rotate in smaller steps like the original but this would be impossible with my current way of determining which way the shot is fired.
heres a little snippet.
....
if ((bulletRotation > (5.496)) || (bulletRotation < 0.785))//find the direction it is facing
{
bullet.Y -= bulletSpeed;//set the speed accordingly
}
if ((bulletRotation > 4.711) && (bulletRotation < 5.496))
{
bullet.Y -= bulletSpeed;
bullet.X -= bulletSpeed;
}
if ((bulletRotation > 3.926 + 0.785 / 2) && (bulletRotation < 4.711))
{
bullet.X -= bulletSpeed;
} ...
im sure theres an easyer way of doing it but i cant think of any, so realy what im asking for is a way to determine what direction the shot should go depending on the direction the ship is facing.
thanks for the help in advance.