#include "DxLib.h" #include "time.h" #include int Key[256]; int GetHitKeyStateAll_2(int KeyStateBuf[]){ char GetHitKeyStateAll_Key[256]; GetHitKeyStateAll( GetHitKeyStateAll_Key ); for(int i=0;i<256;i++){ if(GetHitKeyStateAll_Key[i]==1) KeyStateBuf[i]++; else KeyStateBuf[i]=0; } return 0; } enum MapChipID { MAP_NONE, MAP_WALL, MAP_FLOOR }; enum DirectID { DIRECT_RIGHT, DIRECT_LEFT, DIRECT_UP, DIRECT_DOWN }; enum MoveID { MOVE_NONE, MOVE_RIGHT, MOVE_LEFT, MOVE_UP, MOVE_DOWN }; enum CameraTypeID { CAMERA_PLAYER, //Playerが中心になるようにする CAMERA_FREE, //Playerの位置無視。 CAMERA_SCROLL_R, //右に強制スクロール CAMERA_SCROLL_L //左に強制スクロール }; struct MapInfo { MapChipID m_ChipID; int m_ObjectUniqID[2]; MapInfo(){ m_ChipID = MAP_NONE; m_ObjectUniqID[0] = m_ObjectUniqID[1] = 0; } }; struct PlayerInfo { int m_PosX, m_PosY; MoveID m_MoveFlag; DirectID m_Direct; PlayerInfo(){ m_PosX = m_PosY = 0; m_Direct = DIRECT_DOWN; m_MoveFlag = MOVE_NONE; } }; struct CameraInfo { int m_PosX; int m_PosY; CameraTypeID m_Type; CameraInfo(){ m_PosX = 0; m_PosY = 0; m_Type = CAMERA_PLAYER; } }; struct MapWindowInfo { int m_PosX, m_PosY; int m_MapWindowWidth; int m_MapWindowHeight; MapWindowInfo(){ m_PosX = m_PosY = 0; m_MapWindowWidth = 0; m_MapWindowHeight = 0; } }; PlayerInfo g_Player; std::vector g_CameraVec; MapWindowInfo g_MapWindow; int g_NowCameraNum = 0; int g_StartMoveTime = 0; const int g_MoveTime = 100; int g_PrePosX = 0, g_PrePosY = 0; int g_Map[][80] = {{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,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1,1,0,1,1,1,0,0,0,1,1,1,0,1,1,1,0,0,0,1,0,0,0,1,1,1,0,0,0,1,1,1,0,1,1,1,0,0,0,1,1,1,0,1,1,1,0,0,0,1,1,1,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,0,0,0,0,0,0,0,0,0,0,0,0,}}; std::vector> g_MapVec; int g_White = 0; int g_Red = 0; int g_Yellow = 0; int g_MapChipLength = 16; void LoadMap() { int t_HeightNum = sizeof(g_Map) / sizeof(g_Map[0]); int t_WidthNum = sizeof(g_Map[0]) / sizeof(g_Map[0][0]); g_MapVec.resize(t_HeightNum); for(int y = 0; y < t_HeightNum; y++) { g_MapVec[y].resize(t_WidthNum); for(int x = 0; x < t_WidthNum; x++) { switch(g_Map[y][x]){ case 0: g_MapVec[y][x].m_ChipID = MAP_WALL;break; case 1: g_MapVec[y][x].m_ChipID = MAP_FLOOR;break; default:break; } } } } void MovePlayer() { //MoveFlagが設定されていないとき、キー入力を受け付ける if(g_Player.m_MoveFlag == MOVE_NONE){ int t_KeyType[4] = { KEY_INPUT_RIGHT, KEY_INPUT_LEFT, KEY_INPUT_UP, KEY_INPUT_DOWN}; MoveID t_MoveType[4] = { MOVE_RIGHT, MOVE_LEFT, MOVE_UP, MOVE_DOWN}; int t_NextPosX[4] = {1,-1, 0, 0}; int t_NextPosY[4] = {0, 0,-1, 1}; int t_NowPosX = g_Player.m_PosX/g_MapChipLength; int t_NowPosY = g_Player.m_PosY/g_MapChipLength; if(g_MapVec.size() > 0 && t_NowPosY > 0 && g_MapVec.size() > t_NowPosY){ if(g_MapVec[0].size() > 0 && t_NowPosX > 0 && g_MapVec[0].size() > t_NowPosX){ for(int i = 0; i < 4; i++) { if(Key[t_KeyType[i]] >= 1){ if(g_MapVec[t_NowPosY + t_NextPosY[i]][t_NowPosX + t_NextPosX[i]].m_ChipID == MAP_FLOOR){ g_Player.m_MoveFlag = t_MoveType[i]; g_PrePosX = g_Player.m_PosX; g_PrePosY = g_Player.m_PosY; g_StartMoveTime = timeGetTime(); } break; } } } } } //MoveFlagが設定されているとき、移動を行う if(g_Player.m_MoveFlag != MOVE_NONE){ float t_Rate = (float)(timeGetTime() - g_StartMoveTime) / g_MoveTime; if(t_Rate > 1.0f){ t_Rate = 1.0f; } switch(g_Player.m_MoveFlag){ case MOVE_RIGHT: g_Player.m_PosX = g_PrePosX + t_Rate*g_MapChipLength;break; case MOVE_LEFT: g_Player.m_PosX = g_PrePosX - t_Rate*g_MapChipLength;break; case MOVE_UP: g_Player.m_PosY = g_PrePosY - t_Rate*g_MapChipLength;break; case MOVE_DOWN: g_Player.m_PosY = g_PrePosY + t_Rate*g_MapChipLength;break; default:break; } if(t_Rate == 1.0f){ g_Player.m_MoveFlag = MOVE_NONE; } } } int SetPlayer(int t_PosX, int t_PosY) { int result = -1; if(g_MapVec.size() > 0 && t_PosY >= 0 && g_MapVec.size() > t_PosY){ if(g_MapVec[0].size() > 0 && t_PosX >= 0 && g_MapVec.size() > t_PosX){ g_Player.m_PosX = g_MapChipLength*t_PosX; g_Player.m_PosY = g_MapChipLength*t_PosY; result = 0; } } return(result); } int SetWindow(int t_MapWidthNum, int t_MapHeightNum, int t_WindowPosX, int t_WindowPosY) { int result = -1; if(t_MapWidthNum > 0 && t_MapHeightNum > 0){ g_MapWindow.m_MapWindowWidth = t_MapWidthNum; g_MapWindow.m_MapWindowHeight = t_MapHeightNum; g_MapWindow.m_PosX = t_WindowPosX; g_MapWindow.m_PosY = t_WindowPosY; result = 0; } return(result); } void AddCamera(CameraInfo& t_Info) { //ループ中にこの関数を呼んでしまった場合の、 //カメラ無限生成を防ぐ。(1024個までにする) if(g_CameraVec.size() < 1024){ if(t_Info.m_PosY >= 0 && t_Info.m_PosX >= 0){ g_CameraVec.push_back(t_Info); } } } int GetNowCameraPosX() { int result = 0; if( g_NowCameraNum < g_CameraVec.size()){ result = g_CameraVec[g_NowCameraNum].m_PosX; } return(result); } int GetNowCameraPosY() { int result = 0; if( g_NowCameraNum < g_CameraVec.size()){ result = g_CameraVec[g_NowCameraNum].m_PosY; } return(result); } void MoveCameraPlayer() { g_CameraVec[g_NowCameraNum].m_PosX = g_Player.m_PosX - (g_MapWindow.m_MapWindowWidth>>1)*g_MapChipLength; g_CameraVec[g_NowCameraNum].m_PosY = g_Player.m_PosY - (g_MapWindow.m_MapWindowHeight>>1)*g_MapChipLength; if( g_CameraVec[g_NowCameraNum].m_PosX < 0){ g_CameraVec[g_NowCameraNum].m_PosX = 0; }else if(GetNowCameraPosX()/g_MapChipLength + g_MapWindow.m_MapWindowWidth >= g_MapVec[0].size()){ g_CameraVec[g_NowCameraNum].m_PosX = (g_MapVec[0].size() - g_MapWindow.m_MapWindowWidth)*g_MapChipLength; } if( g_CameraVec[g_NowCameraNum].m_PosY < 0){ g_CameraVec[g_NowCameraNum].m_PosY = 0; }else if(g_CameraVec[g_NowCameraNum].m_PosY > (g_MapVec.size() - g_MapWindow.m_MapWindowHeight)*g_MapChipLength){ g_CameraVec[g_NowCameraNum].m_PosY = (g_MapVec.size() - g_MapWindow.m_MapWindowHeight)*g_MapChipLength; } } void MoveCameraFree() { } void MoverCameraScrollR() { if(g_MapVec.size() > 0 && g_MapVec[0].size()){ if( g_CameraVec[g_NowCameraNum].m_PosX + g_MapWindow.m_MapWindowWidth*g_MapChipLength < g_MapVec[0].size()*g_MapChipLength){ g_CameraVec[g_NowCameraNum].m_PosX += 1; } } } void MoverCameraScrollL() { if(g_MapVec.size() > 0 && g_MapVec[0].size()){ if( g_CameraVec[g_NowCameraNum].m_PosX > 0){ g_CameraVec[g_NowCameraNum].m_PosX -= 1; } } } void MoveCamera() { if(g_CameraVec.size() > 0 && g_NowCameraNum >= 0 && g_CameraVec.size() > g_NowCameraNum){ switch(g_CameraVec[g_NowCameraNum].m_Type){ case CAMERA_PLAYER: MoveCameraPlayer();break; case CAMERA_FREE: MoveCameraFree();break; case CAMERA_SCROLL_R: MoverCameraScrollR();break; case CAMERA_SCROLL_L: MoverCameraScrollL();break; default:break; } } } void DrawFrame() { for(int y = 0, count = g_MapWindow.m_MapWindowHeight + 2; y < count; y++) { for(int x = 0, count2 = g_MapWindow.m_MapWindowWidth + 2; x < count2; x++) { if(y % (g_MapWindow.m_MapWindowHeight + 1) == 0 || x % (g_MapWindow.m_MapWindowWidth + 1) == 0){ DrawString( g_MapWindow.m_PosX + g_MapChipLength*x - g_MapChipLength, g_MapWindow.m_PosY + g_MapChipLength*y - g_MapChipLength, "■", g_Yellow); } } } } void DrawMap() { int t_BaseX = GetNowCameraPosX()/g_MapChipLength; int t_BaseY = GetNowCameraPosY()/g_MapChipLength; for(int y = t_BaseY, count = (int)g_MapVec.size(); y < count && y < t_BaseY + g_MapWindow.m_MapWindowHeight + 1; y++) { if(y < 0){ break; } for(int x = t_BaseX, count2 = (int)g_MapVec[y].size(); x < count2 && x < t_BaseX + g_MapWindow.m_MapWindowWidth + 1; x++) { if(x < 0){ break; } int t_DifX = -GetNowCameraPosX() + g_MapWindow.m_PosX; int t_DifY = -GetNowCameraPosY() + g_MapWindow.m_PosY; switch(g_MapVec[y][x].m_ChipID){ case MAP_FLOOR: DrawString( x*g_MapChipLength + t_DifX, y*g_MapChipLength + t_DifY, "・", g_White);break; case MAP_WALL: DrawString( x*g_MapChipLength + t_DifX, y*g_MapChipLength + t_DifY, "■", g_White);break; default:break; } } } } void DrawPlayer() { int t_DifX = -GetNowCameraPosX() + g_MapWindow.m_PosX; int t_DifY = -GetNowCameraPosY() + g_MapWindow.m_PosY; DrawString( g_Player.m_PosX + t_DifX, g_Player.m_PosY + t_DifY, "▼", g_Red); } int g_DebugModeFlag = 0; int DebugExec() { if(Key[KEY_INPUT_C] == 1){ g_DebugModeFlag = 1; }else if(Key[KEY_INPUT_W] == 1){ g_DebugModeFlag = 2; }else if(Key[KEY_INPUT_P] == 1){ g_DebugModeFlag = 3; }else if(Key[KEY_INPUT_L] == 1){ g_DebugModeFlag = 4; }else if(Key[KEY_INPUT_U] == 1){ g_DebugModeFlag = 0; } switch(g_DebugModeFlag){ case 1: if(Key[KEY_INPUT_UP] == 1){ g_NowCameraNum = (g_NowCameraNum + (g_CameraVec.size() - 1)) % g_CameraVec.size(); }else if(Key[KEY_INPUT_DOWN] == 1){ g_NowCameraNum = (g_NowCameraNum + 1) % g_CameraVec.size(); } break; case 2: if(Key[KEY_INPUT_RIGHT] == 1 || (Key[KEY_INPUT_RIGHT] > 6 && Key[KEY_INPUT_RIGHT] % 6 == 0)){ if(GetNowCameraPosX()/g_MapChipLength + g_MapWindow.m_MapWindowWidth < g_MapVec[0].size()){ g_MapWindow.m_MapWindowWidth += 1; } }else if(Key[KEY_INPUT_LEFT] == 1 || (Key[KEY_INPUT_LEFT] > 6 && Key[KEY_INPUT_LEFT] % 6 == 0)){ if(g_MapWindow.m_MapWindowWidth - 1 > 0){ g_MapWindow.m_MapWindowWidth -= 1; } } if(Key[KEY_INPUT_UP] == 1 || (Key[KEY_INPUT_UP] > 6 && Key[KEY_INPUT_UP] % 6 == 0)){ if(g_MapWindow.m_MapWindowHeight - 1 > 0){ g_MapWindow.m_MapWindowHeight -= 1; } }else if(Key[KEY_INPUT_DOWN] == 1 || (Key[KEY_INPUT_DOWN] > 6 && Key[KEY_INPUT_DOWN] % 6 == 0)){ if(GetNowCameraPosY()/g_MapChipLength + g_MapWindow.m_MapWindowHeight < g_MapVec.size()){ g_MapWindow.m_MapWindowHeight += 1; } } break; case 3: if(Key[KEY_INPUT_RIGHT] >= 1){ g_MapWindow.m_PosX += 2; }else if(Key[KEY_INPUT_LEFT] >= 1){ g_MapWindow.m_PosX -= 2; } if(Key[KEY_INPUT_UP] >= 1){ g_MapWindow.m_PosY -= 2; }else if(Key[KEY_INPUT_DOWN] >= 1){ g_MapWindow.m_PosY += 2; } break; case 4: if(Key[KEY_INPUT_RIGHT] == 1){ if(g_MapChipLength < 64){ g_Player.m_PosX = (g_Player.m_PosX/g_MapChipLength)*(g_MapChipLength + 8); g_Player.m_PosY = (g_Player.m_PosY/g_MapChipLength)*(g_MapChipLength + 8); g_MapChipLength += 8; } }else if(Key[KEY_INPUT_LEFT] == 1){ if(g_MapChipLength > 8){ g_Player.m_PosX = (g_Player.m_PosX/g_MapChipLength)*(g_MapChipLength - 8); g_Player.m_PosY = (g_Player.m_PosY/g_MapChipLength)*(g_MapChipLength - 8); g_MapChipLength -= 8; } } default:break; } SetFontSize( 16 ); //選択中を示す、表示枠の表示 switch(g_DebugModeFlag){ case 1: for(int i = 0, count = g_CameraVec.size() + 2; i < count; i++) { if( i % (count - 1) == 0){ DrawString( 700 - 12, 670 - 16 + i*16, "■■■■■■■■■■■■■■■■■■■", g_White); }else{ DrawString( 700 - 12, 670 - 16 + i*16, "■                 ■", g_White); } } break; case 2: DrawString( 400 - 16, 670 - 16, "■■■■■■■■■■■■■■■■■■■", g_White); DrawString( 400 - 16, 670 - 16 + 16, "■                 ■", g_White); DrawString( 400 - 16, 670 - 16 + 32, "■■■■■■■■■■■■■■■■■■■", g_White); break; case 3: DrawString( 400 - 16, 670 - 16 + 32, "■■■■■■■■■■■■■■■■■■■", g_White); DrawString( 400 - 16, 670 - 16 + 48, "■                 ■", g_White); DrawString( 400 - 16, 670 - 16 + 64, "■■■■■■■■■■■■■■■■■■■", g_White); break; case 4: DrawString( 62 - 16, 670 - 16, "■■■■■■■■■■■■■■■■■■", g_White); DrawString( 62 - 16, 670 - 16 + 16, "■                ■", g_White); DrawString( 62 - 16, 670 - 16 + 32, "■■■■■■■■■■■■■■■■■■", g_White); break; case 0: DrawString( 62 - 16, 670 - 16 + 32, "■■■■■■■■■■■■■■■■■■", g_White); DrawString( 62 - 16, 670 - 16 + 48, "■                ■", g_White); DrawString( 62 - 16, 670 - 16 + 64, "■■■■■■■■■■■■■■■■■■", g_White); break; default:break; } //現在のマップチップの大きさの表示 DrawString( 62 - 54, 670, "【L】", g_Yellow); DrawFormatString( 62, 670, g_White, "マップチップ = %2d × %2d", g_MapChipLength, g_MapChipLength); //プレイヤー座標の表示 DrawString( 62 - 54, 702, "【U】", g_Yellow); DrawFormatString( 62, 702, g_White, "プレイヤー座標 = (%4d × %4d)", g_Player.m_PosX, g_Player.m_PosY); //現在のマップサイズの表示 DrawString( 400 - 54, 670, "【W】", g_Yellow); DrawFormatString( 400, 670, g_White, "マップサイズ    = %3d × %3d", g_MapWindow.m_MapWindowWidth, g_MapWindow.m_MapWindowHeight); //描画開始位置の表示 DrawString( 400 - 54, 702, "【P】", g_Yellow); DrawFormatString( 400, 702, g_White, "マップ描画開始位置 = %3d × %3d", g_MapWindow.m_PosX, g_MapWindow.m_PosY); //現在設定中のカメラ/カメラ一覧の表示 for(int i = 0, count = g_CameraVec.size(); i < count; i++) { int t_Color = g_White; if(i == g_NowCameraNum){ t_Color = g_Yellow; } switch(g_CameraVec[i].m_Type){ case CAMERA_PLAYER: DrawFormatString( 700, 670 + i*16, t_Color, "【%02d】主人公中心  :(%4d, %4d)", i + 1, g_CameraVec[i].m_PosX, g_CameraVec[i].m_PosY);break; case CAMERA_FREE: DrawFormatString( 700, 670 + i*16, t_Color, "【%02d】主人公無視  :(%4d, %4d)", i + 1, g_CameraVec[i].m_PosX, g_CameraVec[i].m_PosY);break; case CAMERA_SCROLL_R: DrawFormatString( 700, 670 + i*16, t_Color, "【%02d】強制視点移動右:(%4d, %4d)", i + 1, g_CameraVec[i].m_PosX, g_CameraVec[i].m_PosY);break; case CAMERA_SCROLL_L: DrawFormatString( 700, 670 + i*16, t_Color, "【%02d】強制視点移動左:(%4d, %4d)", i + 1, g_CameraVec[i].m_PosX, g_CameraVec[i].m_PosY);break; default:break; } } DrawString( 600, 650 + 16, " ",g_White); //デバッグ用に16のサイズにしたフォントを元のサイズに戻す SetFontSize( g_MapChipLength ); return(g_DebugModeFlag); } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){ ChangeWindowMode( TRUE ); if(DxLib_Init() == -1 ) return -1; SetDrawScreen( DX_SCREEN_BACK ); SetGraphMode(1024, 768, 32); SetWindowPosition( 100, -24 ); SetBackgroundColor(0,0,70); srand((unsigned int)time(NULL)); SetFontSize( g_MapChipLength ) ; g_White = GetColor(255,255,255); g_Red = GetColor(255,0,0); g_Yellow = GetColor(255,255,0); LoadMap(); if(SetPlayer(20, 20) == -1){ return(0); } if(SetWindow( 5, 5, 300, 300) == -1){ return(0); } const int CAMERA_NUM = 5; int t_CameraPosX[CAMERA_NUM] = {0,15,0,0,15}; int t_CameraPosY[CAMERA_NUM] = {0,0,0,0,0}; CameraTypeID t_CameraType[CAMERA_NUM] = {CAMERA_PLAYER, CAMERA_FREE, CAMERA_FREE, CAMERA_SCROLL_R, CAMERA_SCROLL_L}; for(int i = 0; i < CAMERA_NUM; i++) { CameraInfo t_Info; t_Info.m_PosX = t_CameraPosX[i]*g_MapChipLength; t_Info.m_PosY = t_CameraPosY[i]*g_MapChipLength; t_Info.m_Type = t_CameraType[i]; AddCamera(t_Info); } while(ProcessMessage()==0 && ClearDrawScreen()==0 && GetHitKeyStateAll_2(Key)==0){ if(DebugExec() == 0){ MovePlayer(); } MoveCamera(); DrawMap(); DrawPlayer(); DrawFrame(); ScreenFlip(); } DxLib_End(); return 0; }