以下のコードは150フレームごとに画面中央から毎フレーム1ドットのスピードで進む弾を撃ちだします。
最初は上方向ですが左右キーで次弾を撃ちだす角度を変更できます。
//-- 以下、テストコード --//
#include "DxLib.h"
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
ChangeWindowMode( TRUE );
if ( DxLib_Init( ) == -1 ) return -1;
SetDrawScreen( DX_SCREEN_BACK );
int StrColor = GetColor( 255, 255, 255 );
float x = 0.0f, y = 0.0f, start_x = 640 / 2.0f, start_y = 480 / 2.0f, angle = 0; // angleは度数
VECTOR move = { 0.0f, 0.0f, 0.0f }, speed = { 0.0f, -1.0f, 0.0f };
int frame = 0;
while ( ProcessMessage( ) == 0 && CheckHitKey( KEY_INPUT_ESCAPE ) == 0 ) {
if ( CheckHitKey( KEY_INPUT_LEFT ) ) angle -= 0.5;
if ( CheckHitKey( KEY_INPUT_RIGHT ) ) angle += 0.5;
if ( !(frame++ % 150) ) {
move = VTransform( speed, MGetRotZ( (TWO_PHI_F / 360) * angle/*度数からラジアンに変換*/ ) );
x = start_x; y = start_y;
}
x += move.x; y += move.y;
ClearDrawScreen( );
DrawFormatString( 0, 0, StrColor, "TEST angle = %f度", angle );
DrawPixel( (int)x, (int)y, StrColor );
ScreenFlip( );
}
DxLib_End( );
return 0;
}
私はMGetRotZで楽をしていますが、座標の回転については以下のURLをご覧下さい。
> ttp://homepage2.nifty.com/natupaji/DxLib/dxprogram.html#N28