Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "DxLib.h"
- int Key[256];
- int gpUpdateKey()
- {
- char tmpKey[256];
- GetHitKeyStateAll(tmpKey);
- for (int i = 0; i < 256; i++)
- (tmpKey[i] == 0) ? (Key[i] = 0) : Key[i]++;
- return 0;
- }
- int stage[4][7][2]; // 盤上のマスの格子点の座標
- int pos[3][6][2]; // キャラ描画座標
- void init_stage() // stage と pos を初期化する
- {
- for (int j = 0; j < 7; j++) {
- int w = (j - 3) * 100, h = 600;
- for (int i = 4; --i >= 0; ) {
- stage[i][j][0] = w + 400, stage[i][j][1] = h - 200;
- w = w * 9 / 10, h = h * 9 / 10;
- }
- }
- for (int i = 0; i < 3; i++)
- for (int j = 0; j < 6; j++) {
- pos[i][j][0] = (stage[i][j][0] + stage[i + 1][j + 1][0]) / 2 - 25;
- pos[i][j][1] = (stage[i][j][1] + stage[i + 1][j + 1][1]) / 2 - 55;
- }
- }
- int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
- {
- SetGraphMode(780, 680, 32); // ウィンドウの大きさを指定
- ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
- if (DxLib_Init() == -1) return -1; // DXライブラリ初期化処理
- SetDrawScreen(DX_SCREEN_BACK); // 裏画面を使用する設定
- init_stage(); // stage, pos の初期化
- int enemyX = 4, enemyY = 1; // 敵の位置
- int playerX = 1, playerY = 1; // 俺の位置
- int enemyMove = 0; // 敵の移動状態
- // 俺の移動状態//1~21で右に振り向きのプログラム①が終わり、22になったら足踏みする②を実行するようにする。
- int playerMove = 1;
- int lock = 0; // ロック状態
- int enemyGHandle[12]; // 敵のグラフィックハンドル格納用配列
- int playerGHandle[12]; // 俺のグラフィックハンドル格納用配列
- // 0-2:後ろ向き、3-5:右向き、6-8:前向き、9-11:左向き
- LoadDivGraph("charall.png", 12, 3, 4, 49, 66, enemyGHandle);
- LoadDivGraph("charall.png", 12, 3, 4, 49, 66, playerGHandle);
- int enemyImage = enemyGHandle[11]; // 敵 左向き
- int playerImage = playerGHandle[4]; // 俺 右向き
- const int MOVE_INTERVAL = 1000; // 何ミリ秒ごとに移動処理をするか
- int nextMoveTime = GetNowCount() + MOVE_INTERVAL; // 次回移動処理をする時刻
- int stopCount = 0; // 動かないのがあと何回か
- while (ProcessMessage() == 0) {
- gpUpdateKey(); // キーの入力状態を取得
- // 俺の移動
- if (Key[KEY_INPUT_RIGHT] == 1 && playerX < 2) {
- playerMove = 1; playerX++; playerImage = playerGHandle[4];
- }
- if (Key[KEY_INPUT_LEFT] == 1 && playerX > 0) {
- playerMove = 1; playerX--; playerImage = playerGHandle[9];
- }
- if (Key[KEY_INPUT_UP] == 1 && playerY > 0) {
- playerMove = 1; playerY--; playerImage = playerGHandle[2];
- }
- if (Key[KEY_INPUT_DOWN] == 1 && playerY < 2) {
- playerMove = 1; playerY++; playerImage = playerGHandle[8];
- }
- if (Key[KEY_INPUT_R] == 1 && playerY==enemyY) {
- enemyImage = enemyGHandle[8];
- int prokey = Key[KEY_INPUT_R] == 1;
- prokey = 1;
- prokey++;//変数prokeyを1ずつ増やしていく
- if (prokey > 0) {
- //Key[KEY_INPUT_R] == 1がRを押した後もデータが残るように変数として置き、一定時間キーRが押された後も残るようにする。
- if (prokey < 100000 && Key[KEY_INPUT_A] == 1) { // アタック
- int player2;//移動後の座標
- player2 = enemyX - 1;//敵の一つ前のX座標がplayer2に入り、
- player2 = playerX ;
- playerMove = 1; playerImage = playerGHandle[4];
- enemyMove = 1; enemyImage = enemyGHandle[10];
- prokey = 1;
- }
- }
- }
- else {
- // 敵の移動
- int t = GetNowCount();
- if (t >= nextMoveTime) { // 指定の時間が経ったら(1sごとに)
- nextMoveTime = t + MOVE_INTERVAL; // 次回移動処理をする時刻
- if (stopCount > 0) { // 停止中のとき
- stopCount--; // 止まっている残り時間(回数)を減らす
- }
- else { // 普通の状態のとき
- if (GetRand(99) < 10) { // たまに(10%の確率で)
- stopCount = GetRand(4); // 数秒間(1~5秒間)その場に止まる
- }
- else { // 9マス上のいずれかのパネルに移動させる
- int cy = enemyY, cx = enemyX;
- do {
- enemyY = GetRand(2);
- enemyX = GetRand(2) + 3;
- } while (enemyX == cx && enemyY == cy ||
- enemyX == playerX && enemyY == playerY);
- enemyImage = enemyGHandle[10];
- enemyMove = 1;
- }
- }
- }
- }
- if (playerMove > 0) {//1フレームで処理を終わらせるためifの後はelse ifを使った。
- playerMove++;
- if (playerMove == 10)//右を向くためのプログラム
- {
- playerImage = playerGHandle[4];
- }
- else if (playerMove == 30)//条件式として書くため=は==と書いた
- {
- playerImage = playerGHandle[5];
- }
- else if (playerMove == 40)
- {
- playerImage = playerGHandle[4];
- }
- else if (playerMove == 50) {
- playerImage = playerGHandle[3];
- playerMove = 1;//
- }
- }
- ClearDrawScreen(); // 裏画面をクリア
- // ステージの描画
- int stageColor = GetColor(160, 64, 64);
- for (int i = 0; i < 4; i++)
- DrawLine(stage[i][0][0], stage[i][0][1],
- stage[i][6][0], stage[i][6][1], stageColor, 5);
- for (int j = 0; j < 7; j++)
- DrawLine(stage[0][j][0], stage[0][j][1],
- stage[3][j][0], stage[3][j][1], stageColor, 5);
- DrawGraph(pos[enemyY][enemyX][0], pos[enemyY][enemyX][1],
- enemyImage, true); // 敵キャラの描画
- DrawGraph(pos[playerY][playerX][0], pos[playerY][playerX][1],
- playerImage, true); // 俺キャラの描画
- if (lock) DrawFormatString(100, 200, GetColor(255, 255, 255), "LOCK");
- ScreenFlip(); // 裏画面を表画面に反映
- }
- DxLib_End(); // DXライブラリ使用の終了処理
- return 0; // ソフトの終了
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement