自機を敵に向けるプログラムについて
Posted: 2011年5月10日(火) 00:44
シューティングのようなものを製作途中なのですが
自機を敵に向けるプログラムで詰まりました。
さまざまなサイトをみて、いじくっていたら敵の方向は向くようになったのですが
「 '引数' : 'double' から 'int' への変換です。データが失われる可能性があります。」
というエラーがでるようになり解決方法がわからなくなりました。
VC++2008 DXライブラリを使用し、OSは7です。
素人故、汚い書き方で見苦しいと思いますが、なにとぞお願いします。
#include <math.h>
#include "DxLib.h"
#define PI 3.141592654
char Key[256];
struct uni{
int image[5];
double x,y;
double rad;
int HP;
};
struct enemys{
int image[5];
double x,y;
int HP;
};
struct zyoukyou {
int map;
};
void dainyuu(struct uni *mainuni,struct enemys *ene){
mainuni->x=300;
mainuni->y=600;
mainuni->image[0]=LoadGraph("usvmm1.png");
ene->image[0]=LoadGraph("ene1.png");
ene->image[1]=LoadGraph("ene2.png");
ene->x=300;
ene->y=100;
}
int attack(){
return 0;
}
void enemy(struct enemys *ene,struct uni *mainuni){
DrawRotaGraph(ene->x, ene->y,1.0,PI/180, ene->image[0], TRUE );//ここをエラーが指しています
}
void move(struct uni *mainuni,struct enemys *ene){
if((mainuni->x>-30)){
if( CheckHitKey( KEY_INPUT_A ) == 1 ){
mainuni->x=mainuni->x-3;
}
}
if((mainuni->y<570)){
if( CheckHitKey( KEY_INPUT_S ) == 1 ){
mainuni->y=mainuni->y+3;
}
}
if((mainuni->x<770)){
if( CheckHitKey( KEY_INPUT_D ) == 1 ){
mainuni->x=mainuni->x+3;
}
}
if((mainuni->y>-30)){
if( CheckHitKey( KEY_INPUT_W ) == 1 ){
mainuni->y=mainuni->y-3;
}
}
mainuni->rad=atan2(ene->y-mainuni->y,ene->x-mainuni->x);
DrawRotaGraph(mainuni->x, mainuni->y,1.0,mainuni->rad+PI/2, mainuni->image[0], TRUE ); //エラーはここを指しています
}
int map(int mapimg){
DrawGraph(0,0,mapimg,TRUE);
return 0;
}
int battle(){
int mapimg;
mapimg=LoadGraph("usmap1.png");
struct uni mainuni;
struct enemys ene;
dainyuu(&mainuni,&ene);
while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){
// attack();
map(mapimg);
move(&mainuni,&ene);
enemy(&ene,&mainuni);
ScreenFlip();
}
return 0;
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){
SetGraphMode( 800 , 600 , 32 ) ;
if( ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1 ) return -1; //初期化処理
SetDrawScreen( DX_SCREEN_BACK ); //裏画面に設定
while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){
//↑メッセージ処理 ↑画面をクリア ↑キーボード入力状態取得 ↑ESCが押されていない
//int story();
battle();
ScreenFlip();
}
DxLib_End();
return 0;
}
自機を敵に向けるプログラムで詰まりました。
さまざまなサイトをみて、いじくっていたら敵の方向は向くようになったのですが
「 '引数' : 'double' から 'int' への変換です。データが失われる可能性があります。」
というエラーがでるようになり解決方法がわからなくなりました。
VC++2008 DXライブラリを使用し、OSは7です。
素人故、汚い書き方で見苦しいと思いますが、なにとぞお願いします。
#include <math.h>
#include "DxLib.h"
#define PI 3.141592654
char Key[256];
struct uni{
int image[5];
double x,y;
double rad;
int HP;
};
struct enemys{
int image[5];
double x,y;
int HP;
};
struct zyoukyou {
int map;
};
void dainyuu(struct uni *mainuni,struct enemys *ene){
mainuni->x=300;
mainuni->y=600;
mainuni->image[0]=LoadGraph("usvmm1.png");
ene->image[0]=LoadGraph("ene1.png");
ene->image[1]=LoadGraph("ene2.png");
ene->x=300;
ene->y=100;
}
int attack(){
return 0;
}
void enemy(struct enemys *ene,struct uni *mainuni){
DrawRotaGraph(ene->x, ene->y,1.0,PI/180, ene->image[0], TRUE );//ここをエラーが指しています
}
void move(struct uni *mainuni,struct enemys *ene){
if((mainuni->x>-30)){
if( CheckHitKey( KEY_INPUT_A ) == 1 ){
mainuni->x=mainuni->x-3;
}
}
if((mainuni->y<570)){
if( CheckHitKey( KEY_INPUT_S ) == 1 ){
mainuni->y=mainuni->y+3;
}
}
if((mainuni->x<770)){
if( CheckHitKey( KEY_INPUT_D ) == 1 ){
mainuni->x=mainuni->x+3;
}
}
if((mainuni->y>-30)){
if( CheckHitKey( KEY_INPUT_W ) == 1 ){
mainuni->y=mainuni->y-3;
}
}
mainuni->rad=atan2(ene->y-mainuni->y,ene->x-mainuni->x);
DrawRotaGraph(mainuni->x, mainuni->y,1.0,mainuni->rad+PI/2, mainuni->image[0], TRUE ); //エラーはここを指しています
}
int map(int mapimg){
DrawGraph(0,0,mapimg,TRUE);
return 0;
}
int battle(){
int mapimg;
mapimg=LoadGraph("usmap1.png");
struct uni mainuni;
struct enemys ene;
dainyuu(&mainuni,&ene);
while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){
// attack();
map(mapimg);
move(&mainuni,&ene);
enemy(&ene,&mainuni);
ScreenFlip();
}
return 0;
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){
SetGraphMode( 800 , 600 , 32 ) ;
if( ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1 ) return -1; //初期化処理
SetDrawScreen( DX_SCREEN_BACK ); //裏画面に設定
while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){
//↑メッセージ処理 ↑画面をクリア ↑キーボード入力状態取得 ↑ESCが押されていない
//int story();
battle();
ScreenFlip();
}
DxLib_End();
return 0;
}