//=============================================================================
// Game処理関係の自作関数群
//=============================================================================
#include "common.h"
//-----------------------------------------------------------------------------
// プロトタイプ宣言(ソース内でしか使わないもの)
//-----------------------------------------------------------------------------
static void ScreenOut(void);
static void CharMove(void);
static void ScreenHitCheck(void);
static void CharHitCheck(void);
static bool HitCheck(RECT, RECT);
//-----------------------------------------------------------------------------
// ゲーム処理用グローバル変数
//-----------------------------------------------------------------------------
static STATUS Angel; // 天使
static RECT GokiRect; // ゴキブリの矩形
static int GokiWidth, GokiHeight; // ゴキブリの幅・高さ
static int GokiX, GokiY; // ゴキブリの表示座標
//-----------------------------------------------------------------------------
// 関数名 : GameInit()
// 機能概要: スタート処理初期化
//-----------------------------------------------------------------------------
void GameInit(HWND hWnd)
{
//------------------------------------------------------- 各変数の初期化
/* 天使(カーソルキーで移動) */
SetRect(&Angel.rect, 0, 608, 48, 656); // キャラクタ矩形設定
SetRect(&Angel.hitrect, 4, 4, 40, 40); // 当たり矩形設定
Angel.width = Angel.rect.right - Angel.rect.left; // 幅
Angel.height = Angel.rect.bottom - Angel.rect.top; // 高さ
Angel.x = 310; // X座標
Angel.y = 230; // Y座標
Angel.move_x = 4; // X方向移動量
Angel.move_y = 4; // Y方向移動量
/* ゴキブリ(動かない) */
・
・
・
//-----------------------------------------------------------------------------
// 関数名 : GameFrame()
// 機能概要: ゲーム画面更新処理
//-----------------------------------------------------------------------------
void GameFrame(HWND hWnd)
{
・
・
・
}
//-----------------------------------------------------------------------------
// 関数名 : ScreenOut()
// 機能概要: ゲーム画像描画処理
//-----------------------------------------------------------------------------
static void ScreenOut(void)
{
HRESULT hRet;
/* ゲーム画面用背景 */
hRet = g_pDDSBack->BltFast(0, 0, g_pDDSGame, &ScreenRect, DDBLTFAST_NOCOLORKEY);
if (hRet != DD_OK)
return;
/* 天使 */
hRet = g_pDDSBack->BltFast(Angel.x, Angel.y, g_pDDSGame, &Angel.rect, DDBLTFAST_SRCCOLORKEY);
if (hRet != DD_OK)
return;
/* ゴキブリ */
hRet = g_pDDSBack->BltFast(GokiX, GokiY, g_pDDSGame, &GokiRect, DDBLTFAST_SRCCOLORKEY);
if (hRet != DD_OK)
return;
}
//-----------------------------------------------------------------------------
// 関数名 : CharMove()
// 機能概要: キャラクタ移動処理
//-----------------------------------------------------------------------------
static void CharMove(void)
{
/* 天使の移動 */
if (KeyTbl[VK_LEFT] & 0x80)
Angel.x -= Angel.move_x;
if (KeyTbl[VK_RIGHT] & 0x80)
Angel.x += Angel.move_x;
if (KeyTbl[VK_UP] & 0x80)
Angel.y -= Angel.move_y;
if (KeyTbl[VK_DOWN] & 0x80)
Angel.y += Angel.move_y;
}
//-----------------------------------------------------------------------------
// 関数名 : ScreenCheck()
// 機能概要: キャラクタがゲーム画面をはみ出している時の処理
//-----------------------------------------------------------------------------
static void ScreenHitCheck(void)
{
/* 天使とゲーム画面(画面全体)をチェック */
if (Angel.x < ScreenRect.left)
Angel.x = ScreenRect.left;
else if (Angel.x > ScreenRect.right - Angel.width)
Angel.x = ScreenRect.right - Angel.width;
if (Angel.y < ScreenRect.top)
Angel.y = ScreenRect.top;
else if (Angel.y > ScreenRect.bottom - Angel.height)
Angel.y = ScreenRect.bottom - Angel.height;
}
//-----------------------------------------------------------------------------
// 関数名 : HitCheck()
// 機能概要: あたり判定関数
//-----------------------------------------------------------------------------
static bool HitCheck(RECT Rect1, RECT Rect2)
{
・
・
・
}
//-----------------------------------------------------------------------------
// 関数名 : CharHitCheck()
// 機能概要: キャラクタ同士の当たり判定と処理
//-----------------------------------------------------------------------------
static void CharHitCheck(void)
{
RECT r1, r2;
/* 天使とゴキブリの衝突を調べ、当たっていたらスタート画面に戻る */
SetRect(&r1, Angel.x + Angel.hitrect.left, Angel.y + Angel.hitrect.top,
Angel.x + Angel.hitrect.right, Angel.y + Angel.hitrect.bottom);
SetRect(&r2, GokiX, GokiY, GokiX + GokiWidth, GokiY + GokiHeight);
if (HitCheck(r1, r2))
{
g_FrameNo = START_INIT;
return;
}
} |