コード:
#include "DxLib.h"
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
// Dxライブラリ初期設定
ChangeWindowMode(true); // 全画面false ウィンドウtrue
SetGraphMode(960,540,16); // 画面サイズ(横、縦、カラービット)
DxLib_Init(); // DXライブラリ初期化
SetDrawScreen(DX_SCREEN_BACK); // 裏画面設定
SetDrawMode(DX_DRAWMODE_BILINEAR); // 描画設定
SetWindowText("VsSTG"); // ウィンドウタイトル
// DXライブラリ初期化処理
if( DxLib_Init() == -1 ){
return -1; // エラーが起きたら直ちに終了
}
// map配列
int Map_1[9][16] =
{
{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,1,1,1,1,1,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,1,0,0,0,},
{0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},
};
int x,y; // プレイヤー座標
x = 100;
y = 400;
// 各頂点座標変数
int leftup_x,leftup_y;
int leftdown_x,leftdown_y;
int rightup_x,rightup_y;
int rightdown_x,rightdown_y;
// while(裏画面を表画面に反映, メッセージ処理, 画面クリア)
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 ){
// マップ描画
for(int i=0;i<9;i++){
for(int j=0;j<16;j++){
if(Map_1[i][j] == 1){
DrawBox(j*60,i*60, (j*60)+60,(i*60)+60,GetColor(255,255,255),1);
}
}
}
// 左上
leftup_x = x / 60;
leftup_y = y / 60;
// 左下
leftdown_x = x / 60;
leftdown_y = (y+60) / 60;
// 右上
rightup_x = (x+60) / 60;
rightup_y = y / 60;
// 右下
rightdown_x = (x+60) / 60;
rightdown_y = (y+60) / 60;
// 左上、左下、右下座標に触れるとき
if( Map_1[ leftup_y ] [leftup_x ] == 1 &&
Map_1[ leftdown_y ] [leftdown_x ] == 1 &&
Map_1[ rightdown_y ] [rightdown_x ] == 1){
DrawString(50,90,"left kado col",GetColor(0,255,0));
x = x / 60*60 + 60;
y = y / 60*60 ;
}else
// 右上、右下、左下座標に触れるとき
if( Map_1[ rightup_y ] [rightup_x ] == 1 &&
Map_1[ rightdown_y ] [rightdown_x ] == 1 &&
Map_1[ leftdown_y ] [leftdown_x ] == 1){
DrawString(50,90,"right kado col",GetColor(0,255,0));
x = x / 60*60;
y = y / 60*60;
}else
// 左上、左下座標に触れるとき
if( Map_1[ leftup_y ] [leftup_x ] == 1 &&
Map_1[ leftdown_y ] [leftdown_x ] == 1 ){
DrawString(50,90,"left col",GetColor(0,255,0));
x = x / 60*60 + 60;
}else
// 左上のみ触れている時
if( Map_1[ leftup_y ] [leftup_x ] == 1 &&
Map_1[ leftdown_y ] [leftdown_x ] == 0 &&
Map_1[ rightdown_y ] [rightdown_x ] == 0 &&
Map_1[ rightup_y ] [rightup_x ] == 0){
DrawString(50,90,"leftup col",GetColor(0,255,0));
x = x / 60*60 + 60;
}else
// 左下のみ触れている時
if( Map_1[ leftup_y ] [leftup_x ] == 0 &&
Map_1[ leftdown_y ] [leftdown_x ] == 1 &&
Map_1[ rightdown_y ] [rightdown_x ] == 0 &&
Map_1[ rightup_y ] [rightup_x ] == 0){
DrawString(50,90,"leftdown col",GetColor(0,255,0));
x = x / 60*60 + 60;
}else
// 右上、右下座標に触れるとき
if( (Map_1[ rightup_y ] [rightup_x ] == 1 &&
Map_1[ rightdown_y ] [rightdown_x ] == 1)){
DrawString(50,90,"right col",GetColor(0,255,0));
x = x / 60*60;
}else
// 右上のみ触れている時
if( Map_1[ leftup_y ] [leftup_x ] == 0 &&
Map_1[ leftdown_y ] [leftdown_x ] == 0 &&
Map_1[ rightdown_y ] [rightdown_x ] == 0 &&
Map_1[ rightup_y ] [rightup_x ] == 1){
DrawString(50,90,"rightup col",GetColor(0,255,0));
x = x / 60*60;
}else
// 右上のみ触れている時
if( Map_1[ leftup_y ] [leftup_x ] == 0 &&
Map_1[ leftdown_y ] [leftdown_x ] == 0 &&
Map_1[ rightdown_y ] [rightdown_x ] == 1 &&
Map_1[ rightup_y ] [rightup_x ] == 0){
DrawString(50,90,"rightdown col",GetColor(0,255,0));
x = x / 60*60;
}else
// 左上、右上座標に触れるとき
if( Map_1[ leftup_y ] [leftup_x ] == 1 &&
Map_1[ rightup_y ] [rightup_x ] == 1 ){
DrawString(50,90,"up col",GetColor(0,255,0));
y = y / 60*60 + 60;
}else
// 左下、右下座標に触れるとき
if( Map_1[ leftdown_y ] [leftdown_x ] == 1 &&
Map_1[ rightdown_y ] [rightdown_x ] == 1 ){
DrawString(50,90,"down col",GetColor(0,255,0));
y = y / 60*60 ;
}
DrawBox(x,y, x+64,y+64,GetColor(255,0,0),1);
if(CheckHitKey(KEY_INPUT_RIGHT) == 1){
x+=5;
}
if(CheckHitKey(KEY_INPUT_LEFT) == 1){
x-=5;
}
if(CheckHitKey(KEY_INPUT_UP) == 1){
y-=5;
}
if(CheckHitKey(KEY_INPUT_DOWN) == 1){
y+=5;
}
}
WaitKey(); // キー入力待ち
DxLib_End(); // DXライブラリ終了処理
return 0;
}