|
一个物体在一定范围内左右移动着向下运动,也就是说物体的y坐标是递增的,x的坐标是一定范围内递增递减。
比如,先向左运动,然后再从左向右运动,然后再从右到左,如此反复
运动过程看上去要平滑,下面的公式只是突然产生向左向右的结果
enemys.x = (int)cos((double)enemys.y * 0.0174532925 ) * 100 + 400;
我是参考下面的程序写的
// Move them left (their speed+1)*0.5*dt units
enemies.xadd(-((float)espeed+1)*dt*0.5);
// If the sprites are colored blue then
if(einfo>0)
{
// Adjust their y coordinate. I wanted smooth motion so
// we make their y position equal the cosinus of
// their x coordiante+some random number that prevents
// everyone from following the same path
// Since we have to convert the degrees into radians, we
// multiply the value with 0.0174532925 (pi/180)
// The cosinus function returs a value from -1 to +1, so we
// multiply it with 100 to get some reasonable value
// We also add 230 to the end result to center everything
// on the screen
enemies.yset(
( cos((enemies.getx()+einfo)*0.0174532925) *100)+230);
他的效果是上下运动从左向右移动。
谁能提供一个左右运动从上到下移动的公式?我的数学基础差,又没课本在手,想了很久都没想出来,各位牛人帮帮忙? |
|