Advertisement
Mr-A

A-Engine: <object> 0.02

Jul 22nd, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 32.05 KB | None | 0 0
  1. using namespace std;
  2.  
  3. class frame{
  4.      
  5.       string frameline;
  6.      
  7.       public:
  8.              int f, img, delay, nxt, state, center_X, center_Y, f_x, f_y, f_z, loop_length, loop_goto, loop_condition;
  9.              int no;
  10.              void init(string, int);
  11. };
  12.  
  13. void frame::init(string frameline, int no_){
  14.                  no=no_;
  15.                  int positions[20];
  16.                  string tempao;
  17.                  string tags[] = {"img=", "delay=", "goto=", "state=", "center=", "f_x=", "f_y=", "f_z=", "loop="};
  18.                  bool done=false;
  19.                        if (frameline.find(tags[0])!=string::npos){positions[0] = frameline.find(tags[0])+tags[0].length();}else{positions[0]=0;}
  20.                        if (frameline.find(tags[1])!=string::npos){positions[1] = frameline.find(tags[1])+tags[1].length();}else{positions[1]=0;}                      
  21.                        if (frameline.find(tags[2])!=string::npos){positions[2] = frameline.find(tags[2])+tags[2].length();}else{positions[2]=0;}
  22.                        if (frameline.find(tags[3])!=string::npos){positions[3] = frameline.find(tags[3])+tags[3].length();}else{positions[3]=0;}
  23.                        if (frameline.find(tags[4])!=string::npos){positions[4] = frameline.find(tags[4])+tags[4].length();}else{positions[4]=0;}
  24.                        if (frameline.find(tags[5])!=string::npos){positions[5] = frameline.find(tags[5])+tags[5].length();}else{positions[5]=0;}
  25.                        if (frameline.find(tags[6])!=string::npos){positions[6] = frameline.find(tags[6])+tags[6].length();}else{positions[6]=0;}
  26.                        if (frameline.find(tags[7])!=string::npos){positions[7] = frameline.find(tags[7])+tags[7].length();}else{positions[7]=0;}
  27.                        if (frameline.find(tags[8])!=string::npos){positions[8] = frameline.find(tags[8])+tags[8].length();}else{positions[8]=0;}
  28.  
  29.                  for (int ice=0; ice < 9; ice ++){ //iter on tags positions
  30.                      for (int food = 0; food < frameline.length(); food++){ //iter on characters of the line
  31.                          done=false;
  32.                          
  33.                          while (!done&&(isdigit(frameline[food+positions[ice]]) || frameline.substr(food+positions[ice], 1)==","||frameline.substr(food+positions[ice], 1)=="-")){
  34.                                tempao+=frameline.substr(food+positions[ice],1);
  35.                                if (!isdigit(frameline[food+positions[ice]+1])&&!(frameline[food+positions[ice]+1]==',') &&!(frameline.substr(food+positions[ice], 1)=="-")){
  36.                                                                switch (ice){
  37.                                                                       case 0: if (frameline.find(tags[0])!=string::npos){img=atoi(tempao.c_str());}else{img=0;}
  38.                                                                       food=99999;done=true;tempao="";break;
  39.                                                                       case 1: if (frameline.find(tags[1])!=string::npos){delay=atoi(tempao.c_str());}else{delay=0;
  40.                                                                       }food=99999;done=true;tempao="";break;
  41.                                                                       case 2: if (frameline.find(tags[2])!=string::npos){nxt=atoi(tempao.c_str());}else{nxt=no+1;
  42.                                                                       }food=99999;done=true;tempao="";break;
  43.                                                                       case 3: if (frameline.find(tags[3])!=string::npos){state=atoi(tempao.c_str());}else{state=2;
  44.                                                                       }food=99999;done=true;tempao="";break;
  45.                                                                       case 4: if (frameline.find(tags[4])!=string::npos){center_X=atoi(tempao.substr(0, tempao.find(",")).c_str());
  46.                                                                            center_Y=atoi(tempao.substr(tempao.find(",")+1, tempao.size()-tempao.find(",")).c_str());}else{center_X=0;center_Y=0;
  47.                                                                            }
  48.                                                                            food=99999;done=true;tempao="";break;
  49.                                                                       case 5: if (frameline.find(tags[7])!=string::npos){f_x=atoi(tempao.c_str());}else{f_x=0;
  50.                                                                       }food=99999;done=true;tempao="";break;
  51.                                                                       case 6: if (frameline.find(tags[6])!=string::npos){f_y=atoi(tempao.c_str());}else{f_y=0;
  52.                                                                       }food=99999;done=true;tempao="";break;
  53.                                                                       case 7: if (frameline.find(tags[7])!=string::npos){f_z=atoi(tempao.c_str());}else{f_z=0;
  54.                                                                       }food=99999;done=true;tempao="";break;
  55.                                                                       case 8: if (frameline.find(tags[8])!=string::npos){loop_length=atoi(tempao.substr(0, tempao.find(",")).c_str());
  56.                                                                            loop_condition=atoi(tempao.substr(tempao.find(",")+1, tempao.rfind(",")-tempao.find(",")).c_str());
  57.                                                                            loop_goto=atoi(tempao.substr(tempao.rfind(",")+1).c_str());}else{loop_condition=4321; loop_length=4321; loop_goto=4321;
  58.                                                                            }food=99999;done=true;tempao="";break;
  59.                                                                       default:;}}
  60.                                else{
  61.                                     food++;}
  62.                          }
  63.                      }
  64.                  }
  65.                  
  66. }
  67.  
  68.  
  69.  
  70. class spritegrid{
  71.      
  72.       int w, h, col, row, frameno;
  73.       public:
  74.       string colk;
  75.       SDL_Surface *grid, *grid_;
  76.       vector<SDL_Rect> clip;
  77.       vector<SDL_Rect> clip_;
  78.  
  79.       void ini(string dir_, int w_, int h_, int col_, int row_, string colk_);
  80. };
  81.  
  82.  
  83. void spritegrid::ini(string dir_, int w_, int h_, int col_, int row_, string colk_){
  84.                              colk = colk_;
  85.                              
  86.                              unsigned int col1, col2, col3;
  87.                              col1=  strtol(("0x"+colk_.substr (3,2)).c_str(), NULL, 16);
  88.                              col2=  strtol(("0x"+ colk_.substr (5,2)).c_str(),NULL, 16);
  89.                              col3=  strtol(("0x"+ colk_.substr (7,2)).c_str(),NULL, 16);
  90.  
  91.  
  92.                              col=col_;
  93.                              row=row_;
  94.                              frameno = row*col;
  95.                              w=w_;
  96.                              h=h_;
  97.                              clip.resize(frameno);
  98.                              clip_.resize(frameno);
  99.               //               clip, clip_ = new SDL_Rect[frameno];
  100.                              grid = SDL_LoadBMP((dir_).c_str());
  101.                              grid_= SDL_LoadBMP((dir_.substr(0, dir_.rfind("\\")+1 ) +"mirror_" + dir_.substr( dir_.rfind("\\")+1 , dir_.rfind(".BMP")-dir_.rfind("\\")+1 )).c_str());
  102.                              int grid_h = (grid->h)/row;
  103.                              int grid_w = (grid->w)/col;
  104.                              for (int j=0;j<row;j++){
  105.                                  for (int i=0;i<col;i++){
  106.                                      SDL_Rect recto =  {i*grid_w, j*grid_h, w, h};
  107.                                      clip[(i+(col*j))] = recto;
  108.                                      SDL_Rect recto2 =  {((col-i)*grid_w)-grid_w+(grid_w-w), j*grid_h, w, h};
  109.                                      clip_[i+(col*j)] = recto2;
  110.                                      }}
  111.  
  112.                              Uint32 colorkey = SDL_MapRGB( grid->format, col1, col2, col3 );
  113.                              SDL_SetColorKey( grid, SDL_SRCCOLORKEY, colorkey );
  114.                              SDL_SetColorKey( grid_, SDL_SRCCOLORKEY, colorkey );
  115.                              }
  116. /*-------------------------------------------------------------------------------------------------------------*/
  117. class background{
  118.       string name, bitmapfiledir;
  119.      
  120.       public:
  121.              SDL_Surface *backgroundSurf;
  122.              int zbound, zboundwidth, xbound, xboundwidth;
  123.              background(int, int, int, int, string);
  124.              void Blit (SDL_Surface *d){SDL_BlitSurface (backgroundSurf, NULL, d, NULL);}
  125.        };
  126. background::background(int a, int  b, int c, int d, string e){
  127.                            zbound = a;
  128.                            zboundwidth = b;
  129.                            xbound = c;
  130.                            xboundwidth = d;
  131.                            bitmapfiledir = e;
  132.                            backgroundSurf =  SDL_LoadBMP(("sys\\"+bitmapfiledir).c_str());
  133. }
  134. /*-------------------------------------------------------------------------------------------------------------*/
  135. class object{
  136.       int posx , posz, wkspdx, wkspdz, frameno, currframe, w, h, facing, id, maxhp, maxmp, maxrp, inihp, inimp, inirp, delayU, nxt;
  137.       int rphit, rpsec, rpdam, armor, walking, standing, dashing, total_fx, total_fy, total_fz, previousframe, U_loop_length;
  138.       int FRICTION, GRAVITY;
  139.       SDL_Rect clip[4];
  140.       Uint32 colorkey;
  141.       vector<frame> Frames;
  142.       vector<spritegrid> IMGS;
  143.       bool newframe, doloop;
  144.       public:
  145.         int DshClksIntrvlR, DshClksIntrvlL, DASHL,DASHR;
  146.       bool P_UP, P_DOWN, P_LEFT, P_RIGHT;
  147.       SDL_Surface *charsheet;
  148.       SDL_Surface *charsheet_;
  149.       int movedirx, movedirz;
  150.       string sprtfl, name, dpndncs, afildir;
  151.      
  152.              void init (int id, string dpndncs, string afildir, int a, int b);
  153.              void Walk (int movedirx, int movedirz, background BG){
  154.                   if (movedirx < 2 || movedirz < 2){
  155.                   if (facing == 0){
  156.                              if (movedirx == 0 && (posx+wkspdx+20 < BG.xbound+BG.xboundwidth)) posx += wkspdx;
  157.                              if (movedirx == 1) facing = 1;
  158.                              if (movedirz == 0 && (posz-wkspdz > BG.zbound)) posz -= wkspdz;
  159.                              if (movedirz == 1 && (posz+wkspdz < BG.zbound+BG.zboundwidth)) posz += wkspdz;}
  160.                   if (facing == 1){
  161.                              if (movedirx == 0) facing = 0;
  162.                              if (movedirx == 1 && (posx-wkspdx-20 > BG.xbound)) posx -= wkspdx;
  163.                              if (movedirz == 0 && (posz-wkspdz > BG.zbound)) posz -= wkspdz;
  164.                              if (movedirz == 1 && (posz+wkspdz < BG.zbound+BG.zboundwidth)) posz += wkspdz;}
  165.  
  166.                   }}
  167.              void Blit   (SDL_Surface *d){
  168.                   if (facing==0){SDL_Rect pos = {posx-Frames[currframe].center_X  , posz-Frames[currframe].center_Y, 0, 0};
  169.                   SDL_BlitSurface (IMGS[0].grid, &IMGS[0].clip[Frames[currframe].img], d, &pos);}
  170.                   if (facing==1){SDL_Rect pos = {posx-((IMGS[0].clip_[Frames[currframe].img].w)-Frames[currframe].center_X), posz-Frames[currframe].center_Y, 0, 0};
  171.                   SDL_BlitSurface (IMGS[0].grid_, &IMGS[0].clip_[Frames[currframe].img], d, &pos);}
  172.              }
  173.              void Update(background);
  174.       };
  175. void object::init(int id, string dpndncs, string afildir, int a, int b){
  176.                           IMGS.resize(20);
  177.                           Frames.resize(650);  
  178.                           previousframe=4321;
  179.                           string tags[] = {"NAME=","MAXPTS_HP_MP_RP=","INITPTS_HP_MP_RP=","WALKSPD_X_Z=","RPRATEPER_HIT_SEC_DAMAGE=","ARMOR=","STANDING=","WALKING=","[img]", "DASHING="};
  180.                           P_UP, P_DOWN, P_LEFT, P_RIGHT = false;
  181.                           DshClksIntrvlR, DshClksIntrvlL, DASHL, DASHR=0;
  182.                           fstream A_FILE(afildir.c_str());
  183.                           string tempariro, frameline, tempariro2;
  184.                           int trigger, triggahcomma=0, imgindx=0;
  185.                           int positions[10];
  186.                           size_t starto, endo, temp0;
  187.                          
  188.                           bool extraction = false;
  189.                           newframe = true;
  190.                           doloop = false;
  191.                          
  192.                           FRICTION=1;
  193.                           GRAVITY =2;
  194.          
  195.                           if (A_FILE.is_open()){
  196.                           while (A_FILE.good()){
  197.                                
  198.                                 getline(A_FILE, frameline);
  199.                                 extraction = false;
  200.                                 temp0=frameline.find(" ");
  201.                                 while(temp0!=string::npos){frameline.erase (temp0, 1);
  202.                                 temp0=frameline.find(" ", temp0);}
  203.                                 if (frameline.find("{info}")!= string::npos) trigger = 1;
  204.                                 while (trigger==1){
  205.                                    getline(A_FILE, frameline);
  206.                                    if (frameline.rfind(tags[0])!=string::npos)positions[0] = frameline.rfind(tags[0])+tags[0].length();
  207.                                    if (frameline.rfind(tags[1])!=string::npos)positions[1] = frameline.rfind(tags[1])+tags[1].length();
  208.                                    if (frameline.rfind(tags[2])!=string::npos)positions[2] = frameline.rfind(tags[2])+tags[2].length();
  209.                                    if (frameline.rfind(tags[3])!=string::npos)positions[3] = frameline.rfind(tags[3])+tags[3].length();
  210.                                    if (frameline.rfind(tags[4])!=string::npos)positions[4] = frameline.rfind(tags[4])+tags[4].length();
  211.                                    if (frameline.rfind(tags[5])!=string::npos)positions[5] = frameline.rfind(tags[5])+tags[5].length();
  212.                                    if (frameline.rfind(tags[6])!=string::npos)positions[6] = frameline.rfind(tags[6])+tags[6].length();
  213.                                    if (frameline.rfind(tags[7])!=string::npos){positions[7] = frameline.rfind(tags[7])+tags[7].length();}
  214.                                    if (frameline.rfind(tags[9])!=string::npos){positions[9] = frameline.rfind(tags[9])+tags[9].length();}
  215.                                    if (frameline.rfind(tags[8])!=string::npos){positions[8] = frameline.rfind(tags[8])+tags[8].length();trigger=0; A_FILE.seekp(ios::beg);getline(A_FILE, frameline);getline(A_FILE, frameline);
  216.                                    }
  217.                                    }
  218.                
  219.                                    
  220.                           if (trigger != 1){
  221.                                      
  222.                                for (int ice=0; ice < 10; ice ++){ //iter on tags positions
  223.  
  224.                                    for (int food = 0; food < frameline.length(); food++){ //iter on characters of the line
  225.                                    
  226.                                    if (trigger==11){
  227.                                                 if (frameline.rfind("[/IMG]")==string::npos) trigger =0;
  228.                                                 string spgdarg0 = string(frameline.substr(0, frameline.find(",")));
  229.                                                 int    spgdarg1 = atoi(frameline.substr(frameline.find(",")+1,frameline.find(",", frameline.find(",")+1)).c_str());
  230.                                                 int    spgdarg2 = atoi(frameline.substr(frameline.find(",", frameline.find(",")+1)+1,  frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)).c_str());
  231.                                                 int    spgdarg3 = atoi(frameline.substr( frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1, frameline.find(",", frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1)).c_str());
  232.                                                 int    spgdarg4 = atoi(frameline.substr(frameline.find(",", frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1)+1, frameline.find(",", (frameline.find(",", frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1)+1))).c_str());
  233.                                                 string spgdarg5 = frameline.substr(frameline.rfind(','));  
  234.                                                 sprtfl =  spgdarg0;
  235.                                                 //*1*/string(frameline.substr(0, frameline.find(","))),
  236.                                                 //*2*/int(frameline.substr(frameline.find(",")+1,frameline.find(",", frameline.find(",")+1)).c_str()),
  237.                                                 //*3*/int(frameline.substr(frameline.find(",", frameline.find(",")+1)+1,  frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)).c_str()),
  238.                                                 //*4*/int(frameline.substr( frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1, frameline.find(",", frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1)).c_str()),
  239.                                                 //*5*/int(frameline.substr(frameline.find(",", frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1)+1, frameline.find(",", (frameline.find(",", frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1)+1)).c_str()),
  240.                                                 //frameline.substr(frameline.rfind(',')));  
  241.                                                 spritegrid a;
  242.                                                 a.ini(spgdarg0, spgdarg1, spgdarg2, spgdarg3, spgdarg4, spgdarg5);
  243.                                                 IMGS[imgindx]= a; imgindx ++;  
  244.                                                 food = 10000;ice=100000;                                  
  245.                                           }                                                                                                                                                                                                                                                                                                                                
  246.                                           else if (ice == 8 && (frameline.rfind(tags[ice])!=string::npos)){
  247.                                                 trigger =11;food=10000;ice=1000;
  248.                                           }
  249.                                          
  250.                                          
  251.                                        if (ice==0||ice ==1||ice==2||ice==3||ice==4||ice==5||ice==6||ice==7||ice==9){
  252.                                                        
  253.                                        
  254.                                           while (ice==4 && (frameline.rfind(tags[ice])!=string::npos) && !extraction){
  255.                                        
  256.                                                 if (triggahcomma==0){  //RPRATEPEhjR_HIT
  257.                                                     if(frameline.substr(food+positions[ice],1).find(",")!=string::npos){triggahcomma =1;}else if (isdigit(frameline[food+positions[ice]])){tempariro+=(frameline.substr(food+positions[ice], 1).c_str());}
  258.                                                     if (triggahcomma==1){ rphit=atoi(tempariro.c_str()); tempariro = "";food++;}}
  259.                                                
  260.                                                 if (triggahcomma==1){  //RPRATEPER_SEC_DAMAGE
  261.                                                     if(frameline.substr(food+positions[ice],1).find(",")!=string::npos){triggahcomma =2;}else{tempariro+=(frameline.substr(positions[ice]+food, 1).c_str());food++;}
  262.                                                     if (triggahcomma==2){ rpsec=atoi(tempariro.c_str()); tempariro = "";rpdam=atoi(frameline.substr(frameline.rfind(",")+1).c_str());triggahcomma=0;extraction = true;food=1000;  }}
  263.                                                 else{
  264.                                                      food++;}}
  265.                                           while (ice==3 && (frameline.rfind(tags[ice])!=string::npos) && !extraction){  
  266.                                                    
  267.                                                 if (triggahcomma==0){  //WALKSPDX
  268.                                                     if(frameline.substr(food+positions[ice],1).find(",")!=string::npos){triggahcomma =1;}else if (isdigit(frameline[food+positions[ice]])){tempariro+=(frameline.substr(food+positions[ice], 1).c_str());}
  269.                                                     if (triggahcomma==1){wkspdx=atoi(tempariro.c_str()); tempariro = "";food++;}}
  270.                                                
  271.                                                 if (triggahcomma==1){ //WALKSPDZ
  272.                                                     wkspdz=atoi(frameline.substr(positions[ice]+food).c_str()); tempariro = "";triggahcomma=0;extraction=true;food=1000;}
  273.                                                 else{
  274.                                                      food++;}}
  275.                                                      
  276.                                           while (ice==2 && (frameline.rfind(tags[ice])!=string::npos) && !extraction){
  277.                                                
  278.                                            
  279.                                                 if (triggahcomma==0){  //INIT_HP
  280.                                                     if(frameline.substr(food+positions[ice],1).find(",")!=string::npos){triggahcomma =1;}else if (isdigit(frameline[food+positions[ice]])){tempariro+=(frameline.substr(food+positions[ice], 1).c_str());}
  281.                                                     if (triggahcomma==1){ inihp=atoi(tempariro.c_str()); tempariro = ""; food++;}}
  282.                                                
  283.                                                 if (triggahcomma==1){  //INIT_MP &INIT_RP
  284.                                                    if(frameline.substr(food+positions[ice],1).find(",")!=string::npos) {triggahcomma =2;}else{tempariro+=(frameline.substr(positions[ice]+food, 1).c_str());food++;}
  285.                                                     if (triggahcomma==2){ inimp=atoi(tempariro.c_str()); tempariro = "";inirp=atoi(frameline.substr(frameline.rfind(",")+1).c_str());triggahcomma=0;extraction=true;food=1000; }}
  286.                                                 else{
  287.                                                      food++;}}
  288.                                                      
  289.                                           while (ice == 1 && (frameline.rfind(tags[ice])!=string::npos) && !extraction){
  290.                                                
  291.                                                 if (triggahcomma==0){  //MAX_HP
  292.                                                    if(frameline.substr(food+positions[ice],1).find(",")!=string::npos){triggahcomma =1;}else if (isdigit(frameline[food+positions[ice]])){tempariro+=(frameline.substr(food+positions[ice], 1).c_str());}
  293.                                                    if (triggahcomma==1){ maxhp=atoi(tempariro.c_str()); tempariro = "";food++;}}
  294.                                                
  295.                                                 if (triggahcomma==1){  //MAX_MP &MAX_RP
  296.                                                     if(frameline.substr(food+positions[ice],1).find(",")!=string::npos) {triggahcomma =2;}else{tempariro+=(frameline.substr(positions[ice]+food, 1).c_str());food++;}
  297.                                                     if (triggahcomma==2){ maxmp=atoi(tempariro.c_str()); tempariro = "";maxrp=atoi(frameline.substr(frameline.rfind(",")+1).c_str());triggahcomma=0;extraction =true;food=1000; }}
  298.                                                 else{
  299.                                                      food++;}}
  300.                                                      
  301.                                         switch (ice){
  302.                                                case 9: if (frameline.rfind(tags[ice])!=string::npos) dashing=atoi(frameline.substr(positions[ice]).c_str());food=1000; break;
  303.                                                case 7: if (frameline.rfind(tags[ice])!=string::npos) walking=atoi(frameline.substr(positions[ice]).c_str());food=1000; break;
  304.                                                case 6: if (frameline.rfind(tags[ice])!=string::npos)standing=atoi(frameline.substr(positions[ice]).c_str());food=1000; break;
  305.                                                case 5: if (frameline.rfind(tags[ice])!=string::npos)armor=atoi(frameline.substr(positions[ice]).c_str());food=1000; break;
  306.                                                case 0: if (frameline.rfind(tags[ice])!=string::npos) name=frameline.substr(positions[ice]);food=1000;break;
  307.                                                default:;}
  308.                                        
  309.                                        
  310.                                           }
  311.                                          
  312.                                       //cout<< "name: " << name << endl <<"WALKSPD_X_Z: "<<maxmp<<endl;    
  313.                                 if (frameline.find("{/info}")!= string::npos){
  314.                                     tempariro2="";
  315.                                     while(A_FILE.good()){
  316.                                         getline(A_FILE, frameline);
  317.                                         tempariro2 +=frameline;
  318.                                     }
  319.                                 A_FILE.seekp(0, A_FILE.end);A_FILE.close();
  320.                                 }}}}}}
  321.                          
  322.                           posx   = a;
  323.                           posz   = b;
  324.                           facing = 0;
  325.                           movedirx=2;
  326.                           movedirz=2;
  327.                          
  328.                           //loadframes:
  329.                           //A_FILE.seekp(0, A_FILE.beg);
  330.                           //A_FILE.seekg(0, A_FILE.beg);
  331.                           //getline(A_FILE, tempariro2);
  332.                           temp0=tempariro2.find(" ");
  333.                           while(temp0!=string::npos){tempariro2.erase (temp0, 1); //clear spaces
  334.                                 temp0=tempariro2.find(" ", temp0);}
  335.                           temp0=tempariro2.find("\n");
  336.                           while(temp0!=string::npos){tempariro2.erase (temp0, 1); //clear newline chars
  337.                                 temp0=tempariro2.find("\n", temp0);}
  338.                                
  339.                           tempariro2=tempariro2.substr(tempariro2.find("[f="));
  340.                           int ideh;
  341.                           while(tempariro2.find("[f=") != string::npos && tempariro2.find("[/f]")!= string::npos){
  342.                                                        frame framah;
  343.                                                        ideh = atoi(tempariro2.substr(3, tempariro2.find("]")-3).c_str());
  344.                                                        framah.init(tempariro2.substr(tempariro2.find("]")+1,tempariro2.find("[/f]")), atoi(tempariro2.substr(3, tempariro2.find("]")-3).c_str())  );
  345.                                                        Frames[framah.no]=framah;
  346.                                                        if (tempariro2.find("[f=", 4) != string::npos){
  347.                                                        
  348.                                                        tempariro2=tempariro2.substr(tempariro2.find("[f=", 4));}else{break;
  349.                                                        }
  350.                                                        }
  351.                                                      
  352.                                
  353.                                
  354.                           currframe = standing;
  355.  
  356.  
  357.                          
  358. }
  359. void object::Update(background A_Field){
  360.      if(Frames[currframe].state==0){
  361.      if (total_fx > 0){
  362.      total_fx-=FRICTION;
  363.      if (total_fx <0) total_fx=0;
  364.      }
  365.      if (total_fx < 0){
  366.      total_fx+=FRICTION;
  367.      if (total_fx >0) total_fx=0;
  368.      }
  369.      }
  370.      if (newframe){delayU=Frames[currframe].delay;if (Frames[currframe].f_x!=0 && Frames[currframe].f_x!=4321){
  371.      total_fx=Frames[currframe].f_x;}else if(Frames[currframe].f_x!=4321){total_fx=0;}newframe=false;}
  372.      
  373.      if (delayU==0){previousframe=currframe;currframe=Frames[currframe].nxt;newframe=true;}else{
  374.      delayU--;}
  375.    
  376.      if (previousframe!=4321 && Frames[currframe].loop_condition==previousframe && !doloop && Frames[currframe].loop_length!=0&&newframe){
  377.         U_loop_length= Frames[currframe].loop_length;
  378.         doloop=true;
  379.        
  380.      }
  381.      if (Frames[currframe].loop_condition==previousframe && doloop&&newframe){
  382.         if (U_loop_length == 0){
  383.             previousframe=currframe;currframe=Frames[currframe].loop_goto;
  384.             doloop=false;newframe=true;
  385.         }else{
  386.        
  387.         U_loop_length--;}
  388.      }
  389.  
  390.      if ((P_UP==true||P_DOWN==true||P_LEFT==true||P_RIGHT==true)&&Frames[currframe].state==0){
  391.         if (DASHR==1&&P_RIGHT==true){
  392.             previousframe=currframe;currframe=dashing;newframe=true;DASHR=0;DASHL=0;DshClksIntrvlL,DshClksIntrvlR=0;
  393.         }else if(DASHL==1&&P_LEFT==true){
  394.             previousframe=currframe;currframe=dashing;newframe=true;DASHL=0;DASHR=0;DshClksIntrvlL,DshClksIntrvlR=0;
  395.         }else{
  396.          previousframe=currframe;currframe=walking;newframe=true;}}
  397.      if (Frames[currframe].state==1 && !(P_UP==true||P_DOWN==true||P_LEFT==true||P_RIGHT==true)){
  398.         currframe=standing;newframe=true;previousframe=currframe;
  399.      }
  400.      
  401.      if (Frames[currframe].state==1){
  402.         if (P_UP==true){movedirz = 0;}
  403.         else if (P_DOWN==true){movedirz =1;}else movedirz = 2;
  404.         if (P_LEFT==true){movedirx = 1;}
  405.         else if (P_RIGHT==true){movedirx= 0;}else movedirx = 2;
  406.         Walk(movedirx, movedirz, A_Field);}
  407.        
  408.         if (facing==0)posx += total_fx;
  409.         if (facing==1)posx -= total_fx;
  410.      }
  411.      
  412.  
  413. /*-------------------------------------------------------------------------------------------------------------*/
  414.  
  415.  
  416.  
  417. class LOAD{
  418.       const char* LOAD_DIR;
  419.       const char* LOAD_TOKEN;
  420.       ifstream LOAD_TXT;
  421.       string line;
  422.       public:
  423.        
  424.              LOAD(string, string);
  425.              //object OBJECT_IDS[500];
  426.              std::vector<object> OBJECT_IDS;
  427.              int OBJID_INDEX;
  428.              void LoadOBJ(){
  429.                              string paraid, paraind, paradir;
  430.                              size_t L_POS, temp0;
  431.                              if (LOAD_TXT.is_open()){
  432.                                 while (LOAD_TXT.good()){
  433.                                       getline(LOAD_TXT, line);
  434.                                       temp0=line.find(" ");
  435.                                       while(temp0!=string::npos){line.erase (temp0, 1);
  436.                                       temp0=line.find(" ", temp0);}
  437.                                       L_POS = line.find(LOAD_TOKEN);
  438.                                       if (L_POS != string::npos){paraid= line.substr(0, L_POS); //the function
  439.                                          
  440.                                       temp0 =L_POS;
  441.                                       L_POS = line.find(LOAD_TOKEN, L_POS+1, 2);}
  442.                                       if (L_POS != string::npos){ paraind=line.substr(temp0+2, L_POS-temp0-2); //the function2
  443.                                          
  444.                                       temp0 =L_POS;
  445.                                       L_POS = line.find(LOAD_TOKEN, L_POS+1, 2);}
  446.                                       if (L_POS != string::npos){ paradir=line.substr(temp0+2, L_POS-temp0-2);
  447.                                       object Stickman;
  448.                                       Stickman.init(atoi(paraid.c_str()), paraind, paradir, 200, 450); //the function3
  449.                                       OBJECT_IDS[OBJID_INDEX++]= Stickman;} //the function3
  450.                                      
  451. }}}};
  452. LOAD::LOAD (string dir, string TOKEN)
  453. :OBJECT_IDS(500)
  454. {
  455.    
  456.     OBJID_INDEX = 0;
  457.     LOAD_DIR = dir.c_str ();
  458.     LOAD_TOKEN = TOKEN.c_str ();
  459.     LOAD_TXT.open (dir.c_str ());
  460. }
  461.  
  462. /*-------------------------------------------------------------------------------------------------------------*/
  463.  
  464. /*-------------------------------------------------------------------------------------------------------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement