Created
August 18, 2020 11:24
-
-
Save LoadDragon0000000000/14773fcc980ae8a5e2cf7692af5df1be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DxLib.h" | |
float PlayerX = 0; | |
float PlayerY = 240; | |
bool RightKeyON = false; | |
bool LeftKeyON = false; | |
bool UpKeyON = false; | |
bool DownKeyON = false; | |
const float PlayerSpeed = 3.0f; | |
const int Map[15][20] = { | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
}; | |
void SetLeftWall(float x, float yTop, float yUnder); // 左壁の作成 | |
int WINAPI WinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPSTR, _In_ int) { | |
// ---ここから設定--- | |
ChangeWindowMode(TRUE), SetMainWindowText("アクションゲームの当たり判定(衝突処理)"), SetGraphMode(640, 480, 32), | |
SetDoubleStartValidFlag(TRUE); DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK); | |
// ---ここまで設定--- | |
// ゲームループ | |
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0) { | |
// 右キーが入力された時、プレイヤーを右へ移動させる | |
RightKeyON = CheckHitKey(KEY_INPUT_RIGHT); | |
if (RightKeyON == true) { | |
PlayerX += PlayerSpeed; | |
} | |
// 左キーが入力された時、プレイヤーを移動させる | |
LeftKeyON = CheckHitKey(KEY_INPUT_LEFT); | |
if (LeftKeyON == true) { | |
PlayerX -= PlayerSpeed; | |
} | |
// 上キーが入力された時、プレイヤーを移動させる | |
UpKeyON = CheckHitKey(KEY_INPUT_UP); | |
if (UpKeyON == true) { | |
PlayerY -= PlayerSpeed; | |
} | |
// 下キーが入力された時、プレイヤーを移動させる | |
DownKeyON = CheckHitKey(KEY_INPUT_DOWN); | |
if (DownKeyON == true) { | |
PlayerY += PlayerSpeed; | |
} | |
for (int Height = 0; Height <= 15; ++Height) { | |
for (int Width = 0; Width <= 20; ++Width) { | |
if (Map[Height][Width] == 1) { | |
SetLeftWall(Width * 32.0f, Height * 32.0f, (Height * 32.0f) + 32.0f); | |
} | |
} | |
} | |
DrawCircle(PlayerX, PlayerY, 10, GetColor(255, 0, 0), true); | |
} | |
DxLib_End(); return 0; | |
} | |
// 左壁の作成 | |
void SetLeftWall(float x, float yTop, float yUnder) { | |
if (x - 3.0f <= PlayerX && PlayerX <= x + 3.0f && yTop <= PlayerY && PlayerY <= yUnder) { // プレイヤーが壁の左側にいつつ、壁の高さと同じ場所にいる時 | |
if (x - 0.10f <= PlayerX) { | |
PlayerX = x - 0.10f; | |
} | |
} | |
DrawLine(x, yTop, x, yUnder, GetColor(255, 255, 255)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment