C++ Pac-Man | 1~2일차 | 메인화면 & 로딩창 & 맵 구현
2021. 11. 9. 23:18ㆍ개발 | 프로젝트/C++ Pac-Man
728x90
#include<cstdio>
#include<iostream>
#include<windows.h>
#include<ctime>
#include<cstdlib>
#include<vector>
using namespace std;
/*
1 : 채도 낮은 파랑색
2 : 채도 낮은 녹색
3 : 채도 낮은 하늘색
4 : 채도 낮은 빨간색
5 : 채도 낮은 분홍색
6 : 채도 낮은 노란색
7 : 연회색
8 : 회색
9 : 파랑색
10 : 초록색
11 : 하늘색
12 : 빨간색
13 : 분홍색
14 : 노랑색
15 : 흰색
*/
int x, y;
int map[24][98]={
{1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2},
{6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6},
{6,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,0,6,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,0,6},
{6,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,6,0,0,0,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0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,6,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,6},
{6,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,6,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,0,6},
{6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6},
{3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4},
};
struct player{
int coin;
bool power;
bool death;
};
void gotoxy(int X, int Y) {
COORD pos = { X,Y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void setcolor(unsigned short text,unsigned short back){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),text|(back<<4));
}
void CursorView()
{
CONSOLE_CURSOR_INFO cursorInfo = { 0, };
cursorInfo.dwSize = 1;
cursorInfo.bVisible = FALSE;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo);
}
void set() {
system("mode con:cols=100 lines=25");
system("title Pac-Man_made_by_Aegis");
x = 33, y = 10;
gotoxy(x, y);
setcolor(12,0);
printf("==================================");
gotoxy(x, y + 1);
printf("=== ");
setcolor(14,0);
printf("Pac-Man!");
setcolor(12,0);
printf(" ===");
gotoxy(x, y + 2);
printf("==================================");
gotoxy(x, y + 3);
setcolor(14,0);
printf("엔터 키를 누르면 게임이 시작됩니다");
}
void start() {
char ch;
while (true) {
cin.get(ch);
if (ch == '\n') {
system("cls");
return;
}
}
}
void loading(int q,int p) {
x = 36, y = 10;
gotoxy(x, y);
for (int i = 0; i <= q;i++) {
printf("■");
}
for (int i = 0; i <= p;i++) {
printf("□");
}
gotoxy(x,y+1);
printf(" loading...");
Sleep(250);
system("cls");
}
void table() {
x = 1, y = 1;
setcolor(9,0);
for (int i = 0; i < 23;i++) {
for (int j = 0; j < 97;j++) {
gotoxy(x,y);
if (map[i][j]==0) {
printf(" ");
}
else{
printf("▣");
}
x++;
}
y++;
x=1;
}
start();
}
void playgame() {
table();
}
int main() {
CursorView();
set();
start();
system("mode con:cols=100 lines=25");
system("title Pac-Man_made_by_Aegis");
setcolor(15,0);
for (int i = 0; i < 12;i++) {
loading(i,10-i);
}
playgame();
}
우선 메인화면, 로딩 창, 기본 팩맨 게임 맵 구현을 진행해봤습니다.
첫날인데도 불구하고 시간이 굉장히 많이 걸렸습니다.
특히 배열에 하나하나 정수를 넣어서 맵을 구현하는 부분에 2시간 정도는 쏟은 것 같습니다.
그래도 나중에 하나하나 충돌처리를 하면서 버릴 시간에 비하면 2시간은 싸게 먹힌 듯합니다.
다음 차시부턴 맵 위에 코인을 생성하고, 구조체를 이용하여 몹과 플레이어를 구현해보겠습니다.
728x90