旧の方を参考に、一定だけ移動するマス目移動を実装したのですが、一定の時間が経過するとキャラクターの画像が消えてしまいます。
キャラクターの画像もサイトを参考に分割保存しているのですが、これは何が原因なのでしょう?
また、「特定のキーを押すと、画面上の特定の座標に向かって一定の速度で移動する」ことを実装したいのですが、上手く動きません。方法を教えて下さい。
magnet関数が私が失敗したものです。どう変えれば良いでしょうか?
#include "DxLib.h"
int Key[256]; // キーが押されているフレーム数を格納する
// キーの入力状態を更新する
int gpUpdateKey() {
char tmpKey[256]; // 現在のキーの入力状態を格納する
GetHitKeyStateAll(tmpKey); // 全てのキーの入力状態を得る
for (int i = 0; i<256; i++) {
if (tmpKey[i] != 0) { // i番のキーコードに対応するキーが押されていたら
Key[i]++; // 加算
}
else { // 押されていなければ
Key[i] = 0; // 0にする
}
}
return 0;
}
int hantei_A[15][20] = {
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,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,1 },
};
int hantei_B[15][20] = {
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,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,1 },
};
int hantei_C[15][20] = {
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,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,1 },
};
int x = 320, y = 160;
int v = 160, z = 160;
int Handle1;
int Handle2;
int walking_flag1 = 0;
int walking_flag2 = 0;
int direction_1a = 3;
int direction_1b = 3;
int direction_2a = 3;
int direction_2b = 3;
int direction_3a = 3;
int direction_3b = 3;
int Image_a[16];//16個の画像を格納する配列
int Image_b[16];//16個の画像を格納する配列
int Green = GetColor(0, 255, 0);//座標表示用
int function_status = 0, White;
typedef struct {
int x, y; // 座標格納用変数
char name[128]; // 項目名格納用変数
} MenuElement_t;
MenuElement_t MenuElement[5] = {
{ 80, 100, "ステージ1 スタート" }, // タグの中身の順番で格納される。xに80が、yに100が、nameに"ゲームスタート"が
{ 100, 150, "ステージ2 スタート" },
{ 100, 200, "ステージ3 スタート" },
{ 100, 250, "操作方法" },
{ 100, 300, "ゲーム終了" },
};
int SelectNum = 0; // 現在の選択番号
void Opening() {
DrawString(100, 100, "オープニング画面 (zをプッシュ)", White);
if (Key[KEY_INPUT_Z] == 1)
function_status = 1;
}
void Menu() {
DrawString(100, 140, "メニュー画面 (Qをプッシュ)", White);
// 計算フェーズ
if (Key[KEY_INPUT_DOWN] == 1) { // 下キーが押された瞬間だけ処理
SelectNum = (SelectNum + 1) % 5; // 現在の選択項目を一つ下にずらす(ループする)
}
if (Key[KEY_INPUT_UP] == 1) { // 上キーが押された瞬間だけ処理
SelectNum = (SelectNum + 4) % 5; // 現在の選択項目を一つ上にずらす(逆ループする)
}
if (Key[KEY_INPUT_DOWN] == 1 || Key[KEY_INPUT_UP] == 1) { // 下キーか、上キーが押された瞬間
for (int i = 0; i<5; i++) { // メニュー項目数である5個ループ処理
if (i == SelectNum) { // 今処理しているのが、選択番号と同じ要素なら
MenuElement[i].x = 80; // 座標を80にする
}
else { // 今処理しているのが、選択番号以外なら
MenuElement[i].x = 100;// 座標を100にする
}
}
}
if (SelectNum == 0 && Key[KEY_INPUT_Q] == 1) {
function_status = 2;
}
if (SelectNum == 1 && Key[KEY_INPUT_Q] == 1) {
function_status = 3;
}
if (SelectNum == 2 && Key[KEY_INPUT_Q] == 1) {
function_status = 4;
}
if (SelectNum == 3 && Key[KEY_INPUT_Q] == 1) {
function_status = 5;
}
}
void Danjon1() {
DrawString(100, 180, "第一ステージ (Oをプッシュ)", White);
if (Key[KEY_INPUT_O]) {
function_status = 3;
}
}
int IsAbleToGo1_A(int x, int y, int direction_a1) {//進む方向が通れるか通れないかを判定
if (direction_a1 == 0)//上向きなら
if (hantei_A[y / 32 - 1][x / 32] == 1)//進めるか判定
return 1;//エラー
if (direction_a1 == 1)//左向きなら
if (hantei_A[y / 32][x / 32 - 1] == 1)
return 1;
if (direction_a1 == 2)//下向きなら
if (hantei_A[y / 32 + 1][x / 32] == 1)
return 1;
if (direction_a1 == 3)//右向きなら
if (hantei_A[y / 32][x / 32 + 1] == 1)
return 1;
return 0;//正常
}
int IsAbleToGo1_B(int v, int z, int direction_a2) {//進む方向が通れるか通れないかを判定
if (direction_a2 == 0)//上向きなら
if (hantei_A[y / 32 - 1][x / 32] == 1)//進めるか判定
return 1;//エラー
if (direction_a2 == 1)//左向きなら
if (hantei_A[y / 32][x / 32 - 1] == 1)
return 1;
if (direction_a2 == 2)//下向きなら
if (hantei_A[y / 32 + 1][x / 32] == 1)
return 1;
if (direction_a2 == 3)//右向きなら
if (hantei_A[y / 32][x / 32 + 1] == 1)
return 1;
return 0;//正常
}
int IsAbleToGo2_A(int x, int y, int direction_b1) {//進む方向が通れるか通れないかを判定
if (direction_b1 == 0)//上向きなら
if (hantei_B[z / 32 - 1][v / 32] == 1)//進めるか判定
return 1;//エラー
if (direction_b1 == 1)//左向きなら
if (hantei_B[z / 32][v / 32 - 1] == 1)
return 1;
if (direction_b1 == 2)//下向きなら
if (hantei_B[z / 32 + 1][v / 32] == 1)
return 1;
if (direction_b1 == 3)//右向きなら
if (hantei_B[z / 32][v / 32 + 1] == 1)
return 1;
return 0;//正常
}
int IsAbleToGo2_B(int v, int z, int direction_b2) {//進む方向が通れるか通れないかを判定
if (direction_b2 == 0)//上向きなら
if (hantei_B[z / 32 - 1][v / 32] == 1)//進めるか判定
return 1;//エラー
if (direction_b2 == 1)//左向きなら
if (hantei_B[z / 32][v / 32 - 1] == 1)
return 1;
if (direction_b2 == 2)//下向きなら
if (hantei_B[z / 32 + 1][v / 32] == 1)
return 1;
if (direction_b2 == 3)//右向きなら
if (hantei_B[z / 32][v / 32 + 1] == 1)
return 1;
return 0;//正常
}
int IsAbleToGo3_A(int x, int y, int direction_c1) {//進む方向が通れるか通れないかを判定
if (direction_c1 == 0)//上向きなら
if (hantei_C[z / 32 - 1][v / 32] == 1)//進めるか判定
return 1;//エラー
if (direction_c1 == 1)//左向きなら
if (hantei_C[z / 32][v / 32 - 1] == 1)
return 1;
if (direction_c1 == 2)//下向きなら
if (hantei_C[z / 32 + 1][v / 32] == 1)
return 1;
if (direction_c1 == 3)//右向きなら
if (hantei_C[z / 32][v / 32 + 1] == 1)
return 1;
return 0;//正常
}
int IsAbleToGo3_B(int v, int z, int direction_c2) {//進む方向が通れるか通れないかを判定
if (direction_c2 == 0)//上向きなら
if (hantei_C[z / 32 - 1][v / 32] == 1)//進めるか判定
return 1;//エラー
if (direction_c2 == 1)//左向きなら
if (hantei_C[z / 32][v / 32 - 1] == 1)
return 1;
if (direction_c2 == 2)//下向きなら
if (hantei_C[z / 32 + 1][v / 32] == 1)
return 1;
if (direction_c2 == 3)//右向きなら
if (hantei_C[z / 32][v / 32 + 1] == 1)
return 1;
return 0;//正常
}
void magnet_a1(int x, int y, int direction_a1) {
if (direction_a1 == 0)//上向きなら
if (hantei_A[y / 32 - 1][x / 32] != 1)//進めるか判定
if (hantei_A[x][y >= 5] == 2 && Key[KEY_INPUT_I] >= 1)
y--;
if (direction_a1 == 1)//左向きなら
if (hantei_A[y / 32][x / 32 - 1] != 1)
if (hantei_A[x >= 5][y] == 2 && Key[KEY_INPUT_I] >= 1)
x--;
if (direction_a1 == 2)//下向きなら
if (hantei_A[y / 32 + 1][x / 32] != 1)
if (hantei_A[x][y <= 5] == 2 && Key[KEY_INPUT_I] >= 1)
y++;
if (direction_a1 == 3)//右向きなら
if (hantei_A[y / 32][x / 32 + 1] != 1)
if (hantei_A[x <= 5][y] == 2 && Key[KEY_INPUT_I] >= 1);
}
void magnet_a2(int x, int y, int direction_a2) {
if (direction_a2 == 0)//上向きなら
if (hantei_A[y / 32 - 1][x / 32] != 1)//進めるか判定
if (hantei_A[x][y >= 5] == 2 && Key[KEY_INPUT_U] >= 1)
y--;
if (direction_a2 == 1)//左向きなら
if (hantei_A[y / 32][x / 32 - 1] != 1)
if (hantei_A[x >= 5][y] == 2 && Key[KEY_INPUT_U] >= 1)
x--;
if (direction_a2 == 2)//下向きなら
if (hantei_A[y / 32 + 1][x / 32] != 1)
if (hantei_A[x][y <= 5] == 2 && Key[KEY_INPUT_U] >= 1)
y++;
if (direction_a2 == 3)//右向きなら
if (hantei_A[y / 32][x / 32 + 1] != 1)
if (hantei_A[x <= 5][y] == 2 && Key[KEY_INPUT_U] >= 1);
}
void magnet_b1(int x, int y, int direction_b1) {
if (direction_b1 == 0)//上向きなら
if (hantei_B[y / 32 - 1][x / 32] != 1)//進めるか判定
if (hantei_B[x][y >= 5] == 2 && Key[KEY_INPUT_I] >= 1)
y--;
if (direction_b1 == 1)//左向きなら
if (hantei_B[y / 32][x / 32 - 1] != 1)
if (hantei_B[x >= 5][y] == 2 && Key[KEY_INPUT_I] >= 1)
x--;
if (direction_b1 == 2)//下向きなら
if (hantei_B[y / 32 + 1][x / 32] != 1)
if (hantei_B[x][y <= 5] == 2 && Key[KEY_INPUT_I] >= 1)
y++;
if (direction_b1 == 3)//右向きなら
if (hantei_B[y / 32][x / 32 + 1] != 1)
if (hantei_B[x <= 5][y] == 2 && Key[KEY_INPUT_I] >= 1);
}
void magnet_b2(int x, int y, int direction_b2) {
if (direction_b2 == 0)//上向きなら
if (hantei_B[y / 32 - 1][x / 32] != 1)//進めるか判定
if (hantei_B[x][y >= 5] == 2 && Key[KEY_INPUT_U] >= 1)
y--;
if (direction_b2 == 1)//左向きなら
if (hantei_B[y / 32][x / 32 - 1] != 1)
if (hantei_B[x >= 5][y] == 2 && Key[KEY_INPUT_U] >= 1)
x--;
if (direction_b2 == 2)//下向きなら
if (hantei_B[y / 32 + 1][x / 32] != 1)
if (hantei_B[x][y <= 5] == 2 && Key[KEY_INPUT_U] >= 1)
y++;
if (direction_b2 == 3)//右向きなら
if (hantei_B[y / 32][x / 32 + 1] != 1)
if (hantei_B[x <= 5][y] == 2 && Key[KEY_INPUT_U] >= 1);
}
void magnet_c1(int x, int y, int direction_c1) {
if (direction_c1 == 0)//上向きなら
if (hantei_C[y / 32 - 1][x / 32] != 1)//進めるか判定
if (hantei_C[x][y >= 5] == 2 && Key[KEY_INPUT_I] >= 1)
y--;
if (direction_c1 == 1)//左向きなら
if (hantei_C[y / 32][x / 32 - 1] != 1)
if (hantei_C[x >= 5][y] == 2 && Key[KEY_INPUT_I] >= 1)
x--;
if (direction_c1 == 2)//下向きなら
if (hantei_C[y / 32 + 1][x / 32] != 1)
if (hantei_C[x][y <= 5] == 2 && Key[KEY_INPUT_I] >= 1)
y++;
if (direction_c1 == 3)//右向きなら
if (hantei_C[y / 32][x / 32 + 1] != 1)
if (hantei_C[x <= 5][y] == 2 && Key[KEY_INPUT_I] >= 1);
}
void magnet_c2(int x, int y, int direction_c2) {
if (direction_c2 == 0)//上向きなら
if (hantei_C[y / 32 - 1][x / 32] != 1)//進めるか判定
if (hantei_C[x][y >= 5] == 2 && Key[KEY_INPUT_U] >= 1)
y--;
if (direction_c2 == 1)//左向きなら
if (hantei_C[y / 32][x / 32 - 1] != 1)
if (hantei_C[x >= 5][y] == 2 && Key[KEY_INPUT_U] >= 1)
x--;
if (direction_c2 == 2)//下向きなら
if (hantei_C[y / 32 + 1][x / 32] != 1)
if (hantei_C[x][y <= 5] == 2 && Key[KEY_INPUT_U] >= 1)
y++;
if (direction_c2 == 3)//右向きなら
if (hantei_C[y / 32][x / 32 + 1] != 1)
if (hantei_C[x <= 5][y] == 2 && Key[KEY_INPUT_U] >= 1);
}
void gpCalc1_A() {
if (x % 32 == 0 && y % 32 == 0) {
walking_flag1 = 1;
if (Key[KEY_INPUT_UP] >= 1) { //上ボタンが押されたら
direction_1a = 0;
}
else if (Key[KEY_INPUT_LEFT] >= 1) { //左ボタンが押されたら
direction_1a = 1;
}
else if (Key[KEY_INPUT_DOWN] >= 1) { //下ボタンが押されたら
direction_1a = 2;
}
else if (Key[KEY_INPUT_RIGHT] >= 1) { //右ボタン
direction_1a = 3;
}
else {
walking_flag1 = 0;
}
}
if (walking_flag1 == 1) {
if (direction_1a == 0) {
y--;
}
else if (direction_1a == 1) {
x--;
}
else if (direction_1a == 2) {
y++;
}
else if (direction_1a == 3) {
x++;
}
if (walking_flag1 == 1) { //もし歩くなら
if (IsAbleToGo1_A(x, y, direction_1a) == 1)//行き先が歩けないなら
walking_flag1 = 0; //歩かないフラグを立てる。
}
if (walking_flag1 == 0) {
if (IsAbleToGo1_A(x, y, direction_1a) == 0)//行き先が歩けるなら
walking_flag1 = 1; //歩くフラグを立てる。
}
}
}
void gpCalc1_B() {
if (v % 32 == 0 && z % 32 == 0) {
walking_flag2 = 1;
if (Key[KEY_INPUT_W] >= 1) { //Wボタンが押されたら
direction_1b = 0;
}
else if (Key[KEY_INPUT_A] >= 1) { //Aボタンが押されたら
direction_1b = 1;
}
else if (Key[KEY_INPUT_Z] >= 1) { //Sボタンが押されたら
direction_1b = 2;
}
else if (Key[KEY_INPUT_S] >= 1) { //Zボタン
direction_1b = 3;
}
else {
walking_flag2 = 0;
}
}
if (walking_flag2 == 1) {
if (direction_1b == 0) {
z--;
}
else if (direction_1b == 1) {
v--;
}
else if (direction_1b == 2) {
z++;
}
else if (direction_1b == 3) {
v++;
}
if (walking_flag2 == 1) { //もし歩くなら
if (IsAbleToGo1_B(v, z, direction_1b) == 1)//行き先が歩けないなら
walking_flag2 = 0; //歩かないフラグを立てる。
}
if (walking_flag2 == 0) {
if (IsAbleToGo1_B(v, z, direction_1b) == 0)//行き先が歩けるなら
walking_flag2 = 1; //歩くフラグを立てる。
}
}
}
void gpCalc2_A() {
if (x % 32 == 0 && y % 32 == 0) {
walking_flag1 = 1;
if (Key[KEY_INPUT_UP] >= 1) { //上ボタンが押されたら
direction_2a = 0;
}
else if (Key[KEY_INPUT_LEFT] >= 1) { //左ボタンが押されたら
direction_2a = 1;
}
else if (Key[KEY_INPUT_DOWN] >= 1) { //下ボタンが押されたら
direction_2a = 2;
}
else if (Key[KEY_INPUT_RIGHT] >= 1) { //右ボタン
direction_2a = 3;
}
else {
walking_flag1 = 0;
}
}
if (walking_flag1 == 1) {
if (direction_2a == 0) {
y--;
}
else if (direction_2a == 1) {
x--;
}
else if (direction_2a == 2) {
y++;
}
else if (direction_2a == 3) {
x++;
}
if (walking_flag1 == 1) { //もし歩くなら
if (IsAbleToGo2_A(x, y, direction_2a) == 1)//行き先が歩けないなら
walking_flag1 = 0; //歩かないフラグを立てる。
}
if (walking_flag1 == 0) {
if (IsAbleToGo2_A(x, y, direction_2a) == 0)//行き先が歩けるなら
walking_flag1 = 1; //歩くフラグを立てる。
}
}
}
void gpCalc2_B() {
if (v % 32 == 0 && z % 32 == 0) {
walking_flag2 = 1;
if (Key[KEY_INPUT_W] >= 1) { //Wボタンが押されたら
direction_2b = 0;
}
else if (Key[KEY_INPUT_A] >= 1) { //Aボタンが押されたら
direction_2b = 1;
}
else if (Key[KEY_INPUT_Z] >= 1) { //Sボタンが押されたら
direction_2b = 2;
}
else if (Key[KEY_INPUT_S] >= 1) { //Zボタン
direction_2b = 3;
}
else {
walking_flag2 = 0;
}
}
if (walking_flag2 == 1) {
if (direction_2b == 0) {
z--;
}
else if (direction_2b == 1) {
v--;
}
else if (direction_2b == 2) {
z++;
}
else if (direction_2b == 3) {
v++;
}
if (walking_flag2 == 1) { //もし歩くなら
if (IsAbleToGo2_B(v, z, direction_2b) == 1)//行き先が歩けないなら
walking_flag2 = 0; //歩かないフラグを立てる。
}
if (walking_flag2 == 0) {
if (IsAbleToGo2_B(v, z, direction_2b) == 0)//行き先が歩けるなら
walking_flag2 = 1; //歩くフラグを立てる。
}
}
}
void gpCalc3_A() {
if (x % 32 == 0 && y % 32 == 0) {
walking_flag1 = 1;
if (Key[KEY_INPUT_UP] >= 1) { //上ボタンが押されたら
direction_3a = 0;
}
else if (Key[KEY_INPUT_LEFT] >= 1) { //左ボタンが押されたら
direction_3a = 1;
}
else if (Key[KEY_INPUT_DOWN] >= 1) { //下ボタンが押されたら
direction_3a = 2;
}
else if (Key[KEY_INPUT_RIGHT] >= 1) { //右ボタン
direction_3a = 3;
}
else {
walking_flag1 = 0;
}
}
if (walking_flag1 == 1) {
if (direction_3a == 0) {
y--;
}
else if (direction_3a == 1) {
x--;
}
else if (direction_3a == 2) {
y++;
}
else if (direction_3a == 3) {
x++;
}
if (walking_flag1 == 1) { //もし歩くなら
if (IsAbleToGo3_A(x, y, direction_2a) == 1)//行き先が歩けないなら
walking_flag1 = 0; //歩かないフラグを立てる。
}
if (walking_flag1 == 0) {
if (IsAbleToGo3_A(x, y, direction_2a) == 0)//行き先が歩けるなら
walking_flag1 = 1; //歩くフラグを立てる。
}
}
}
void gpCalc3_B() {
if (v % 32 == 0 && z % 32 == 0) {
walking_flag2 = 1;
if (Key[KEY_INPUT_W] >= 1) { //Wボタンが押されたら
direction_3b = 0;
}
else if (Key[KEY_INPUT_A] >= 1) { //Aボタンが押されたら
direction_3b = 1;
}
else if (Key[KEY_INPUT_Z] >= 1) { //Sボタンが押されたら
direction_3b = 2;
}
else if (Key[KEY_INPUT_S] >= 1) { //Zボタン
direction_3b = 3;
}
else {
walking_flag2 = 0;
}
}
if (walking_flag2 == 1) {
if (direction_3b == 0) {
z--;
}
else if (direction_3b == 1) {
v--;
}
else if (direction_3b == 2) {
z++;
}
else if (direction_3b == 3) {
v++;
}
if (walking_flag2 == 1) { //もし歩くなら
if (IsAbleToGo3_B(v, z, direction_2b) == 1)//行き先が歩けないなら
walking_flag2 = 0; //歩かないフラグを立てる。
}
if (walking_flag2 == 0) {
if (IsAbleToGo3_B(v, z, direction_2b) == 0)//行き先が歩けるなら
walking_flag2 = 1; //歩くフラグを立てる。
}
}
}
void gpDraw1() {
DrawRotaGraph(x, y, 1.0, 0.0, Handle1, TRUE);
}
void gpDraw2() {
DrawRotaGraph(v, z, 1.0, 0.0, Handle2, TRUE);
}
void Danjon2() {
DrawString(100, 220, "第二ステージ (vをプッシュ)", White);
if (Key[KEY_INPUT_V] == 1)
function_status = 4;
}
void Danjon3() {
DrawString(100, 220, "第三ステージ (Pをプッシュ)", White);
if (Key[KEY_INPUT_P] == 1)
function_status = 6;
}
void Guide() {
DrawString(100, 260, "操作方法 (Dをプッシュ)", White);
if (Key[KEY_INPUT_D] == 1)
function_status = 1;
}
void Ending() {
DrawString(100, 260, "エンディング画面 (bをプッシュ)", White);
if (Key[KEY_INPUT_B] == 1)
function_status = 7;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
ChangeWindowMode(TRUE); //ウィンドウモードに変更
if (DxLib_Init() == -1) return -1; // DXライブラリ初期化処理 エラーが起きたら終了
White = GetColor(255, 255, 255); //色の取得
SetDrawScreen(DX_SCREEN_BACK); // 描画先を裏画面に設定
while (1) {
ClearDrawScreen(); // 裏画面のデータを全て削除
gpUpdateKey(); // すべてのキーの状態を得る
switch (function_status) {
case 0:
Opening();
break;
case 1:
// メニュー項目の表示に必要な構造体を用意する
Menu();
for (int i = 0; i<5; i++) { // メニュー項目を描画
DrawFormatString(MenuElement[i].x, MenuElement[i].y, GetColor(255, 255, 255), MenuElement[i].name);
}
break;
case 2:
Danjon1();
int IsAbleToGo1_A(int x, int y, int direction_1a);
int IsAbleToGo1_B(int v, int z, int direction_1b);
void magnet_a1(int x, int y, int direction_a1);
void magnet_a2(int x, int y, int direction_a2);
gpCalc1_A();
gpDraw1();
gpCalc1_B();
gpDraw2();
/*白い壁を描画*/
for (int i = 0; i < 15; i++)
for (int j = 0; j < 20; j++)
if (hantei_A[i][j] == 1)
DrawBox(j * 32, i * 32, (j + 1) * 32, (i + 1) * 32, GetColor(255, 255, 255), TRUE);
//磁石ブロックを描画
for (int i = 0; i < 15; i++)
for (int j = 0; j < 20; j++)
if(hantei_A[i][j] ==2)
DrawBox(j * 32, i * 32, (j + 1) * 32, (i + 1) * 32, GetColor(0, 255, 255), TRUE);
LoadDivGraph("画像/キャラクタ10.png", 16, 4, 4, 32, 32, Image_a);//画像を16個に分割してImage_a配列に保存
LoadDivGraph("画像/キャラクタ10.png", 16, 4, 4, 32, 32, Image_b);//画像を16個に分割してImage_b配列に保存
DrawGraph(x, y, Image_a[(x % 32 + y % 32) / 8 + direction_1a * 4], TRUE);
DrawGraph(v, z, Image_b[(v % 32 + z % 32) / 8 + direction_1b * 4], TRUE);
//座標表示装置
DrawFormatString(0, 0, Green, "座標[%d,%d]", x, y); // 文字を描画する
DrawFormatString(0, 15, Green, "座標[%d,%d]", v, z); // 文字を描画する
break;
case 3:
Danjon2();
int IsAbleToGo2_A(int x, int y, int direction_2a);
int IsAbleToGo2_B(int v, int z, int direction_2b);
gpCalc2_A();
gpDraw1();
gpCalc2_B();
gpDraw2();
/*白い壁を描画*/
for (int i = 0; i < 15; i++)
for (int j = 0; j < 20; j++)
if (hantei_B[i][j] == 1)
DrawBox(j * 32, i * 32, (j + 1) * 32, (i + 1) * 32, GetColor(255, 255, 255), TRUE);
LoadDivGraph("画像/girl.jpg", 16, 4, 4, 28, 28, Image_a);//画像を16個に分割してImage_a配列に保存
LoadDivGraph("画像/girl.jpg", 16, 4, 4, 28, 28, Image_b);//画像を16個に分割してImage_b配列に保存
DrawGraph(x, y, Image_a[(x % 32 + y % 32) / 8 + direction_2a * 4], TRUE);
DrawGraph(v, z, Image_b[(v % 32 + z % 32) / 8 + direction_2b * 4], TRUE);
//座標表示装置
DrawFormatString(0, 0, Green, "座標[%d,%d]", x, y); // 文字を描画する
DrawFormatString(0, 15, Green, "座標[%d,%d]", v, z); // 文字を描画する
break;
case 4:
Danjon3();
int IsAbleToGo3_A(int x, int y, int direction_3a);
int IsAbleToGo3_B(int v, int z, int direction_3b);
gpCalc3_A();
gpDraw1();
gpCalc3_B();
gpDraw2();
/*白い壁を描画*/
for (int i = 0; i < 15; i++)
for (int j = 0; j < 20; j++)
if (hantei_C[i][j] == 1)
DrawBox(j * 32, i * 32, (j + 1) * 32, (i + 1) * 32, GetColor(255, 255, 255), TRUE);
LoadDivGraph("画像/girl.jpg", 16, 4, 4, 32, 32, Image_a);//画像を16個に分割してImage_a配列に保存
LoadDivGraph("画像/girl.jpg", 16, 4, 4, 32, 32, Image_b);//画像を16個に分割してImage_b配列に保存
DrawGraph(x, y, Image_a[(x % 32 + y % 32) / 8 + direction_3a * 4], TRUE);
DrawGraph(v, z, Image_b[(v % 32 + z % 32) / 8 + direction_3b * 4], TRUE);
//座標表示装置
DrawFormatString(0, 0, Green, "座標[%d,%d]", x, y); // 文字を描画する
DrawFormatString(0, 15, Green, "座標[%d,%d]", v, z); // 文字を描画する
break;
case 5:
Guide();
break;
case 6:
Ending();
break;
default:
DxLib_End(); // DXライブラリ使用の終了処理
return 0;
break;
}
if (ProcessMessage() == -1) break; //エラーが起きたら終了
ScreenFlip(); // 裏画面データを表画面へ反映
}
DxLib_End(); // DXライブラリ使用の終了処理
return 0; // ソフトの終了
}