Hi everyone! I´m trying to create a tank game (very basic), I have created a function for drawing a tank in every direction and I was able to make it move when pressing "w, a, s or d". The problem is that these tanks continuously overlap and I can´t get them erased... may anybody help me? I don´t want to use complex codes yet, I´m just working with the basics like do-while, if-else, void functions, etc. (actually I´m meant to) Here is the code:

# include
# include
# include
# include
# include


# include <iostream>
# include <cstdlib>
# include <windows.h>
# include <string>
# include <conio.h>

using namespace std ;

void gotoxy ( int x , int y) {
COORD coord ;
coord.X = x ;
coord.Y = y ;
SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), coord) ; 
}
void drawObstacle ( string tipe, int xPos, int yPos, int width, int height, int width2, int height2 ) {
if ( tipe == "rectangle") {
gotoxy ( xPos, yPos) ;
for (int i = 0; i < width; i++) { 
cout << "_" ;
}
for (int i = 0 ; i < height; i++) { 
gotoxy ( xPos - 1, yPos + 1 + i) ;
cout << "|\n" ;
}
for (int i = 0; i < width; i++) { 
gotoxy ( xPos + i, yPos + height ) ;
cout << "_" ;
}
for (int i = 0 ; i < height; i++) { 
gotoxy ( xPos + width, yPos + 1 + i) ;
cout << "|\n" ;
}
} else if ( tipe == "polygonRigthUp") {
gotoxy (xPos, yPos) ;
for (int i = 0; i < width  ; i++) { 
cout << "_" ;
}
for (int i = 0 ; i < height ;i++) { 
gotoxy ( xPos - 1, yPos + 1 + i) ;
cout << "|\n" ;
}
for (int i = 0; i < width - width2 - 1; i++) { 
gotoxy ( xPos + i , yPos + height ) ;
cout << "_" ;
}
for (int i = 0 ; i < height2 ; i++) { 
gotoxy ( xPos + width, yPos +1 + i) ;
cout << "|" ;
}
for (int i = 0; i < width2; i++) { 
gotoxy ( xPos + width - width2 + i, yPos + height2 ) ;
cout << "_" ;
}
for (int i = 0; i < height - height2; i++) { 
gotoxy ( xPos + width - width2 -1 , yPos + height2 + i +1) ;
cout << "|\n" ;
}
} else if ( tipe == "polygonLeftUp") {
gotoxy ( xPos, yPos) ;
for (int i = 0; i < width; i++) { //lado de arriba
cout << "_" ;
}
for (int i = 0 ; i < height2; i++) { //lado de la izquierda
gotoxy ( xPos - 1, yPos + 1 + i) ;
cout << "|\n" ;
}
for (int i = 0; i < width - width2 ; i++) { //lado de abajo
gotoxy ( xPos + i +width2, yPos + height ) ;
cout << "_" ;
}
for (int i = 0 ; i < height; i++) { //lado de la derecha
gotoxy ( xPos + width, yPos + 1 + i) ;
cout << "|\n" ;
}
for (int i = 0; i < width2; i++) { //lado de abajo (cuadrilatero pequeño)
gotoxy ( xPos + i, yPos + height2 ) ;
cout << "_" ;
}
for (int i = 0; i < height - height2; i++) { //lado de derecha (medio)
gotoxy ( xPos + width2   , yPos + height2 + i +1) ;
cout << "|\n" ;

} else if (tipe == "polygonRigthDown") {
gotoxy (xPos, yPos) ;
for (int i = 0; i < width2; i++){
cout << "_" ;
}
for (int i = 0; i < height; i++){
gotoxy (xPos-1, yPos + i + 1) ;
cout << "|" ;
}
for (int i = 0; i < width; i++){
gotoxy (xPos + i, yPos + height) ;
cout << "_" ;
}
for (int i = 0; i <height2; i++) {
gotoxy (xPos + width2 , yPos + 1+ i) ;
cout << "|" ;
}
for (int i = 0; i < width - width2 - 1; i++) {
gotoxy (xPos + width2+1 + i, yPos + height2) ;
cout << "_" ;
}
for (int i = 0; i <height - height2; i++) {
gotoxy ( xPos + width, yPos + height2 + 1+i) ;
cout << "|" ;
}
} else if (tipe == "polygonLeftDown") {
gotoxy (xPos + width - width2, yPos) ;
for (int i = 0; i < width2; i++){
cout << "_" ;
}
for (int i = 0; i < height; i++){
gotoxy (xPos +width, yPos + i + 1) ;
cout << "|" ;
}
for (int i = 0; i < width; i++){
gotoxy (xPos + i, yPos + height) ;
cout << "_" ;
}
for (int i = 0; i <height2; i++) {
gotoxy (xPos +width- width2 -1, yPos + 1+ i) ;
cout << "|" ;
}
for (int i = 0; i < width - width2 - 1; i++) {
gotoxy (xPos +i, yPos + height2) ;
cout << "_" ;
}
for (int i = 0; i <height - height2; i++) {
gotoxy ( xPos -1, yPos + height2 + 1+i) ;
cout << "|" ;
}
}
}
void drawTank (string orientation, float xPos, float yPos) {
if (orientation == "up" ) {


drawObstacle ("rectangle" , xPos, yPos, 6, 6, 0, 0) ;
drawObstacle ("rectangle" , xPos + 1, yPos +1, 4, 4, 0, 0) ;
drawObstacle ("rectangle" , xPos + 2, yPos - 3, 2, 3, 0, 0) ;
for ( int i = 0; i <6 ; i++) {
drawObstacle ("rectangle" , xPos-2, yPos + i, 1, 1, 0, 0) ;
}
for ( int i = 0; i <6 ; i++) {
drawObstacle ("rectangle" , xPos + 7, yPos + i, 1, 1, 0, 0) ;
}
} else if (orientation == "right") {


int width = 9 ;
int height = 5 ;

drawObstacle ("rectangle" , xPos , yPos, width, height, 0, 0) ;
drawObstacle ("rectangle" , xPos +1, yPos +1, width - 2, height - 2, 0, 0) ;
drawObstacle ("rectangle" , xPos + width + 1, yPos + (height+1)/2 -1, 3, 2, 0, 0) ;
for ( int i = 0; i < (width + 1)/2 ; i++) {
drawObstacle ("rectangle" , xPos +2*i, yPos -1, 1, 1, 0, 0) ;
}
for ( int i = 0; i <(width + 1)/2; i++) {
drawObstacle ("rectangle" , xPos + 2*i, yPos + height, 1, 1, 0, 0) ;
}
} else if ( orientation == "left") {
int width = 9 ;
int height = 5 ;

drawObstacle ("rectangle" , xPos , yPos, width, height, 0, 0) ;
drawObstacle ("rectangle" , xPos +1, yPos +1, width - 2, height - 2, 0, 0) ;
drawObstacle ("rectangle" , xPos -4, yPos + (height+1)/2 -1, 3, 2, 0, 0) ;
for ( int i = 0; i < (width + 1)/2 ; i++) {
drawObstacle ("rectangle" , xPos +2*i, yPos -1, 1, 1, 0, 0) ;
}
for ( int i = 0; i <(width + 1)/2; i++) {
drawObstacle ("rectangle" , xPos + 2*i, yPos + height, 1, 1, 0, 0) ;
}

} else if ( orientation == "down") {
drawObstacle ("rectangle" , xPos, yPos, 6, 6, 0, 0) ;
drawObstacle ("rectangle" , xPos + 1, yPos +1, 4, 4, 0, 0) ;
drawObstacle ("rectangle" , xPos + 2, yPos +6, 2, 3, 0, 0) ;
for ( int i = 0; i <6 ; i++) {
drawObstacle ("rectangle" , xPos-2, yPos + i, 1, 1, 0, 0) ;
}
for ( int i = 0; i <6 ; i++) {
drawObstacle ("rectangle" , xPos + 7, yPos + i, 1, 1, 0, 0) ;
}
}
}

int main () {
int c = 5;
int initialPosX = 20 ;
int initialPosY = 5 ;
int always = 1 ;
int command = 1;
int posTankX = 96;
int posTankY = 20;
drawObstacle ("rectangle", 10 -1*c, 1, 29*c + initialPosX , 14*c , 0*c, 0*c) ; //background
drawObstacle ("rectangle", 10, 3, 27*c + initialPosX , 13*c, 0*c, 0*c) ;
drawObstacle ("polygonRigthUp", initialPosX, initialPosY, 3*c, 4*c, 1*c, 2*c ) ;
drawObstacle ("rectangle", initialPosX, initialPosY + 6*c, 4*c, 2*c, 0*c, 0*c ) ;
drawObstacle ("polygonRigthDown", initialPosX, initialPosY + 9*c, 6*c, 2*c, 1*c, 1*c ) ; 
drawObstacle ("rectangle", initialPosX +5*c, initialPosY + 1*c, 5*c, 2*c, 0*c, 0*c ) ;
drawObstacle ("polygonLeftUp", initialPosX +6*c, initialPosY +5*c, 4*c, 3*c, 3*c, 2*c ) ;
drawObstacle ("rectangle", initialPosX + 7*c, initialPosY + 9*c, 7*c, 2*c, 0*c, 0*c ) ;
drawObstacle ("rectangle", initialPosX +12*c, initialPosY , 2*c, 8*c, 0*c, 0*c ) ;
drawObstacle ("polygonLeftUp", initialPosX +16*c, initialPosY , 4*c, 5*c, 2*c, 2*c ) ;
drawObstacle ("polygonRigthDown", initialPosX +16*c, initialPosY + 6*c, 3*c, 2*c, 2*c, 1*c ) ; 
drawObstacle ("polygonLeftUp", initialPosX + 16*c, initialPosY +9*c, 3*c, 2*c, 1*c, 1*c ) ;
drawObstacle ("rectangle", initialPosX + 22*c, initialPosY , 4*c, 2*c, 0*c, 0*c ) ;
drawObstacle ("polygonRigthDown", initialPosX +22*c, initialPosY + 3*c, 4*c, 4*c, 2*c, 2*c ) ; 
drawObstacle ("rectangle", initialPosX + 22*c, initialPosY + 8*c, 1*c, 3*c, 0*c, 0*c ) ;
drawObstacle ("rectangle", initialPosX + 24*c, initialPosY + 8*c, 1*c, 3*c,0*c, 0*c ) ;



do{ // I believe this need modification of any kind
if ( command == 1) {
drawTank ("up", posTankX, posTankY) ;
} else if (command == 119) { //up "W"
drawTank ("up", posTankX, posTankY + 1) ;
posTankY --;
} else if (command == 115) { //down "S"
drawTank ("down", posTankX, posTankY - 1) ;
posTankY ++;
}else if (command == 97) { //left "A"
drawTank ("left", posTankX - 1, posTankY) ;
posTankX --;
} else if (command == 100 ) { //right "D"
drawTank ("right", posTankX + 1, posTankY) ;
posTankX ++;
}
command = _getch() ;
}while ( always != 0) ;

return 0 ;
}