mercredi 3 juin 2020

Console RPG in DEV C++ / Map

Im trying to make a Dev C++ RPG game. Im stuck at the map, its a twodimesnional array with the dimensions measured with how many chars can fit before "breaking" a line. The map prints out just fine, but i want to make the player move with the arrow keys. Heres what ive got so far (doesnt work):

#include <iostream>
#include <string>
#include <conio.h>
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 75
#define KEY_RIGHT 77

void MapPrint(int StartX, int StartY){
    int Map[12][80]={0};
    Map[StartX][StartY]=1;
    for (int x=0; x<12; x++) 
    { 
        for (int y=0; y<80; y++) 
        { 
            if(Map[x][y]==0){
                std::cout<<"=";
            }
            if (y==80){
                std::cout<<"\n";
                continue;
            }
            if (Map[x][y]==1){
                std::cout<<"#";
                continue;
            }
        }   
    }
}
int main(){
    int Map[12][80]={0};
    int StartX,StartY;
    Map[StartX][StartY]=1;
    int c = 0;
    StartX=6;
    StartY=40;
    MapPrint(StartX,StartY);
    while(1)
    {

        c=0;

        switch((c=getch())) {
        case KEY_UP:
            system("CLS");
            Map[StartX][StartY]=0;
            Map[StartX][StartY+1]=1;
            std::cout<<StartY; //remains of a fix attempt
            MapPrint(StartX,StartY);
        case KEY_DOWN:
            system("CLS");
            Map[StartX][StartY]=0;
            Map[StartX][StartY-1]=1;
            MapPrint(StartX,StartY);
        case KEY_LEFT:
            system("CLS");
            Map[StartX][StartY]=0;
            Map[StartX-1][StartY]=1;
            MapPrint(StartX,StartY);
        case KEY_RIGHT:
            system("CLS");
            Map[StartX][StartY]=0;
            Map[StartX+1][StartY]=1;
            MapPrint(StartX,StartY);
        }

    }
    return 0;
}`

Aucun commentaire:

Enregistrer un commentaire