예전부터 게임개발을 해보고 싶었는데,
언리얼이나 로블록스 책은 많은데 게임개발 무경력자에겐 왠지 어림없어보였다.
그러던 중 레트로게임바이블 책을 발견했다
어렸을때 플레이했던 재믹스의 마성전설이 예시로 소개되어 눈길을 끌었다.
상대적으로 쉬어보이는 그래픽과 로직, C로 개발할 수 있다니 자신감도 붙는다.
https://github.com/pdpdds/retrogamedev.git
GitHub - pdpdds/retrogamedev: retro game development book helper
retro game development book helper. Contribute to pdpdds/retrogamedev development by creating an account on GitHub.
github.com
서론이 길었다.
8번예제의 소코반 = 박스옮기기 게임 과제 풀이한 내용이다.
과제1. 새로운 맵추가, g_stage 배열 1번에 위치시키기
//game.c
const unsigned char g_map6[SOCOBAN_MAX_WIDTH][SOCOBAN_MAX_HEIGHT] = {
{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, 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, 1, 1, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 3, 2, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 3, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 3, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 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, 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, 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}};
const unsigned char (*g_stages[MAX_STAGE_NUM])[SOCOBAN_MAX_WIDTH][SOCOBAN_MAX_HEIGHT] = {
&g_map6,
&g_map1,
&g_map2,
&g_map3,
&g_map4,
&g_map5,
};
과제2
UpdateGameStatus함수에서 iCurrentExactBoxCount 동적 구하기 -> 정적 구하도록
//game.c
char ProcessMove(char xdir, char ydir)
{
if (xdir == 0 && ydir == 0)
return 0;
g_playerInfo.prev_x = g_playerInfo.x;
g_playerInfo.prev_y = g_playerInfo.y;
g_playerInfo.x += xdir;
g_playerInfo.y += ydir;
if (!IsCanGo(xdir, ydir))
{
g_playerInfo.x -= xdir;
g_playerInfo.y -= ydir;
return 0;
}
uint8_t xPos = g_playerInfo.x;
uint8_t yPos = g_playerInfo.y;
if (g_mapInfo.boxInfo[yPos][xPos] == SPACE_BOX)
{
g_mapInfo.boxInfo[yPos][xPos] = SPACE_EMPTY;
g_mapInfo.boxInfo[yPos + ydir][xPos + xdir] = SPACE_BOX;
//추가한 코드
if (g_mapInfo.boxInfo[yPos + ydir][xPos + xdir] == SPACE_BOX && g_mapInfo.mapData[yPos + ydir][xPos + xdir] == SPACE_BOX_POINT)
g_mapInfo.boxCount--;
}
return 1;
}
void UpdateGameStatus()
{
//불필요 코드 주석처리
// uint8_t iCurrentExactBoxCount = 0;
// for (uint8_t y = 0; y < SOCOBAN_MAX_HEIGHT; y++)
// for (uint8_t x = 0; x < SOCOBAN_MAX_WIDTH; x++)
// {
// if (g_mapInfo.boxInfo[y][x] == SPACE_BOX && g_mapInfo.mapData[y][x] == SPACE_BOX_POINT)
// iCurrentExactBoxCount++;
// }
// if (iCurrentExactBoxCount == g_mapInfo.boxCount)
// {
// g_mapInfo.stageNum++;
// g_mapInfo.boxCount = 0;
// g_gamestate = STATE_GAME_CLEAR;
// }
// 추가
if (g_mapInfo.boxCount == 0)
{
g_mapInfo.stageNum++;
g_gamestate = STATE_GAME_CLEAR;
}
}
과제3
int -> uint8_t 로 타입 변환
이건 그냥 하면 됨.
실행해보자.

728x90