推箱子游戏1

#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();

}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值