Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(e.key.keysym.sym == SDLK_b)
- {
- int distances[100];
- for(int a = 0; a<100; a++)
- {
- if(mobs[a].alive && mobs[a].ready)
- {
- distances[a] = abs(mainCharacter.posx-mobs[a].posx)+abs(mainCharacter.posy-mobs[a].posy);
- }
- else
- distances[a] = 999999;
- }
- int lowestdistance = 999999;
- int lowestid = -1;
- for(int a = 0; a<100; a++)
- {
- if(distances[a] < lowestdistance)
- {
- lowestdistance = distances[a];
- lowestid = a;
- }
- }
- if(lowestdistance > 100)
- Mix_PlayChannel(-1,nope,0);
- else
- {
- bool programcont = true;
- int cursorx = 0,cursory = 0;
- string code = mobs[lowestid].scriptL;
- char charactergrid[1000][1000];
- for(int xq = 0; xq<1000; xq++)
- for(int yq = 0; yq<1000; yq++)
- charactergrid[xq][yq] = 0;
- int yaxis = 0;
- int xaxis = 0;
- int textoffset = 0;
- for(int a = 0; a<code.length(); a++)
- {
- if(code[a] != '\n')
- {
- charactergrid[xaxis][yaxis] = code[a];
- xaxis++;
- }
- else
- {
- xaxis = 0;
- yaxis++;
- }
- }
- while(programcont)
- {
- clearScreen();
- SDL_Event pe;
- Uint8 *thekeystates = SDL_GetKeyState(NULL);
- while(SDL_PollEvent(&pe))
- {
- if(pe.type == SDL_QUIT)
- {
- programcont = false;
- cont = false;
- }
- else if(pe.type == SDL_KEYDOWN)
- {
- if(pe.key.keysym.sym == SDLK_ESCAPE)
- programcont = false;
- else if(pe.key.keysym.sym == SDLK_DOWN)
- cursory++;
- else if(pe.key.keysym.sym == SDLK_UP)
- {
- if(textoffset > 0)
- textoffset--;
- else
- cursory--;
- }
- else if(pe.key.keysym.sym == SDLK_RIGHT)
- cursorx++;
- else if(pe.key.keysym.sym == SDLK_LEFT)
- cursorx--;
- else if(pe.key.keysym.sym == SDLK_BACKSPACE)
- {
- charactergrid[cursorx-1][cursory+textoffset] = ' ';
- cursorx--;
- }
- else if(pe.key.keysym.sym == SDLK_HOME)
- {
- cursorx = 0;
- }
- else if(pe.key.keysym.sym == SDLK_RETURN)
- {
- cursory++;
- int tq = 0;
- for(tq = 0; tq<500; tq++)
- {
- if(charactergrid[tq][cursory+textoffset] == 0 || charactergrid[tq][cursory] == '\n')
- break;
- }
- cursorx = tq;
- }
- else if(thekeystates[SDLK_LCTRL] && pe.key.keysym.sym == SDLK_s)
- {
- mobs[lowestid].scriptL = "";
- for(int y = 0; y<100; y++)
- {
- string line = "";
- for(int x = 0; x<1000; x++)
- {
- if(charactergrid[x][y] == 0)
- break;
- else
- line += charactergrid[x][y];
- }
- mobs[lowestid].scriptL = mobs[lowestid].scriptL + line + "\n";
- }
- mobs[lowestid].ready = false;
- programcont = false;
- }
- else
- {
- 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)
- {
- charactergrid[cursorx][cursory+textoffset] = (char)pe.key.keysym.unicode;
- cursorx++;
- }
- }
- }
- else if(pe.type == SDL_MOUSEBUTTONDOWN)
- {
- if(pe.button.button == SDL_BUTTON_WHEELUP)
- {
- if(textoffset > 0)
- textoffset--;
- else
- cursory--;
- }
- else if(pe.button.button == SDL_BUTTON_WHEELDOWN)
- cursory++;
- }
- }
- if(cursorx < 0)
- cursorx = 0;
- if(cursorx > 100)
- cursorx = 100;
- if(cursory < 0)
- cursory = 0;
- if(cursory > 32)
- {
- cursory = 32;
- textoffset++;
- }
- for(int y = 0; y<100; y++)
- {
- string line = "";
- for(int x = 0; x<1000; x++)
- {
- if(charactergrid[x][y] == 0)
- break;
- else
- line += charactergrid[x][y];
- }
- applyText(20,20*(y-textoffset),line);
- }
- applyTextRed(20+(cursorx*10),cursory*20,"|");
- flipScreen();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement