-1

right now im a sorta half fine in a way programmer and im trying to make an text based game. i started today and i made some what of a world map that will later be updated and i will make it vast! but for the life of me i cant update frames properly. i uses the normal window, and i have put my code below. please help me update my frames cleanly!

map class and header

#include<string>
#include <Windows.h>



class map {
protected:
    char mep[200][50];

public:
    map();
    ~map();
    void bs();
    void buildTree(int X, int Y);
    void addTree();
    void buildMap();
    void printMap(int X, int Y);
};

#include"map.h"


map::map() {
    buildMap();
    printMap(0, 0);
}
map::~map() {

}


void map::bs() {
    //this builds a square world later cool things like trees get added
    for (int x = 0; x<200; x++) {
        for (int y = 0; y<500; y++) {
            mep[x][y] = '_';

        }

    }
}


void map::buildTree(int X, int Y) {

    //¨    /\¨ [x][y-4] 
    //    /  \"[x][y-3] 
    //¨  /-o  \¨ [x][y-2]  
    //¨ /-o-o- \¨[x][y-1]  
    //¨ / o0-o \¨ [x][y]   
    //¨/o-ooo-  \¨[x][y+1] 
    //¨   ||||¨ [x][y+2] 
    //¨   ||||¨ [x][y+3] 

    mep[X][Y - 4] = '/'; mep[X + 1][Y - 4] = '\\';
    mep[X - 1][Y - 3] = '/'; mep[X][Y - 3] = ' '; mep[X + 1][Y - 3] = ' '; mep[X + 2][Y - 3] = '\\';
    mep[X - 2][Y - 2] = '/'; mep[X - 1][Y - 2] = '-'; mep[X][Y - 2] = 'o'; mep[X + 1][Y - 2] = ' '; mep[X + 2][Y - 2] = ' '; mep[X + 3][Y - 2] = '\\';
    mep[X - 3][Y - 1] = '/'; mep[X - 2][Y - 1] = '-'; mep[X - 1][Y - 1] = 'o'; mep[X][Y - 1] = '-'; mep[X + 1][Y - 1] = 'o'; mep[X + 2][Y - 1] = '-'; mep[X + 3][Y - 1] = ' '; mep[X + 4][Y - 1] = '\\';
    mep[X - 3][Y] = '/'; mep[X - 2][Y] = ' '; mep[X - 1][Y] = 'o'; mep[X][Y] = '0'; mep[X + 1][Y] = '-'; mep[X + 2][Y] = 'o'; mep[X + 3][Y] = ' '; mep[X + 4][Y] = '\\';
    mep[X - 4][Y + 1] = '/'; mep[X - 3][Y + 1] = 'o'; mep[X - 2][Y + 1] = '-'; mep[X - 1][Y + 1] = 'o'; mep[X][Y + 1] = 'o'; mep[X + 1][Y + 1] = 'o'; mep[X + 2][Y + 1] = '-'; mep[X + 3][Y + 1] = ' '; mep[X + 4][Y + 1] = ' '; mep[X + 5][Y + 1] = '\\';
    mep[X - 1][Y + 2] = '|'; mep[X][Y + 2] = '|'; mep[X + 1][Y + 2] = '|'; mep[X + 2][Y + 2] = '|';
    mep[X - 1][Y + 3] = '|'; mep[X][Y + 3] = '|'; mep[X + 1][Y + 3] = '|'; mep[X + 2][Y + 3] = '|';

}
void map::addTree() {
    buildTree(74, 69);
    buildTree(5, 6);
    //add 18 more
}
void map::buildMap() {
    bs();
    addTree();
}
void map::printMap(int X, int Y) {
    //this is what the players will see
    std::string viewMap[15];

    for (int x = 0; x<15; x++) {
        for (int y = 0; y <= 70; y++) {
            viewMap[x] += mep[Y + y][X + x];

        }
    }
    //this prints the visible map for the players
    std::cout << viewMap[1] + "\n" + viewMap[2] + "\n" + viewMap[3]
        + "\n" + viewMap[4] + "\n" + viewMap[5] + "\n" + viewMap[6]
        + "\n" + viewMap[7] + "\n" + viewMap[8] + "\n" + viewMap[9]
        + "\n" + viewMap[10] + "\n" + viewMap[11] + "\n" + viewMap[12]
        + "\n" + viewMap[13] + "\n" + viewMap[14] << std::endl;

}
int main()
{
    //this is my main im using it as an update frames right now
    while (1) {
//also i will have the world render and build it self as a whole first and only loop the frame update ik its given but ill say it anway
        map mp;
        mp.~map();
    }
}
Pie Pie
  • 13
  • 4
  • 2
    Don't call destructors manually. – melpomene Dec 22 '17 at 21:18
  • i was at first using the destructor to clear the screen and im used to google docs which does caps for me. – Pie Pie Dec 22 '17 at 21:33
  • An object's destructor is called automatically when that object's lifetime ends. There are very, very few situations where you should call it explicitly, and this is not one of them. – Miles Budnek Dec 22 '17 at 21:35
  • 1
    As for your actual question: the answer will depend on what type of terminal you're using. There are also libraries like ncurses that will abstract away the underlying terminal differences and let your code work on various platforms. – Miles Budnek Dec 22 '17 at 21:40
  • hi, so after looking into it way more i learned my problem, also how to clarify my problem and make it clear to you guys of what i'm asking. my games uses a basic while(1) loop and system("cls") which i know is bad but basically to sum up my question how to i make a basic frame snyc function. i uses normal visual studios with out any cool unique libraries and i kinda don't what to change that. how would i got about making a simple frame sync function / class – Pie Pie Dec 28 '17 at 03:43
  • ive made many update in my code when it comes to handling arrays and moving the protagonist but it still prints in a very strobe light way. i just want clean 60 fts with out the weird flickering i was told i have to sync my frames anyway heres my basic loop while (1) { system("cls");// clears map gamePlay(); // moves the character mp.printMap(pl); // prints map } – Pie Pie Dec 28 '17 at 03:47

1 Answers1

0

I hope I understood you right.

If your program is only using the terminal, you can print a certain ascii character to go back to the beginning of the line. Then you can rewrite the whole screen.

\033[f

This is what I used for a terminal based ascii game. Just print this for the amount of rows you want to overwrite.

std::cout << "\033[f";

Hope this is the solution for you

  • hi, so after looking into it way more i learned my problem, also how to clarify my problem and make it clear to you guys of what i'm asking. my games uses a basic while(1) loop and system("cls") which i know is bad, but basically to sum up my question how do i make a basic frame snyc function. i uses normal visual studios with out any cool, unique, libraries and i kinda don't what to change that. how would i got about making a simple frame sync function / class????? – Pie Pie Dec 28 '17 at 03:33