Advertisement
Guest User

Untitled

a guest
Sep 4th, 2019
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.80 KB | None | 0 0
  1. #include "DxLib.h"
  2.  
  3. int Key[256];
  4.  
  5. int gpUpdateKey()
  6. {
  7.     char tmpKey[256];
  8.     GetHitKeyStateAll(tmpKey);
  9.     for (int i = 0; i < 256; i++)
  10.         (tmpKey[i] == 0) ? (Key[i] = 0) : Key[i]++;
  11.     return 0;
  12. }
  13.  
  14. int stage[4][7][2];  // 盤上のマスの格子点の座標
  15. int pos[3][6][2];    // キャラ描画座標
  16.  
  17. void init_stage()  // stage と pos を初期化する
  18. {
  19.     for (int j = 0; j < 7; j++) {
  20.         int w = (j - 3) * 100, h = 600;
  21.         for (int i = 4; --i >= 0; ) {
  22.             stage[i][j][0] = w + 400, stage[i][j][1] = h - 200;
  23.             w = w * 9 / 10, h = h * 9 / 10;
  24.         }
  25.     }
  26.     for (int i = 0; i < 3; i++)
  27.         for (int j = 0; j < 6; j++) {
  28.             pos[i][j][0] = (stage[i][j][0] + stage[i + 1][j + 1][0]) / 2 - 25;
  29.             pos[i][j][1] = (stage[i][j][1] + stage[i + 1][j + 1][1]) / 2 - 55;
  30.         }
  31. }
  32.  
  33. int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  34. {
  35.     SetGraphMode(780, 680, 32);         // ウィンドウの大きさを指定
  36.     ChangeWindowMode(TRUE);             // 全画面ではなくウインドウを使用
  37.     if (DxLib_Init() == -1) return -1;  // DXライブラリ初期化処理
  38.     SetDrawScreen(DX_SCREEN_BACK);      // 裏画面を使用する設定
  39.  
  40.     init_stage(); // stage, pos の初期化
  41.  
  42.     int enemyX = 4, enemyY = 1;   // 敵の位置
  43.     int playerX = 1, playerY = 1;  // 俺の位置
  44.  
  45.     int enemyMove = 0;   // 敵の移動状態
  46.       // 俺の移動状態//1~21で右に振り向きのプログラム①が終わり、22になったら足踏みする②を実行するようにする。
  47.     int playerMove = 1;
  48.  
  49.  
  50.  
  51.     int lock = 0;  // ロック状態
  52.  
  53.     int enemyGHandle[12];   // 敵のグラフィックハンドル格納用配列
  54.     int playerGHandle[12];  // 俺のグラフィックハンドル格納用配列
  55.             // 0-2:後ろ向き、3-5:右向き、6-8:前向き、9-11:左向き
  56.     LoadDivGraph("charall.png", 12, 3, 4, 49, 66, enemyGHandle);
  57.     LoadDivGraph("charall.png", 12, 3, 4, 49, 66, playerGHandle);
  58.  
  59.     int enemyImage = enemyGHandle[11];    // 敵 左向き
  60.     int playerImage = playerGHandle[4];   // 俺 右向き
  61.  
  62.    
  63.  
  64.     const int MOVE_INTERVAL = 1000; // 何ミリ秒ごとに移動処理をするか
  65.     int nextMoveTime = GetNowCount() + MOVE_INTERVAL; // 次回移動処理をする時刻
  66.     int stopCount = 0; // 動かないのがあと何回か
  67.  
  68.     while (ProcessMessage() == 0) {
  69.        
  70.         gpUpdateKey();  // キーの入力状態を取得
  71.  
  72.         // 俺の移動
  73.         if (Key[KEY_INPUT_RIGHT] == 1 && playerX < 2) {
  74.             playerMove = 1; playerX++; playerImage = playerGHandle[4];
  75.         }
  76.         if (Key[KEY_INPUT_LEFT] == 1 && playerX > 0) {
  77.             playerMove = 1; playerX--; playerImage = playerGHandle[9];
  78.         }
  79.         if (Key[KEY_INPUT_UP] == 1 && playerY > 0) {
  80.             playerMove = 1; playerY--; playerImage = playerGHandle[2];
  81.         }
  82.         if (Key[KEY_INPUT_DOWN] == 1 && playerY < 2) {
  83.             playerMove = 1; playerY++; playerImage = playerGHandle[8];
  84.         }
  85.  
  86.         if (Key[KEY_INPUT_R] == 1 && playerY==enemyY) {
  87.             enemyImage = enemyGHandle[8];
  88.             int prokey = Key[KEY_INPUT_R] == 1;
  89.             prokey = 1;
  90.             prokey++;//変数prokeyを1ずつ増やしていく
  91.             if (prokey > 0) {
  92.            
  93.             //Key[KEY_INPUT_R] == 1がRを押した後もデータが残るように変数として置き、一定時間キーRが押された後も残るようにする。
  94.                 if (prokey < 100000 && Key[KEY_INPUT_A] == 1) {  // アタック
  95.                     int player2;//移動後の座標
  96.                     player2 = enemyX - 1;//敵の一つ前のX座標がplayer2に入り、
  97.                     player2 = playerX ;
  98.                     playerMove = 1; playerImage = playerGHandle[4];
  99.                     enemyMove = 1; enemyImage = enemyGHandle[10];
  100.                     prokey = 1;
  101.                 }
  102.            
  103.  
  104.             }
  105.  
  106.            
  107.         }
  108.         else {
  109.             // 敵の移動
  110.             int t = GetNowCount();
  111.             if (t >= nextMoveTime) { // 指定の時間が経ったら(1sごとに)
  112.                 nextMoveTime = t + MOVE_INTERVAL; // 次回移動処理をする時刻
  113.                 if (stopCount > 0) { // 停止中のとき
  114.                     stopCount--; // 止まっている残り時間(回数)を減らす
  115.                 }
  116.                 else { // 普通の状態のとき
  117.                     if (GetRand(99) < 10) { // たまに(10%の確率で)
  118.                         stopCount = GetRand(4); // 数秒間(1~5秒間)その場に止まる
  119.                     }
  120.                     else { // 9マス上のいずれかのパネルに移動させる
  121.                         int cy = enemyY, cx = enemyX;
  122.                         do {
  123.                             enemyY = GetRand(2);
  124.                             enemyX = GetRand(2) + 3;
  125.                         } while (enemyX == cx && enemyY == cy ||
  126.                             enemyX == playerX && enemyY == playerY);
  127.                         enemyImage = enemyGHandle[10];
  128.                         enemyMove = 1;
  129.                     }
  130.                 }
  131.             }
  132.  
  133.            
  134.            
  135.         }
  136.        
  137.  
  138.         if (playerMove > 0) {//1フレームで処理を終わらせるためifの後はelse ifを使った。
  139.             playerMove++;
  140.             if (playerMove == 10)//右を向くためのプログラム
  141.             {
  142.                 playerImage = playerGHandle[4];
  143.             }
  144.             else if (playerMove == 30)//条件式として書くため=は==と書いた
  145.             {
  146.                 playerImage = playerGHandle[5];
  147.             }
  148.             else if (playerMove == 40)
  149.             {
  150.                 playerImage = playerGHandle[4];
  151.             }
  152.             else if (playerMove == 50) {
  153.                 playerImage = playerGHandle[3];
  154.                 playerMove = 1;//
  155.             }
  156.         }
  157.  
  158.         ClearDrawScreen();  // 裏画面をクリア
  159.  
  160.         // ステージの描画
  161.         int stageColor = GetColor(160, 64, 64);
  162.         for (int i = 0; i < 4; i++)
  163.             DrawLine(stage[i][0][0], stage[i][0][1],
  164.                 stage[i][6][0], stage[i][6][1], stageColor, 5);
  165.         for (int j = 0; j < 7; j++)
  166.             DrawLine(stage[0][j][0], stage[0][j][1],
  167.                 stage[3][j][0], stage[3][j][1], stageColor, 5);
  168.  
  169.         DrawGraph(pos[enemyY][enemyX][0], pos[enemyY][enemyX][1],
  170.             enemyImage, true);   // 敵キャラの描画
  171.         DrawGraph(pos[playerY][playerX][0], pos[playerY][playerX][1],
  172.             playerImage, true);  // 俺キャラの描画
  173.  
  174.         if (lock) DrawFormatString(100, 200, GetColor(255, 255, 255), "LOCK");
  175.         ScreenFlip();  // 裏画面を表画面に反映
  176.     }
  177.  
  178.     DxLib_End();  // DXライブラリ使用の終了処理
  179.     return 0;  // ソフトの終了
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement