真上に投げて達する高さが120px強で計算どうりなのですが、時間が2倍近くかかっています。(1px=1mで換算)
計算の都合上、左下を原点とするためにyがちょっと複雑になってます。
あと添付は背景画像です。
(WinXpPro,Dxlib,BCC)
//以下ソース
/***************************************************************************
* *
* 真上に投げ上げたときY方向に49m/s(初速度) *
* 頂点に達するまでG=9.8m/s^2より5秒 *
* また、最高点は49*5-9.8*5*5/2よって122.5mのはず *
* *
***************************************************************************/
#include "DxLib.h"
#include<math.h>
#define SPEED 49.0
#define GRAVITY 9.8
#define BASE_X 0
#define BASE_Y 0
typedef struct{
BOOL bAppear;
double Xspeed,Yspeed;
double X,Y;
}BOAL_T;
void fps(){
int i;
static int t=0,ave=0,f[60];
static int count=0;
f[count%60]=GetNowCount()-t;
t=GetNowCount();
if(count%60==59){
ave=0;
for(i=0;i<60;i++)
ave+=f;
ave/=60;
}
if(ave!=0){
DrawFormatString(100,0,0,"%.1fFPS",1000.0/(double)ave);
}
count++;
return;
}
int WINAPI WinMain(HINSTANCE, HINSTANCE,LPSTR,int){
int x=120,y=120,hRed,hBgImg,StTime=0,EdTime=0;
BOAL_T Boal={FALSE,0,0,0,0};
double obliq; //斜辺
char Key[256];
if(ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK ||DxLib_Init() == -1 ) return -1;
SetDrawScreen( DX_SCREEN_BACK );
hRed=GetColor(255,0,0);
hBgImg=LoadGraph("Bg.png");
while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){
DrawGraph(0,0,hBgImg,FALSE);
fps();
if(Boal.bAppear){
Boal.X+=Boal.Xspeed/60; //60fpsの為
Boal.Y+=Boal.Yspeed/60; //同上
Boal.Yspeed-=GRAVITY/60; //同上
if(Boal.Y<0 || Boal.Y>480 || Boal.X>640 || Boal.X<0){ //投射終了時
EdTime=GetNowCount();
Boal.bAppear=FALSE;
}
}
if(GetMouseInput()&MOUSE_INPUT_LEFT && !Boal.bAppear){
if(!GetMousePoint(&x,&y)){
y=480-y;
Boal.bAppear=TRUE;
Boal.X=BASE_X;
Boal.Y=BASE_Y;
obliq=sqrt((x-BASE_X)*(x-BASE_X)+(y-BASE_Y)*(y-BASE_Y));
Boal.Xspeed=SPEED*(x-BASE_X)/obliq;
Boal.Yspeed=SPEED*(y-BASE_Y)/obliq;
StTime=GetNowCount();
}
}
if(StTime<EdTime)
DrawFormatString(500,0,0,"%05dms",EdTime-StTime); //斜方投射にかかった時間の表示
if(Boal.bAppear)
DrawCircle((int)Boal.X,(int)(480-Boal.Y),2,hRed,TRUE);
ScreenFlip();
}
DxLib_End();
return 0;
}