(右上と右下と左下左上に対応させたい)
void PlayerControl()のところです。
よろしくお願いいたします。
/********************************************************************
** ゲージを表示する
********************************************************************/
#include "DxLib.h"
#define _USE_MATH_DEFINES
#include <math.h>
/***********************************************
* 定数の宣言
***********************************************/
// 画面領域の大きさ
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
// 自機の初期値
const int PLAYER_POS_X = SCREEN_WIDTH / 2;
const int PLAYER_POS_Y = SCREEN_HEIGHT - 200;
const int PLAYER_WIDTH = 63;
const int PLAYER_HEIGHT = 120;
const int PLAYER_SPEED = 2;
/***********************************************
* 変数の宣言
***********************************************/
int value = 0; //ゲージと右下に表示する数字の値
int g_OldKey; // 前回の入力キー
int g_NowKey; // 今回の入力キー
int g_KeyFlg; // 入力キー情報
int g_Car;
int BackImage2;
int BackImage2_Y;
int speed = 0;
/***********************************************
* 関数のプロトタイプ宣言
***********************************************/
void GameInit(void);//ゲーム初期
void PlayerControl(); //プレイヤーの表示
void GameMain(void);
void DrawGauge(void);
void BackScrool();
//実機の構造体
struct PLAYER {
int x, y;
int w, h;
int speed;
};
struct PLAYER g_player;
/***********************************************
* プログラムの開始
***********************************************/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
SetWindowText("Drive&Avoid");
ChangeWindowMode(TRUE); // ウィンドウモードで起動する
if (DxLib_Init() == -1) return -1; // DXライブラリの初期化処理:エラーが起きたら直ちに終了
SetDrawScreen(DX_SCREEN_BACK); // 描画先画面を裏にする
//if ((BackImage1 = LoadGraph("images/BackImage1.bmp")) == -1)return -1;
if ((BackImage2 = LoadGraph("images/back.bmp")) == -1)return -1;
if ((g_Car = LoadGraph("images/car1pol.bmp")) == -1)return -1;
GameInit();
// ゲームループ
while (ProcessMessage() == 0 && !(g_KeyFlg & PAD_INPUT_9)) {
// 入力キー取得
g_OldKey = g_NowKey;
g_NowKey = GetJoypadInputState(DX_INPUT_KEY_PAD1);
g_KeyFlg = g_NowKey & g_OldKey;
//メニューカーソル移動処理
if (g_KeyFlg == PAD_INPUT_DOWN && (value > 0)) { //↓キーが押されていた時
value--;
speed--;
}
if (g_KeyFlg == PAD_INPUT_UP && (value < 9999950)) { //↑キーが押されていた時
value++;
speed++;
}
ClearDrawScreen();
PlayerControl();
GameMain();
ScreenFlip();
DrawGauge();
}
WaitKey();
DxLib_End(); // DXライブラリ使用の終了処理
return 0; // ソフトの終了
}
void BackScrool()
{
BackImage2_Y += speed;
//背景表示
SetDrawArea(0, 0, 640, 499);
DrawGraph(0, BackImage2_Y % 480 - 480, BackImage2, TRUE);
DrawGraph(0, BackImage2_Y % 480,BackImage2, TRUE);
SetDrawArea(0, 0, 640, 480);
}
void GameInit(void)
{
g_player.x = PLAYER_POS_X;
g_player.y = PLAYER_POS_Y;
g_player.w = PLAYER_WIDTH;
g_player.h = PLAYER_HEIGHT;
g_player.speed = PLAYER_SPEED;
}
void PlayerControl()
{
//上下左右移動
if (g_NowKey & PAD_INPUT_UP) g_player.y -= g_player.speed;
if (g_NowKey & PAD_INPUT_DOWN) g_player.y += g_player.speed;
if (g_NowKey & PAD_INPUT_LEFT) g_player.x -= g_player.speed;
if (g_NowKey & PAD_INPUT_RIGHT) g_player.x += g_player.speed;
//プレイヤーの表示
if (g_NowKey & PAD_INPUT_LEFT) {
DrawRotaGraph(g_player.x, g_player.y, 1.0f, -M_PI / 2, g_Car, TRUE, FALSE);
}
else if (g_NowKey & PAD_INPUT_RIGHT) {
DrawRotaGraph(g_player.x, g_player.y, 1.0f, M_PI / 2, g_Car, TRUE, FALSE);
}
else if (g_NowKey & PAD_INPUT_DOWN) {
DrawRotaGraph(g_player.x, g_player.y, 1.0f, M_PI / 1, g_Car, TRUE, FALSE);
}
else {
DrawRotaGraph(g_player.x, g_player.y, 1.0f, 0, g_Car, TRUE, FALSE);
}
}
void GameMain(void)
{
BackScrool();
DrawGauge();
PlayerControl();
}
void DrawGauge(void)
{
SetFontSize(60);
DrawFormatString(560, 400, 0xFFFFFF, "%d", value); //白文字でvalueの値を表示
DrawBox(500, 350, 520, 450, 0xFFFFFF, 1); //ゲージの背景(白)を描画
DrawBox(500, 450 - (value * 2), 520, 450, 0x0000FF, 1); //ゲージの背景(白)を描画
}
[code/]