Hello, i need some help in a small game i am doing.
it involves ships moving in angles.
i have some problems , and if someone is available i will be more than happy if he contacts me in my icq : 38901147
thank you.
email : [email protected]
Printable View
Hello, i need some help in a small game i am doing.
it involves ships moving in angles.
i have some problems , and if someone is available i will be more than happy if he contacts me in my icq : 38901147
thank you.
email : [email protected]
well for angles:
you have an angle your ship is going to move at let's say it 50 degree.
now you need to know how far it moves on the x and the y axis so you go like
xmovement = velocity * cos(angle)
ymovement = velocity * sin(angle)
now since VB uses radians you need to convert the angle first before typing this in as vbcode
To convert take the angle times Pi and devide it by 180.
First of all thanks for replying.
this i already know
i need to know more about rotating the image itself to point 20 degs , for example that the y-axis ?
i mean , if i press left and right the ship rotates in few degs
i have the rotating fucn. but i dont understand it , and thus i have difficulties adjusting it to my own needs.
there is a good example on how to rotate a bitmap by angles on www.ur.co.nz
but you could also use d3d to do it (it's even faster and easier)
hmm , in d3d , without math , just functions ?
hm well depending on how you do it a little bit of math to turn the polygon on which you draw your ship I guess, or the camera.
Here is a little exe in vb that i wrote , it concludes anything i know about rotating .
few problems :
1. holes in the rotated picture , i know there is another way to rotate so there wont be holes.
2. speed are problamatic.
3. when i give him x=x+veloicty*cos(angle) , its not excat , i want it to move in good angle . not sort of angle .
The File
you probably put an integer value for the position since in the end it will be represented by an integer value (pixels) anyways, but that compromises any accuracy if you take many little steps so just use floats.
Sorry , but i didnt quite understood u.
i use something like this x=100+fix(veiolicty*cos(angle))
and for y as well with sin.
and for the rotation i use
x=point.x*cos(angle)-point.y*sin(angle)
destx=100+fix(x)
y=point.x*sin(angle)+point.y*cos(angle)
desty=100+fix(y)
this does not seem to make a lot of sense to me:
x=100+fix(veiolicty*cos(angle))
I think it should be like
x=x+fix(velocity *cos(angle)) 'angle in radian
that so it can move further not just be on one fixed place
than I don't know why you do the fix, it will make it inaccurate go like:
dim x as double
x=x+velocity*cos(angle)
this will be way more accurate.
First of all
i do x=x+fix(veiolicty*cos(angle)
not +100
i dont know why i wrote +100 , but about the fix , i must use it , how can i write a pixel at 581.34278427 ?
it should be a fix number , or am i mistaken ?
the pixel yeah but not the position
you need to keep the exact position because you keep on calculating with it it get very inaccurate if you round it.
so fix it to draw but not the position itself
get it?
if not tell me I will explain better after getting some sleep it is 4:20 in the morning and I am drunk....
oh , ofcourse , i didnt see i do fix in the calculate instead of the setpixel function
yeah,
well , just one more question , i wanted to check Frame Rate
so i did every 18.2 ticks (with gettickcount) a counter that shows how many time the main loop was running
and i got 3 , how could this be ? , its very smooth and cant be just 3 frames ?
i did some precalc like sin and cos tables and any math , and i just have 2 bitblt and 2 mul functions
?
I never did an precalc on sin and cos does it speed things up a lot?
well you check it all 18 ticks?
1000 ticks is one second, so just put some kind of sub into you loop going like this
VB Code:
function fps() as string static framesPS static lasttic as long static count as long count = count if lassttick < GetTickCout then lasttick = GetTickCount +1000 framesPS = count count = 0 endif fps = str(framesPS) end function
(you can do it much better than that here but that should work and give you fps that don't change around all the time but only once a second.... (and than they will be more consistent too))
well here some little recent discussion about Frames per second measurement...
you can go for Zaeis version too, or use the code I gave in the other thread, it does not use statics, but it is in the loop so it's kind of the same thing. (one var less though because I made it a function and not just write to a global var this time)
Frames Per Second
Thats ok , thanks .
i thought one second is 18.2
but if its 1000 its about 120fps
now for my last question , if u dont mind , and its about tcp/ip connection.
i want that the remote computer will update data in real time
i mean , if the remote computer moved , i want the local computer to know without lag , which means i need to transmirt X,Y of the sprite about 30-40 times a second , is it possible ?
yeah it should be possible over network (internet also) but you will never be safe from lagging... you should ask in a new thread to get more qualified answers! (I really know crap about networking.)