• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:C++を使ったゲーム制作で困っています)

C++でゲーム制作で困っています

nondaku0の回答

  • ベストアンサー
  • nondaku0
  • ベストアンサー率66% (10/15)
回答No.1

//白玉を描く gsDraw2D( sWhite, 100, 100 ); ↑の所が間違っていますね。 これだと白玉は常に100,100の位置に表示されてしまいます。 gsDraw2D( sWhite, wx, wy); ↑に修正すると白玉が動くようになります。

zeruden0905
質問者

お礼

自分の足りなさに少し驚いています。とても簡単なミスでした。これからも回答お願いします。

関連するQ&A

  • vc++2008で画像処理

    こんばんは、最近画像処理に手を出したものの双六が作れる程度の自分なので案の定上手くいきません。 やりたいことはVisual c ++ 2008、esplibとewclibを使って画像をキャプチャ、画像のbitデータの大きさで処理を決めるというシンプルなもののハズが画像の大きさを取得できなくて困ってます。 何回やっても画像保存バッファが表示されるため?比較ができません。 どなたか画像データの大きさで処理をできるようなプログラムをご教授ください。 opencvはあんまり考えていないのですが、opencvでできそうならそちらの方法でも教えてくださいますと大変助かります。 二つのhのヘルプを見てもどうも保存形式が良くわからないとです。int型らしいのですが比較できません。 vc++2008自体に画像データが入っている変数の大きさを測れるようなものがあるなら遠回りはしなくても良いのですが・・・。 カメラは安価なlogicool c270です。 #include <esplib.h> #include <ewclib.h> #include<stdio.h> #define WX 640 #define WY 480 void ESP_Ready(void) { ESP_CreateImage(0,"Camera",0,0,WX,WY,100); ESP_OpenTextWindow(0,86,512,439,135); ESP_Printf("Startをクリックしてください.\n"); } void ESP_Main(void) { ESP_Printf("初期化中...\n"); int r= EWC_Open(0,WX,WY,30.); int set,sset,key; key=0; if(r){ ESP_Printf("Error %d\n",r); return; } for(;;){ if(ESP_STOP) break; if(EWC_IsCaptured(0)){ EWC_GetImage(0,ESP_VramPtr[0]); EWC_GetImage(0,&set); ESP_Update_(0); ESP_Printf("*"); key=key+1; } } EWC_Close(0); ESP_Printf("Stopped\n"); if(key>10){ EWC_GetImage(0,&sset); if(sset<set){//判断部分} else{//逆なら}   ESP_Printf("%d""%d",&set,&sset);//大きさ表示 } } void ESP_Finish(void) { }

  • プログラミングで質問です。言語はC++です。

    いま、 While文でループし、Enterキーを おすとループから抜けます。 そこで、上矢印キー↑を押すと マウスカーソルがそれに応じて動くようなプログラムを while文でループさせたいのですが やり方がわかりません。 途中まで書いてみたのですが動きません。 詳しく教えていただけると嬉しいです。 #include <stdio.h> #include <windows.h> #include <Windows.h> int main( void ) { printf("roop in\n"); POINT po; while(1){ po.x=0; po.y=0; if( GetAsyncKeyState(VK_RETURN)) break; if(GetAsyncKeyState(VK_UP)&0x8000 <0) po.x+=7; Sleep(500); } printf("roop out\n"); return 0; }

  • C言語 ゲーム

    今回が質問初めてです。見にくかったらすいません。下のプログラムですが、これに構造体を使わなくてはいけないのですが、まったくわかりません。みなさんはどう書き換えますか? #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> int KEY(int *Kn,int *Y,int *X); int main(void) { //数値格納 int kn; //入力キー int sty,stx; //座標 int fy,fx; //マップ範囲 int jm[25][40]; //移動可不判定 char mapc[3]={0};//複写されたマップ構成情報 //カウント int y,x; //判定生成、座標生成・描写用 //マップチップ char mc[2][3]={ /*mc[0] 移動可能*/" ", /*mc[1] 移動不可*/"■"}; //マップ構成 (最大値 25行x40列) char map[][81]={ /*00*/"■■■■■■■■■■", /*01*/"■ ■      ■", /*02*/"■ ■■■■ ■ ■", /*03*/"■ ■■   ■ ■", /*04*/"■  ■ ■■■ ■", /*05*/"■■ ■ ■   ■", /*06*/"■  ■ ■ ■■■", /*07*/"■ ■■ ■   ■", /*08*/"■    ■ ■ ■", /*09*/"■■■■■■■■■■"}; //マップ範囲算出 fy=sizeof(map)/81; //行 fx=strlen(map[0])/2; //列 //キャラクター初期座標指定 sty=8,stx=8; /* 判定生成 */ for(y=0;y<fy;y++){ for(x=0;x<fx;x++){ strncpy(mapc ,&map[y][(x)*2] ,2 ); if(strncmp(mc[1],mapc,2)==0){jm[y][x]=1;} //移動不可判定 else if(strncmp(mc[0],mapc,2)==0){jm[y][x]=0;} //移動可能判定 } } /* 画面出力 */ while(1){ system("cls"); //画面消去 /* 座標生成、描写 */ for(y=0;y<fy;y++){ for(x=0;x<fx;x++){ strncpy(mapc ,&map[y][(x)*2] ,2); if(jm[y][x]==0){ if(y==sty&&x==stx) {printf("%s","○");} //キャラ表示 else if(strncmp(mc[0],mapc,2)==0) {printf("%s",mapc );} //移動可能表示 } else if (strncmp(mc[1],mapc,2)==0) {printf("%s",mapc );} //移動不可表示 } if(fx<40){printf("\n");} //fxが40未満の場合、改行 } if(sty==1&&stx==1){ printf("ゴールしました\n"); } /* 入力キー、移動座標出力 */ KEY(&kn,&sty,&stx); /* 壁、マップ外への侵入防止 */ for(y=0;y<sty+1;y++){ for(x=0;x<fx;x++){ if((y==sty&&x==stx&&jm[y][x]==1)||(fy<=sty||fx<=stx)){ if(kn==0x4b){stx++;} else if(kn==0x4d){stx--;} else if(kn==0x48){sty++;} else if(kn==0x50){sty--;} break; } } } /* 終了操作 */ if(kn==0x1b){printf("▼終了します。\n") ;break;} } } /* 入力キー、移動座標出力 */ int KEY(int *Kn,int *Y,int *X){ while(1){ *Kn=getch( ); //1:通常キー if (*Kn==0){ *Kn=getch( ); //2:特殊キー if (*Kn==0x4b){(*X)--;}// ← else if (*Kn==0x4d){(*X)++;}// → else if (*Kn==0x48){(*Y)--;}// ↑ else if (*Kn==0x50){(*Y)++;}// ↓ else if (*Kn==0x80){ }//特殊キー追加場所 else {continue;} break; } else if (*Kn==0x1b){}// Esc //else if (*Kn== ){} 通常キー追加場所 else {continue;} break; } return 0; }

  • 動的に変数だけを切り替える

    <script> (function($) { $.ipop001 = function() { var wx, wy; // ウインドウの左上座標 // ウインドウの座標を画面中央にする。 wx = $(document).scrollLeft() + ($(window).width() - $('.ipop').outerWidth()) / 2; if (wx < 0) wx = 0; wy = $(document).scrollTop() + ($(window).height() - $('.ipop').outerHeight()) / 2; if (wy < 0) wy = 0; // ポップアップウインドウを表示する。 $('.ipop').css({top: wy, left: wx}).fadeIn(100); // 閉じるボタンを押したとき $('.ipop_close').click(function() {$('.ipop').fadeOut(100);}); // タイトルバーをドラッグしたとき $('.ipop_title').mousedown(function(e) { var mx = e.pageX; var my = e.pageY; $(document).on('mousemove.ipop', function(e) { wx += e.pageX - mx; wy += e.pageY - my; $('.ipop').css({top: wy, left: wx}); mx = e.pageX; my = e.pageY; return false; }).one('mouseup', function(e) { $(document).off('mousemove.ipop'); }); return false; }); } })(jQuery); (function($) { $.test = function() { var wx, wy; // ウインドウの左上座標 // ウインドウの座標を画面中央にする。 wx = $(document).scrollLeft() + ($(window).width() - $('.ipop').outerWidth()) / 2; if (wx < 0) wx = 0; wy = $(document).scrollTop() + ($(window).height() - $('.ipop').outerHeight()) / 2; if (wy < 0) wy = 0; // ポップアップウインドウを表示する。 $('.ipop').css({top: wy, left: wx}).fadeIn(100); // 閉じるボタンを押したとき $('.ipop_close').click(function() {$('.ipop').fadeOut(100);}); // タイトルバーをドラッグしたとき $('.ipop_title').mousedown(function(e) { var mx = e.pageX; var my = e.pageY; $(document).on('mousemove.ipop', function(e) { wx += e.pageX - mx; wy += e.pageY - my; $('.ipop').css({top: wy, left: wx}); mx = e.pageX; my = e.pageY; return false; }).one('mouseup', function(e) { $(document).off('mousemove.ipop'); }); return false; }); } })(jQuery); $(function() { $("a").click(function() { eval("$."+this.id+"();"); var text = this.id; $("#text").text(text); }); }); </script> 『$.ipop001 = function() { も『$.test = function() {』以降の中身一緒なのですが、クリックした時に変数の部分だけを切り替える方法はないのでしょうか。 仮にリンクが100個あったら変数が違う&中身が一緒のfunction()を100個文書かなければいけないのでご教示お願いします。

  • C言語で画面がおかしくなる

    最近C言語でプログラムを書き始めました。 二次関数を作るスクリプトなんですが、一定時間がたつと画面がおかしくなります。 どこが問題なのか探しても見つからないので、わかる方教えてください。 WinMainの部分は省いてます #include<windows.h> #include<stdio.h> #include <stdlib.h> #include<time.h> #define TIMER_ID 1 #define spy(num) (wy-num) int rnd(int r); void bset(HDC hdc, int x, int y); LRESULT CALLBACK WndProc(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp) { HDC hDC; static int DesktopX ,DesktopY; static HDC hdc; static HDC Mhdc; static HBITMAP BMPhdc; PAINTSTRUCT paint; RECT Rect; LOGPEN lopnPen; POINT CursorP, ScreenP; char str[250]; int i; static int wx, wy ,ky; static double a ,b ,c ,x ,y ,n ,m ,s ,t; switch (msg) { case WM_DESTROY: DeleteObject( BMPhdc ); DeleteDC( Mhdc ); PostQuitMessage(0); return 0; case WM_CREATE: SetTimer(hwnd, TIMER_ID, 10, NULL); hDC = GetDC(hwnd); hdc = CreateCompatibleDC( hDC ); GetClientRect(GetDesktopWindow() ,&Rect); DesktopX = Rect.right ;DesktopY = Rect.bottom; BMPhdc = CreateCompatibleBitmap( hDC, DesktopX, DesktopY ); SelectObject( hdc, BMPhdc ); ReleaseDC( hwnd, hDC ); GetClientRect(hwnd, &Rect); wx = Rect.right ;wy = Rect.bottom; x = rnd(wx); y = rnd(wy); n = rnd(wx); m = rnd(wy); return 0; case WM_TIMER: ScreenP.x = LOWORD(lp); ScreenP.y = HIWORD(lp); GetClientRect(hwnd, &Rect); wx = Rect.right ;wy = Rect.bottom; if( ky == 1 ){ x = rnd(wx); y = rnd(wy); n = rnd(wx); m = rnd(wy); } ClientToScreen(hwnd ,&ScreenP); GetCursorPos(&CursorP); s = CursorP.x-ScreenP.x; t = wy-(CursorP.y-ScreenP.y); InvalidateRect(hwnd, NULL, FALSE); return 0; case WM_RBUTTONDOWN: ky = 1; return 0; case WM_RBUTTONUP: ky = 0; return 0; case WM_PAINT: Mhdc = BeginPaint(hwnd, &paint); SelectObject(hdc , CreateSolidBrush(RGB(255,255,255))); lopnPen.lopnStyle = PS_NULL; SelectObject(hdc , CreatePenIndirect(&lopnPen)); Rectangle(hdc , 0 , 0 , wx+1 , wy+1); SelectObject(hdc , CreateSolidBrush(RGB(255,0,0))); if ((s-n) != 0 && (n-x) != 0 && (s-x) != 0){ a = ((t-m)/(s-n) - (m-y)/(n-x)) / (s-x); b = (m-y)/(n-x) - a*(n+x); c = y - a*x*x -b*x; } bset(hdc, x,spy(y)); bset(hdc, n,spy(m)); bset(hdc, s,spy(t)); lopnPen.lopnStyle = PS_SOLID; lopnPen.lopnColor = RGB(0,0,255); SelectObject(hdc , CreatePenIndirect(&lopnPen)); MoveToEx(hdc , -1 , spy( a + b - c) , NULL); for(i = 0 ; i <= wx ;i++){ LineTo(hdc , i , spy( a*i*i - b*i - c)); } BitBlt(Mhdc, 0, 0, DesktopX, DesktopY, hdc, 0, 0, SRCCOPY ); EndPaint(hwnd, &paint); return 0; } return DefWindowProc(hwnd , msg , wp , lp); } int rnd(int r){ static int flag; if (flag == 0) { srand((unsigned int)time(NULL)); flag = 1; } return (int)(rand()*(r+1.0)/(1.0+RAND_MAX)); } void bset(HDC hdc, int x, int y){ static LOGPEN lopnPen; lopnPen.lopnStyle = PS_NULL; SelectObject(hdc , CreatePenIndirect(&lopnPen)); Rectangle(hdc , x-3 , y-3 , x+3 , y+3); return; }

  • WEBカメラの動画制御を動的配列で、、

    先日「WEBカメラの画像を一定時間溜め込んで、    任意のタイミングで出力するプログラムのメモリ領域の    確保」に関して質問した者です。2次元配列を当初グローバルに宣言したところ、速度が遅くなってしまったため、動的に宣言したところ目標の速度を達成しました。 しかし停止時に例外が出てしまい、何度もプログラムを繰り返しているとどんどん速度が遅くなってしまいます。 原因を探っておりますがわかりません。 プログラムの変更箇所(動的配列の宣言部)を載せました。 これ以外のところは遅くとも正常に動作していた時と同様です。 例外の具体的な内容を明日にでもアップします。 情報不十分かもしれませんが、明らかな不具合等ありましたら、 お教えいただけますでしょうか? -ーーーーーーーーーーーーーーーーーーーーーーーー #define FRAMES 200 #define WX 640 #define WY 480 //int array[FRAMES][WX*WY]; グローバル宣言時のもの void Main(void) { int **array; array = new int*[FRAMES]; for(int i=0;i<FRAMES+1;i++){ array[i] = new int[WX*WY]; } //array[FRAMES][WX*WY]溜め込んで、     //任意のタイミングでディスプレイに出力します。 if(STOP) goto fin; } fin: for(int i=0;i<FRAMES+1;i++){ delete[] latesc[i]; } delete[] latesc; }

  • 動画の遅延再生プログラム

    PCとPCカメラを使って、 10秒前後の遅延再生する簡易プログラムを 作りたいと思っております。 WEBカメラのドライバのフリーソフト EWCLIBを利用して、下記ソースまで 作ったのですが、高スペックなPCにも かかわらず、フレームレートが ばらつきます。 フレームレートは30にしており、 妥協して15にしても同様の 問題がおこるので、おそらくWindowsかカメラの 自動制御が悪さをしていると思われます。 当方試行錯誤したのですが、ついに行き詰りました。 ソースの改良、ハードの取替え、動作環境の 変更等対策がありましたらご教授願います。 ちなみに高価なものであれば、すでに同機能以上の ものが世の中にあるのは把握しておりますので、 なるべくなら、安価に仕上げれるものが 望ましいです。 #include <esplib.h> #include <ewclib.h> #pragma comment(lib, "winmm.lib") #include <crtdbg.h> #define FRAMES 60 #define WX 320 #define WY 240 float a=0,b=0,c=0; void ESP_Ready(void) { ESP_CreateImage(0,"000",0,0,WX,WY,400); ESP_OpenTextWindow(0,86,512,439,135); ESP_Printf("初期化中...\n"); int r= EWC_Open(WX,WY,15); if(r){ ESP_Printf("Error %d\n",r); return; } ESP_Printf("Startをクリックしてください.\n"); } void ESP_Main(void) { int w=0; int **latesc; latesc = new int*[FRAMES]; for(int i=0;i<FRAMES;i++){ latesc[i] = new int[WX*WY]; } for(;;){ a=timeGetTime(); CopyMemory(ESP_VramPtr[0],latesc[w],WX*WY*4); // フレームバッファを指定 ESP_Select(0); ESP_Update(); // 新しいフレームが来るまで待つ for(;;){ Sleep(1); if(EWC_IsCaptured(0)) break; } // フレーム番号 r の表示 c=timeGetTime(); b = c - a; ESP_Locate(0,5); ESP_Printf("ewc_time[0]= %f [s]\n",b); ESP_Locate(0,3); ESP_Printf("w=%03d\n",w); EWC_SetBuffer(0,latesc[w]); w=(w+1)%(FRAMES-1); //wには最後に書き込まれたフレームを指定する if(ESP_STOP) break; } for(int i=0;i<FRAMES;i++){ delete[] latesc[i]; } delete[] latesc; ESP_Printf("Stop\n"); } void ESP_Finish(void) { EWC_Close(); }

  • C++のプログラムが走りません。

    <<条件は以下です。>> データメンバ x:xの座標(ただし 0-1000とする) y:yの座標(ただし 0-1000とする) z:zの座標(ただし 0-1000とする) メンバ関数 void setX(int a): xの座標を設計する(範囲外の値は、error messageを出力する) void setY(int b): Yの座標を設計する(範囲外の値は、error messageを出力する) void setZ(int c) Zの座標を設計する(範囲外の値は、error messageを出力する) int getX(): Xの座標値を得る int getY(): Yの座標値を得る int getZ(): Zの座標値を得る << 不明な点は、 if文で、どう戻るかがわからないことと、 最後の結果表示の部分です。 以下が、作成したプログラムです。ネットで検索して類似しているプログラムを参考にしたんですが。 よろしくお願いします。>> #include <iostream> using namespace std; class Zahyou{ private: int getX();//Xの座標値を得る int getY();//Yの座標値を得る int getZ();//Zの座標値を得る int a,b,c; public: void setX(int a);//Xの座標を設計する void setY(int b);//Yの座標を設計する void setZ(int c);//Zの座標を設計する void show(); }; void Zahyou::show(){ cout << "The result is: (" << a << "," << b << "," << c << ")"; } void Zahyou::setX(int a){ cout << " Please Input X " << "\n "; cin >> a ; if(a < 0 && a > 1000){ cout << "The value of X is a mistake, Please input X again! " << " \n "; } } void Zahyou::setY(int b){ cout << "Please Input Y " << "\n "; cin >> b ; if(b < 0 && b > 1000){ cout << "The value of y is a mistake, Please input X again! " << " \n "; cin >> b ; } } void Zahyou::setZ(int c){ cout << " Please Input Z " << "\n "; cin >> c ; if(c < 0 && c > 1000){ cout << "The value of Z is a mistake, Please input X again! " << " \n "; cin >> c ; } } int main(){ Zahyou zahyou1; zahyou1.getX(); zahyou1.getY(); zahyou1.getZ(); zahyou1.show(); return 0; }

  • キーリピート?(Javaプログラミング)

    こんにちは。 Javaの基礎を一通り勉強したので、簡単なゲームでも作ってみようと思ったのですが、早速問題にぶつかってしまいました。 キーを入力して左右にキャラを移動させたいのですが、 キーを押し続けると最初の1歩はすぐに移動してくれるのですが、 そのあとワンテンポ遅れてから、「ズダダダダダ」ってな感じ?で動いてしまいます。 調べてみたら、キーリピートというのが問題になっていることは分かったのですが、 どうすれば普通のゲームのように動いてくれるのでしょうか? 今はまだ下のような感じなんですが・・・。(右に動くとき) public void keyPressed(KeyEvent e) {   if(e.getKeyCode() == e.VK_RIGHT){     muki = 1; // キャラの向き     px += 10; // キャラのx座標   } } よろしくお願いします。

    • ベストアンサー
    • Java
  • C言語 ゲーム

    このプログラムに関数を一つ増やしたいのですが、うまくできません。どこを、どうすればいいでしょう? 迷路の内容は未完成です。 #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> int KEY(int *Kn,int *Y,int *X); int main(void) { //数値格納 int kn; //入力キー int sty,stx; //座標 int fy,fx; //マップ範囲 int jm[25][40]; //移動可不判定 char mapc[3]={0};//複写されたマップ構成情報 //カウント int y,x; //判定生成、座標生成・描写用 //マップチップ char mc[2][3]={ /*mc[0] 移動可能*/" ", /*mc[1] 移動不可*/"■"}; //マップ構成 (最大値 25行x40列) char map[][81]={ /*00*/"■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■", /*01*/"■ ■                                    ■", /*02*/"■ ■■■■ ■                               ■", /*03*/"■ ■■   ■                               ■", /*04*/"■  ■ ■■■                               ■", /*05*/"■■ ■ ■                                 ■", /*06*/"■  ■ ■                                 ■", /*07*/"■ ■■ ■                                 ■", /*08*/"■    ■ ■                               ■", /*09*/"■                                      ■", /*10*/"■                                      ■", /*11*/"■                                      ■", /*12*/"■                                      ■", /*13*/"■                                      ■", /*14*/"■                                      ■", /*15*/"■                                      ■", /*16*/"■                                      ■", /*17*/"■                                      ■", /*18*/"■                                      ■", /*19*/"■                                      ■", /*20*/"■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■"}; //マップ範囲算出 fy=sizeof(map)/81; //行 fx=strlen(map[0])/2; //列 //キャラクター初期座標指定 sty=8,stx=8; /* 判定生成 */ for(y=0;y<fy;y++){ for(x=0;x<fx;x++){ strncpy(mapc ,&map[y][(x)*2] ,2 ); if(strncmp(mc[1],mapc,2)==0){jm[y][x]=1;} //移動不可判定 else if(strncmp(mc[0],mapc,2)==0){jm[y][x]=0;} //移動可能判定 } } /* 画面出力 */ while(1){ system("cls"); //画面消去 /* 座標生成、描写 */ for(y=0;y<fy;y++){ for(x=0;x<fx;x++){ strncpy(mapc ,&map[y][(x)*2] ,2); if(jm[y][x]==0){ if(y==sty&&x==stx) {printf("%s","○");} //キャラ表示 else if(strncmp(mc[0],mapc,2)==0) {printf("%s",mapc );} //移動可能表示 } else if (strncmp(mc[1],mapc,2)==0) {printf("%s",mapc );} //移動不可表示 } if(fx<40){printf("\n");} //fxが40未満の場合、改行 } if(sty==1&&stx==1){ printf("ゴールしました\n"); } /* 入力キー、移動座標出力 */ KEY(&kn,&sty,&stx); /* 壁、マップ外への侵入防止 */ for(y=0;y<sty+1;y++){ for(x=0;x<fx;x++){ if((y==sty&&x==stx&&jm[y][x]==1)||(fy<=sty||fx<=stx)){ if(kn==0x4b){stx++;} else if(kn==0x4d){stx--;} else if(kn==0x48){sty++;} else if(kn==0x50){sty--;} break; } } } /* 終了操作 */ if(kn==0x1b){printf("▼終了します。\n") ;break;} } } /* 入力キー、移動座標出力 */ int KEY(int *Kn,int *Y,int *X){ while(1){ *Kn=getch( ); //1:通常キー if (*Kn==0){ *Kn=getch( ); //2:特殊キー if (*Kn==0x4b){(*X)--;}// ← else if (*Kn==0x4d){(*X)++;}// → else if (*Kn==0x48){(*Y)--;}// ↑ else if (*Kn==0x50){(*Y)++;}// ↓ else if (*Kn==0x80){ }//特殊キー追加場所 else {continue;} break; } else if (*Kn==0x1b){}// Esc //else if (*Kn== ){} 通常キー追加場所 else {continue;} break; } return 0; }