キャラのアニメーションとカメラのズーム処理

「キャラのアニメーションとカメラのズーム処理」の編集履歴(バックアップ)一覧はこちら

キャラのアニメーションとカメラのズーム処理」(2008/11/11 (火) 03:05:15) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

#include "DxLib.h" #define WINDOW_WIDTH 640 #define WINDOW_HEIGHT 480 #define WINDOW_TEXT "RozenMaidenDuoDectet" #define IMG_BACK "image\\Back.bmp" #define IMG_TABLE "image\\gtable.bmp" #define IMG_BACK02 "image\\Back02.bmp" #define IMG_BLACK "image\\Black.bmp" typedef enum tagCharaState{ STATE_WALK_FW, STATE_WALK_BK, STATE_STAND } CharaState; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { SetMainWindowText(WINDOW_TEXT); //ウィンドウの文字列設定 SetWindowIconID(101); //Resouce.rcでID定義してます。 ChangeWindowMode(TRUE); //ウィンドウモードに SetGraphMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32); //解像度、カラーモードを設定 //DXライブラリの初期化 if(DxLib_Init() == -1) return false; //バックバッファの設定 SetDrawScreen(DX_SCREEN_BACK); //グラフィックデータのロード int gh_Background = LoadGraph(IMG_BACK02); int gh_Black = LoadGraph(IMG_BLACK); //グラフィックの分割読み込み int gh_Table[100]; LoadDivGraph(IMG_TABLE,100, 10, 10, 150, 200, gh_Table); int x = 0, y = 0; int ghi = 0; //ステージサイズ const int stage_width = 2800; const int stage_height = 2100; //キャラ座標 int chara_x = 0, chara_y = 200; const int chara_width = 150; const int chara_height = 200; int chara_gh = 0; CharaState cs = STATE_STAND; int chara_state_frames = 1; int plus_frames = 0; //キャラモーションのデータ const int ANI_STAND_START = 11; const int NUM_STAND = 8; const int STAND_FRAMES = 150; const int ANI_WALK_START = 1;//歩きアニメが始まる場所 const int NUM_WALK = 7; //歩きアニメ枚数 const int WALK_FRAMES = 100; //動作全体フレーム数 //カメラ変数 double camera_zoom = 1; int camera_x = 0, camera_y = 0; int camera_width = 640, camera_height = 480; int last_input = 0; //メイン処理 while(1) { if( CheckHitKey( KEY_INPUT_LEFT ) == 1) { //前のフレームが後ろ歩きならフレームをインクリメント if(cs == STATE_WALK_BK){ chara_state_frames++; } else{ cs = STATE_WALK_BK; chara_state_frames = 1; } chara_x -= 8 ; } else if( CheckHitKey( KEY_INPUT_RIGHT) == 1){ if(cs == STATE_WALK_FW){ chara_state_frames++; } else{ cs = STATE_WALK_FW; chara_state_frames = 1; } chara_x += 8 ; } else { if(cs == STATE_STAND){ chara_state_frames++; } else{ cs = STATE_STAND; chara_state_frames = 0; } } if( CheckHitKey( KEY_INPUT_Z ) == 1) camera_zoom *= 1.05; if( CheckHitKey( KEY_INPUT_X ) == 1) camera_zoom *= 0.95; if( CheckHitKey( KEY_INPUT_A ) == 1) camera_x -= 8; if( CheckHitKey( KEY_INPUT_D ) == 1) camera_x += 8; if( CheckHitKey( KEY_INPUT_S ) == 1) camera_y += 8; if( CheckHitKey( KEY_INPUT_W ) == 1) camera_y -= 8; if( CheckHitKey( KEY_INPUT_SPACE) == 1){ camera_zoom = 1; camera_x = 0; camera_y = 0; } //キャラ移動補正 if(chara_x < 0) chara_x = 0; if(chara_x > stage_width - chara_width) chara_x = stage_width - chara_width; //カメラズーム補正 if(camera_zoom < 1); //カメラ位置補正 if(camera_x < 0) camera_x = 0; if(camera_x > stage_width*camera_zoom - camera_width) camera_x = stage_width*camera_zoom - camera_width; if(camera_y < 0) camera_y = 0; if(camera_y > stage_height*camera_zoom - camera_height) camera_y = stage_height*camera_zoom - camera_height; //アニメ動作更新 switch(cs){ case STATE_WALK_BK: if(chara_state_frames == 1){ chara_gh = ANI_WALK_START; break; } plus_frames = (int)(chara_state_frames*NUM_WALK/WALK_FRAMES) % NUM_WALK; chara_gh = ANI_WALK_START + plus_frames; break; case STATE_WALK_FW: if(chara_state_frames == 1){ chara_gh = ANI_WALK_START; break; } plus_frames = (int)(chara_state_frames*NUM_WALK/WALK_FRAMES) % NUM_WALK; chara_gh = ANI_WALK_START + plus_frames; break; case STATE_STAND: if(chara_state_frames == 1){ chara_gh = ANI_STAND_START; break; } plus_frames = (int)(chara_state_frames*NUM_STAND/STAND_FRAMES) % NUM_STAND; chara_gh = ANI_STAND_START + plus_frames; break; } DrawGraph(0, 0, gh_Black, FALSE); DrawExtendGraph(-camera_x, -camera_y, stage_width*camera_zoom - camera_x, stage_height*camera_zoom -camera_y, gh_Background,FALSE); DrawExtendGraph(chara_x*camera_zoom - camera_x, chara_y*camera_zoom - camera_y, (chara_x + chara_width)*camera_zoom -camera_x, (chara_y + chara_height)*camera_zoom -camera_y, gh_Table[chara_gh-1], FALSE); printfDx("zoom = %lf\n", camera_zoom); ScreenFlip(); // バッファをフリップ WaitTimer(20); if(ProcessMessage() == -1) break; if(CheckHitKey( KEY_INPUT_ESCAPE) == 1) break; } //DXライブラリの終了 DxLib_End(); return 0 ; // ソフトの終了 }
//C++ #include "DxLib.h" #define WINDOW_WIDTH 640 #define WINDOW_HEIGHT 480 #define WINDOW_TEXT "RozenMaidenDuoDectet" #define IMG_BACK "image\\Back.bmp" #define IMG_TABLE "image\\gtable.bmp" #define IMG_BACK02 "image\\Back02.bmp" #define IMG_BLACK "image\\Black.bmp" typedef enum tagCharaState{ STATE_WALK_FW, STATE_WALK_BK, STATE_STAND } CharaState; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { SetMainWindowText(WINDOW_TEXT); //ウィンドウの文字列設定 SetWindowIconID(101); //Resouce.rcでID定義してます。 ChangeWindowMode(TRUE); //ウィンドウモードに SetGraphMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32); //解像度、カラーモードを設定 //DXライブラリの初期化 if(DxLib_Init() == -1) return false; //バックバッファの設定 SetDrawScreen(DX_SCREEN_BACK); //グラフィックデータのロード int gh_Background = LoadGraph(IMG_BACK02); int gh_Black = LoadGraph(IMG_BLACK); //グラフィックの分割読み込み int gh_Table[100]; LoadDivGraph(IMG_TABLE,100, 10, 10, 150, 200, gh_Table); int x = 0, y = 0; int ghi = 0; //ステージサイズ const int stage_width = 2800; const int stage_height = 2100; //キャラ座標 int chara_x = 0, chara_y = 200; const int chara_width = 150; const int chara_height = 200; int chara_gh = 0; CharaState cs = STATE_STAND; int chara_state_frames = 1; int plus_frames = 0; //キャラモーションのデータ const int ANI_STAND_START = 11; const int NUM_STAND = 8; const int STAND_FRAMES = 150; const int ANI_WALK_START = 1;//歩きアニメが始まる場所 const int NUM_WALK = 7; //歩きアニメ枚数 const int WALK_FRAMES = 100; //動作全体フレーム数 //カメラ変数 double camera_zoom = 1; int camera_x = 0, camera_y = 0; int camera_width = 640, camera_height = 480; int last_input = 0; //メイン処理 while(1) { if( CheckHitKey( KEY_INPUT_LEFT ) == 1) { //前のフレームが後ろ歩きならフレームをインクリメント if(cs == STATE_WALK_BK){ chara_state_frames++; } else{ cs = STATE_WALK_BK; chara_state_frames = 1; } chara_x -= 8 ; } else if( CheckHitKey( KEY_INPUT_RIGHT) == 1){ if(cs == STATE_WALK_FW){ chara_state_frames++; } else{ cs = STATE_WALK_FW; chara_state_frames = 1; } chara_x += 8 ; } else { if(cs == STATE_STAND){ chara_state_frames++; } else{ cs = STATE_STAND; chara_state_frames = 0; } } if( CheckHitKey( KEY_INPUT_Z ) == 1) camera_zoom *= 1.05; if( CheckHitKey( KEY_INPUT_X ) == 1) camera_zoom *= 0.95; if( CheckHitKey( KEY_INPUT_A ) == 1) camera_x -= 8; if( CheckHitKey( KEY_INPUT_D ) == 1) camera_x += 8; if( CheckHitKey( KEY_INPUT_S ) == 1) camera_y += 8; if( CheckHitKey( KEY_INPUT_W ) == 1) camera_y -= 8; if( CheckHitKey( KEY_INPUT_SPACE) == 1){ camera_zoom = 1; camera_x = 0; camera_y = 0; } //キャラ移動補正 if(chara_x < 0) chara_x = 0; if(chara_x > stage_width - chara_width) chara_x = stage_width - chara_width; //カメラズーム補正 if(camera_zoom < 1); //カメラ位置補正 if(camera_x < 0) camera_x = 0; if(camera_x > stage_width*camera_zoom - camera_width) camera_x = stage_width*camera_zoom - camera_width; if(camera_y < 0) camera_y = 0; if(camera_y > stage_height*camera_zoom - camera_height) camera_y = stage_height*camera_zoom - camera_height; //アニメ動作更新 switch(cs){ case STATE_WALK_BK: if(chara_state_frames == 1){ chara_gh = ANI_WALK_START; break; } plus_frames = (int)(chara_state_frames*NUM_WALK/WALK_FRAMES) % NUM_WALK; chara_gh = ANI_WALK_START + plus_frames; break; case STATE_WALK_FW: if(chara_state_frames == 1){ chara_gh = ANI_WALK_START; break; } plus_frames = (int)(chara_state_frames*NUM_WALK/WALK_FRAMES) % NUM_WALK; chara_gh = ANI_WALK_START + plus_frames; break; case STATE_STAND: if(chara_state_frames == 1){ chara_gh = ANI_STAND_START; break; } plus_frames = (int)(chara_state_frames*NUM_STAND/STAND_FRAMES) % NUM_STAND; chara_gh = ANI_STAND_START + plus_frames; break; } DrawGraph(0, 0, gh_Black, FALSE); DrawExtendGraph(-camera_x, -camera_y, stage_width*camera_zoom - camera_x, stage_height*camera_zoom -camera_y, gh_Background,FALSE); DrawExtendGraph(chara_x*camera_zoom - camera_x, chara_y*camera_zoom - camera_y, (chara_x + chara_width)*camera_zoom -camera_x, (chara_y + chara_height)*camera_zoom -camera_y, gh_Table[chara_gh-1], FALSE); printfDx("zoom = %lf\n", camera_zoom); ScreenFlip(); // バッファをフリップ WaitTimer(20); if(ProcessMessage() == -1) break; if(CheckHitKey( KEY_INPUT_ESCAPE) == 1) break; } //DXライブラリの終了 DxLib_End(); return 0 ; // ソフトの終了 }

表示オプション

横に並べて表示:
変化行の前後のみ表示:
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。