QWERTYUIOPas
@QWERTYUIOPas
КраткоОСеБе

Как избавиться от лишнего куска фона текста, который торчит непонятно зачем, хотя я ничего лишнего не рисовал?

631e180894751942909009.png
Слева от текста торчит какой-то кусок, его надо укоротить, а лучше убрать.

Код:
#include <L:\\Soft\\Dev-Cpp\\MinGW\\include\\graphics.h>
#include <conio.h>
#include <cmath>
#include <iostream>
#include <winuser.h>
#define pi 3.14159265
using namespace std;

int level1(){
 int map[15][16]={
  {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
  {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16},
  {1,0,0,2,12,1,1,0,4,1,1,0,1,1,1,1},
  {1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1},
  {1,1,1,1,1,0,1,1,1,1,1,1,1,0,0,1},
  {1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1},
  {1,1,1,0,1,0,4,1,1,0,1,1,1,1,1,1},
  {0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
  {1,1,1,1,1,0,1,1,1,0,1,0,0,1,1,1},
  {1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,1},
  {1,0,1,1,0,1,1,0,1,1,1,0,1,0,0,1},
  {1,0,1,0,0,0,1,0,0,0,0,0,0,0,1,1},
  {1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,1},
  {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
  {4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,4},
 };
 int interactive_map[15][16]={
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
 };
 int text_map[15][16]={
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
 };
 char *msg1="EXIT";
 char *msg2="EXIT2";
 char *msg3="EXIT3";
 char *msg4="EXIT4";
 int horror_effect=0;
 int font_size1=0;
 int font_size2=0;
 int font_size3=0;
 int font_size4=0;
 double horror_effect_quality=0.001;
 double rndr_quality=100.0;
 double split_line_width=0.04;
 int color_mode=0;//0=distance color 1=map color with distance coloring support
 //BLACK            0
 //BLUE          	1
 //GREEN        	2
 //CYAN 	        3
 //RED          	4
 //MAGENTA      	5
 //BROWN   	        6
 //LIGHTGRAY    	7
 //DARKGRAY     	8
 //LIGHTBLUE    	9
 //LIGHTGREEN   	10
 //LIGHTCYAN    	11
 //LIGHTRED     	12
 //LIGHTMAGENTA 	13
 //YELLOW       	14
 //WHITE        	15
 //distance color   16
 double distance=0.0;
 double width=640.0;
 double height=480.0;
 double proj_height=0.0;
 double num_rays=640.0;
 double ray_width=width/num_rays;
 double plyr_angle=45.0;
 double view_angle=80.0;
 double half_fov=view_angle/2.0;
 double step_angle=view_angle/num_rays;
 double start_rndr_angle=0.0;
 double rndr_angle=0.0;
 double plyr_x=1.5;
 double plyr_y=1.5;
 double test_plyr_x=1.5;
 double test_plyr_y=1.5;
 double top=0.0;
 double rndr_pos_x=1.5;
 double rndr_pos_y=1.5;
 double rndr_pos_x_x=22.2;
 double rndr_pos_y_y=1.11111111;
 double rndr_pos_x_x_x=22.2;
 double rndr_pos_y_y_y=1.11111111;
 double plyr_spd=0.05;
 double nxt_pos_step_y=0.22;
 double nxt_pos_step_x=0.22;
 bool textShowed1=false;
 bool textShowed2=false;
 bool textShowed3=false;
 bool textShowed4=false;
 double textDist1=0.0;
 double textDist2=0.0;
 double textDist3=0.0;
 double textDist4=0.0;
 int textX1_min=0;
 int textX1_max=0;
 int textX2_min=0;
 int textX2_max=0;
 int textX3_min=0;
 int textX3_max=0;
 int textX4_min=0;
 int textX4_max=0;
 int txt_value=0;
 bool exitOk=false;
 while (!exitOk){
  //c = getch();
  textShowed1=false;
  textShowed2=false;
  textShowed3=false;
  textShowed4=false;
  cleardevice();
  if(interactive_map[(int)plyr_y][(int)plyr_x]==1){
   exitOk=true;
  }
  if(GetKeyState('R')<0){
   plyr_angle=45;
   plyr_x=1.5;
   plyr_y=1.5;
  }
  if(GetKeyState(VK_RETURN)<0){
   plyr_angle=45;
   plyr_x=1.5;
   plyr_y=1.5;
  }
  if(GetKeyState(VK_ESCAPE)<0){               //Выход по "Escape"
   return 0;
  }
  if(GetKeyState(VK_LEFT)<0){     //Left
   plyr_angle-=1;
  }
  if(GetKeyState('Z')<0){     //Left
   plyr_angle-=1;
  }
  if(GetKeyState(VK_UP)<0){     //Up
   test_plyr_y=plyr_y+sin(plyr_angle*pi/180)*plyr_spd;
   test_plyr_x=plyr_x+cos(plyr_angle*pi/180)*plyr_spd;
   if(map[(int)test_plyr_y][(int)plyr_x]==0){plyr_y=test_plyr_y;}
   if(map[(int)plyr_y][(int)test_plyr_x]==0){plyr_x=test_plyr_x;}
  }
  if(GetKeyState(VK_RIGHT)<0){    //Right
   plyr_angle+=1;
  }
  if(GetKeyState('X')<0){    //Right
   plyr_angle+=1;
  }
  if(GetKeyState(VK_DOWN)<0) {     //Down
   test_plyr_y=plyr_y-sin(plyr_angle*pi/180)*plyr_spd;
   test_plyr_x=plyr_x-cos(plyr_angle*pi/180)*plyr_spd;
   if(map[(int)test_plyr_y][(int)plyr_x]==0){plyr_y=test_plyr_y;}
   if(map[(int)plyr_y][(int)test_plyr_x]==0){plyr_x=test_plyr_x;}
  }
  if(GetKeyState('W')<0){     //w
   test_plyr_y=plyr_y+sin(plyr_angle*pi/180)*plyr_spd;
   test_plyr_x=plyr_x+cos(plyr_angle*pi/180)*plyr_spd;
   if(map[(int)test_plyr_y][(int)plyr_x]==0){plyr_y=test_plyr_y;}
   if(map[(int)plyr_y][(int)test_plyr_x]==0){plyr_x=test_plyr_x;}
  }
  if(GetKeyState('A')<0){     //a
   test_plyr_y=plyr_y+sin((plyr_angle-90)*pi/180)*plyr_spd;
   test_plyr_x=plyr_x+cos((plyr_angle-90)*pi/180)*plyr_spd;
   if(map[(int)test_plyr_y][(int)plyr_x]==0){plyr_y=test_plyr_y;}
   if(map[(int)plyr_y][(int)test_plyr_x]==0){plyr_x=test_plyr_x;}
  }
  if(GetKeyState('S')<0){      //s
   test_plyr_y=plyr_y-sin(plyr_angle*pi/180)*plyr_spd;
   test_plyr_x=plyr_x-cos(plyr_angle*pi/180)*plyr_spd;
   if(map[(int)test_plyr_y][(int)plyr_x]==0){plyr_y=test_plyr_y;}
   if(map[(int)plyr_y][(int)test_plyr_x]==0){plyr_x=test_plyr_x;}
  }
  if(GetKeyState('D')<0){     //d
   test_plyr_y=plyr_y-sin((plyr_angle-90)*pi/180)*plyr_spd;
   test_plyr_x=plyr_x-cos((plyr_angle-90)*pi/180)*plyr_spd;
   if(map[(int)test_plyr_y][(int)plyr_x]==0){plyr_y=test_plyr_y;}
   if(map[(int)plyr_y][(int)test_plyr_x]==0){plyr_x=test_plyr_x;}
  }
  start_rndr_angle=plyr_angle-half_fov;
  rndr_angle=start_rndr_angle;
  for(int rndr_ray=0;rndr_ray<900;rndr_ray+=1){
   rndr_pos_x=plyr_x;
   rndr_pos_y=plyr_y;
   nxt_pos_step_x=cos(rndr_angle*pi/180)/rndr_quality;
   nxt_pos_step_y=sin(rndr_angle*pi/180)/rndr_quality;
   rndr_angle+=step_angle;
   distance=0.0;
   while(map[(int)rndr_pos_y][(int)rndr_pos_x]==0){
   distance+=1.0/rndr_quality;
    rndr_pos_x+=nxt_pos_step_x;
    rndr_pos_y+=nxt_pos_step_y;
	txt_value=text_map[(int)rndr_pos_y][(int)rndr_pos_x];
	if(txt_value>0){
     switch(txt_value){
      case 1:
       if(!textShowed1){
        textShowed1=true;
        textDist1=distance+0.0;
        textX1_min=rndr_ray+0;
       }else{textX1_max=rndr_ray+0;}
       break;
      case 2:
       if(!textShowed2){
        textShowed2=true;
        textDist2=distance+0.0;
        textX2_min=rndr_ray+0;
       }else{textX2_max=rndr_ray+0;}
       break;
      case 3:
       if(!textShowed3){
        textShowed3=true;
        textDist3=distance+0.0;
        textX3_min=rndr_ray+0;
       }else{textX3_max=rndr_ray+0;}
       break;
      case 4:
       if(!textShowed4){
        textShowed4=true;
        textDist4=distance+0.0;
        textX4_min=rndr_ray+0;
       }else{textX4_max=rndr_ray+0;}
       break;
     }
	}
   }
   proj_height=min((height/(distance+0.001)),height);
   //font_size=(int)(proj_height/10);
   if(textShowed1){
    outtextxy(((int)((textX1_max+textX1_min)/2-textwidth(msg1)/2)),(int)((height-textheight(msg1))/2),msg1);
   }
   top=(height-proj_height)/2;
   switch(color_mode){
    case 1:
     if(map[(int)rndr_pos_y][(int)rndr_pos_x]!=16){setcolor(map[(int)rndr_pos_y][(int)rndr_pos_x]);}
     else{setcolor(15-((int)distance)%14);}
	 break;
    case 0:
     setcolor(15-((int)distance)%15);
	 break;
   }
   rndr_pos_x_x=rndr_pos_x-(int)rndr_pos_x;
   rndr_pos_y_y=rndr_pos_y-(int)rndr_pos_y;
   rndr_pos_x_x_x=min(rndr_pos_x_x,1-rndr_pos_x_x);
   rndr_pos_y_y_y=min(rndr_pos_y_y,1-rndr_pos_y_y);
   switch(horror_effect){
    case 1:
     if(min(min(rndr_pos_x_x+0,rndr_pos_y_y+0),min(1-rndr_pos_x_x,1-rndr_pos_y_y))>horror_effect_quality){
      line(rndr_ray,top,rndr_ray,top+proj_height);
     }
     break;
    case 0:
     if(rndr_pos_x_x_x+rndr_pos_y_y_y>split_line_width){
      line(rndr_ray,top,rndr_ray,top+proj_height);
     }
     break;
   }
  }
  swapbuffers();
 }
 return 1;
}
int main(){
 int gd = DETECT, gm;
 initgraph(&gd, &gm, NULL);
 settextjustify(1,1);
 settextstyle(4,0,5);
 level1();
 closegraph();
}

Желаемое
631e1af87933d045488359.png

Частный пример только с тремя функциями

settextjustify(1,1);
settextstyle(4,0,5);
outtextxy(324,219,"EXIT");
  • Вопрос задан
  • 91 просмотр
Решения вопроса 1
wataru
@wataru Куратор тега C++
Разработчик на С++, экс-олимпиадник.
Выведите куда-нибудь в файл аргументы у функции outtextxy перед каждыймы вызовом.

Я подозреваю, что черный фон - это следы кучи отрисовок текста с постеппенным сдвигов вправо.

Но тут, я думаю, вы баг не исправите без рефакторинга кода. Его надо разбить на функции, исправиль логику, упрастить.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы