トップページ > 過去ログ > 記事閲覧
ゲームの計算について。
名前:sousi 日時: 2008/06/23 12:31

前のスレに書くのでは長くなると思ったので新しいスレを作らせていただきました。 前のスレアドレスはhttp://hpcgi2.nifty.com/natupaji/bbs/patio.cgi?mode=view&no=894です. C言語なんでも掲示板のhttp://l.huu.cc/board/にも同じ内容を投稿させていただいています。 DXトップのミニテクニック、ゲーム製作は、ある程度読ませていただきました。自分で少し勉強して、 多少前進しましたが、座標計算のところでつまずいたので質問させてください。 今、やりたいのはゴールまでの座標を計算して1、マス進ませることです。 ですが、画像分割、描画の計算が悪いのか上方向に進むのに右方向を向いている。1マスでなく進み続ける。 進み続け、y座標がゴールと同じになると画像が止まり、微妙にぶれる。 ソースは以下の通りです。 #include "DxLib.h" typedef struct{ int x,y,img,walking_flag; }ch_t; typedef struct{ int x,y,img,san,san_flag; }waku; typedef struct{ int x,y,goal_img; }goal_t; int hantei[15][20] = { {15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 },//1 {15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,15 },//2 {15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,15 },//3 {15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,15 },//4 {15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0,15 },//5 {15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0,15 },//6 {15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0,15 },//7 {15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0,15 },//8 {15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0,15 },//9 {15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0,15 },//10 {15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0,15 },//11 {15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0,15 },//12 {15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0,15 },//13 {15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0,15 },//14 {15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 },//15 }; int can_or_cannot(int x,int y,int muki){//進めるかを判定する switch(muki){ case 0:/* 上 */ if((hantei[y/32][x/32]&1)!=0){ return 1; } else{ return 0; } break; case 1:/* 下 */ if((hantei[y/32][x/32]&2)!=0){ return 1; } else{ return 0; } break; case 2:/* 左 */ if((hantei[y/32][x/32]&4)!=0){ return 1; } else{ return 0; } break; case 3:/* 右 */ if((hantei[y/32][x/32]&8)!=0){ return 1; } else{ return 0; } break; } } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){ goal_t goal; //ゴール int goal_img; ch_t ch; //キャラクター int image[16]; int imag[2][2];//枠 waku waku[2]; int gamen;//バック画面 int a; //入れ替え時の変数 int k_x,k_y; //キャラクターの座標計算変数 char Key[256]; if( ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1 ) return -1; //ウィンドウ化と初期化処理 goal.x=32; goal.y=64; goal_img=LoadGraph ("goal.png"); ch.x =320; ch.y =320; ch.walking_flag=0; waku[0].x=0; waku[0].y=0; waku[0].san=4; waku[0].san_flag=0; waku[1].x=0; waku[1].y=0; waku[1].san=4; waku[1].san_flag=0; int kaeru=0; int kaeru_flag; int keisan_flag; gamen=LoadGraph( "000.bmp" ) ; SetDrawScreen( DX_SCREEN_BACK ) ; //描画先を裏画面に設定 LoadDivGraph( "char.png" , 16 , 4 , 4 , 32 , 32 , image ) ;//画像を分割してimage配列に保存 LoadDivGraph( "abcd.png" , 2 , 2 , 1 , 32 , 32 , imag[0] ) ;//画像を分割してimage配列に保存 LoadDivGraph( "abcd.png" , 2 , 2 , 1 , 32 , 32 , imag[1] ) ;//画像を分割してimage配列に保存 while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){ //↑メッセージ処理 ↑画面をクリア ↑キーボード入力状態取得 ↑ESCが押されると終了 if(waku[kaeru].x%32==0 && waku[kaeru].y%32==0){ //座標がで割り切れたら入力可能\par waku[kaeru].san_flag=1; //歩くフラグを立てる。 if ( Key[ KEY_INPUT_UP]==1 ) //上ボタンが押されたら waku[kaeru].san=0; //上向きフラグを立てる else if( Key[ KEY_INPUT_LEFT ]==1 ) //左ボタンが押されたら waku[kaeru].san=1; //左向きフラグを立てる else if( Key[ KEY_INPUT_DOWN ]==1 ) //下ボタンが押されたら waku[kaeru].san=2; //下向きフラグを立てる else if( Key[ KEY_INPUT_RIGHT]==1 ) //右ボタンが押されたら waku[kaeru].san=3; //右向きフラグを立てる else if(Key[ KEY_INPUT_A]==1){ kaeru_flag=1; waku[kaeru].san_flag=0; } else if(Key[ KEY_INPUT_S]==1){ kaeru_flag=2; waku[kaeru].san_flag=0; } else if(Key[ KEY_INPUT_D]==1){ keisan_flag=1; waku[kaeru].san_flag=0; } else //何のボタンも押されてなかったら waku[kaeru].san_flag=0; //歩かないフラグを立てる } if(waku[kaeru].san_flag==1){ //歩くフラグが立っていたら if(waku[kaeru].san==0) //上向きならch.y座標を減らす waku[kaeru].y--; else if(waku[kaeru].san==1) //左向きならch.x座標を減らす waku[kaeru].x--; else if(waku[kaeru].san==2) //下向きならch.y座標を増やす waku[kaeru].y++; else if(waku[kaeru].san==3) //右向きならch.x座標を増やす waku[kaeru].x++; } if(kaeru_flag==1){ if(kaeru==0) kaeru=1; else keisan_flag=0; } if(kaeru_flag==2){ if(kaeru==1) kaeru=0; } if( keisan_flag==1 ){ k_x = goal.x-ch.x; k_y = goal.y-ch.y; if(k_x >= k_y){ if(k_x > 0) {ch.x++;} else {ch.x--;} } else {if(k_y > 0) {ch.y++;} else {ch.y--;} } } waku[0].img=imag[0][(waku[0].x%32+waku[0].y%32)/32 + waku[0].san*0]; //画像をセット waku[1].img=imag[1][(waku[1].x%32+waku[1].y%32)/32 + waku[1].san*0]; //画像をセット ch.img=image[(ch.x%32+ch.y%32)/8 +0]; DrawGraph(0,0,gamen,FALSE); DrawGraph(32,64,goal_img,TRUE); DrawGraph( waku[0].x , waku[0].y , waku[0].img , TRUE ) ;//画像を描画 DrawGraph( waku[1].x , waku[1].y , waku[1].img , TRUE ) ;//画像を描画 DrawGraph( ch.x , ch.y , ch.img , TRUE ) ;//画像を描画 kaeru_flag=0; ScreenFlip(); } DxLib_End(); return 0; }

Page: 1 |

Re: ゲームの計算について。 ( No.1 )
名前:Mist 日時:2008/06/23 09:47

マルチです。 http://l.huu.cc/board/ 「ループと関数について」 こちらの掲示板はマルチ禁止ではないですが、マナーとして情報の共有化ぐらい図りましょう。

Page: 1 |