1

Just a quick question. I'm trying to make a simple animation for a program in C and i can't find a way to move this object through the console. I'm using printf to draw the figure on the console and i was thinking on use the gotoxy function to make it move but that doesn't seem to move the object. This is the figure:

        printf("          / \\");
        printf("         // \\\\");
        printf("        //   \\\\");
        printf("       //     \\\\");
        printf("       ||     ||");
        printf("=======|| [ ] ||=======");
        printf("\\\\     || [ ] ||     //");
        printf(" \\\\====|| [ ] ||====//");
        printf("       +++++++++");
        printf("    // | | | | | \\\\");

What i want to make is that when i select the option of the animation, the rocket needs to make like it's going up. I did a for loop changing the Y values but it didn't work. Any ideas?

Space_Shift
  • 83
  • 11

2 Answers2

2

In Windows with MSVC you can do it like this, avoiding OS interaction. It's based on the idea that printing a newline moves all the text up. Assumed 25 lines in the console. I expect the Linux solution to be quite similar.

#include <windows.h>
#include <stdio.h>

#define LINES 25

int main(void) {
    for(int i = 0; i < LINES; i++) {            // clear console
        printf("\n");
    }

    printf("          / \\\n");                 // added newline to each of these lines
    printf("         // \\\\\n");
    printf("        //   \\\\\n");
    printf("       //     \\\\\n");
    printf("       ||     ||\n");
    printf("=======|| [ ] ||=======\n");
    printf("\\\\     || [ ] ||     //\n");
    printf(" \\\\====|| [ ] ||====//\n");
    printf("       +++++++++\n");
    printf("    // | | | | | \\\\\n");
    Sleep(3000);                                // start the burn

    for(int i = 0; i < LINES; i++) {
        Sleep(200);
        printf("\n");                           // lift-off
    }
    return 0;
}
Weather Vane
  • 33,872
  • 7
  • 36
  • 56
0

You should useclear screen option, and redraw your rocket in another condition next time.

How to clear screen in C, depends on what compiler are you using. if you use c++ use

system("cls");

otherwise look up this article

Community
  • 1
  • 1
bobra
  • 615
  • 3
  • 18