Advertisement
Guest User

text editor

a guest
Jan 7th, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.08 KB | None | 0 0
  1.  
  2. if(e.key.keysym.sym == SDLK_b)
  3.                         {
  4.                             int distances[100];
  5.                             for(int a = 0; a<100; a++)
  6.                             {
  7.                                 if(mobs[a].alive && mobs[a].ready)
  8.                                 {
  9.                                     distances[a] = abs(mainCharacter.posx-mobs[a].posx)+abs(mainCharacter.posy-mobs[a].posy);
  10.                                 }
  11.                                 else 
  12.                                     distances[a] = 999999;
  13.                             }
  14.                             
  15.                             int lowestdistance = 999999;
  16.                             int lowestid = -1;
  17.                             for(int a = 0; a<100; a++)
  18.                             {
  19.                                 if(distances[a] < lowestdistance)
  20.                                 {
  21.                                     lowestdistance = distances[a];
  22.                                     lowestid = a;
  23.                                 }
  24.                             }
  25.                             if(lowestdistance > 100)
  26.                                 Mix_PlayChannel(-1,nope,0);
  27.                             else
  28.                             {
  29.  
  30.                                 bool programcont = true; 
  31.                                 int cursorx = 0,cursory = 0;
  32.                                 string code = mobs[lowestid].scriptL;
  33.                                 char charactergrid[1000][1000];
  34.                                 for(int xq = 0; xq<1000; xq++)
  35.                                     for(int yq = 0; yq<1000; yq++)
  36.                                             charactergrid[xq][yq] = 0;
  37.                                 int yaxis = 0;
  38.                                 int xaxis = 0;
  39.                                 int textoffset = 0;
  40.  
  41.                                     for(int a = 0; a<code.length(); a++)
  42.                                     {
  43.                                         if(code[a] != '\n')
  44.                                         {
  45.                                             charactergrid[xaxis][yaxis] = code[a];
  46.                                             xaxis++;
  47.                                         }
  48.                                         else
  49.                                         {
  50.                                             xaxis = 0;
  51.                                             yaxis++;
  52.                                         }
  53.                                     }
  54.  
  55.                                 while(programcont)
  56.                                 {
  57.                                     clearScreen();
  58.                                     SDL_Event pe;
  59.  
  60.                                     Uint8 *thekeystates = SDL_GetKeyState(NULL);
  61.  
  62.                                     while(SDL_PollEvent(&pe))
  63.                                     {
  64.                                         if(pe.type == SDL_QUIT)
  65.                                         {
  66.                                             programcont = false;
  67.                                             cont = false;
  68.                                         }
  69.                                         else if(pe.type == SDL_KEYDOWN)
  70.                                         {
  71.                                             if(pe.key.keysym.sym == SDLK_ESCAPE)
  72.                                                 programcont = false;
  73.                                             else if(pe.key.keysym.sym == SDLK_DOWN)
  74.                                                 cursory++;
  75.                                             else if(pe.key.keysym.sym == SDLK_UP)
  76.                                             {
  77.                                                 if(textoffset > 0)
  78.                                                     textoffset--;
  79.                                                 else
  80.                                                     cursory--;
  81.                                             }
  82.                                             else if(pe.key.keysym.sym == SDLK_RIGHT)
  83.                                                 cursorx++;
  84.                                             else if(pe.key.keysym.sym == SDLK_LEFT)
  85.                                                 cursorx--;
  86.                                             else if(pe.key.keysym.sym == SDLK_BACKSPACE)
  87.                                             {
  88.                                                 charactergrid[cursorx-1][cursory+textoffset] = ' ';
  89.                                                 cursorx--;
  90.                                             }
  91.                                             else if(pe.key.keysym.sym == SDLK_HOME)
  92.                                             {
  93.                                                 cursorx = 0;
  94.                                             }
  95.                                             else if(pe.key.keysym.sym == SDLK_RETURN)
  96.                                             {
  97.                                                 cursory++;
  98.                                                 int tq = 0;
  99.                                                 for(tq = 0; tq<500; tq++)
  100.                                                 {
  101.                                                     if(charactergrid[tq][cursory+textoffset] == 0 || charactergrid[tq][cursory] == '\n')
  102.                                                         break;
  103.                                                 }
  104.                                                 cursorx = tq;
  105.                                             }
  106.                                             else if(thekeystates[SDLK_LCTRL] && pe.key.keysym.sym == SDLK_s)
  107.                                             {
  108.                                                 mobs[lowestid].scriptL = "";
  109.                                                 for(int y = 0; y<100; y++)
  110.                                                 {
  111.                                                     string line = "";
  112.                                                     for(int x = 0; x<1000; x++)
  113.                                                     {
  114.                                                         if(charactergrid[x][y] == 0)
  115.                                                             break;
  116.                                                         else
  117.                                                                 line += charactergrid[x][y];
  118.                                                     }
  119.                                                     mobs[lowestid].scriptL = mobs[lowestid].scriptL + line + "\n";
  120.                                                 }
  121.                                                 mobs[lowestid].ready = false;
  122.                                                 programcont = false; 
  123.                                             }
  124.                                             else
  125.                                             {
  126.                                                 if(pe.key.keysym.sym != SDLK_CAPSLOCK && pe.key.keysym.sym != SDLK_LSHIFT && pe.key.keysym.sym != SDLK_RSHIFT && pe.key.keysym.sym != SDLK_LCTRL && pe.key.keysym.sym != SDLK_RCTRL)
  127.                                                 {
  128.                                                     charactergrid[cursorx][cursory+textoffset] = (char)pe.key.keysym.unicode;
  129.                                                     cursorx++;
  130.                                                 }
  131.                                             }
  132.                                         }
  133.                                         else if(pe.type == SDL_MOUSEBUTTONDOWN)
  134.                                         {
  135.                                             if(pe.button.button == SDL_BUTTON_WHEELUP)
  136.                                             {
  137.                                                 if(textoffset > 0)
  138.                                                     textoffset--;
  139.                                                 else
  140.                                                     cursory--;
  141.                                             }
  142.                                             else if(pe.button.button == SDL_BUTTON_WHEELDOWN)
  143.                                                 cursory++;
  144.                                         }
  145.                                     }
  146.  
  147.                                    if(cursorx < 0)
  148.                                        cursorx = 0;
  149.                                    if(cursorx > 100)
  150.                                        cursorx = 100;
  151.                                    if(cursory < 0)
  152.                                        cursory = 0;
  153.                                    if(cursory > 32)
  154.                                    {
  155.                                        cursory = 32;
  156.                                        textoffset++;
  157.                                    }
  158.  
  159.                                    for(int y = 0; y<100; y++)
  160.                                    {
  161.                                        string line = "";
  162.                                        for(int x = 0; x<1000; x++)
  163.                                        {
  164.                                            if(charactergrid[x][y] == 0)
  165.                                                break;
  166.                                            else
  167.                                                    line += charactergrid[x][y];
  168.                                        }
  169.                                        applyText(20,20*(y-textoffset),line);
  170.                                    }
  171.  
  172.                                    applyTextRed(20+(cursorx*10),cursory*20,"|");
  173.  
  174.                                     flipScreen();
  175.                                 }
  176.                             }
  177.                       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement