無題
Posted: 2008年2月22日(金) 03:46
はじめまして、いつもこちらのHPを参考にさせてもらってます。
今、シューティングゲームを作ってるんですが画面をスクロールさせるプログラムが思いつきません。
どのようにコードを書けばよいか、教えていただけますでしょうか
今、シューティングゲームを作ってるんですが画面をスクロールさせるプログラムが思いつきません。
どのようにコードを書けばよいか、教えていただけますでしょうか
#include "DxLib.h" void Speed_Change ( int &Temp_Speed );// スクロールスピードの変更 void Speed_Scope_Check ( int &Temp_Speed );// スクロールスピードの範囲チェック void Graphic_Scroll ( int &Start_Pos, int &End_Pos, int Temp_Handle, int Roll_Spd = 1 ); // 背景の下方向スクロール(のみ)を行う関数 // ***************************************************************************** // メイン // ***************************************************************************** int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { if ( DxLib_Init () == -1 ) { // ---- DXライブラリ初期化処理 return -1; } SetDrawScreen ( DX_SCREEN_BACK ); ClearDrawScreen (); int Gr_Handle = LoadGraph ( "Test_Graphic.bmp" ); // グラフィックの読み込み int Start_Y_Position = 0, End_Y_Position = 480; // スクロールに使う変数の宣言と初期化 int Scroll_Speed = 1; // スクロールスピードの宣言と初期化 while ( ProcessMessage () == 0 ) { // ------------------ ループ開始 Speed_Change ( Scroll_Speed ); // スクロールスピードの変更 Graphic_Scroll ( Start_Y_Position, End_Y_Position, Gr_Handle, Scroll_Speed ); // スクロールを行う関数呼び出し ScreenFlip (); ClearDrawScreen (); if ( CheckHitKey ( KEY_INPUT_F12 ) != 0 ) { break; } } InitGraph (); DxLib_End (); // -DXライブラリの使用終了処理 return 0; // ---------------- ソフトの終了 } void Speed_Change ( int &Temp_Speed ) { if ( CheckHitKey ( KEY_INPUT_A ) != 0 ) { Temp_Speed --; } if ( CheckHitKey ( KEY_INPUT_Z ) != 0 ) { Temp_Speed ++; } Speed_Scope_Check ( Temp_Speed ); return; } void Speed_Scope_Check ( int &Temp_Speed ) { if ( Temp_Speed <= 1 ) { Temp_Speed = 1; } if ( Temp_Speed >= 16 ) { Temp_Speed = 16; } return; } void Graphic_Scroll ( int &Start_Pos, int &End_Pos, int Temp_Handle, int Roll_Spd ) { /* if ( Start_Pos >= 480 ) { Start_Pos = 0; End_Pos = 480; } DrawRectGraph ( 0, 0, 0, Start_Pos, 640, End_Pos, Temp_Handle, TRUE, FALSE ); if ( End_Pos != 480 ) { DrawRectGraph ( 0, End_Pos, 0, 0, 640, 480 +End_Pos, Temp_Handle, TRUE, FALSE ); } Start_Pos += Roll_Spd; if ( ( Start_Pos +End_Pos ) > 480 ) { End_Pos -= Roll_Spd; } */ if ( Start_Pos <= 0 ) { Start_Pos = 480; End_Pos = 0; } DrawRectGraph ( 0, 0, 0, Start_Pos, 640, 480, Temp_Handle, TRUE, FALSE ); DrawRectGraph ( 0, End_Pos, 0, 0, 640, Start_Pos, Temp_Handle, TRUE, FALSE ); Start_Pos -= Roll_Spd; End_Pos += Roll_Spd; return; }あまり上手なコードではないですが参考程度に・・・(640×480の画像は御自分で用意してください)