#include <iostream>
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
using namespace std;
#define width 800
#define height 800
//e:empty w:wall t:target b:box p:player
char maps[8][8] = { {'w','w','w','w','w','w','w','w'},
{'w','w','w','t','b','e','e','w'},
{'w','e','e','e','e','e','e','w'},
{'w','e','e','e','e','e','e','w'},
{'w','e','e','e','e','e','e','w'},
{'w','e','p','b','t','e','e','w'},
{'w','e','e','e','w','w','w','w'},
{'w','w','w','w','w','w','w','w'}
};
int block_size = 100;
int player_x = 350;
int player_y = 350;
bool running = true;
int box1_x = 450;
int box1_y = 150;
int box2_x = 450;
int box2_y = 50;
int m1 = 1; int n1 = 4;
int m2 = 5; int n2 = 3;
void startup()
{
initgraph(width, height);
setbkcolor(RGB(150, 150, 150));
cleardevice();
}
void PlayerMove()
{
setfillcolor(RED);
setlinecolor(RED);
fillcircle(player_x, player_y, 45);
setfillcolor(BLACK);
fillcircle(player_x - 20, player_y - 10, 10);
fillcircle(player_x + 20, player_y - 10, 10);
fillrectangle(player_x - 15, player_y + 15, player_x + 15, player_y + 20);
if (_kbhit)
{
char input = _getch();
if (input == 'd')
{
player_x += 100;
}
else if (input == 'w')
{
player_y -= 100;
}
else if (input == 's')
{
player_y += 100;
}
else if (input == 'a')
{
player_x -= 100;
}
}
cleardevice();
}
void UpdateWithoutInput()
{
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
if (maps[i][j] == 'w')
{
setfillcolor(RED);
fillrectangle(j * block_size, i * block_size, (j + 1) * block_size, (i + 1) * block_size);
setlinecolor(WHITE);
rectangle(j * block_size, i * block_size, (j + 1) * block_size, (i + 1) * block_size);
}
else if (maps[i][j] == 't')
{
setfillcolor(WHITE);
fillrectangle(j * block_size + 30, i * block_size + 30, (j + 1) * block_size - 30, (i + 1) * block_size - 30);
}
else if (maps[i][j] == 'b')
{
setfillcolor(YELLOW);
fillrectangle(j * block_size, i * block_size, (j + 1) * block_size, (i + 1) * block_size);
}
}
}
}
int main()
{
startup();
while (running)
{
UpdateWithoutInput();
PlayerMove();
}
_getch();
closegraph();
}