int main(void) { // irqs are nice irqInit(); irqEnable(IRQ_VBLANK); titlescreen(); gamescreen(); //doorminigame(); return 0; }
/* This is the render loop At this point, you should know exactly what to draw onto the screen. Just draw it! To get an idea of the values for colours, look at console.h and the URL listed there */ void render() { clearScreen(); // clears the current screen and draw from scratch switch (g_eGameState) { case SPLASH: splash(); // splash screen break; case TITLE: titlescreen(); // title screen break; case VICTORY: victory(); // victory screen break; case CREDITS: credits(); // credits & statistics screen break; case PAUSE: pausemenu(); // pause screen break; case CLASSSELECT: classSelect(); // class selection screen break; case GAME: renderGame(); // Game screen break; case GAMEOVER: gameend(); // Retry screen break; } renderToScreen();// dump the contents of the buffer to the screen, one frame worth of game }
///main program int main() { int i,j,k,upos=11,cpos=11,cmove,winner=0,uhealth=10,chealth=40,bullets=500,qtyofboomerang=20,qtyofwall=50,boost=0,nofboost=1; int boomerang[4]={188,187,201,200},wall[4]={219,178,177,176}; clock_t start=-1,reloadtime=-1; SetConsoleTitle("ASCII Showdown"); printf("controls:\n'a': left\n'd': right\n'w': fire bullet\n'o': fire homing boomerang\n'p': place a wall\n'i': Engage triple bullet firing mode\n"); system("pause"); titlescreen(); system("cls"); printbuffer(); printscoreboard(); getch(); srand(time(NULL)); ///seeds random numbers using system time while(1) { ///user's turn if(kbhit()) ///listens if user pressed a key { switch(getch()) ///takes the key input { case 'w': if(bullets>0) { if(boost==0) { grid[17][upos]='b'; ///fires a bullet bullets--; } else { if(bullets>2) { for(i=-1;i<=1;i++) { if(upos+i>0 && upos+i<39) { grid[17][upos+i]='b'; ///fires 3 bullets via weapon boost bullets--; } } } } } break; case 'a': ///moves user left if(upos>1) { grid[18][upos]=' '; upos=upos-1; grid[18][upos]='u'; } break; case 'd': ///moves user right if(upos<38) { grid[18][upos]=' '; upos=upos+1; grid[18][upos]='u'; } break; case 'o': if(qtyofboomerang>0) { grid[17][upos]=boomerang[0]; ///fires homing boomerang qtyofboomerang--; } break; case 'p': if(qtyofwall>0) { grid[16][upos]=219; ///sets up a wall qtyofwall--; } break; case 'i': if(nofboost>0) {boost=1; ///starts weapon boost start=clock(); nofboost--; } break; } } ///cpu's turn cmove=rand()%4; ///randomizing cpu's move switch(cmove) { case 0: if(chealth>10) grid[2][cpos]='B'; ///fires a bullet else { for(i=-1;i<=1;i++) { if(cpos+i>0 && cpos+i<39) grid[2][cpos+i]='B'; ///fires 3 bullets when health goes 10 or below 10 } } break; case 1: if(cpos>1) ///moves left { grid[1][cpos]=' '; cpos=cpos-1; grid[1][cpos]='c'; } break; case 2: ///moves right if(cpos<38) { grid[1][cpos]=' '; cpos=cpos+1; grid[1][cpos]='c'; } break; case 3: ///does nothing break; } ///prints the arena printbuffer(); ///prints score score(uhealth,chealth,bullets,qtyofboomerang,qtyofwall,boost,nofboost); ///time delay Sleep(70); ///user bullets for(i=0;i<20;i++) { for(j=0;j<40;j++) { if(grid[i][j]=='b' && i>1 && grid[i-1][j]==' ') { grid[i][j]=' '; grid[i-1][j]='b'; ///moves the bullets forward } if(grid[i][j]=='b' && i==1) grid[i][j]=' '; ///bullets collision with wall if(grid[i][j]=='b' && grid[i-1][j]=='B') { grid[i][j]=' '; ///bullets collision grid[i-1][j]=' '; } if(grid[i][j]=='b' && grid[i-1][j]=='c') { grid[i][j]=' '; ///bullet hits cpu chealth--; screenflash(); } for(k=0;k<4;k++) { if(grid[i][j]==boomerang[k]-256 && (grid[i-1][j]=='c' || grid[i-1][j-1]=='c' || grid[i-1][j+1]=='c')) { grid[i][j]=' '; ///boomerang hits cpu chealth-=1; screenflash(); screenflash(); } if(grid[i][j]==boomerang[k]-256 && i>1 && grid[i-1][j]==' ') { grid[i][j]=' '; if(j>cpos) grid[i-1][j-1]=boomerang[(k+1)%4]; /// boomerang moves forward if(j<cpos) grid[i-1][j+1]=boomerang[(k+1)%4]; ///homing boomerang if(j==cpos) grid[i-1][j]=boomerang[(k+1)%4]; break; } if(grid[i][j]==boomerang[k]-256 && grid[i-1][j]=='B') { grid[i][j]=' '; ///bullet and boomerang collision grid[i-1][j]=boomerang[(k+1)%4]; } if(grid[i][j]==boomerang[k]-256 && i==1) grid[i][j]=' '; ///boomerang hits wall } for(k=0;k<4;k++) { if(grid[i][j]=='b' && grid[i-1][j]==wall[k]-256) { grid[i][j]=' '; grid[i-2][j]='b'; ///bullets collision with user's wall } if(grid[i][j]==boomerang[0]-256 && grid[i-1][j]==wall[k]-256) { grid[i][j]=' '; grid[i-1][j]=' '; ///boomerang collision with user's wall grid[i-2][j]=boomerang[2]; } } } } ///cpu bullets for(i=19;i>-1;i--) { for(j=0;j<40;j++) { if(grid[i][j]=='B' && i<18 && grid[i+1][j]==' ') { grid[i][j]=' '; ///moves the bullets forward grid[i+1][j]='B'; } if(grid[i][j]=='B' && i==18) grid[i][j]=' '; ///bullets collision with wall if(grid[i][j]=='B' && grid[i+1][j]=='u') { grid[i][j]=' '; ///bullet hits user uhealth--; screenflash(); } for(k=0;k<4;k++) { if(grid[i][j]=='B' && grid[i+1][j]==wall[k]-256) { grid[i][j]=' '; ///cpu's bullets collision with user's wall if(k<3) grid[i+1][j]=wall[k+1]; else grid[i+1][j]=' '; } } } } if(clock()-start>5000 && start>0) { boost=0; ///stops the weapon boost start=-1; reloadtime=clock(); } if(clock()-reloadtime>10000 && reloadtime>0) { if(nofboost==0) nofboost++; ///reloads the weapon boost reloadtime=-1; } if(chealth<=0) { winner=1; ///user wins break; } if(uhealth<=0 || (bullets<=0 && qtyofboomerang==0)) { winner=2; ///cpu wins break; } } win(winner); ///selects the winner. 0 : no winner, 1 : user wins, 2 : cpu wins return 0; ///end of program }
/* DigiBand (c)2005 Seijinohki PC Services and Software, This code written by Joe Wall with assitance from Velex * Loutzenhiser, and respected other parties. This code is protected under the GPL License. For any questions * regarding this code, please contact Joe @ www.seijinohki.net. * * This software is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the: * Free Software Foundation, Inc. * 59 Temple Place - Suite 330 * Boston, MA 02111-1307, USA */ void renderscreen(){ #ifdef EXCESSIVE printf("renderscreen\n"); #endif //things that need to happen before rendering, but on screen change. drawbgavi(); if (currbpm==0){ currbpm=100; } if (currscreen>=7&&currscreen<=11){ draw_quad(0,512,384,-9000,640,400,255,255,255,255,0,0,1); if(!arcademode){ draw_quad(0,512,384,-5000,640,400,255,255,255,255,0,0,55); }else{ draw_quad(0,512,384,-5000,640,400,255,255,255,255,0,0,2); } draw_quad(0,512,384,-8990,640,400,255,255,255,255,0,0,3); } if (currscreen==17){ draw_quad(0,512,384,-9000,640,400,255,255,255,255,0,0,1); if(!arcademode){ draw_quad(0,512,384,-5000,640,400,255,255,255,255,0,0,55); }else{ draw_quad(0,512,384,-5000,640,400,255,255,255,255,0,0,2); } draw_quad(0,512,384,-8990,640,400,255,255,255,255,0,0,3); } static long long totalframes=0; totalframes++; if (totalframes>65535)totalframes=-65536; if (currscreen==1) titlescreen(totalframes); if (currscreen==2) optionsscreen(totalframes); if (currscreen==4) gameselectscreen(totalframes); if (currscreen==5) songselectscreen(totalframes); if (currscreen==6) gameplayscreen(totalframes); if (currscreen==7) configuredrum(); if (currscreen==8) configureguitar1(); if (currscreen==9) configureguitar2(); if (currscreen==10) configuresound(); if (currscreen==12) gameresultscreen(); if (currscreen==13) gamecreditsscreen(); if (currscreen==14) gameoverscreen(); if (currscreen==15) savesettingsscreen(); if (currscreen==17) arcadesettingsscreen(); if (currscreen==20) autoplayscreen(); if (currscreen==21) logoscreen(); if (currscreen==6&&screenfaddingout&&songs[thesong].offset!=songs[thesong].poffset){ nextscreen=15; } static char screentext[128]; snprintf(screentext,127,"Options"); static drawtext screentextt; screentextt.load(screentext,"font.ttf",255,255,255,uivars.options_screenname_s); if (currscreen>=7&&currscreen<=11){ screentextt.draw(uivars.options_screenname_x,uivars.options_screenname_y,5100,255,255,255,255,false,true); } if (currscreen==17){ screentextt.draw(uivars.options_screenname_x,uivars.options_screenname_y,5100,255,255,255,255,false,true); } if (currscreen==2){ if (!screenfaddingout&&!screenfaddingin)screentextt.draw(uivars.options_screenname_x,uivars.options_screenname_y,5100,255,255,255,255,false,true); } //things that need to happen after rendering, but on screen change. if (prevscreen!=currscreen){ if (currscreen<5&&currscreen!=2){ playpreview(); } if (currscreen==2&&prevscreen<7){ playpreview(); } if (currscreen!=5) optionselected=0; if (currscreen==1)optionselected=1; prevscreen=currscreen; snprintf(curravi,255,"NULL"); } if (screenfaddingout){ if (screenfaddingouttime>=255) screenfaddingouttime=255.0; if (currscreen==5&&nextscreen==4){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,640,400,255,255,255,255-int(screenfaddingouttime),0,0,14); } if (currscreen==6&&nextscreen==15){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==2) if (screenfaddingouttime<255) draw_quad(0,512,384,9000,640,400,255,255,255,255-int(screenfaddingouttime),0,0,3); if (currscreen==1&&nextscreen==4){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==20&&nextscreen==4){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==21&&nextscreen==4){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==1&&nextscreen==20){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==20&&nextscreen==21){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==21&&nextscreen==1){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==4&&nextscreen==1){//my how the tides have turned! if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==4&&nextscreen==5){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,640,400,255,255,255,255-int(screenfaddingouttime),0,0,12); } if (currscreen==6&&nextscreen==5){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==5&&nextscreen==6){ if (screenfaddingouttime<255){ if (widemode){ draw_quadt2(0,512,384,9000,640,400,255,255,255,int(screenfaddingouttime),0,0,tempbackgroundtexture); }else{ draw_quadt2(0,512,384,9000,512,384,255,255,255,int(screenfaddingouttime),0,0,tempbackgroundtexture); } }else{ if (widemode){ draw_quadt2(0,512,384,9000,640,400,255,255,255,255,0,0,tempbackgroundtexture); }else{ draw_quadt2(0,512,384,9000,512,384,255,255,255,255,0,0,tempbackgroundtexture); } } } if (currscreen==6&&nextscreen==14){ draw_quad(0,int(screenfaddingouttime)*2,384,8900,640,400,255,255,255,255,0,0,46); draw_quad(0,1024-int(screenfaddingouttime*2),384,9000,640,400,255,255,255,255,0,0,47); } if (currscreen==14&&nextscreen==1){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==6&&nextscreen==12){ if (screenfaddingouttime<255) draw_quad(0,512,384,8500,640,400,255,255,255,int(screenfaddingouttime),0,0,48); else draw_quad(0,512,384,8500,640,400,255,255,255,255,0,0,48); draw_quad(0,512,int(screenfaddingouttime*3)-384,9000,512,384,255,255,255,255,0,0,49); } if (currscreen==12&&nextscreen==5){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==12&&nextscreen==13){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==13&&nextscreen==1){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==16&&nextscreen==1){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } if (currscreen==4&&nextscreen==16){ if (screenfaddingouttime<255) draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingouttime),0,0,51); else draw_quad(0,512,384,9000,642,404,0,0,0,255,0,0,51); } }else{ screenfaddingouttime=0.0; } if (screenfaddingin){ if (lastscreen==6&&currscreen==5){ if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (lastscreen==5&&currscreen==6){ if (screenfaddingintime>0){ if (widemode){ draw_quadt2(0,512,384,9000,640,400,255,255,255,int(screenfaddingintime),0,0,tempbackgroundtexture); }else{ draw_quadt2(0,512,384,9000,512,384,255,255,255,int(screenfaddingintime),0,0,tempbackgroundtexture); } } } if (lastscreen==4&&currscreen==5){ if (screenfaddingintime>0)draw_quad(0,512,384,9000,640,400,255,255,255,255-int(screenfaddingintime),0,0,14); else draw_quad(0,512,384,9000,640,400,255,255,255,255,0,0,14); } if (lastscreen==5&&currscreen==4){ if (screenfaddingintime>0)draw_quad(0,512,384,9000,640,400,255,255,255,255-int(screenfaddingintime),0,0,12); else draw_quad(0,512,384,9000,640,400,255,255,255,255,0,0,12); } if (lastscreen==4&&currscreen==1){ if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (lastscreen==15&&currscreen==14){ if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (lastscreen==15&&currscreen==12){ if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (lastscreen==1&&currscreen==4){//we meet again batman! if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (lastscreen==20&&currscreen==4){//we meet again batman! if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (lastscreen==21&&currscreen==4){//we meet again batman! if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (lastscreen==1&&currscreen==20){//we meet again batman! if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (lastscreen==20&&currscreen==21){//we meet again batman! if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (lastscreen==21&&currscreen==1){//we meet again batman! if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (lastscreen==1&&currscreen==1){ if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (currscreen==2&&lastscreen==1){ if (screenfaddingintime>0){ draw_quad(0,512,384,9000,640,400,255,255,255,255-int(screenfaddingintime),0,0,3); }else draw_quad(0,512,384,9000,640,400,255,255,255,255,0,0,3); } if (currscreen==1&&lastscreen==14){ if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (currscreen==13&&lastscreen==12){ if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (currscreen==1&&lastscreen==13){ if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (currscreen==16&&lastscreen==4){ if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } if (currscreen==1&&lastscreen==16){ if (screenfaddingintime>0)draw_quad(0,512,384,9000,642,404,0,0,0,int(screenfaddingintime),0,0,51); } }else{ screenfaddingintime=255.0; } if (screenfaddingout){ screenfaddingouttime+=10*double(steptime)/16.0; if (screenfaddingouttime>=255){ screenfaddingout=false; screenfaddingouttime=0.0; screenchangenow=true; } }else if (screenfaddingin){ screenfaddingintime-=10.0*double(steptime)/16.0; if (screenfaddingintime<=0.0){ screenfaddingin=false; screenfaddingintime=255.0; } } }
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 initgrph(int showtitle) { int i; FILE *f; char *pigname; struct ws_event ws; struct ws_bitmap *cursor; inittimer(); #if defined (GNU_C) && defined (GO32) if ( showtitle && ws_initgrfx(640, 480, 256, init.fontname) && titlescreen() ) { ws_getevent(&ws, 1); } ws_textmode(); #endif if ( !w_initwins(init.xres, init.yres, 256, init.fontname) ) { printf(TXT_CANTINITWINS); my_exit(); } if ( ( f = fopen(init.menuname, "r") ) == NULL ) { fprintf(errf, TXT_NOMENUFILE, init.menuname); my_exit(); } my_assert( w_initmenu(f, do_event, ec_num_of_codes) ); fclose(f); pigname = pig.current_pigname; pig.current_pigname = NULL; newpigfile(pigname, NULL); FREE(pigname); /* draw the cursors (init the cursor data) */ cntrlcursor_ysize = altcursor_ysize = w_titlebarheight(); cntrlcursor_xsize = (ws_pixstrlen(TXT_TAG) + 2 + 3) / 4 * 4; altcursor_xsize = (ws_pixstrlen(TXT_INFO) + 2 + 3) / 4 * 4; cursor = ws_createbitmap(cntrlcursor_xsize, cntrlcursor_ysize, control_cursor); ws_bmdrawtext(cursor, 1, 0, cntrlcursor_xsize, TXT_TAG, 1, 0); ws_freebitmap(cursor); cursor = ws_createbitmap(altcursor_xsize, altcursor_ysize, alt_cursor); ws_bmdrawtext(cursor, 1, 0, altcursor_xsize, TXT_INFO, 1, 0); ws_freebitmap(cursor); cursor_initialized = 1; checkmem( pig.txt_buffer = MALLOC(64 * 64) ); memset(pig.txt_buffer, 0, 64 * 64); pig.txt_bm = ws_createbitmap(64, 64, pig.txt_buffer); checkmem( pig.door_buffer = MALLOC(64 * 64) ); memset(pig.door_buffer, 0, 64 * 64); pig.door_bm = ws_createbitmap(64, 64, pig.door_buffer); checkmem( pig.thing_buffer = MALLOC(64 * 64) ); memset(pig.thing_buffer, 0, 64 * 64); pig.thing_bm = ws_createbitmap(64, 64, pig.thing_buffer); button_win.xpos = w_xmaxwinsize() - button_win.xsize - 10; button_win.ypos = w_ymaxwinsize() - button_win.ysize - 10; if (init.d_ver >= d2_10_reg) { button_win.ypos -= 20; button_win.ysize += 20; if (init.d_ver >= d2_12_reg) { button_win.ypos -= 16; } button_win.ysize += 16; } checkmem( view.movewindow = w_openwindow(&button_win) ); drawallbuttons(view.movewindow); for (i = 0; i <= in_internal; i++) { makeoptwindow(i); } init_txtgrfx(); read_lightsources(); }