void MainWindow::newLevel(int l){ attack += 1; // clear the beam deque, intialize variables if(attack == 1){ QBrush back1(*bg1); gameScene->setBackgroundBrush(back1); maxcount = 15; } else if(attack == 2){ QBrush back2(*bg2); gameScene->setBackgroundBrush(back2); maxcount = 20; } else if(attack == 3){ QBrush back3(*bg3); gameScene->setBackgroundBrush(back3); maxcount = 25; } beampellets.clear(); hasRed = false; ecount = 0; // make the game faster gameSpeed = gameSpeed * 3 / 5 + 1; maxhp += 5; if(l == 1){gameSpeed = 15; maxhp = 10; attack = 1;} timer->setInterval(gameSpeed); // reset player HP human->setHP(std::min(maxhp, human->getHP() + 5)); // make temporarily invincible human->setInvincible(); // start the game timer->start(); }
/* * Get a line into genbuf after gcursor. * Cnt limits the number of input characters * accepted and is used for handling the replace * single character command. Aescaped is the location * where we stick a termination indicator (whether we * ended with an ESCAPE or a newline/return. * * We do erase-kill type processing here and also * are careful about the way we do this so that it is * repeatable. (I.e. so that your kill doesn't happen, * when you repeat an insert if it was escaped with \ the * first time you did it. */ char * vgetline(int cnt, char *gcursor, bool *aescaped) { register int c, ch; register char *cp; int x, y, iwhite; char *iglobp; void (*OO)() = Outchar; /* * Clear the output state and counters * for autoindent backwards motion (counts of ^D, etc.) * Remember how much white space at beginning of line so * as not to allow backspace over autoindent. */ *aescaped = 0; ogcursor = gcursor; flusho(); CDCNT = 0; HADUP = 0; HADZERO = 0; gobbled = 0; iwhite = whitecnt(genbuf); iglobp = vglobp; /* * Carefully avoid using vinschar in the echo area. */ if (splitw) Outchar = vputchar; else { Outchar = vinschar; vprepins(); } for (;;) { if (gobblebl) gobblebl--; if (cnt != 0) { cnt--; if (cnt == 0) goto vadone; } ch = c = getkey() & (QUOTE|TRIM); if (!iglobp) { /* * Erase-kill type processing. * Only happens if we were not reading * from untyped input when we started. * Map users erase to ^H, kill to -1 for switch. */ if (c == tty.c_cc[VERASE]) c = CTRL('h'); else if (c == tty.c_cc[VKILL]) c = -1; switch (c) { /* * ^? Interrupt drops you back to visual * command mode with an unread interrupt * still in the input buffer. * * ^\ Quit does the same as interrupt. * If you are a ex command rather than * a vi command this will drop you * back to command mode for sure. */ case ATTN: case QUIT: ungetkey(c); goto vadone; /* * ^H Backs up a character in the input. * * BUG: Can't back around line boundaries. * This is hard because stuff has * already been saved for repeat. */ case CTRL('h'): bakchar: cp = gcursor - 1; if (cp < ogcursor) { beep(); continue; } goto vbackup; /* * ^W Back up a white/non-white word. */ case CTRL('w'): wdkind = 1; for (cp = gcursor; cp > ogcursor && isspace((int)cp[-1]); cp--) continue; for (c = wordch(cp - 1); cp > ogcursor && wordof(c, cp - 1); cp--) continue; goto vbackup; /* * users kill Kill input on this line, back to * the autoindent. */ case -1: cp = ogcursor; vbackup: if (cp == gcursor) { beep(); continue; } endim(); *cp = 0; c = cindent(); vgotoCL(qcolumn(cursor - 1, genbuf)); if (doomed >= 0) doomed += c - cindent(); gcursor = cp; continue; /* * \ Followed by erase or kill * maps to just the erase or kill. */ case '\\': x = destcol, y = destline; ex_putchar('\\'); vcsync(); c = getkey(); if (c == tty.c_cc[VERASE] || c == tty.c_cc[VKILL]) { vgoto(y, x); if (doomed >= 0) doomed++; goto def; } ungetkey(c), c = '\\'; goto noput; /* * ^Q Super quote following character * Only ^@ is verboten (trapped at * a lower level) and \n forces a line * split so doesn't really go in. * * ^V Synonym for ^Q */ case CTRL('q'): case CTRL('v'): x = destcol, y = destline; ex_putchar('^'); vgoto(y, x); c = getkey(); if (c != NL) { if (doomed >= 0) doomed++; goto def; } break; } } /* * If we get a blank not in the echo area * consider splitting the window in the wrapmargin. */ if (c == ' ' && !splitw) { if (gobblebl) { gobbled = 1; continue; } if (value(WRAPMARGIN) && outcol >= WCOLS - value(WRAPMARGIN)) { c = NL; gobblebl = 2; } } switch (c) { /* * ^M Except in repeat maps to \n. */ case CR: if (vglobp) goto def; c = '\n'; /* presto chango ... */ /* * \n Start new line. */ case NL: *aescaped = c; goto vadone; /* * escape End insert unless repeat and more to repeat. */ case ESCAPE: if (vglobp && *vglobp) goto def; goto vadone; /* * ^D Backtab. * ^T Software forward tab. * * Unless in repeat where this means these * were superquoted in. */ case CTRL('d'): case CTRL('t'): if (vglobp) goto def; /* fall into ... */ /* * ^D|QUOTE Is a backtab (in a repeated command). */ case CTRL('d') | QUOTE: *gcursor = 0; cp = vpastwh(genbuf); c = whitecnt(genbuf); if (ch == CTRL('t')) { /* * ^t just generates new indent replacing * current white space rounded up to soft * tab stop increment. */ if (cp != gcursor) /* * BUG: Don't hack ^T except * right after initial * white space. */ continue; cp = genindent(iwhite = backtab(c + value(SHIFTWIDTH) + 1)); ogcursor = cp; goto vbackup; } /* * ^D works only if we are at the (end of) the * generated autoindent. We count the ^D for repeat * purposes. */ if (c == iwhite && c != 0) { if (cp == gcursor) { iwhite = backtab(c); CDCNT++; ogcursor = cp = genindent(iwhite); goto vbackup; } else if (&cp[1] == gcursor && (*cp == '^' || *cp == '0')) { /* * ^^D moves to margin, then back * to current indent on next line. * * 0^D moves to margin and then * stays there. */ HADZERO = *cp == '0'; ogcursor = cp = genbuf; HADUP = 1 - HADZERO; CDCNT = 1; endim(); back1(); vputc(' '); goto vbackup; } } if (vglobp && vglobp - iglobp >= 2 && (vglobp[-2] == '^' || vglobp[-2] == '0') && gcursor == ogcursor + 1) goto bakchar; continue; default: /* * Possibly discard control inputs. */ if (!vglobp && junk(c)) { beep(); continue; } def: ex_putchar(c); noput: if (gcursor > &genbuf[LBSIZE - 2]) error("Line too long"); *gcursor++ = c & TRIM; vcsync(); #ifdef LISP if (value(SHOWMATCH) && !iglobp) if (c == ')' || c == '}') lsmatch(gcursor); #endif continue; } } vadone: *gcursor = 0; Outchar = OO; endim(); return (gcursor); }
void vappend(int ch, int cnt, int indent) { register int i; register char *gcursor; bool escape; int repcnt; short oldhold = hold; /* * Before a move in hardopen when the line is dirty * or we are in the middle of the printed representation, * we retype the line to the left of the cursor so the * insert looks clean. */ if (ch != 'o' && state == HARDOPEN && (rubble || !ateopr())) { rubble = 1; wcursor = cursor; vmove(); } vaifirst = indent == 0; /* * Handle replace character by (eventually) * limiting the number of input characters allowed * in the vgetline routine. */ if (ch == 'r') repcnt = 2; else repcnt = 0; /* * If an autoindent is specified, then * generate a mixture of blanks to tabs to implement * it and place the cursor after the indent. * Text read by the vgetline routine will be placed in genbuf, * so the indent is generated there. */ if (value(AUTOINDENT) && indent != 0) { gcursor = genindent(indent); *gcursor = 0; vgotoCL(qcolumn(cursor - 1, genbuf)); } else { gcursor = genbuf; *gcursor = 0; if (ch == 'o') vfixcurs(); } /* * Prepare for undo. Pointers delimit inserted portion of line. */ vUA1 = vUA2 = cursor; /* * If we are not in a repeated command and a ^@ comes in * then this means the previous inserted text. * If there is none or it was too long to be saved, * then beep() and also arrange to undo any damage done * so far (e.g. if we are a change.) */ if ((vglobp && *vglobp == 0) || peekbr()) { if ((INS[0] & (OVERBUF|TRIM)) == OVERBUF) { beep(); if (!splitw) ungetkey('u'); doomed = 0; hold = oldhold; return; } /* * Unread input from INS. * An escape will be generated at end of string. * Hold off n^^2 type update on dumb terminals. */ vglobp = INS; hold |= HOLDQIK; } else if (vglobp == 0) /* * Not a repeated command, get * a new inserted text for repeat. */ INS[0] = 0; /* * For wrapmargin to hack away second space after a '.' * when the first space caused a line break we keep * track that this happened in gobblebl, which says * to gobble up a blank silently. */ gobblebl = 0; /* * Text gathering loop. * New text goes into genbuf starting at gcursor. * cursor preserves place in linebuf where text will eventually go. */ if (*cursor == 0 || state == CRTOPEN) hold |= HOLDROL; for (;;) { if (ch == 'r' && repcnt == 0) escape = 0; else { gcursor = vgetline(repcnt, gcursor, &escape); /* * After an append, stick information * about the ^D's and ^^D's and 0^D's in * the repeated text buffer so repeated * inserts of stuff indented with ^D as backtab's * can work. */ if (HADUP) addtext("^"); else if (HADZERO) addtext("0"); while (CDCNT > 0) addtext("\204"), CDCNT--; if (gobbled) addtext(" "); addtext(ogcursor); } repcnt = 0; /* * Smash the generated and preexisting indents together * and generate one cleanly made out of tabs and spaces * if we are using autoindent. */ if (!vaifirst && value(AUTOINDENT)) { i = fixindent(indent); if (!HADUP) indent = i; gcursor = strend(genbuf); } /* * Limit the repetition count based on maximum * possible line length; do output implied * by further count (> 1) and cons up the new line * in linebuf. */ cnt = vmaxrep(ch, cnt); CP(gcursor + 1, cursor); do { CP(cursor, genbuf); if (cnt > 1) { int oldhold = hold; Outchar = vinschar; hold |= HOLDQIK; ex_printf("%s", genbuf); hold = oldhold; Outchar = vputchar; } cursor += gcursor - genbuf; } while (--cnt > 0); endim(); vUA2 = cursor; if (escape != '\n') CP(cursor, gcursor + 1); /* * If doomed characters remain, clobber them, * and reopen the line to get the display exact. */ if (state != HARDOPEN) { DEPTH(vcline) = 0; if (doomed > 0) { register int cind = cindent(); physdc(cind, cind + doomed); doomed = 0; } i = vreopen(LINE(vcline), lineDOT(), vcline); } /* * All done unless we are continuing on to another line. */ if (escape != '\n') break; /* * Set up for the new line. * First save the current line, then construct a new * first image for the continuation line consisting * of any new autoindent plus the pushed ahead text. */ killU(); addtext(gobblebl ? " " : "\n"); vsave(); cnt = 1; if (value(AUTOINDENT)) { #ifdef LISP if (value(LISP)) indent = lindent(dot + 1); else #endif if (!HADUP && vaifirst) indent = whitecnt(linebuf); vaifirst = 0; strcLIN(vpastwh(gcursor + 1)); gcursor = genindent(indent); *gcursor = 0; if (gcursor + strlen(linebuf) > &genbuf[LBSIZE - 2]) gcursor = genbuf; CP(gcursor, linebuf); } else { CP(genbuf, gcursor + 1); gcursor = genbuf; } /* * If we started out as a single line operation and are now * turning into a multi-line change, then we had better yank * out dot before it changes so that undo will work * correctly later. */ if (vundkind == VCHNG) { vremote(1, (void (*)(int))yank, 0); undap1--; } /* * Now do the append of the new line in the buffer, * and update the display. If slowopen * we don't do very much. */ vdoappend(genbuf); vundkind = VMANYINS; vcline++; if (state != VISUAL) vshow(dot, NOLINE); else { i += LINE(vcline - 1); vopen(dot, i); if (value(SLOWOPEN)) vscrap(); else vsync1(LINE(vcline)); } strcLIN(gcursor); *gcursor = 0; cursor = linebuf; vgotoCL(qcolumn(cursor - 1, genbuf)); } /* * All done with insertion, position the cursor * and sync the screen. */ hold = oldhold; if (cursor > linebuf) cursor--; if (state != HARDOPEN) vsyncCL(); else if (cursor > linebuf) back1(); doomed = 0; wcursor = cursor; vmove(); }
/* * Get a line into genbuf after gcursor. * Cnt limits the number of input characters * accepted and is used for handling the replace * single character command. Aescaped is the location * where we stick a termination indicator (whether we * ended with an ESCAPE or a newline/return. * * We do erase-kill type processing here and also * are careful about the way we do this so that it is * repeatable. (I.e. so that your kill doesn't happen, * when you repeat an insert if it was escaped with \ the * first time you did it. commch is the command character * involved, including the prompt for readline. */ char * vgetline(int cnt, char *gcursor, bool *aescaped, int commch) { register int c, ch; register char *cp; int x, y, iwhite, backsl=0; cell *iglobp; char cstr[2]; int (*OO)(int) = Outchar; /* * Clear the output state and counters * for autoindent backwards motion (counts of ^D, etc.) * Remember how much white space at beginning of line so * as not to allow backspace over autoindent. */ *aescaped = 0; ogcursor = gcursor; flusho(); CDCNT = 0; HADUP = 0; HADZERO = 0; gobbled = 0; iwhite = whitecnt(genbuf); iglobp = vglobp; /* * Carefully avoid using vinschar in the echo area. */ if (splitw) Outchar = vputchar; else { Outchar = vinschar; vprepins(); } for (;;) { backsl = 0; if (gobblebl) gobblebl--; if (cnt != 0) { cnt--; if (cnt == 0) goto vadone; } c = getkey(); if (c != ATTN) c &= (QUOTE|TRIM); ch = c; maphopcnt = 0; if (vglobp == 0 && Peekkey == 0 && commch != 'r') while ((ch = map(c, immacs)) != c) { c = ch; if (!value(REMAP)) break; if (++maphopcnt > 256) error(catgets(catd, 1, 234, "Infinite macro loop")); } if (!iglobp) { /* * Erase-kill type processing. * Only happens if we were not reading * from untyped input when we started. * Map users erase to ^H, kill to -1 for switch. */ if (c == tty.c_cc[VERASE]) c = CTRL('h'); else if (c == tty.c_cc[VKILL]) c = -1; if (c == ATTN) goto case_ATTN; switch (c) { /* * ^? Interrupt drops you back to visual * command mode with an unread interrupt * still in the input buffer. * * ^\ Quit does the same as interrupt. * If you are a ex command rather than * a vi command this will drop you * back to command mode for sure. */ case QUIT: case_ATTN: ungetkey(c); goto vadone; /* * ^H Backs up a character in the input. * * BUG: Can't back around line boundaries. * This is hard because stuff has * already been saved for repeat. */ case CTRL('h'): bakchar: cp = gcursor + skipleft(ogcursor, gcursor); if (cp < ogcursor) { if (splitw) { /* * Backspacing over readecho * prompt. Pretend delete but * don't beep. */ ungetkey(c); goto vadone; } beep(); continue; } goto vbackup; /* * ^W Back up a white/non-white word. */ case CTRL('w'): wdkind = 1; for (cp = gcursor; cp > ogcursor && isspace(cp[-1]&0377); cp--) continue; for (c = wordch(cp - 1); cp > ogcursor && wordof(c, cp - 1); cp--) continue; goto vbackup; /* * users kill Kill input on this line, back to * the autoindent. */ case -1: cp = ogcursor; vbackup: if (cp == gcursor) { beep(); continue; } endim(); *cp = 0; c = cindent(); vgotoCL(qcolumn(cursor + skipleft(linebuf, cursor), genbuf)); if (doomed >= 0) doomed += c - cindent(); gcursor = cp; continue; /* * \ Followed by erase or kill * maps to just the erase or kill. */ case '\\': x = destcol, y = destline; putchar('\\'); vcsync(); c = getkey(); if (c == tty.c_cc[VERASE] || c == tty.c_cc[VKILL]) { vgoto(y, x); if (doomed >= 0) doomed++; goto def; } ungetkey(c), c = '\\'; backsl = 1; break; /* * ^Q Super quote following character * Only ^@ is verboten (trapped at * a lower level) and \n forces a line * split so doesn't really go in. * * ^V Synonym for ^Q */ case CTRL('q'): case CTRL('v'): x = destcol, y = destline; putchar('^'); vgoto(y, x); c = getkey(); if (c != NL) { if (doomed >= 0) doomed++; goto def; } break; } } /* * If we get a blank not in the echo area * consider splitting the window in the wrapmargin. */ if (c != NL && !splitw) { if (c == ' ' && gobblebl) { gobbled = 1; continue; } if (value(WRAPMARGIN) && (outcol >= OCOLUMNS - value(WRAPMARGIN) || (backsl && outcol == 0)) && commch != 'r') { /* * At end of word and hit wrapmargin. * Move the word to next line and keep going. */ wdkind = 1; gappend(c); if (backsl) gappend(getkey()); *gcursor = 0; /* * Find end of previous word if we are past it. */ for (cp=gcursor; cp>ogcursor && isspace(cp[-1]&0377); cp--) ; if (outcol+(backsl?OCOLUMNS:0) - (gcursor-cp) >= OCOLUMNS - value(WRAPMARGIN)) { /* * Find beginning of previous word. */ for (; cp>ogcursor && !isspace(cp[-1]&0377); cp--) ; if (cp <= ogcursor) { /* * There is a single word that * is too long to fit. Just * let it pass, but beep for * each new letter to warn * the luser. */ c = *--gcursor; *gcursor = 0; beep(); goto dontbreak; } /* * Save it for next line. */ macpush(cp, 0); cp--; } macpush("\n", 0); /* * Erase white space before the word. */ while (cp > ogcursor && isspace(cp[-1]&0377)) cp--; /* skip blank */ gobblebl = 3; goto vbackup; } dontbreak:; } /* * Word abbreviation mode. */ cstr[0] = c; if (anyabbrs && gcursor > ogcursor && !wordch(cstr) && wordch(gcursor-1)) { int wdtype, abno; cstr[1] = 0; wdkind = 1; cp = gcursor + skipleft(ogcursor, gcursor); for (wdtype = wordch(cp - 1); cp > ogcursor && wordof(wdtype, cp - 1); cp--) ; *gcursor = 0; for (abno=0; abbrevs[abno].mapto; abno++) { if (!abbrevs[abno].hadthis && eq(cp, abbrevs[abno].cap)) { abbrevs[abno].hadthis++; macpush(cstr, 0); macpush(abbrevs[abno].mapto, 0); goto vbackup; } } } #ifdef BIT8 if (c == OVERBUF) goto btrp; #endif switch (c) { /* * ^M Except in repeat maps to \n. */ case CR: if (vglobp) goto def; c = '\n'; /* presto chango ... */ /* * \n Start new line. */ case NL: *aescaped = c; goto vadone; /* * escape End insert unless repeat and more to repeat. */ case ESCAPE: if (lastvgk) goto def; goto vadone; /* * ^D Backtab. * ^T Software forward tab. * * Unless in repeat where this means these * were superquoted in. */ case CTRL('d'): case CTRL('t'): if (vglobp) goto def; /* fall into ... */ /* * ^D|QUOTE Is a backtab (in a repeated command). */ #ifndef BIT8 case CTRL('d') | QUOTE: #else btrp: #endif *gcursor = 0; cp = vpastwh(genbuf); c = whitecnt(genbuf); if (ch == CTRL('t')) { /* * ^t just generates new indent replacing * current white space rounded up to soft * tab stop increment. */ if (cp != gcursor) /* * BUG: Don't hack ^T except * right after initial * white space. */ continue; cp = genindent(iwhite = backtab(c + value(SHIFTWIDTH) + 1)); ogcursor = cp; goto vbackup; } /* * ^D works only if we are at the (end of) the * generated autoindent. We count the ^D for repeat * purposes. */ if (c == iwhite && c != 0) { if (cp == gcursor) { iwhite = backtab(c); CDCNT++; ogcursor = cp = genindent(iwhite); goto vbackup; } else if (&cp[1] == gcursor && (*cp == '^' || *cp == '0')) { /* * ^^D moves to margin, then back * to current indent on next line. * * 0^D moves to margin and then * stays there. */ HADZERO = *cp == '0'; ogcursor = cp = genbuf; HADUP = 1 - HADZERO; CDCNT = 1; endim(); back1(); vputchar(' '); goto vbackup; } } if (vglobp && vglobp - iglobp >= 2 && (vglobp[-2] == '^' || vglobp[-2] == '0') && gcursor == ogcursor + 1) goto bakchar; continue; default: /* * Possibly discard control inputs. */ if (!vglobp && junk(c)) { beep(); continue; } def: if (!backsl) { /* int cnt; */ putchar(c); flush(); } if (gcursor > &genbuf[LBSIZE - 2]) error(catgets(catd, 1, 235, "Line too long")); gappend(c & TRIM); vcsync(); if (value(SHOWMATCH) && !iglobp) if (c == ')' || c == '}') lsmatch(gcursor); continue; } } vadone: *gcursor = 0; if (Outchar != termchar) Outchar = OO; endim(); return (gcursor); }
int main (int argc, const char * argv[]) { mainWindow = new sf::RenderWindow(sf::VideoMode(1440,900), "Alpha & Omega",sf::Style::Fullscreen); ezCursor cursor; std::vector<std::string> klm; getFileList(getResourcePath(0), "ttf", klm); // std::cout<<klm.size()<<std::endl; sf::Texture texture; if (!texture.loadFromFile(getResourcePath(1) + "davsan.png")) return EXIT_FAILURE; sf::Texture background; if(!background.loadFromFile(getResourcePath(1)+"ConfusedOrc.png")) return EXIT_FAILURE; sf::Sprite backSprite(background); backSprite.setPosition(0, 0); sf::Sprite back1(background); back1.setPosition(backSprite.getPosition().x+backSprite.getGlobalBounds().width, backSprite.getPosition().y); sf::Sprite back2(background); back2.setPosition(back1.getPosition().x+back1.getGlobalBounds().width, back1.getPosition().y); sf::Sprite sprite(texture); sprite.setPosition(720, 450); sf::Clock frameClock; int i=0,j=0; sf::View view = mainWindow->getView(); sf::View newView(sf::FloatRect(0,0,1440,900)); mainWindow->setFramerateLimit(90); while (mainWindow->isOpen()) { // Process events mainWindow->clear(); sf::Event event; while (mainWindow->pollEvent(event)) { // Close window : exit if (event.type == sf::Event::Closed) mainWindow->close(); // Escape pressed : exit if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) mainWindow->close(); if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Left) { newView.move(-10,0); } if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Right) { newView.move(10,0); } if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Up) { newView.move(0,-10); } if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Down) { newView.move(0,10); } } //sf::FloatRect rect(sf::Vector2f(view.getCenter() - sf::Vector2f(view.getSize().x/2, view.getSize().y/2)), sf::Vector2f(view.getSize())); //sprite.setPosition(rect.left+(rect.width/2), rect.top+(rect.height/2)); // sf::Vector2f paka=mainWindow->convertCoords(sf::Vector2i(ty,kl), view); // sf::Mouse::setPosition(sf::Vector2i(paka.x,paka.y)); if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) { std::cout<<"Mouse = "<<cursor.getPosition(newView).x<<" "<<cursor.getPosition(newView).y<<std::endl; std::cout<<"img = "<<back2.getGlobalBounds().left<<" "<<back2.getGlobalBounds().top<<std::endl; } //sprite.move(8.f*frameClock.getElapsedTime().asSeconds(),0.f*frameClock.getElapsedTime().asSeconds()); if(frameClock.getElapsedTime().asMilliseconds() >= 10000/100) { frameClock.restart(); i++; if(i==11) { j++; i=0; } if(j==5) { j=0; } } // std::cout<<i<<" "<<j<<std::endl; sprite.setTextureRect(sf::IntRect(100*i,120*0,100,120)); //sprite2.setTextureRect(sf::IntRect(100*i,120*0,100,120)); // Clear screen mainWindow->setView(newView); mainWindow->draw(backSprite); mainWindow->draw(back1); mainWindow->draw(back2); // Draw the sprite mainWindow->setView(mainWindow->getDefaultView()); mainWindow->draw(sprite); cursor.render(); mainWindow->display(); } return EXIT_SUCCESS; }
int main() { // setup window sf::Vector2i screenDimensions(576,272); sf::RenderWindow window(sf::VideoMode(screenDimensions.x, screenDimensions.y), "Rainsford"); window.setFramerateLimit(60); sf::Vector2f scaler(screenDimensions.x/72, screenDimensions.y/34); /*background setup There are 3 copies of each background layer (z-score), one is drawn in left and one is drawn right of the default background that is automatically drawn. After the any of the 3 copies moves its entire width left (position.x is negative width) it is assigned position.x = positive width. This "shuffles" the copies and gives an illusion of continuity. */ sf::RectangleShape titlescreen (sf::Vector2f(screenDimensions.x, screenDimensions.y)); sf::Texture title; if (!title.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Rainsford Titlescreen.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } titlescreen.setTexture(&title); // texture is a sf::Texture titlescreen.setTextureRect(sf::IntRect(0, 0, 576,272)); sf::RectangleShape titleback (sf::Vector2f(screenDimensions.x, screenDimensions.y)); sf::Texture titlebackTex; if (!titlebackTex.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Titleback.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } titleback.setTexture(&titlebackTex); // texture is a sf::Texture titleback.setTextureRect(sf::IntRect(0, 0, 576,272)); sf::RectangleShape moon (sf::Vector2f(screenDimensions.x, screenDimensions.y)); sf::Texture moonT; if (!moonT.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Moon.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } moon.setTexture(&moonT); // texture is a sf::Texture moon.setTextureRect(sf::IntRect(0, 0, 576,272)); //back1 sf::RectangleShape back1(sf::Vector2f(72,34)); sf::Texture textureBack1; if (!textureBack1.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background1.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } back1.setTexture(&textureBack1); // texture is a sf::Texture back1.setTextureRect(sf::IntRect(0, 0, 72,34)); //back2 sf::RectangleShape back2(sf::Vector2f(128,32)); sf::Texture textureBack2; if (!textureBack2.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background2.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } back2.setTexture(&textureBack2); // texture is a sf::Texture back2.setTextureRect(sf::IntRect(0, 0, 128,32)); sf::RectangleShape back2a(sf::Vector2f(128,32)); back2a.setTexture(&textureBack2); // texture is a sf::Texture back2a.setTextureRect(sf::IntRect(0, 0, 128,32)); back2a.setPosition(-128*8, 0); sf::RectangleShape back2b(sf::Vector2f(128,32)); back2b.setTexture(&textureBack2); // texture is a sf::Texture back2b.setTextureRect(sf::IntRect(0, 0, 128,32)); back2b.setPosition(128*8, 0); //back3 sf::RectangleShape back3(sf::Vector2f(128,32)); sf::Texture textureBack3; if (!textureBack3.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background3.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } back3.setTexture(&textureBack3); // texture is a sf::Texture back3.setTextureRect(sf::IntRect(0, 0, 128,32)); sf::RectangleShape back3a(sf::Vector2f(128,32)); back3a.setTexture(&textureBack3); // texture is a sf::Texture back3a.setTextureRect(sf::IntRect(0, 0, 128,32)); back3a.setPosition(-128*8, 0); sf::RectangleShape back3b(sf::Vector2f(128,32)); back3b.setTexture(&textureBack3); // texture is a sf::Texture back3b.setTextureRect(sf::IntRect(0, 0, 128,32)); back3b.setPosition(128*8, 0); //back4 sf::RectangleShape back4(sf::Vector2f(112,32)); sf::Texture textureBack4; if (!textureBack4.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background4.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } back4.setTexture(&textureBack4); // texture is a sf::Texture back4.setTextureRect(sf::IntRect(0, 0, 112,32)); sf::RectangleShape back4a(sf::Vector2f(112,32)); back4a.setTexture(&textureBack4); // texture is a sf::Texture back4a.setTextureRect(sf::IntRect(0, 0, 112,32)); back4a.setPosition(-112*8, 0); sf::RectangleShape back4b(sf::Vector2f(112,32)); back4b.setTexture(&textureBack4); // texture is a sf::Texture back4b.setTextureRect(sf::IntRect(0, 0, 112,32)); back4b.setPosition(112*8, 0); //back5 sf::RectangleShape back5(sf::Vector2f(96,32)); sf::Texture textureBack5; if (!textureBack5.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background5.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } back5.setTexture(&textureBack5); // texture is a sf::Texture back5.setTextureRect(sf::IntRect(0, 0, 96,32)); sf::RectangleShape back5a(sf::Vector2f(96,32)); back5a.setTexture(&textureBack5); // texture is a sf::Texture back5a.setTextureRect(sf::IntRect(0, 0, 96,32)); back5a.setPosition(-96*8, 0); sf::RectangleShape back5b(sf::Vector2f(96,32)); back5b.setTexture(&textureBack5); // texture is a sf::Texture back5b.setTextureRect(sf::IntRect(0, 0, 96,32)); back5b.setPosition(96*8, 0); //back6 sf::RectangleShape back6(sf::Vector2f(72,32)); sf::Texture textureBack6; if (!textureBack6.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background6.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } back6.setTexture(&textureBack6); // texture is a sf::Texture back6.setTextureRect(sf::IntRect(0, 0, 72,32)); sf::RectangleShape back6a(sf::Vector2f(72,32)); back6a.setTexture(&textureBack6); // texture is a sf::Texture back6a.setTextureRect(sf::IntRect(0, 0, 72,32)); back6a.setPosition(-72*8, 0); sf::RectangleShape back6b(sf::Vector2f(72,32)); back6b.setTexture(&textureBack6); // texture is a sf::Texture back6b.setTextureRect(sf::IntRect(0, 0, 72,32)); back6b.setPosition(72*8, 0); //moonlight sf::RectangleShape moonlight(sf::Vector2f(96,32)); sf::Texture textureMoon; if (!textureMoon.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Moonlight.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } moonlight.setTexture(&textureMoon); // texture is a sf::Texture moonlight.setTextureRect(sf::IntRect(0, 0, 96,32)); sf::RectangleShape moonlighta(sf::Vector2f(96,32)); moonlighta.setTexture(&textureBack6); // texture is a sf::Texture moonlighta.setTextureRect(sf::IntRect(0, 0, 96,32)); moonlighta.setPosition(-96*8, 0); sf::RectangleShape moonlightb(sf::Vector2f(96,32)); moonlightb.setTexture(&textureMoon); // texture is a sf::Texture moonlightb.setTextureRect(sf::IntRect(0, 0, 96,32)); moonlightb.setPosition(96*8, 0); //vines sf::RectangleShape vines(sf::Vector2f(96,32)); sf::Texture textureVines; if (!textureVines.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Vines.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } vines.setTexture(&textureVines); // texture is a sf::Texture vines.setTextureRect(sf::IntRect(0, 0, 96,32)); sf::RectangleShape vinesa(sf::Vector2f(96,32)); vinesa.setTexture(&textureVines); // texture is a sf::Texture vinesa.setTextureRect(sf::IntRect(0, 0, 96,32)); vinesa.setPosition(-96*8, 0); sf::RectangleShape vinesb(sf::Vector2f(96,32)); vinesb.setTexture(&textureVines); // texture is a sf::Texture vinesb.setTextureRect(sf::IntRect(0, 0, 96,32)); vinesb.setPosition(96*8, 0); //end of backgrounds *********************************************************** back1.scale(scaler); back2.scale(scaler); back3.scale(scaler); back4.scale(scaler); back5.scale(scaler); back6.scale(scaler); vines.scale(scaler); back2a.scale(scaler); back3a.scale(scaler); back4a.scale(scaler); back5a.scale(scaler); back6a.scale(scaler); vinesa.scale(scaler); back2b.scale(scaler); back3b.scale(scaler); back4b.scale(scaler); back5b.scale(scaler); back6b.scale(scaler); vinesb.scale(scaler); moonlight.scale(scaler); moonlighta.scale(scaler); moonlightb.scale(scaler); //flickering stormlamp spritesheet sf::Texture stormLamp; if (!stormLamp.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/RainsfordStormLamp_Spritesheet.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } Animation flicker; flicker.setSpriteSheet(stormLamp); flicker.addFrame(sf::IntRect (0, 0, 160, 90)); flicker.addFrame(sf::IntRect (0, 90, 160, 90)); flicker.addFrame(sf::IntRect (0, 180, 160, 90)); flicker.addFrame(sf::IntRect (0, 90, 160, 90)); AnimatedSprite flickerSprite(sf::seconds(.3), true, false); flickerSprite.scale(scaler); flickerSprite.setPosition(((-160/scaler.x)*18), -120*scaler.y/4); //IVAN STUFF // load texture (spritesheet) sf::Texture textureIvan; if (!textureIvan.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Spritesheet_Ivan.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } // set up the animations for all four directions (set spritesheet and push frames) Animation ivan_standingRight; ivan_standingRight.setSpriteSheet(textureIvan); ivan_standingRight.addFrame(sf::IntRect(0, 0, 8, 8)); ivan_standingRight.addFrame(sf::IntRect(8, 0, 8, 8)); ivan_standingRight.addFrame(sf::IntRect(16, 0, 8, 8)); ivan_standingRight.addFrame(sf::IntRect( 24, 0, 8, 8)); ivan_standingRight.addFrame(sf::IntRect(32, 0, 8, 8)); ivan_standingRight.addFrame(sf::IntRect( 40, 0, 8, 8)); Animation ivan_standingLeft; ivan_standingLeft.setSpriteSheet(textureIvan); ivan_standingLeft.addFrame(sf::IntRect(0, 8, 8, 8)); ivan_standingLeft.addFrame(sf::IntRect(8, 8, 8, 8)); ivan_standingLeft.addFrame(sf::IntRect(16, 8, 8, 8)); ivan_standingLeft.addFrame(sf::IntRect( 24, 8, 8, 8)); ivan_standingLeft.addFrame(sf::IntRect(32, 8, 8, 8)); ivan_standingLeft.addFrame(sf::IntRect(40, 8, 8, 8)); Animation ivan_walkingRight; ivan_walkingRight.setSpriteSheet(textureIvan); ivan_walkingRight.addFrame(sf::IntRect(0, 16, 8, 8)); ivan_walkingRight.addFrame(sf::IntRect(8, 16, 8, 8)); ivan_walkingRight.addFrame(sf::IntRect(16, 16, 8, 8)); ivan_walkingRight.addFrame(sf::IntRect( 24, 16, 8, 8)); ivan_walkingRight.addFrame(sf::IntRect(32, 16, 8, 8)); ivan_walkingRight.addFrame(sf::IntRect( 40, 16, 8, 8)); Animation ivan_walkingLeft; ivan_walkingLeft.setSpriteSheet(textureIvan); ivan_walkingLeft.addFrame(sf::IntRect(0, 24, 8, 8)); ivan_walkingLeft.addFrame(sf::IntRect(8, 24, 8, 8)); ivan_walkingLeft.addFrame(sf::IntRect(16, 24, 8, 8)); ivan_walkingLeft.addFrame(sf::IntRect( 24, 24, 8, 8)); ivan_walkingLeft.addFrame(sf::IntRect(32, 24, 8, 8)); ivan_walkingLeft.addFrame(sf::IntRect( 40, 24, 8, 8)); Animation* currentIvanAnimation = &ivan_standingRight; AnimatedSprite ivan(sf::seconds(.07), true, false); ivan.setPosition(sf::Vector2f(screenDimensions.x / 2 - 264, 192)); ivan.scale(scaler); // DOG load texture (spritesheet) sf::Texture textureDog; if (!textureDog.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Spritesheet_Dog.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } //dog spritesheet animation setup Animation dog_standingRight; dog_standingRight.setSpriteSheet(textureDog); dog_standingRight.addFrame(sf::IntRect(0, 0, 8, 8)); dog_standingRight.addFrame(sf::IntRect(8, 0, 8, 8)); dog_standingRight.addFrame(sf::IntRect(16, 0, 8, 8)); dog_standingRight.addFrame(sf::IntRect( 24, 0, 8, 8)); Animation dog_standingLeft; dog_standingLeft.setSpriteSheet(textureDog); dog_standingLeft.addFrame(sf::IntRect(0, 8, 8, 8)); dog_standingLeft.addFrame(sf::IntRect(8, 8, 8, 8)); dog_standingLeft.addFrame(sf::IntRect(16, 8, 8, 8)); dog_standingLeft.addFrame(sf::IntRect( 24, 8, 8, 8)); Animation dog_walkingRight; dog_walkingRight.setSpriteSheet(textureDog); dog_walkingRight.addFrame(sf::IntRect(0, 16, 8, 8)); dog_walkingRight.addFrame(sf::IntRect(8, 16, 8, 8)); dog_walkingRight.addFrame(sf::IntRect(16, 16, 8, 8)); dog_walkingRight.addFrame(sf::IntRect( 24, 16, 8, 8)); Animation dog_walkingLeft; dog_walkingLeft.setSpriteSheet(textureDog); dog_walkingLeft.addFrame(sf::IntRect(0, 24, 8, 8)); dog_walkingLeft.addFrame(sf::IntRect(8, 24, 8, 8)); dog_walkingLeft.addFrame(sf::IntRect(16, 24, 8, 8)); dog_walkingLeft.addFrame(sf::IntRect( 24, 24, 8, 8)); Animation dog_walkingRightHostile; dog_walkingRightHostile.setSpriteSheet(textureDog); dog_walkingRightHostile.addFrame(sf::IntRect(0, 32, 8, 8)); dog_walkingRightHostile.addFrame(sf::IntRect(8, 32, 8, 8)); dog_walkingRightHostile.addFrame(sf::IntRect(16, 32, 8, 8)); dog_walkingRightHostile.addFrame(sf::IntRect( 24, 32, 8, 8)); Animation dog_walkingLeftHostile; dog_walkingLeftHostile.setSpriteSheet(textureDog); dog_walkingLeftHostile.addFrame(sf::IntRect(0, 40, 8, 8)); dog_walkingLeftHostile.addFrame(sf::IntRect(8, 40, 8, 8)); dog_walkingLeftHostile.addFrame(sf::IntRect(16, 40, 8, 8)); dog_walkingLeftHostile.addFrame(sf::IntRect( 24, 40, 8, 8)); Animation* currentDogAnimation = &dog_standingRight; AnimatedSprite dog(sf::seconds(.07), true, false); dog.setPosition(sf::Vector2f(screenDimensions.x / 2 - 200, 192)); dog.scale(scaler); // load texture (spritesheet) sf::Texture texture; if (!texture.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Spritesheet_Rainsford.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } // set up the animations for all directions (set spritesheet and push frames) Animation standingRight; standingRight.setSpriteSheet(texture); standingRight.addFrame(sf::IntRect(0, 0, 8, 8)); standingRight.addFrame(sf::IntRect(8, 0, 8, 8)); standingRight.addFrame(sf::IntRect(16, 0, 8, 8)); standingRight.addFrame(sf::IntRect( 24, 0, 8, 8)); // standingRight.addFrame(sf::IntRect(32, 0, 8, 8)); // standingRight.addFrame(sf::IntRect( 40, 0, 8, 8)); Animation standingLeft; standingLeft.setSpriteSheet(texture); standingLeft.addFrame(sf::IntRect(0, 8, 8, 8)); standingLeft.addFrame(sf::IntRect(8, 8, 8, 8)); standingLeft.addFrame(sf::IntRect(16, 8, 8, 8)); standingLeft.addFrame(sf::IntRect( 24, 8, 8, 8)); // standingLeft.addFrame(sf::IntRect(32, 8, 8, 8)); // standingLeft.addFrame(sf::IntRect(40, 8, 8, 8)); Animation walkingRight; walkingRight.setSpriteSheet(texture); walkingRight.addFrame(sf::IntRect(0, 16, 8, 8)); walkingRight.addFrame(sf::IntRect(8, 16, 8, 8)); walkingRight.addFrame(sf::IntRect(16, 16, 8, 8)); walkingRight.addFrame(sf::IntRect( 24, 16, 8, 8)); //walkingRight.addFrame(sf::IntRect(32, 16, 8, 8)); //walkingRight.addFrame(sf::IntRect( 40, 16, 8, 8)); Animation walkingLeft; walkingLeft.setSpriteSheet(texture); walkingLeft.addFrame(sf::IntRect(0, 24, 8, 8)); walkingLeft.addFrame(sf::IntRect(8, 24, 8, 8)); walkingLeft.addFrame(sf::IntRect(16, 24, 8, 8)); walkingLeft.addFrame(sf::IntRect( 24, 24, 8, 8)); //walkingLeft.addFrame(sf::IntRect(32, 24, 8, 8)); //walkingLeft.addFrame(sf::IntRect( 40, 24, 8, 8)); Animation jumpingRight; jumpingRight.setSpriteSheet(texture); jumpingRight.addFrame(sf::IntRect(0, 32, 8, 8)); jumpingRight.addFrame(sf::IntRect(8, 32, 8, 8)); jumpingRight.addFrame(sf::IntRect(16, 32, 8, 8)); jumpingRight.addFrame(sf::IntRect( 24, 32, 8, 8)); //jumpingRight.addFrame(sf::IntRect(32, 32, 8, 8)); //jumpingRight.addFrame(sf::IntRect( 40, 32, 8, 8)); Animation jumpingLeft; jumpingLeft.setSpriteSheet(texture); jumpingLeft.addFrame(sf::IntRect(0, 40, 8, 8)); jumpingLeft.addFrame(sf::IntRect(8, 40, 8, 8)); jumpingLeft.addFrame(sf::IntRect(16, 40, 8, 8)); jumpingLeft.addFrame(sf::IntRect( 24, 40, 8, 8)); //jumpingLeft.addFrame(sf::IntRect(32, 40, 8, 8)); //jumpingLeft.addFrame(sf::IntRect( 40, 40, 8, 8)); Animation crawlingRight; crawlingRight.setSpriteSheet(texture); crawlingRight.addFrame(sf::IntRect(0, 64, 8, 8)); crawlingRight.addFrame(sf::IntRect(8, 64, 8, 8)); crawlingRight.addFrame(sf::IntRect(16, 64, 8, 8)); crawlingRight.addFrame(sf::IntRect( 24, 64, 8, 8)); //jumpingRight.addFrame(sf::IntRect(32, 32, 8, 8)); //jumpingRight.addFrame(sf::IntRect( 40, 32, 8, 8)); Animation crawlingLeft; crawlingLeft.setSpriteSheet(texture); crawlingLeft.addFrame(sf::IntRect(0, 72, 8, 8)); crawlingLeft.addFrame(sf::IntRect(8, 72, 8, 8)); crawlingLeft.addFrame(sf::IntRect(16, 72, 8, 8)); crawlingLeft.addFrame(sf::IntRect( 24, 72, 8, 8)); //jumpingLeft.addFrame(sf::IntRect(32, 40, 8, 8)); //jumpingLeft.addFrame(sf::IntRect( 40, 40, 8, 8)); Animation disguise1; disguise1.setSpriteSheet(texture); disguise1.addFrame(sf::IntRect(0, 48, 8, 8)); Animation disguise2; disguise2.setSpriteSheet(texture); disguise2.addFrame(sf::IntRect(8, 48, 8, 8)); Animation disguise3; disguise3.setSpriteSheet(texture); disguise3.addFrame(sf::IntRect(16, 48, 8, 8)); Animation disguise4; disguise4.setSpriteSheet(texture); disguise4.addFrame(sf::IntRect(24, 48, 8, 8)); Animation crouchedRight; crouchedRight.setSpriteSheet(texture); crouchedRight.addFrame(sf::IntRect(0, 56, 8, 8)); Animation crouchedLeft; crouchedLeft.setSpriteSheet(texture); crouchedLeft.addFrame(sf::IntRect(8, 56, 8, 8)); Animation* currentAnimation = &standingRight; float rainsfordAnimationSpeed = .07; // set up AnimatedSprite AnimatedSprite animatedSprite(sf::seconds(rainsfordAnimationSpeed), true, false); animatedSprite.setPosition(sf::Vector2f(screenDimensions.x / 2 - 64, 192)); animatedSprite.scale(scaler); sf::Clock frameClock; float speed = 650.f; bool noKeyWasPressed = true; enum direction { left, right}; direction currentDir = right; while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) window.close(); } sf::Time frameTime = frameClock.restart(); // if a key was pressed set the correct animation and move correctly sf::Vector2f movement(0.f, 0.f); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { if(currentDir == left) { currentAnimation = &jumpingLeft; noKeyWasPressed = false; } if(currentDir == right) { currentAnimation = &jumpingRight; noKeyWasPressed = false; } } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { currentAnimation = &crawlingLeft; currentDogAnimation = &dog_walkingLeft; //DOG ANIMATION currentIvanAnimation = &ivan_walkingLeft; //Ivan ANIMATION movement.x += .2*speed; noKeyWasPressed = false; currentDir = left; } else { currentAnimation = &walkingLeft; currentDogAnimation = &dog_walkingLeftHostile; //DOG ANIMATION currentIvanAnimation = &ivan_walkingLeft; //Ivan ANIMATION movement.x += speed; noKeyWasPressed = false; currentDir = left; } } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { currentAnimation = &crawlingRight; currentDogAnimation = &dog_walkingRight; //DOG ANIMATION currentIvanAnimation = &ivan_walkingRight; //Ivan ANIMATION movement.x -= .2*speed; noKeyWasPressed = false; currentDir = right; } else { currentAnimation = &walkingRight; currentDogAnimation = &dog_walkingRightHostile; //DOG ANIMATION currentIvanAnimation = &ivan_walkingRight; //Ivan ANIMATION movement.x -= speed; noKeyWasPressed = false; currentDir = right; } } } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { if(currentDir == left) { currentAnimation = &crouchedLeft; noKeyWasPressed = false; } if(currentDir == right) { currentAnimation = &crouchedRight; noKeyWasPressed = false; } } if (sf::Keyboard::isKeyPressed(sf::Keyboard::E)) { currentAnimation = &disguise1; noKeyWasPressed = false; movement.x = 0; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::R)) { currentAnimation = &disguise2; noKeyWasPressed = false; movement.x = 0; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::T)) { currentAnimation = &disguise3; noKeyWasPressed = false; movement.x = 0; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Y)) { currentAnimation = &disguise4; noKeyWasPressed = false; movement.x = 0; } // if no key was pressed if (noKeyWasPressed) { sf::Time slowerFrameTime = sf::seconds(.3); animatedSprite.setFrameTime(slowerFrameTime); dog.setFrameTime(slowerFrameTime); //DOG WUZ HERE ivan.setFrameTime(slowerFrameTime); //IVAn if (currentDir == left) { currentAnimation = &standingLeft; currentDogAnimation = &dog_standingLeft;// DAWG HERE TOO DOG currentIvanAnimation = &ivan_standingLeft;// IVAN } if (currentDir == right) { currentAnimation = &standingRight; currentDogAnimation = &dog_standingRight; // DAWG HERE TOO 2 DOG currentIvanAnimation = &ivan_standingRight;// IVAN } } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { animatedSprite.setFrameTime(sf::seconds(.15)); dog.setFrameTime(sf::seconds(.15));//DOOOOOOOGGGGEEE DOG ivan.setFrameTime(sf::seconds(.15));//IVAN } else { animatedSprite.setFrameTime(sf::seconds(.07)); dog.setFrameTime(sf::seconds(.07));//DOOOOOOOGGGGEEEDOOOOOOOGGGGEEEDOOOOOOOGGGGEEE DOG ivan.setFrameTime(sf::seconds(.07));//IVAN } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { //EDGE EFFECT HERE if (back2.getPosition().x <= back2.getSize().x*-8) { back2.setPosition(back2.getSize().x*8, 0); } if (back2a.getPosition().x <= back2a.getSize().x*-8) { back2a.setPosition(back2a.getSize().x*8, 0); } if (back2b.getPosition().x <= back2b.getSize().x*-8) { back2b.setPosition(back2b.getSize().x*8, 0); } if (back3.getPosition().x <= back3.getSize().x*-8) { back3.setPosition(back3.getSize().x*8, 0); } if (back3a.getPosition().x <= back3a.getSize().x*-8) { back3a.setPosition(back3a.getSize().x*8, 0); } if (back3b.getPosition().x <= back3b.getSize().x*-8) { back3b.setPosition(back3b.getSize().x*8, 0); } if (back4.getPosition().x <= back4.getSize().x*-8) { back4.setPosition(back4.getSize().x*8, 0); } if (back4a.getPosition().x <= back4a.getSize().x*-8) { back4a.setPosition(back4a.getSize().x*8, 0); } if (back4b.getPosition().x <= back4b.getSize().x*-8) { back4b.setPosition(back4b.getSize().x*8, 0); } if (back5.getPosition().x <= back5.getSize().x*-8) { back5.setPosition(back5.getSize().x*8, 0); } if (back5a.getPosition().x <= back5a.getSize().x*-8) { back5a.setPosition(back5a.getSize().x*8, 0); } if (back5b.getPosition().x <= back5b.getSize().x*-8) { back5b.setPosition(back5b.getSize().x*8, 0); } if (back6.getPosition().x <= back6.getSize().x*-8) { back6.setPosition(back6.getSize().x*8, 0); } if (back6a.getPosition().x <= back6a.getSize().x*-8) { back6a.setPosition(back6a.getSize().x*8, 0); } if (back6b.getPosition().x <= back6b.getSize().x*-8) { back6b.setPosition(back6b.getSize().x*8, 0); } //vines if (vines.getPosition().x <= vines.getSize().x*-8) { vines.setPosition(vines.getSize().x*8, 0); } if (vinesa.getPosition().x <= vinesa.getSize().x*-8) { vinesa.setPosition(vinesa.getSize().x*8, 0); } if (vinesb.getPosition().x <= vinesb.getSize().x*-8) { vinesb.setPosition(vinesb.getSize().x*8, 0); } //moonlight if (moonlight.getPosition().x <= moonlight.getSize().x*-8) { moonlight.setPosition(moonlight.getSize().x*8, 0); } if (moonlighta.getPosition().x <= moonlighta.getSize().x*-8) { moonlighta.setPosition(moonlighta.getSize().x*8, 0); } if (moonlightb.getPosition().x <= moonlightb.getSize().x*-8) { moonlightb.setPosition(moonlightb.getSize().x*8, 0); } } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { //positive /* if (back2.getPosition().x >= back2.getSize().x*8) { back2.setPosition(back2.getSize().x*-8, 0); } if (back2a.getPosition().x >= back2a.getSize().x*8) { back2a.setPosition(back2a.getSize().x*-8, 0); } if (back2b.getPosition().x >= back2b.getSize().x*8) { back2b.setPosition(back2b.getSize().x*-8, 0); } if (back3.getPosition().x >= back3.getSize().x*8) { back3.setPosition(back3.getSize().x*-8, 0); } if (back3a.getPosition().x >= back3a.getSize().x*8) { back3a.setPosition(back3a.getSize().x*-8, 0); } if (back3b.getPosition().x >= back3b.getSize().x*8) { back3b.setPosition(back3b.getSize().x*-8, 0); } */ if (back4.getPosition().x >= back4.getSize().x*8) { back4.setPosition(back4.getSize().x*-8, 0); } if (back4a.getPosition().x >= back4a.getSize().x*8) { back4a.setPosition(back4a.getSize().x*-8, 0); } if (back4b.getPosition().x >= back4b.getSize().x*8) { back4b.setPosition(back4b.getSize().x*-8, 0); } if (back5.getPosition().x >= back5.getSize().x*8) { back5.setPosition(back5.getSize().x*-8, 0); } if (back5a.getPosition().x >= back5a.getSize().x*8) { back5a.setPosition(back5a.getSize().x*-8, 0); } if (back5b.getPosition().x >= back5b.getSize().x*8) { back5b.setPosition(back5b.getSize().x*-8, 0); } if (back6.getPosition().x >= back6.getSize().x*8) { back6.setPosition(back6.getSize().x*-8, 0); } if (back6a.getPosition().x >= back6a.getSize().x*8) { back6a.setPosition(back6a.getSize().x*-8, 0); } if (back6b.getPosition().x >= back6b.getSize().x*8) { back6b.setPosition(back6b.getSize().x*-8, 0); } //vines if (vines.getPosition().x >= vines.getSize().x*8) { vines.setPosition(vines.getSize().x*-8, 0); } if (vinesa.getPosition().x >= vinesa.getSize().x*8) { vinesa.setPosition(vinesa.getSize().x*-8, 0); } if (vinesb.getPosition().x >= vinesb.getSize().x*8) { vinesb.setPosition(vinesb.getSize().x*-8, 0); } //moonlight if (moonlight.getPosition().x >= moonlight.getSize().x*8) { moonlight.setPosition(moonlight.getSize().x*-8, 0); } if (moonlighta.getPosition().x >= moonlighta.getSize().x*8) { moonlighta.setPosition(moonlighta.getSize().x*-8, 0); } if (moonlightb.getPosition().x >= moonlightb.getSize().x*8) { moonlightb.setPosition(moonlightb.getSize().x*-8, 0); } } float timeMov = 1; timeMov = frameTime.asSeconds(); ivan.play(*currentIvanAnimation); dog.play(*currentDogAnimation);//dog animation here animatedSprite.play(*currentAnimation); flickerSprite.play(flicker); animatedSprite.move(0,0); back2.move(-16 * timeMov, 0); back3.move(-32 * timeMov, 0); back4.move(.3*movement.x * timeMov, 0); moonlight.move(.45*movement.x * timeMov, 0); back5.move(.55*movement.x * timeMov, 0); vines.move(.65*movement.x * timeMov, 0); back6.move(.8*movement.x * timeMov, 0); back2a.move(-16 * timeMov, 0); back3a.move(-32 * timeMov, 0); back4a.move(.3*movement.x * timeMov, 0); moonlighta.move(.45*movement.x * timeMov, 0); back5a.move(.55*movement.x * timeMov, 0); vinesa.move(.65*movement.x * timeMov, 0); back6a.move(.8*movement.x * timeMov, 0); back2b.move(-16 * timeMov, 0); back3b.move(-32 * timeMov, 0); back4b.move(.3*movement.x * timeMov, 0); moonlightb.move(.45*movement.x * timeMov, 0); back5b.move(.55*movement.x * timeMov, 0); vinesb.move(.65*movement.x * timeMov, 0); back6b.move(.8*movement.x * timeMov, 0); noKeyWasPressed = true; // update AnimatedSprite dog.update(frameTime);//dog ivan.update(frameTime);//ivan animatedSprite.update(frameTime); flickerSprite.update(sf::seconds(.03f)); // draw window.clear(); window.draw(titleback); window.draw(moon); //window.draw(back1); window.draw(back2); window.draw(back2a); window.draw(back2b); window.draw(back3); window.draw(back3a); window.draw(back3b); /*window.draw(back4); window.draw(back4a); window.draw(back4b); window.draw(back5); window.draw(back5a); window.draw(back5b); window.draw(back6); window.draw(back6a); window.draw(back6b); window.draw(animatedSprite); window.draw(dog);//dog window.draw(ivan);//ivan */ window.draw(titlescreen); int flickerCounter = 0; if (sf::Keyboard::isKeyPressed(sf::Keyboard::F)) { if(flickerCounter==0) flickerCounter++; else flickerCounter--; } if(flickerCounter!=0) window.draw(flickerSprite); window.display(); } return 0; }
void player::draw(float x, float y, float z){ glPushAttrib(GL_ALL_ATTRIB_BITS); float ambient=1; float diffuse=1; float specular=1; float emission=0; float shininess=50; GLfloat mat_ambient[] = {ambient, ambient, ambient, 1.0f}; GLfloat mat_diffuse[] = {diffuse, diffuse, diffuse, 1.0f}; GLfloat mat_specular[] = {specular, specular, specular, 1.0f}; GLfloat mat_emission[] = {emission, emission, emission, 1.0f}; GLfloat mat_shininess = shininess; glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission); glMaterialf (GL_FRONT, GL_SHININESS, mat_shininess); glPushMatrix(); glTranslatef(x, 0, 0); glTranslatef(0, y-1, 0); glTranslatef(0, 0, z-5); glRotatef(45,1,0,0); glEnable(GL_TEXTURE_2D); node back1(-0.25, 0.15, 0.25); node back2(-.5, -.35, .25); node back3(.5, -.35, .25); node back4(.25, .15, .25); node front1(-.25,.25,-.25); node front2(.25, .25, -.25); node front3(.25,-.25,-.25); node front4(-.25, -.25, -.25); node hexA1(0.05, .087, -0.25); node hexA2(0.1, 0, -0.25); node hexA3(0.05, -0.087, -0.25); node hexA4(-0.05, -0.087, -0.25); node hexA5(-0.1, 0, -0.25); node hexA6(-0.05, 0.087, -0.25); node hexB1(0.05, .087, -0.75); node hexB2(0.1, 0, -0.75); node hexB3(0.05, -0.087, -0.75); node hexB4(-0.05, -0.087, -0.75); node hexB5(-0.1, 0, -0.75); node hexB6(-0.05, 0.087, -0.75); node fa1(0.25, 0.087, -0.25); node fa2(0.25, 0, -0.25); node fa3(0.25, -0.087, -0.25); node fb1(-0.25, 0.087, -0.25); node fb2(-0.25, 0, -0.25); node fb3(-0.25, -0.087, -0.25); //backside glBindTexture(GL_TEXTURE_2D, p_tex); glColor3f(.25, .30, 0.3); glBegin(GL_QUADS); glTexCoord2d(1, 1); glVertex3f(back1.x, back1.y, back1.z); glTexCoord2d(0, 1); glVertex3f(back2.x, back2.y, back2.z); glTexCoord2d(1, 0); glVertex3f(back3.x, back3.y, back3.z); glTexCoord2d(0, 0); glVertex3f(back4.x, back4.y, back4.z); glEnd(); glDisable(GL_TEXTURE_2D); //frontside glBegin(GL_QUADS); glColor3f(0.6, 0.1, 0); glVertex3f(front1.x, front1.y, front1.z); glColor3f(0.6, 0.1, 0); glVertex3f(front2.x, front2.y, front2.z); glColor3f(0.6, 0.1, 0); glVertex3f(fa1.x, fa1.y, fa1.z); glColor3f(0.6, 0.1, 0); glVertex3f(fb1.x, fb1.y, fb1.z); glColor3f(0.6, 0.1, 0); glVertex3f(fa1.x, fa1.y, fa1.z); glColor3f(0.6, 0.1, 0); glVertex3f(fa2.x, fa2.y, fa2.z); glColor3f(0.6, 0.1, 0); glVertex3f(hexA2.x, hexA2.y, hexA2.z); glColor3f(0.6, 0.1, 0); glVertex3f(hexA1.x, hexA1.y, hexA1.z); glColor3f(0.6, 0.1, 0); glVertex3f(fa2.x, fa2.y, fa2.z); glColor3f(0.6, 0.1, 0); glVertex3f(fa3.x, fa3.y, fa3.z); glColor3f(0.6, 0.1, 0); glVertex3f(hexA3.x, hexA3.y, hexA3.z); glColor3f(0.6, 0.1, 0); glVertex3f(hexA2.x, hexA2.y, hexA2.z); glColor3f(0.6, 0.1, 0); glVertex3f(fa3.x, fa3.y, fa3.z); glColor3f(0.6, 0.1, 0); glVertex3f(front3.x, front3.y, front3.z); glColor3f(0.6, 0.1, 0); glVertex3f(front4.x, front4.y, front4.z); glColor3f(0.6, 0.1, 0); glVertex3f(fb3.x, fb3.y, fb3.z); glColor3f(0.6, 0.1, 0); glVertex3f(hexA5.x, hexA5.y, hexA5.z); glColor3f(0.6, 0.1, 0); glVertex3f(hexA4.x, hexA4.y, hexA4.z); glColor3f(0.6, 0.1, 0); glVertex3f(fb3.x, fb3.y, fb3.z); glColor3f(0.6, 0.1, 0); glVertex3f(fb2.x, fb2.y, fb2.z); glColor3f(0.6, 0.1, 0); glVertex3f(hexA5.x, hexA5.y, hexA5.z); glColor3f(0.6, 0.1, 0); glVertex3f(fb2.x, fb2.y, fb2.z); glColor3f(0.6, 0.1, 0); glVertex3f(fb1.x, fb1.y, fb1.z); glColor3f(0.6, 0.1, 0); glVertex3f(hexA6.x, hexA6.y, hexA6.z); glEnd(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, p_tex1); //upside glColor3f(.25, .30, 0.3); glBegin(GL_QUADS); // glTexCoord2d(1, 1); glVertex3f(back1.x, back1.y, back1.z); glTexCoord2d(0, 1); glVertex3f(back4.x, back4.y, back4.z); glTexCoord2d(1, 0); glVertex3f(front2.x, front2.y, front2.z); glTexCoord2d(0, 0); glVertex3f(front1.x, front1.y, front1.z); glEnd(); glBindTexture(GL_TEXTURE_2D, p_tex); //leftside glColor3f(.25, .30, 0.3); glBegin(GL_QUADS); // glTexCoord2d(1, 1); glVertex3f(back1.x, back1.y, back1.z); glTexCoord2d(0, 1); glVertex3f(front1.x, front1.y, front1.z); glTexCoord2d(1, 0); glVertex3f(front4.x, front4.y, front4.z); glTexCoord2d(0, 0); glVertex3f(back2.x, back2.y, back2.z); glEnd(); glBindTexture(GL_TEXTURE_2D, p_tex); //rightside glColor3f(.25, .30, 0.3); glBegin(GL_QUADS); // glTexCoord2d(1, 1); glVertex3f(back4.x, back4.y, back4.z); glTexCoord2d(0, 1); glVertex3f(back3.x, back3.y, back3.z); glTexCoord2d(1, 0); glVertex3f(front3.x, front3.y, front3.z); glTexCoord2d(0, 0); glVertex3f(front2.x, front2.y, front2.z); glEnd(); glDisable(GL_TEXTURE_2D); //downside glBegin(GL_QUADS); glColor3f(.25, .30, 0.3); glVertex3f(back3.x, back3.y, back3.z); glColor3f(.25, .30, 0.3); glVertex3f(back2.x, back2.y, back2.z); glColor3f(.25, .30, 0.3); glVertex3f(front4.x, front4.y, front4.z); glColor3f(.25, .30, 0.3); glVertex3f(front3.x, front3.y, front3.z); glEnd(); //pipe glBegin(GL_QUADS); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA1.x, hexA1.y, hexA1.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA2.x, hexA2.y, hexA2.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB2.x, hexB2.y, hexB2.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB1.x, hexB1.y, hexB1.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB2.x, hexB2.y, hexB2.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA2.x, hexA2.y, hexA2.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA3.x, hexA3.y, hexA3.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB3.x, hexB3.y, hexB3.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA3.x, hexA3.y, hexA3.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA4.x, hexA4.y, hexA4.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB4.x, hexB4.y, hexB4.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB3.x, hexB3.y, hexB3.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA4.x, hexA4.y, hexA4.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA5.x, hexA5.y, hexA5.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB5.x, hexB5.y, hexB5.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB4.x, hexB4.y, hexB4.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA5.x, hexA5.y, hexA5.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA6.x, hexA6.y, hexA6.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB6.x, hexB6.y, hexB6.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB5.x, hexB5.y, hexB5.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA6.x, hexA6.y, hexA6.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA1.x, hexA1.y, hexA1.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB1.x, hexB1.y, hexB1.z); glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB6.x, hexB6.y, hexB6.z); glEnd(); glTranslatef(0, 0.4, 0); glTranslatef(0, 0, -1); glBegin(GL_LINES); glColor3f(1, 0, 0); glVertex3f(-0.25, 0, 0); glColor3f(1, 0, 0); glVertex3f(0.25, 0, 0); glColor3f(1, 0, 0); glVertex3f(0, 0.25, 0); glColor3f(1, 0, 0); glVertex3f(0, -0.25, 0); glEnd(); /* //glTranslatef(x, 0, 0); glTranslatef(0, 1, 0); glTranslatef(0, 0, 0); glBegin(GL_LINES); glColor3f(1, 0, 0); glVertex3f(-0.5, 0, 0); glVertex3f(0.5, 0, 0); glVertex3f(0, 0.5, 0); glVertex3f(0, -0.5, 0); /*glEnable(GL_LINE_STIPPLE); glLineStipple(1,0xAAAA); glBegin(GL_LINES); glVertex2f(0.0,0.0); glVertex2f(0.0,0.5); //glDisable(GL_LINE_STIPPLE); glEnd(); glDisable(GL_LINE_STIPPLE); glBegin(GL_LINE_LOOP); //draw a circle with specific points. int circle_points = 100; float angle = 0; int i = 0; for(i = 0;i<circle_points;i++) { // draw with yellow and black in turn. if(i%2==0){ glColor3f(1.0,1.0,0.0); }else{ glColor3f(0.0,0.0,0.0); } angle = 2*i*PI/circle_points; //the cos and sin will occupy hole screen. glVertex2f(0.5*cos(angle),0.5*sin(angle)); } */ //glEnd(); glPopMatrix(); glPopAttrib(); }
void vappend(int ch, int cnt, int indent) { int i; unsigned char *gcursor; bool escape; int repcnt, savedoomed; short oldhold = hold; int savecnt = cnt; line *startsrcline; int startsrccol, endsrccol; int gotNL = 0; int imultlinecnt = 0; int omultlinecnt = 0; if ((savecnt > 1) && (ch == 'o' || ch == 'O')) { omultlinecnt = 1; } #ifdef XPG6 if ((savecnt > 1) && (ch == 'a' || ch == 'A' || ch == 'i' || ch == 'I')) imultlinecnt = 1; #endif /* XPG6 */ /* * Before a move in hardopen when the line is dirty * or we are in the middle of the printed representation, * we retype the line to the left of the cursor so the * insert looks clean. */ if (ch != 'o' && state == HARDOPEN && (rubble || !ateopr())) { rubble = 1; gcursor = cursor; i = *gcursor; *gcursor = ' '; wcursor = gcursor; (void) vmove(); *gcursor = i; } /* * If vrep() passed indent = 0, this is the 'r' command, * so don't autoindent until the last char. */ vaifirst = indent == 0; /* * Handle replace character by (eventually) * limiting the number of input characters allowed * in the vgetline routine. */ if (ch == 'r') repcnt = 2; else repcnt = 0; /* * If an autoindent is specified, then * generate a mixture of blanks to tabs to implement * it and place the cursor after the indent. * Text read by the vgetline routine will be placed in genbuf, * so the indent is generated there. */ if (value(vi_AUTOINDENT) && indent != 0) { unsigned char x; gcursor = genindent(indent); *gcursor = 0; vgotoCL(nqcolumn(lastchr(linebuf, cursor), genbuf)); } else { gcursor = genbuf; *gcursor = 0; if (ch == 'o') vfixcurs(); } /* * Prepare for undo. Pointers delimit inserted portion of line. */ vUA1 = vUA2 = cursor; /* * If we are not in a repeated command and a ^@ comes in * then this means the previous inserted text. * If there is none or it was too long to be saved, * then beep() and also arrange to undo any damage done * so far (e.g. if we are a change.) */ switch (ch) { case 'r': break; case 'a': /* * TRANSLATION_NOTE * "A" is a terse mode message corresponding to * "APPEND MODE". * Translated message of "A" must be 1 character (not byte). * Or, just leave it. */ if (value(vi_TERSE)) { vshowmode(gettext("A")); } else { vshowmode(gettext("APPEND MODE")); } break; case 's': /* * TRANSLATION_NOTE * "S" is a terse mode message corresponding to * "SUBSTITUTE MODE". * Translated message of "S" must be 1 character (not byte). * Or, just leave it. */ if (value(vi_TERSE)) { vshowmode(gettext("S")); } else { vshowmode(gettext("SUBSTITUTE MODE")); } break; case 'c': /* * TRANSLATION_NOTE * "C" is a terse mode message corresponding to * "CHANGE MODE". * Translated message of "C" must be 1 character (not byte). * Or, just leave it. */ if (value(vi_TERSE)) { vshowmode(gettext("C")); } else { vshowmode(gettext("CHANGE MODE")); } break; case 'R': /* * TRANSLATION_NOTE * "R" is a terse mode message corresponding to * "REPLACE MODE". * Translated message of "R" must be 1 character (not byte). * Or, just leave it. */ if (value(vi_TERSE)) { vshowmode(gettext("R")); } else { vshowmode(gettext("REPLACE MODE")); } break; case 'o': /* * TRANSLATION_NOTE * "O" is a terse mode message corresponding to * "OPEN MODE". * Translated message of "O" must be 1 character (not byte). * Or, just leave it. */ if (value(vi_TERSE)) { vshowmode(gettext("O")); } else { vshowmode(gettext("OPEN MODE")); } break; case 'i': /* * TRANSLATION_NOTE * "I" is a terse mode message corresponding to * "INSERT MODE" and the following "INPUT MODE". * Translated message of "I" must be 1 character (not byte). * Or, just leave it. */ if (value(vi_TERSE)) { vshowmode(gettext("I")); } else { vshowmode(gettext("INSERT MODE")); } break; default: /* * TRANSLATION_NOTE * "I" is a terse mode message corresponding to * "INPUT MODE" and the previous "INSERT MODE". * Translated message of "I" must be 1 character (not byte). * Or, just leave it. */ if (value(vi_TERSE)) { vshowmode(gettext("I")); } else { vshowmode(gettext("INPUT MODE")); } } ixlatctl(1); if ((vglobp && *vglobp == 0) || peekbr()) { if (INS[128] == 0200) { (void) beep(); if (!splitw) ungetkey('u'); doomed = 0; hold = oldhold; return; } /* * Unread input from INS. * An escape will be generated at end of string. * Hold off n^^2 type update on dumb terminals. */ vglobp = INS; inscdcnt = INSCDCNT; hold |= HOLDQIK; } else if (vglobp == 0) { /* * Not a repeated command, get * a new inserted text for repeat. */ INS[0] = 0; INS[128] = 0; INSCDCNT = 0; } /* * For wrapmargin to hack away second space after a '.' * when the first space caused a line break we keep * track that this happened in gobblebl, which says * to gobble up a blank silently. */ gobblebl = 0; startsrcline = dot; startsrccol = cursor - linebuf; /* * Text gathering loop. * New text goes into genbuf starting at gcursor. * cursor preserves place in linebuf where text will eventually go. */ if (*cursor == 0 || state == CRTOPEN) hold |= HOLDROL; for (;;) { if (ch == 'r' && repcnt == 0) escape = 0; else { ixlatctl(1); /* * When vgetline() returns, gcursor is * pointing to '\0' and vgetline() has * read an ESCAPE or NL. */ gcursor = vgetline(repcnt, gcursor, &escape, ch); if (escape == '\n') { gotNL = 1; #ifdef XPG6 if (ch == 'r') { /* * XPG6 assertion 313 [count]r\n : * Arrange to set cursor correctly. */ endsrccol = gcursor - genbuf - 1; } #endif /* XPG6 */ } else { /* * Upon escape, gcursor is pointing to '\0' * terminating the string in genbuf. */ endsrccol = gcursor - genbuf - 1; } ixlatctl(0); /* * After an append, stick information * about the ^D's and ^^D's and 0^D's in * the repeated text buffer so repeated * inserts of stuff indented with ^D as backtab's * can work. */ if (HADUP) addtext("^"); else if (HADZERO) addtext("0"); if(!vglobp) INSCDCNT = CDCNT; while (CDCNT > 0) { addtext("\004"); CDCNT--; } if (gobbled) addtext(" "); addtext(ogcursor); } repcnt = 0; /* * Smash the generated and preexisting indents together * and generate one cleanly made out of tabs and spaces * if we are using autoindent and this isn't 'r' command. */ if (!vaifirst && value(vi_AUTOINDENT)) { i = fixindent(indent); if (!HADUP) indent = i; gcursor = strend(genbuf); } /* * Set cnt to 1 to avoid repeating the text on the same line. * Do this for commands 'i', 'I', 'a', and 'A', if we're * inserting anything with a newline for XPG6. Always do this * for commands 'o' and 'O'. */ if ((imultlinecnt && gotNL) || omultlinecnt) { cnt = 1; } /* * Limit the repetition count based on maximum * possible line length; do output implied * by further count (> 1) and cons up the new line * in linebuf. */ cnt = vmaxrep(ch, cnt); /* * cursor points to linebuf * Copy remaining old text (cursor) in original * line to after new text (gcursor + 1) in genbuf. */ CP(gcursor + 1, cursor); /* * For [count] r \n command, when replacing [count] chars * with '\n', this loop replaces [count] chars with "". */ do { /* cp new text (genbuf) into linebuf (cursor) */ CP(cursor, genbuf); if (cnt > 1) { int oldhold = hold; Outchar = vinschar; hold |= HOLDQIK; viprintf("%s", genbuf); hold = oldhold; Outchar = vputchar; } /* point cursor after new text in linebuf */ cursor += gcursor - genbuf; } while (--cnt > 0); endim(); vUA2 = cursor; /* add the remaining old text after the cursor */ if (escape != '\n') CP(cursor, gcursor + 1); /* * If doomed characters remain, clobber them, * and reopen the line to get the display exact. * eg. c$ to change to end of line */ if (state != HARDOPEN) { DEPTH(vcline) = 0; savedoomed = doomed; if (doomed > 0) { int cind = cindent(); physdc(cind, cind + doomed); doomed = 0; } if(MB_CUR_MAX > 1) rewrite = _ON; i = vreopen(LINE(vcline), lineDOT(), vcline); if(MB_CUR_MAX > 1) rewrite = _OFF; #ifdef TRACE if (trace) fprintf(trace, "restoring doomed from %d to %d\n", doomed, savedoomed); #endif if (ch == 'R') doomed = savedoomed; } /* * Unless we are continuing on to another line * (got a NL), break out of the for loop (got * an ESCAPE). */ if (escape != '\n') { vshowmode(""); break; } /* * Set up for the new line. * First save the current line, then construct a new * first image for the continuation line consisting * of any new autoindent plus the pushed ahead text. */ killU(); addtext(gobblebl ? " " : "\n"); /* save vutmp (for undo state) into temp file */ vsave(); cnt = 1; if (value(vi_AUTOINDENT)) { if (value(vi_LISP)) indent = lindent(dot + 1); else if (!HADUP && vaifirst) indent = whitecnt(linebuf); vaifirst = 0; strcLIN(vpastwh(gcursor + 1)); gcursor = genindent(indent); *gcursor = 0; if (gcursor + strlen(linebuf) > &genbuf[LBSIZE - 2]) gcursor = genbuf; CP(gcursor, linebuf); } else { /* * Put gcursor at start of genbuf to wipe * out previous line in preparation for * the next vgetline() loop. */ CP(genbuf, gcursor + 1); gcursor = genbuf; } /* * If we started out as a single line operation and are now * turning into a multi-line change, then we had better yank * out dot before it changes so that undo will work * correctly later. */ if (FIXUNDO && vundkind == VCHNG) { vremote(1, yank, 0); undap1--; } /* * Now do the append of the new line in the buffer, * and update the display, ie: append genbuf to * the file after dot. If slowopen * we don't do very much. */ vdoappend(genbuf); vundkind = VMANYINS; vcline++; if (state != VISUAL) vshow(dot, NOLINE); else { i += LINE(vcline - 1); vopen(dot, i); if (value(vi_SLOWOPEN)) vscrap(); else vsync1(LINE(vcline)); } switch (ch) { case 'r': break; case 'a': if (value(vi_TERSE)) { vshowmode(gettext("A")); } else { vshowmode(gettext("APPEND MODE")); } break; case 's': if (value(vi_TERSE)) { vshowmode(gettext("S")); } else { vshowmode(gettext("SUBSTITUTE MODE")); } break; case 'c': if (value(vi_TERSE)) { vshowmode(gettext("C")); } else { vshowmode(gettext("CHANGE MODE")); } break; case 'R': if (value(vi_TERSE)) { vshowmode(gettext("R")); } else { vshowmode(gettext("REPLACE MODE")); } break; case 'i': if (value(vi_TERSE)) { vshowmode(gettext("I")); } else { vshowmode(gettext("INSERT MODE")); } break; case 'o': if (value(vi_TERSE)) { vshowmode(gettext("O")); } else { vshowmode(gettext("OPEN MODE")); } break; default: if (value(vi_TERSE)) { vshowmode(gettext("I")); } else { vshowmode(gettext("INPUT MODE")); } } strcLIN(gcursor); /* zero genbuf */ *gcursor = 0; cursor = linebuf; vgotoCL(nqcolumn(cursor - 1, genbuf)); } /* end for (;;) loop in vappend() */ if (imultlinecnt && gotNL) { imultlinerep(savecnt, startsrcline, startsrccol, endsrccol); } else if (omultlinecnt) { omultlinerep(savecnt, startsrcline, endsrccol); #ifdef XPG6 } else if (savecnt > 1 && ch == 'r' && gotNL) { /* * XPG6 assertion 313 & 254 : Position cursor for [count]r\n * then insert [count -1] newlines. */ endsrccol = gcursor - genbuf - 1; rmultlinerep(savecnt, endsrccol); #endif /* XPG6 */ } /* * All done with insertion, position the cursor * and sync the screen. */ hold = oldhold; if ((imultlinecnt && gotNL) || omultlinecnt) { fixdisplay(); #ifdef XPG6 } else if (savecnt > 1 && ch == 'r' && gotNL) { fixdisplay(); /* * XPG6 assertion 313 & 254 [count]r\n : Set flag to call * fixdisplay() after operate() has finished. To be sure that * the text (after the last \n followed by an indent) is always * displayed, fixdisplay() is called right before getting * the next command. */ redisplay = 1; #endif /* XPG6 */ } else if (cursor > linebuf) { cursor = lastchr(linebuf, cursor); #ifdef XPG6 /* * XPG6 assertion 313 & 254 [count]r\n : * For 'r' command, when the replacement char causes new * lines to be created, point cursor to first non-blank. * The old code, ie: cursor = lastchr(linebuf, cursor); * set cursor to the blank before the first non-blank * for r\n */ if (ch == 'r' && gotNL && isblank((int)*cursor)) ++cursor; #endif /* XPG6 */ } if (state != HARDOPEN) vsyncCL(); else if (cursor > linebuf) back1(); doomed = 0; wcursor = cursor; (void) vmove(); }
/* * Put the character c on the screen at the current cursor position. * This routine handles wraparound and scrolling and understands not * to roll when splitw is set, i.e. we are working in the echo area. * There is a bunch of hacking here dealing with the difference between * QUOTE, QUOTE|' ', and ' ' for CONCEPT-100 like terminals, and also * code to deal with terminals which overstrike, including CRT's where * you can erase overstrikes with some work. CRT's which do underlining * implicitly which has to be erased (like CONCEPTS) are also handled. */ int vputchar(register int c) { register cell *tp; register int d, m, n; #ifndef BIT8 c &= (QUOTE|TRIM); #endif #ifdef TRACE if (trace) tracec(c); #endif /* Fix problem of >79 chars on echo line. */ if (destcol >= WCOLS-1 && splitw && destline == WECHO) pofix(); #ifdef MB if (mb_cur_max > 1) { if (c == MULTICOL) return c; /* * If a multicolumn character extends beyond the screen * width, it must be put on the next line. A tilde is * printed as an indicator but must disappear when the * text is moved at a later time. */ if (c == ('~'|INVBIT|QUOTE)) c = '~'|INVBIT; else if (c == ('~'|INVBIT)) return c; else if (destcol < WCOLS && destcol + colsc(c==QUOTE ? ' ' : c&TRIM&~MULTICOL) - 1 >= WCOLS) vputchar('~'|INVBIT|QUOTE); } #endif /* MB */ if (destcol >= WCOLS) { destline += destcol / WCOLS; destcol %= WCOLS; } if (destline > WBOT && (!splitw || destline > WECHO)) vrollup(destline); tp = vtube[destline] + destcol; if (c == QUOTE) { if (insmode) { /* * When in insert mode, tabs have to expand * to real, printed blanks. */ c = ' ' | QUOTE; goto def; } if (*tp == 0) { /* * A ``space''. */ if ((hold & HOLDPUPD) == 0) *tp = QUOTE; destcol++; return c; } /* * A ``space'' ontop of a part of a tab. */ if (*tp & QUOTE) { destcol++; return c; } c = ' ' | QUOTE; goto def; } #ifdef notdef #ifdef BIT8 if (c == ' ' | QUOTE) { c = ' '; goto def; } #endif #endif switch (c) { case '\t': vgotab(); return c; case ' ': /* * We can get away without printing a space in a number * of cases, but not always. We get away with doing nothing * if we are not in insert mode, and not on a CONCEPT-100 * like terminal, and either not in hardcopy open or in hardcopy * open on a terminal with no overstriking, provided, * in all cases, that nothing has ever been displayed * at this position. Ugh. */ if (!insmode && !IN && (state != HARDOPEN || OS) && (*tp"E)) { *tp = ' '; destcol++; return c; } goto def; def: default: d = *tp & TRIM; /* * Now get away with doing nothing if the characters * are the same, provided we are not in insert mode * and if we are in hardopen, that the terminal has overstrike. */ if ((d & ~MULTICOL) == (c & TRIM & ~MULTICOL) && !insmode && (state != HARDOPEN || OS) && c != MULTICOL) { n = colsc(d); for (m = 1; m < n; m++) if ((tp[m] & (MULTICOL|TRIM)) != MULTICOL) break; if (m == n) { if ((hold & HOLDPUPD) == 0) *tp = c | (n > 1 ? MULTICOL : 0); destcol += n; return c; } } /* * Backwards looking optimization. * The low level cursor motion routines will use * a cursor motion right sequence to step 1 character * right. On, e.g., a DM3025A this is 2 characters * and printing is noticeably slower at 300 baud. * Since the low level routines are not allowed to use * spaces for positioning, we discover the common * case of a single space here and force a space * to be printed. */ if (destcol == outcol + 1 && tp[-1] == ' ' && outline == destline) { vputc(' '); outcol++; } /* * This is an inline expansion a call to vcsync() dictated * by high frequency in a profile. */ if (outcol != destcol || outline != destline) vgoto(destline, destcol); /* * Deal with terminals which have overstrike. * We handle erasing general overstrikes, erasing * underlines on terminals (such as CONCEPTS) which * do underlining correctly automatically (e.g. on nroff * output), and remembering, in hardcopy mode, * that we have overstruct something. */ if (!insmode && d && d != ' ' && d != (c & TRIM)) { if (EO && (OS || UL && (c == '_' || d == '_'))) { vputc(' '); outcol++, destcol++; back1(); } else rubble = 1; } /* * Unless we are just bashing characters around for * inner working of insert mode, update the display. */ if ((hold & HOLDPUPD) == 0) *tp = c; /* * In insert mode, put out the IC sequence, padded * based on the depth of the current line. * A terminal which had no real insert mode, rather * opening a character position at a time could do this. * Actually should use depth to end of current line * but this rarely matters. */ #ifdef notdef if (insmode) #else /* * It seems today's termcap writers consider this * an either-or situation; if both im and ic * are used vi puts out additional spaces. * * SVR4 ex does not include this change. If it hits * your terminal, change back to the old way and * mail me a description. * * GR July 2000 */ if (insmode && (!IM || !*IM)) #endif /* !notdef */ { n = colsc(c&TRIM); for (m = 0; m < n; m++) vputp(IC, DEPTH(vcline)); } vputc(c & TRIM); /* * In insert mode, IP is a post insert pad. */ if (insmode) vputp(IP, DEPTH(vcline)); destcol++, outcol++; /* * CONCEPT braindamage in early models: after a wraparound * the next newline is eaten. It's hungry so we just * feed it now rather than worrying about it. * Fixed to use return linefeed to work right * on vt100/tab132 as well as concept. */ if (XN && outcol % WCOLS == 0) { vputc('\r'); vputc('\n'); } } #ifdef MB if (mb_cur_max > 1 && (d = colsc(c&TRIM&~MULTICOL)) > 1) { if ((hold & HOLDPUPD) == 0) *tp |= MULTICOL; while (--d) { if ((hold & HOLDPUPD) == 0) *++tp = MULTICOL; destcol++; outcol++; } } #endif /* MB */ return c; }
void WallClock::paintBackground(QPainter & painter) { initCoordinateSystem(painter); // Malowanie obwiedni tarczy. //QColor ramka(17,50,214);// ³adny niebieski QColor ramka(215,0,0); // g³êboki czerwony // Gradient zewnêtrznego okrêgu QRadialGradient back1(QPointF(0,0),135, QPointF(-27.5,110.0)); back1.setColorAt(0.0,QColor(255,255,255)); back1.setColorAt(1.0,ramka); // Gradient wewnêtrznego okrêgu QRadialGradient back2(QPoint(0,0),170, QPointF(57.5,100)); back2.setColorAt(0.0,ramka); back2.setColorAt(1.0,QColor(255,255,255)); QRadialGradient shield(QPointF(0,0),122,QPointF(-12.0,-15.0)); shield.setColorAt(0.0,Qt::white); shield.setColorAt(0.5,QColor(240,240,240)); shield.setColorAt(1.0,QColor(215,215,215)); QPen Pen(Qt::black); Pen.setWidth(2); painter.setPen(Pen); // Koperta zegark painter.setBrush(QBrush(back1)); painter.drawEllipse(-116,-116,232,232); painter.setBrush(QBrush(back2)); painter.setPen(Qt::NoPen); painter.drawEllipse(-109,-109,218,218); painter.setPen(Pen); painter.setBrush(QBrush(shield)); painter.drawEllipse(-102,-102,204,204); painter.setBrush(Qt::black); // rysowanie kó³ek godzin i samych godzin for (int i = 0; i < 12; ++i) { painter.drawEllipse(94, -2, 4, 4); painter.rotate(30.0); } // rysowanie kresek minut painter.setPen(Qt::black); Pen.setWidth(2); painter.setPen(Pen); for (int j = 0; j < 60; ++j) { if ((j % 5) != 0) painter.drawLine(94, 0, 97, 0); painter.rotate(6.0); } QSize Size; QString Str; // Rysowanie cyfr na tarczy if (digitOffset()!=0.0) { painter.setFont(digitFont()); painter.setPen(digitColor()); for ( int z = 1; z <= 12; ++z) { QString hour = QString("%1").arg(z); Size = painter.fontMetrics().size(Qt::TextSingleLine, hour); painter.save(); painter.translate(digitOffset() * cos(PI*z/6.0-PI/2.0),digitOffset() * sin(PI*z/6.0-PI/2.0)); painter.setPen(digitColor()); painter.drawText( QPointF ( Size.width()/ -2.0, Size.height() / 4.0), hour); painter.restore(); } } }// paintBackground