#8
by かずま » 4年前
インデントがおかしなプログラムをまともなプログラムとは言えません。
if (prokey > 0) があると、else 以降は prokey が 0 以下の場合の処理と
なりますが、prokey が 0以下にはならないので、まともなプログラムとは
言えません。
playerX = playerX; を見ると、代入を理解しているとはとても思えません。
ヒントを出そうと思いましたが、私には、Ouxiy さんが理解できるような
説明をする能力はありません。お詫びに、ロック、アタックを適当に
実装したソースを示します。
コード:
#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(); // ステージとキャラ描画座標の初期化
int enemyX = 4, enemyY = 1; // 敵の位置
int playerX = 1, playerY = 1; // 俺の位置
int playerX2 = 1, playerY2 = 1; // ロック解除の戻り位置
int enemyMove = 0; // 敵の移動状態
int playerMove = 1; // 俺の移動状態
int lock = 0; // ロック状態
int attack = 0; // アタック状態
int enemyGHandle[12]; // 敵のグラフィックハンドル格納用配列
int playerGHandle[12]; // 俺のグラフィックハンドル格納用配列
// 0:後向き右足前, 1:後向き, 2:後向き左足前
// 3:右向き左足前, 4:右向き, 5:右向き右足前
// 6:前向き右足前, 7:前向き, 8:前向き左足前
// 9:左向き右足前, 10:左向き, 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]; // 敵の画像変更
playerX2 = playerX; playerY2 = playerY; // 元の位置保存
lock = 1; // ロックオン
}
if (lock > 0 && ++lock > 3*60) { // 3秒経った
playerX = playerX2, playerY = playerY2; // 元の位置に戻る
playerMove = 1; playerImage = playerGHandle[4];
lock = 0; // ロック解除
}
if (lock && Key[KEY_INPUT_A] == 1) { // アタック
playerX = enemyX - 1; // 敵の左に移動
playerMove = 1; playerImage = playerGHandle[4];
lock = 0; attack = 1; // ロック状態からアタック状態に移行
}
if (attack > 0 && ++attack > 60) { // 1秒経った
playerX = playerX2, playerY = playerY2; // 元の位置に戻る
playerMove = 1; playerImage = playerGHandle[4];
attack = 0; // アタック状態解除
}
// 敵の移動
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) {
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; // ソフトの終了
}
か
インデントがおかしなプログラムをまともなプログラムとは言えません。
if (prokey > 0) があると、else 以降は prokey が 0 以下の場合の処理と
なりますが、prokey が 0以下にはならないので、まともなプログラムとは
言えません。
playerX = playerX; を見ると、代入を理解しているとはとても思えません。
ヒントを出そうと思いましたが、私には、Ouxiy さんが理解できるような
説明をする能力はありません。お詫びに、ロック、アタックを適当に
実装したソースを示します。
[code]
#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(); // ステージとキャラ描画座標の初期化
int enemyX = 4, enemyY = 1; // 敵の位置
int playerX = 1, playerY = 1; // 俺の位置
int playerX2 = 1, playerY2 = 1; // ロック解除の戻り位置
int enemyMove = 0; // 敵の移動状態
int playerMove = 1; // 俺の移動状態
int lock = 0; // ロック状態
int attack = 0; // アタック状態
int enemyGHandle[12]; // 敵のグラフィックハンドル格納用配列
int playerGHandle[12]; // 俺のグラフィックハンドル格納用配列
// 0:後向き右足前, 1:後向き, 2:後向き左足前
// 3:右向き左足前, 4:右向き, 5:右向き右足前
// 6:前向き右足前, 7:前向き, 8:前向き左足前
// 9:左向き右足前, 10:左向き, 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]; // 敵の画像変更
playerX2 = playerX; playerY2 = playerY; // 元の位置保存
lock = 1; // ロックオン
}
if (lock > 0 && ++lock > 3*60) { // 3秒経った
playerX = playerX2, playerY = playerY2; // 元の位置に戻る
playerMove = 1; playerImage = playerGHandle[4];
lock = 0; // ロック解除
}
if (lock && Key[KEY_INPUT_A] == 1) { // アタック
playerX = enemyX - 1; // 敵の左に移動
playerMove = 1; playerImage = playerGHandle[4];
lock = 0; attack = 1; // ロック状態からアタック状態に移行
}
if (attack > 0 && ++attack > 60) { // 1秒経った
playerX = playerX2, playerY = playerY2; // 元の位置に戻る
playerMove = 1; playerImage = playerGHandle[4];
attack = 0; // アタック状態解除
}
// 敵の移動
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) {
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; // ソフトの終了
}
[/code]
か