예제 #1
0
void Stage::loadDialogues(std::string file)
{
    writeLogLine("Loading dialogues from XML.");

    char *archivo=new char[255];
    strcpy(archivo,"stages/");
    strcat(archivo,file.c_str());
    strcat(archivo,"/dialogues.xml");
    TiXmlDocument doc_t( archivo );
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;

    TiXmlNode *dialogues_file=doc->FirstChild("DialoguesFile");

    if(dialogues_file==NULL)
        return;

    for(TiXmlNode *dialogue_node=dialogues_file->FirstChild("dialogue");
            dialogue_node!=NULL;
            dialogue_node=dialogue_node->NextSibling("dialogue"))
    {
        int frame=atoi(dialogue_node->ToElement()->Attribute("frame"));
        std::string text=dialogue_node->ToElement()->Attribute("text");
        std::string path=dialogue_node->ToElement()->Attribute("path");

        dialogues[frame]=new Dialogue(painter,sonido,receiver,text,painter->getTexture("stages/"+file+"/"+path));
    }
}
예제 #2
0
void RosalilaInputs::loadFromXML(int jugador,Receiver* receiver)
{
    this->jugador=jugador;
    this->receiver=receiver;
    this->inteligencia_artificial=false;
    string xml_path=assets_directory+"misc/inputs.xml";
    TiXmlDocument doc_t(xml_path.c_str());
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;

    std::vector<Boton> botones_temp;
    for(TiXmlNode* input=doc->FirstChild("Input");
            input!=NULL;
            input=input->NextSibling("Input"))
    {
        if(jugador==atoi(input->ToElement()->Attribute("player")))
        {
            //Key
            if(strcmp("keyboard",input->ToElement()->Attribute("type"))==0)
            {
                for(TiXmlNode* boton=input->FirstChild("button");
                        boton!=NULL;
                        boton=boton->NextSibling("button"))
                {
                    int key=0;
                    if(boton->ToElement()->Attribute("input")[0]=='Q' || boton->ToElement()->Attribute("input")[0]=='q')
                        key=SDLK_q;
                    if(boton->ToElement()->Attribute("input")[0]=='W' || boton->ToElement()->Attribute("input")[0]=='w')
                        key=SDLK_w;
                    if(boton->ToElement()->Attribute("input")[0]=='E' || boton->ToElement()->Attribute("input")[0]=='e')
                        key=SDLK_e;
                    if(boton->ToElement()->Attribute("input")[0]=='R' || boton->ToElement()->Attribute("input")[0]=='r')
                        key=SDLK_r;
                    if(boton->ToElement()->Attribute("input")[0]=='T' || boton->ToElement()->Attribute("input")[0]=='t')
                        key=SDLK_t;
                    if(boton->ToElement()->Attribute("input")[0]=='Y' || boton->ToElement()->Attribute("input")[0]=='y')
                        key=SDLK_y;
                    if(boton->ToElement()->Attribute("input")[0]=='U' || boton->ToElement()->Attribute("input")[0]=='u')
                        key=SDLK_u;
                    if(boton->ToElement()->Attribute("input")[0]=='I' || boton->ToElement()->Attribute("input")[0]=='i')
                        key=SDLK_i;
                    if(boton->ToElement()->Attribute("input")[0]=='O' || boton->ToElement()->Attribute("input")[0]=='o')
                        key=SDLK_o;
                    if(boton->ToElement()->Attribute("input")[0]=='P' || boton->ToElement()->Attribute("input")[0]=='p')
                        key=SDLK_p;
                    if(boton->ToElement()->Attribute("input")[0]=='A' || boton->ToElement()->Attribute("input")[0]=='a')
                        key=SDLK_a;
                    if(boton->ToElement()->Attribute("input")[0]=='S' || boton->ToElement()->Attribute("input")[0]=='s')
                        key=SDLK_s;
                    if(boton->ToElement()->Attribute("input")[0]=='D' || boton->ToElement()->Attribute("input")[0]=='d')
                        key=SDLK_d;
                    if(boton->ToElement()->Attribute("input")[0]=='F' || boton->ToElement()->Attribute("input")[0]=='f')
                        key=SDLK_f;
                    if(boton->ToElement()->Attribute("input")[0]=='G' || boton->ToElement()->Attribute("input")[0]=='g')
                        key=SDLK_g;
                    if(boton->ToElement()->Attribute("input")[0]=='H' || boton->ToElement()->Attribute("input")[0]=='h')
                        key=SDLK_h;
                    if(boton->ToElement()->Attribute("input")[0]=='J' || boton->ToElement()->Attribute("input")[0]=='j')
                        key=SDLK_j;
                    if(boton->ToElement()->Attribute("input")[0]=='K' || boton->ToElement()->Attribute("input")[0]=='k')
                        key=SDLK_k;
                    if(boton->ToElement()->Attribute("input")[0]=='L' || boton->ToElement()->Attribute("input")[0]=='l')
                        key=SDLK_l;
                    if(boton->ToElement()->Attribute("input")[0]=='Z' || boton->ToElement()->Attribute("input")[0]=='z')
                        key=SDLK_z;
                    if(boton->ToElement()->Attribute("input")[0]=='X' || boton->ToElement()->Attribute("input")[0]=='x')
                        key=SDLK_x;
                    if(boton->ToElement()->Attribute("input")[0]=='C' || boton->ToElement()->Attribute("input")[0]=='c')
                        key=SDLK_c;
                    if(boton->ToElement()->Attribute("input")[0]=='V' || boton->ToElement()->Attribute("input")[0]=='v')
                        key=SDLK_v;
                    if(boton->ToElement()->Attribute("input")[0]=='B' || boton->ToElement()->Attribute("input")[0]=='b')
                        key=SDLK_b;
                    if(boton->ToElement()->Attribute("input")[0]=='N' || boton->ToElement()->Attribute("input")[0]=='n')
                        key=SDLK_n;
                    if(boton->ToElement()->Attribute("input")[0]=='M' || boton->ToElement()->Attribute("input")[0]=='m')
                        key=SDLK_m;
                    botones_temp.push_back(Boton(receiver,key,std::string(boton->ToElement()->Attribute("map"))));
                }
            }
            //Joy
            if(strcmp("joystick",input->ToElement()->Attribute("type"))==0)
            {
                for(TiXmlNode* boton=input->FirstChild("button");
                        boton!=NULL;
                        boton=boton->NextSibling("button"))
                {
                    int int_boton;
                    if(strcmp(boton->ToElement()->Attribute("input"),"up")==0)
                        int_boton=-8;
                    else if(strcmp(boton->ToElement()->Attribute("input"),"down")==0)
                        int_boton=-2;
                    else if(strcmp(boton->ToElement()->Attribute("input"),"left")==0)
                        int_boton=-4;
                    else if(strcmp(boton->ToElement()->Attribute("input"),"right")==0)
                        int_boton=-6;
                    else
                        int_boton=boton->ToElement()->Attribute("input")[0]-48;
                    botones_temp.push_back(Boton(receiver,int_boton,input->ToElement()->Attribute("joystick_number")[0]-48,boton->ToElement()->Attribute("map")));
                }
            }
        }
    }

    tecla_arriba=true;
    for(int i=0;i<20;i++)
        buffer_inputs.push_back("5");
    for(int i=0;i<20;i++)
        printable_buffer_inputs.push_back("5");
    for(int i=0;i<(int)botones_temp.size();i++)
    {
        if(botones_temp[i].getMapeo()=="2" || botones_temp[i].getMapeo()=="4" || botones_temp[i].getMapeo()=="6" || botones_temp[i].getMapeo()=="8")
        {
            this->cruz.push_back(botones_temp[i]);
        }
        else
        {
            this->botones.push_back(botones_temp[i]);
        }
    }
}
예제 #3
0
void Enemy::loadModifiersFromXML()
{
    //Loading file
    std::string main_path=assets_directory+directory+"modifiers.xml";
    TiXmlDocument doc_t(main_path.c_str());
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;
    TiXmlNode *modifiers_file=doc->FirstChild("ModifiersFile");
    //Loading sprites
    for(TiXmlNode* modifier_node=modifiers_file->FirstChild("Modifier");
            modifier_node!=NULL;
            modifier_node=modifier_node->NextSibling("Modifier"))
    {
        vector<Modifier*>* temp_modifiers=new vector<Modifier*>();

        int at=atoi(modifier_node->ToElement()->Attribute("at"));

        if(modifier_node->ToElement()->Attribute("velocity")!=NULL)
        {
            std::string value=modifier_node->ToElement()->Attribute("velocity");
            temp_modifiers->push_back(new Modifier("velocity",value));
        }

        if(modifier_node->ToElement()->Attribute("angle")!=NULL)
        {
            std::string value=modifier_node->ToElement()->Attribute("angle");
            temp_modifiers->push_back(new Modifier("angle",value));
        }

        if(modifier_node->ToElement()->Attribute("pattern_type")!=NULL)
        {
            std::string value=modifier_node->ToElement()->Attribute("pattern_type");
            temp_modifiers->push_back(new Modifier("pattern_type",value));
        }

        if(modifier_node->ToElement()->Attribute("angle_change")!=NULL)
        {
            std::string value=modifier_node->ToElement()->Attribute("angle_change");
            temp_modifiers->push_back(new Modifier("angle_change",value));
        }

        if(modifier_node->ToElement()->Attribute("iterator")!=NULL)
        {
            std::string value=modifier_node->ToElement()->Attribute("iterator");
            temp_modifiers->push_back(new Modifier("iterator",value));
        }

        this->modifiers[at]=temp_modifiers;

        if(modifier_node->ToElement()->Attribute("repeat")!=NULL)
        {
            int repeats = atoi(modifier_node->ToElement()->Attribute("repeat"));
            int frequency = 1;
            if(modifier_node->ToElement()->Attribute("repeat_frequency")!=NULL)
                frequency = atoi(modifier_node->ToElement()->Attribute("repeat_frequency"));
            for(int i=0; i<repeats; i++)
            {
                this->modifiers[at+frequency*(i+1)]=temp_modifiers;
            }
        }
    }
}
예제 #4
0
void Automata::loadFromXML(string archivo,string archivo_default)
{
    TiXmlDocument doc_t(archivo.c_str());
    bool loadOkay = doc_t.LoadFile();
    if(!loadOkay)
    {
        doc_t=TiXmlDocument(archivo_default.c_str());
        loadOkay=doc_t.LoadFile();
        cout.flush();
    }
    TiXmlDocument *doc;
    doc=&doc_t;

    for(TiXmlNode* nodo=doc->FirstChild("State");
            nodo!=NULL;
            nodo=nodo->NextSibling("State"))
    {
        std::vector<Transicion*> transiciones;
        for(TiXmlElement *e_action=nodo->FirstChild("Action")->ToElement();
                e_action!=NULL;
                e_action=e_action->NextSiblingElement("Action"))
        {
            Transicion *transicion;
            if(e_action->Attribute("rewardable")!=NULL)
                transicion=new Transicion(e_action->Attribute("input"),e_action->Attribute("destination"),strcmp(e_action->Attribute("rewardable"),"yes")==0);
            else
                transicion=new Transicion(e_action->Attribute("input"),e_action->Attribute("destination"),false);
            if(e_action->Attribute("reward")!=NULL)
                transicion->setRecompensa(atoi(e_action->Attribute("reward")));
            if(e_action->Attribute("wait")!=NULL)
                transicion->setWait(atoi(e_action->Attribute("wait")));




            if(e_action->FirstChild("condition")!=NULL)
            {
                for(TiXmlElement *elemento_condicion=e_action->FirstChild("condition")->ToElement();
                        elemento_condicion!=NULL;
                        elemento_condicion=elemento_condicion->NextSiblingElement("condition"))
                {
                    std::string exp_i(elemento_condicion->Attribute("left_exp"));
                    std::string op(elemento_condicion->Attribute("relational_op"));
                    std::string exp_d(elemento_condicion->Attribute("right_exp"));
                    std::string str_contrario(elemento_condicion->Attribute("to_opponent"));
                    bool contrario=(str_contrario=="yes");
                    transicion->agregarCondicion(Condicion2(exp_i,op,exp_d,contrario));
                }
            }

            if(e_action->FirstChild("condition_integer")!=NULL)
            {
                for(TiXmlElement *elemento_condicion=e_action->FirstChild("condition_integer")->ToElement();
                        elemento_condicion!=NULL;
                        elemento_condicion=elemento_condicion->NextSiblingElement("condition_integer"))
                {
                    std::string exp_i(elemento_condicion->Attribute("left_exp"));
                    std::string op(elemento_condicion->Attribute("relational_op"));
                    int exp_d=atoi(elemento_condicion->Attribute("right_exp"));
                    std::string str_contrario(elemento_condicion->Attribute("to_opponent"));
                    bool contrario=(str_contrario=="yes");
                    transicion->agregarCondicion(Condicion2(exp_i,op,exp_d,contrario));
                }
            }
            transiciones.push_back(transicion);
        }
        estados[std::string(nodo->ToElement()->Attribute("name"))]=new Estado(transiciones);
    }
}
예제 #5
0
파일: Stage.cpp 프로젝트: Rosalila/Fighter
void Stage::loadFromXML(std::string path)
{
    writeLogLine("Loading stage from XML.");

    string xml_path=assets_directory+"stages/"+path+"/main.xml";

    TiXmlDocument doc_t(xml_path.c_str());
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;

    TiXmlNode *stage_file=doc->FirstChild("StageFile");

    //Load settings
    music_path=assets_directory+"stages/"+path+"/music.ogg";

    TiXmlNode *nodo_ss=stage_file->FirstChild("StageSize");
    this->size=atoi(nodo_ss->ToElement()->Attribute("x"));

    TiXmlNode *nodo_floor=stage_file->FirstChild("Floor");
    this->pos_piso=atoi(nodo_floor->ToElement()->Attribute("position"));

    writeLogLine("Loading stage's BackLayers.");

    //Load back layer
    for(TiXmlNode *nodo_back=stage_file->FirstChild("BackLayer");
            nodo_back!=NULL;
            nodo_back=nodo_back->NextSibling("BackLayer"))
    {
        int frame_duration=atoi(nodo_back->ToElement()->Attribute("frame_duration"));
        int depth_effect_x=atoi(nodo_back->ToElement()->Attribute("depth_effect_x"));
        int depth_effect_y=atoi(nodo_back->ToElement()->Attribute("depth_effect_y"));
        int alignment_x=atoi(nodo_back->ToElement()->Attribute("alignment_x"));
        int alignment_y=atoi(nodo_back->ToElement()->Attribute("alignment_y"));

        int velocity_x=0;
        if(nodo_back->ToElement()->Attribute("velocity_x")!=NULL)
            velocity_x=atoi(nodo_back->ToElement()->Attribute("velocity_x"));

        int min_x=-999999;
        if(nodo_back->ToElement()->Attribute("min_x")!=NULL)
            min_x=atoi(nodo_back->ToElement()->Attribute("min_x"));

        int max_x=999999;
        if(nodo_back->ToElement()->Attribute("max_x")!=NULL)
            max_x=atoi(nodo_back->ToElement()->Attribute("max_x"));

        std::vector <Image*> textures;
        std::vector <int> textures_size_x;
        std::vector <int> textures_size_y;

        for(TiXmlNode* layer=nodo_back->FirstChild("frame");
                layer!=NULL;
                layer=layer->NextSibling("frame"))
        {
            string image_path=assets_directory+"stages/"+path+"/images/"+layer->ToElement()->Attribute("image_path");

            Image* image=painter->getTexture(image_path);
            textures.push_back(image);

            int size_x=image->getWidth();
            if(layer->ToElement()->Attribute("size_x")!=NULL)
                size_x=atoi(layer->ToElement()->Attribute("size_x"));

            int size_y=image->getHeight();
            if(layer->ToElement()->Attribute("size_y")!=NULL)
                size_y=atoi(layer->ToElement()->Attribute("size_y"));

            textures_size_x.push_back(size_x);
            textures_size_y.push_back(size_y);
        }

        back.push_back(new Layer(textures,textures_size_x,textures_size_y,frame_duration,depth_effect_x,depth_effect_y,alignment_x,alignment_y,velocity_x,min_x,max_x));
    }

    writeLogLine("Loading stage's FrontLayers.");

    //Load front layer
    for(TiXmlNode *nodo_back=stage_file->FirstChild("FrontLayer");
            nodo_back!=NULL;
            nodo_back=nodo_back->NextSibling("FrontLayer"))
    {
        int frame_duration=atoi(nodo_back->ToElement()->Attribute("frame_duration"));
        int depth_effect_x=atoi(nodo_back->ToElement()->Attribute("depth_effect_x"));
        int depth_effect_y=atoi(nodo_back->ToElement()->Attribute("depth_effect_y"));
        int alignment_x=atoi(nodo_back->ToElement()->Attribute("alignment_x"));
        int alignment_y=atoi(nodo_back->ToElement()->Attribute("alignment_y"));

        int velocity_x=0;
        if(nodo_back->ToElement()->Attribute("velocity_x")!=NULL)
            velocity_x=atoi(nodo_back->ToElement()->Attribute("velocity_x"));

        int min_x=-999999;
        if(nodo_back->ToElement()->Attribute("min_x")!=NULL)
            min_x=atoi(nodo_back->ToElement()->Attribute("min_x"));

        int max_x=999999;
        if(nodo_back->ToElement()->Attribute("max_x")!=NULL)
            max_x=atoi(nodo_back->ToElement()->Attribute("max_x"));

        std::vector <Image*> textures;
        std::vector <int> textures_size_x;
        std::vector <int> textures_size_y;

        for(TiXmlNode* layer=nodo_back->FirstChild("frame");
                layer!=NULL;
                layer=layer->NextSibling("frame"))
        {
            string image_path=assets_directory+"stages/"+path+"/images/"+layer->ToElement()->Attribute("image_path");

            Image* image=painter->getTexture(image_path);
            textures.push_back(image);

            int size_x=image->getWidth();
            if(layer->ToElement()->Attribute("size_x")!=NULL)
                size_x=atoi(layer->ToElement()->Attribute("size_x"));

            int size_y=image->getHeight();
            if(layer->ToElement()->Attribute("size_y")!=NULL)
                size_y=atoi(layer->ToElement()->Attribute("size_y"));

            textures_size_x.push_back(size_x);
            textures_size_y.push_back(size_y);
        }

        front.push_back(new Layer(textures,textures_size_x,textures_size_y,frame_duration,depth_effect_x,depth_effect_y,alignment_x,alignment_y,velocity_x,min_x,max_x));
    }
    writeLogLine("Stage loaded succesfully from XML.");
}
RosalilaGraphics::RosalilaGraphics()
{
    //XML Initializations
    string configxml_path=assets_directory+"config.xml";
    TiXmlDocument doc_t( configxml_path.c_str() );
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;

    TiXmlNode *config_file=doc->FirstChild("ConfigFile");

    TiXmlElement *screensize_element=config_file->FirstChild("Resolution")->ToElement();
    screen_width=atoi(screensize_element->Attribute("x"));
    screen_height=atoi(screensize_element->Attribute("y"));

    TiXmlElement *resolution_element=config_file->FirstChild("ScreenSize")->ToElement();
    int screen_resized_width=atoi(resolution_element->Attribute("x"));
    int screen_resized_height=atoi(resolution_element->Attribute("y"));

    TiXmlElement *fullscreen_element=config_file->FirstChild("Fullscreen")->ToElement();
    fullscreen=strcmp(fullscreen_element->Attribute("enabled"),"yes")==0;

    TiXmlElement *font_element=config_file->FirstChild("Font")->ToElement();

    int font_size=10;
    if(font_element->Attribute("size")!=NULL)
    {
        font_size=atoi(font_element->Attribute("size"));
    }
    int font_red=0;
    if(font_element->Attribute("red")!=NULL)
    {
        font_red=atoi(font_element->Attribute("red"));
    }
    int font_green=0;
    if(font_element->Attribute("green")!=NULL)
    {
        font_green=atoi(font_element->Attribute("green"));
    }
    int font_blue=0;
    if(font_element->Attribute("blue")!=NULL)
    {
        font_blue=atoi(font_element->Attribute("blue"));
    }
    //Internal initializations
    joystick_1 = NULL;
    joystick_2 = NULL;

    screen_bpp = 32;
    camera_x=camera_y=0;

    //Initialize all SDL subsystems
    if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0 )
    {
        writeLogLine(SDL_GetError());
        return;
    }

    //Initialize SDL_ttf
    if( TTF_Init() == -1 )
    {
        writeLogLine(SDL_GetError());
        return;
    }

    font = NULL;
    textColor.r = font_red;
    textColor.g = font_green;
    textColor.b = font_blue;

    string font_path=assets_directory+"misc/font.ttf";
    font = TTF_OpenFont( font_path.c_str(), font_size );

    if(font==NULL)
    {
        writeLogLine("Could not init font. Place it on /misc/font.ttf .");
    }

    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new*

    window = SDL_CreateWindow( "Rosalila Engine", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                               screen_resized_width, screen_resized_height,
                               SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );

    if(fullscreen)
        SDL_SetWindowFullscreen(window,SDL_WINDOW_FULLSCREEN);

    renderer = SDL_CreateRenderer(window, -1, 0);

    //Set the openGL state?
    glEnable( GL_TEXTURE_2D );
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );

    glViewport( 0, 0, screen_resized_width, screen_resized_height );

    glClear( GL_COLOR_BUFFER_BIT );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();

    glOrtho(0.0f, screen_width, screen_height, 0.0f, -1.0f, 1.0f);

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    //Fps cap
    frames_per_seccond = 60;
    frame = 0;
    fps=new Timer();
    update=new Timer();
    fps->start();
    update->start();

    //Init joysticks
    if( SDL_NumJoysticks() == 1 )
    {
        writeLogLine("1 joystick was found.");
        joystick_1 = SDL_JoystickOpen( 0 );
        if(joystick_1 != NULL)
            writeLogLine("Joystick for player 1 initialized succesfully.");
        else
            writeLogLine("Error initializing joystick for player 1.");
    }
    if( SDL_NumJoysticks() == 2 )
    {
        writeLogLine("2 joysticks were found.");
        joystick_1 = SDL_JoystickOpen( 0 );
        if(joystick_1 != NULL)
            writeLogLine("Joystick for player 1 initialized succesfully.");
        else
            writeLogLine("Error initializing joystick for player 1.");
        joystick_2 = SDL_JoystickOpen( 1 );
        if(joystick_2 != NULL)
            writeLogLine("Joystick for player 2 initialized succesfully.");
        else
            writeLogLine("Error initializing joystick for player 2.");
    }

    //If everything initialized fine
    writeLogLine("Success! SDL initialized.");

     SDL_GL_CreateContext(window);
    GLenum error = GL_NO_ERROR;
    error = glGetError();
    if( error != GL_NO_ERROR ) {
/* Died as glu did
         printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) );
*/
         exit(12);
    }

    return;
}
void Character::loadMainXML()
{
    //Loading file
    std::string main_path=assets_directory+directory+"main.xml";
    TiXmlDocument doc_t(main_path.c_str());
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;
    TiXmlNode *main_file=doc->FirstChild("MainFile");

    //Loading attributes
    TiXmlElement *attributes=main_file->FirstChild("Attributes")->ToElement();
    this->velocity=5;
    if(attributes->Attribute("velocity")!=NULL)
    {
        this->velocity=atoi(attributes->Attribute("velocity"));
    }

    this->animation_velocity=5;
    if(attributes->Attribute("animation_velocity")!=NULL)
    {
        this->animation_velocity=atoi(attributes->Attribute("animation_velocity"));
    }

    this->max_hp=100;
    this->hp=100;
    if(attributes->Attribute("hp")!=NULL)
    {
        this->max_hp=atoi(attributes->Attribute("hp"));
    }
    this->hp=this->max_hp;

    this->x=100;
    if(attributes->Attribute("initial_x")!=NULL)
    {
        this->x=atoi(attributes->Attribute("initial_x"));
    }

    this->y=500;
    if(attributes->Attribute("initial_y")!=NULL)
    {
        this->y=atoi(attributes->Attribute("initial_y"));
    }

    this->life_bar_x=0;
    this->life_bar_y=0;
    this->life_bar_rect_offset_x=0;
    this->life_bar_rect_offset_y=0;
    this->life_bar_rect_height=0;
    this->life_bar_rect_width=0;
    this->color.red=0;
    this->color.green=0;
    this->color.blue=0;
    this->color.alpha=255;

    if(main_file->FirstChild("LifeBar")!=NULL)
    {
        TiXmlElement *life_bar=main_file->FirstChild("LifeBar")->ToElement();
        if(life_bar->Attribute("x")!=NULL)
            this->life_bar_x=atoi(life_bar->Attribute("x"));
        if(life_bar->Attribute("y")!=NULL)
            this->life_bar_y=atoi(life_bar->Attribute("y"));
        if(life_bar->Attribute("color_r")!=NULL)
            this->color.red=atoi(life_bar->Attribute("color_r"));
        if(life_bar->Attribute("color_g")!=NULL)
            this->color.green=atoi(life_bar->Attribute("color_g"));
        if(life_bar->Attribute("color_b")!=NULL)
            this->color.blue=atoi(life_bar->Attribute("color_b"));
        if(life_bar->Attribute("color_a")!=NULL)
            this->color.alpha=atoi(life_bar->Attribute("color_a"));
        if(life_bar->Attribute("rect_offset_x")!=NULL)
            this->life_bar_rect_offset_x=atoi(life_bar->Attribute("rect_offset_x"));
        if(life_bar->Attribute("rect_offset_y")!=NULL)
            this->life_bar_rect_offset_y=atoi(life_bar->Attribute("rect_offset_y"));
        if(life_bar->Attribute("rect_height")!=NULL)
            this->life_bar_rect_height=atoi(life_bar->Attribute("rect_height"));
        if(life_bar->Attribute("rect_width")!=NULL)
            this->life_bar_rect_width=atoi(life_bar->Attribute("rect_width"));
    }

    TiXmlNode*hitboxes_node = main_file->FirstChild("Hitboxes");

    if(hitboxes_node->FirstChild("Hitbox"))
    for(TiXmlNode* hitbox_node=hitboxes_node->FirstChild("Hitbox");
            hitbox_node!=NULL;
            hitbox_node=hitbox_node->NextSibling("Hitbox"))
    {
        TiXmlElement *hitbox_element=hitbox_node->ToElement();
        int hitbox_x=atoi(hitbox_element->Attribute("x"));
        int hitbox_y=atoi(hitbox_element->Attribute("y"));
        int hitbox_width=atoi(hitbox_element->Attribute("width"));
        int hitbox_height=atoi(hitbox_element->Attribute("height"));
        int hitbox_angle=atoi(hitbox_element->Attribute("angle"));
        Hitbox* hitbox=new Hitbox(hitbox_x,hitbox_y,hitbox_width,hitbox_height,hitbox_angle);
        this->hitboxes.push_back(hitbox);
    }

    if(main_file->FirstChild("Sounds"))
    {
        TiXmlElement *sounds_element=main_file->FirstChild("Sounds")->ToElement();
        if(sounds_element->Attribute("hit"))
        {
            sonido->addSound(this->name+".hit",assets_directory+directory+"/sounds/"+sounds_element->Attribute("hit"));
        }
    }

    //Loading sprites
    for(TiXmlNode* sprites_node=main_file->FirstChild("Sprites");
            sprites_node!=NULL;
            sprites_node=sprites_node->NextSibling("Sprites"))
    {
        std::vector<Image*>sprites_vector;
        std::string sprites_orientation=sprites_node->ToElement()->Attribute("orientation");
        if(sprites_node->ToElement()->Attribute("sound")!=NULL)
        {
            std::string sprites_sound=sprites_node->ToElement()->Attribute("sound");
            this->sonido->addSound(name+"."+sprites_orientation,assets_directory+directory+"sounds/"+sprites_sound);
        }
        for(TiXmlNode* sprite_node=sprites_node->FirstChild("Sprite");
                sprite_node!=NULL;
                sprite_node=sprite_node->NextSibling("Sprite"))
        {
            sprites_vector.push_back(painter->getTexture(assets_directory+directory+"sprites/"+sprite_node->ToElement()->Attribute("path")));
        }
        sprites[sprites_orientation]=sprites_vector;
    }

    if(main_file->FirstChild("FlatShadow")!=NULL)
    {
        flat_shadow_texture = painter->getTexture(assets_directory+directory+"sprites/"+main_file->FirstChild("FlatShadow")->ToElement()->Attribute("image_path"));
        for(TiXmlNode* point_node=main_file->FirstChild("FlatShadow")->FirstChild("CaseRight")->FirstChild("Point");
                point_node!=NULL;
                point_node=point_node->NextSibling("Point"))
        {
            int x=atoi(point_node->ToElement()->Attribute("x"));
            int y=atoi(point_node->ToElement()->Attribute("y"));
            shadow_align_points_right.push_back(new Point(x,y));
        }
        for(TiXmlNode* point_node=main_file->FirstChild("FlatShadow")->FirstChild("CaseLeft")->FirstChild("Point");
                point_node!=NULL;
                point_node=point_node->NextSibling("Point"))
        {
            int x=atoi(point_node->ToElement()->Attribute("x"));
            int y=atoi(point_node->ToElement()->Attribute("y"));
            shadow_align_points_left.push_back(new Point(x,y));
        }
        for(TiXmlNode* point_node=main_file->FirstChild("FlatShadow")->FirstChild("CaseTop")->FirstChild("Point");
                point_node!=NULL;
                point_node=point_node->NextSibling("Point"))
        {
            int x=atoi(point_node->ToElement()->Attribute("x"));
            int y=atoi(point_node->ToElement()->Attribute("y"));
            shadow_align_points_top.push_back(new Point(x,y));
        }



        if(main_file->FirstChild("FlatShadow")->FirstChild("CaseRight")->FirstChild("Inbetween"))
        for(TiXmlNode* point_node=main_file->FirstChild("FlatShadow")->FirstChild("CaseRight")->FirstChild("Inbetween")->FirstChild("Point");
                point_node!=NULL;
                point_node=point_node->NextSibling("Point"))
        {
            int x=atoi(point_node->ToElement()->Attribute("x"));
            int y=atoi(point_node->ToElement()->Attribute("y"));
            inbetween_shadow_align_points_right.push_back(new Point(x,y));
        }
        if(main_file->FirstChild("FlatShadow")->FirstChild("CaseLeft")->FirstChild("Inbetween"))
        for(TiXmlNode* point_node=main_file->FirstChild("FlatShadow")->FirstChild("CaseLeft")->FirstChild("Inbetween")->FirstChild("Point");
                point_node!=NULL;
                point_node=point_node->NextSibling("Point"))
        {
            int x=atoi(point_node->ToElement()->Attribute("x"));
            int y=atoi(point_node->ToElement()->Attribute("y"));
            inbetween_shadow_align_points_left.push_back(new Point(x,y));
        }
        if(main_file->FirstChild("FlatShadow")->FirstChild("CaseTop")->FirstChild("Inbetween"))
        for(TiXmlNode* point_node=main_file->FirstChild("FlatShadow")->FirstChild("CaseTop")->FirstChild("Inbetween")->FirstChild("Point");
                point_node!=NULL;
                point_node=point_node->NextSibling("Point"))
        {
            int x=atoi(point_node->ToElement()->Attribute("x"));
            int y=atoi(point_node->ToElement()->Attribute("y"));
            inbetween_shadow_align_points_top.push_back(new Point(x,y));
        }
    }
}
예제 #8
0
파일: STG.cpp 프로젝트: Rosalila/STG
STG::STG(Player*player,Enemy*enemy,Stage*stage,string game_mode, int current_player_best_score)
{
    this->player=player;
    this->enemy=enemy;
    this->stage=stage;
    this->game_mode=game_mode;
    this->current_player_best_score = current_player_best_score;

    this->api_state = "";

    this->score = -1;

    this->game_over_timeout = 128;

    this->image_upload_error = rosalila()->graphics->getTexture(assets_directory+"misc/upload_error.png");

    this->image_training_box = NULL;
    this->image_training_x = NULL;
    this->image_training_bar = NULL;
    this->image_training_bar_fill = NULL;

    this->player_is_immortal = false;

    rosalila()->graphics->camera_y=0;
    frame=0;

    parry_count=0;
    charge_destroy_count=0;
    parry_dash_count=0;

    current_training_transparency=0;

    //XML Initializations
    string config_directory = assets_directory+"config.xml";
    TiXmlDocument doc_t( (char*)config_directory.c_str() );
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;

    TiXmlNode *config_file=doc->FirstChild("ConfigFile");

    TiXmlNode *you_loose_node=config_file->FirstChild("YouLose");

    int you_loose_x=atoi(you_loose_node->ToElement()->Attribute("x"));
    int you_loose_y=atoi(you_loose_node->ToElement()->Attribute("y"));
    int you_loose_animation_velocity=atoi(you_loose_node->ToElement()->Attribute("animation_velocity"));
    you_loose=Animation(you_loose_x,you_loose_y,you_loose_animation_velocity);

    if(you_loose_node->ToElement()->Attribute("sound"))
    {
        rosalila()->sound->addSound("you lose",assets_directory+you_loose_node->ToElement()->Attribute("sound"));
    }

    for(TiXmlNode* sprites_node=you_loose_node->FirstChild("sprite");
            sprites_node!=NULL;
            sprites_node=sprites_node->NextSibling("sprite"))
    {
        std::string path=sprites_node->ToElement()->Attribute("path");
        you_loose.addImage(rosalila()->graphics->getTexture(assets_directory+path));
    }


    TiXmlNode *you_win_node=config_file->FirstChild("YouWin");

    int you_win_x=atoi(you_win_node->ToElement()->Attribute("x"));
    int you_win_y=atoi(you_win_node->ToElement()->Attribute("y"));
    int you_win_animation_velocity=atoi(you_win_node->ToElement()->Attribute("animation_velocity"));
    you_win=Animation(you_win_x,you_win_y,you_win_animation_velocity);

    if(you_win_node->ToElement()->Attribute("sound"))
    {
        rosalila()->sound->addSound("you win",assets_directory+you_win_node->ToElement()->Attribute("sound"));
    }

    for(TiXmlNode* sprites_node=you_win_node->FirstChild("sprite");
            sprites_node!=NULL;
            sprites_node=sprites_node->NextSibling("sprite"))
    {
        std::string path=sprites_node->ToElement()->Attribute("path");
        you_win.addImage(rosalila()->graphics->getTexture(assets_directory+path));
    }

    if(game_mode=="Stage select" || game_mode=="charge training" || game_mode=="parry training" || game_mode=="parry dash training" || "replay")
    {
        stageSelectModeInit();
    }

    if(game_mode=="charge training")
    {
        image_training_bar=rosalila()->graphics->getTexture(assets_directory+"misc/training/bar.png");
        image_training_bar_fill=rosalila()->graphics->getTexture(assets_directory+"misc/training/bar_fill.png");
        charge_destroy_count_objective=300;
        player_is_immortal = true;
    }
    if(game_mode=="parry training")
    {
        image_training_box=rosalila()->graphics->getTexture(assets_directory+"misc/training/box.png");
        image_training_x=rosalila()->graphics->getTexture(assets_directory+"misc/training/x.png");
        parry_count_objective=3;
        player_is_immortal = true;
    }
    if(game_mode=="parry dash training")
    {
        image_training_bar=rosalila()->graphics->getTexture(assets_directory+"misc/training/bar.png");
        image_training_bar_fill=rosalila()->graphics->getTexture(assets_directory+"misc/training/bar_fill.png");
        parry_dash_count_objective=15;
        player_is_immortal = true;
    }

    setGameOver(false);
    setIsFirstWin(false);
    mainLoop();
}
예제 #9
0
void Player::loadPlayerFromXML()
{
    loadFromXML();

    //Loading file
    std::string main_path=assets_directory+directory+"main.xml";
    TiXmlDocument doc_t(main_path.c_str());
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;
    TiXmlNode *main_file=doc->FirstChild("MainFile");

    this->current_slow=0;
    this->max_slow=-1;
    TiXmlElement *attributes=main_file->FirstChild("Attributes")->ToElement();
    if(attributes->Attribute("slow")!=NULL)
    {
        this->current_slow=atoi(attributes->Attribute("slow"));
        this->max_slow=atoi(attributes->Attribute("slow"));
    }

    this->slow_decrement=3;
    if(attributes->Attribute("slow_decrement")!=NULL)
    {
        this->slow_decrement=atoi(attributes->Attribute("slow_decrement"));
    }

    this->slow_increment=1;
    if(attributes->Attribute("slow_increment")!=NULL)
    {
        this->slow_increment=atoi(attributes->Attribute("slow_increment"));
    }

    this->slow_cooldown_increment=2;
    if(attributes->Attribute("slow_cooldown_increment")!=NULL)
    {
        this->slow_cooldown_increment=atoi(attributes->Attribute("slow_cooldown_increment"));
    }

    this->slow_bar_x=0;
    this->slow_bar_y=0;
    this->slow_bar_rect_offset_x=0;
    this->slow_bar_rect_offset_y=0;
    this->slow_bar_rect_height=0;
    this->slow_bar_rect_width=0;
    this->slow_bar_color.red=0;
    this->slow_bar_color.green=0;
    this->slow_bar_color.blue=0;
    this->slow_bar_color.alpha=255;
    this->slow_bar_cooldown_color.red=0;
    this->slow_bar_cooldown_color.green=0;
    this->slow_bar_cooldown_color.blue=0;
    this->slow_bar_cooldown_color.alpha=128;

    if(main_file->FirstChild("SlowBar")!=NULL)
    {
        TiXmlElement *slow_bar=main_file->FirstChild("SlowBar")->ToElement();
        if(slow_bar->Attribute("x")!=NULL)
            this->slow_bar_x=atoi(slow_bar->Attribute("x"));
        if(slow_bar->Attribute("y")!=NULL)

            this->slow_bar_y=atoi(slow_bar->Attribute("y"));
        if(slow_bar->Attribute("color_r")!=NULL)
            this->slow_bar_color.red=atoi(slow_bar->Attribute("color_r"));
        if(slow_bar->Attribute("color_g")!=NULL)
            this->slow_bar_color.green=atoi(slow_bar->Attribute("color_g"));
        if(slow_bar->Attribute("color_b")!=NULL)
            this->slow_bar_color.blue=atoi(slow_bar->Attribute("color_b"));
        if(slow_bar->Attribute("color_a")!=NULL)
            this->slow_bar_color.alpha=atoi(slow_bar->Attribute("color_a"));

        if(slow_bar->Attribute("cooldown_color_r")!=NULL)
            this->slow_bar_cooldown_color.red=atoi(slow_bar->Attribute("cooldown_color_r"));
        if(slow_bar->Attribute("cooldown_color_g")!=NULL)
            this->slow_bar_cooldown_color.green=atoi(slow_bar->Attribute("cooldown_color_g"));
        if(slow_bar->Attribute("cooldown_color_b")!=NULL)
            this->slow_bar_cooldown_color.blue=atoi(slow_bar->Attribute("cooldown_color_b"));
        if(slow_bar->Attribute("cooldown_color_a")!=NULL)
            this->slow_bar_cooldown_color.alpha=atoi(slow_bar->Attribute("cooldown_color_a"));

        if(slow_bar->Attribute("rect_offset_x")!=NULL)
            this->slow_bar_rect_offset_x=atoi(slow_bar->Attribute("rect_offset_x"));
        if(slow_bar->Attribute("rect_offset_y")!=NULL)
            this->slow_bar_rect_offset_y=atoi(slow_bar->Attribute("rect_offset_y"));
        if(slow_bar->Attribute("rect_height")!=NULL)
            this->slow_bar_rect_height=atoi(slow_bar->Attribute("rect_height"));
        if(slow_bar->Attribute("rect_width")!=NULL)
            this->slow_bar_rect_width=atoi(slow_bar->Attribute("rect_width"));
    }
}
예제 #10
0
void Input::cargarDesdeXML(int jugador,Receiver* receiver)
{
    this->jugador=jugador;
    this->receiver=receiver;
    this->inteligencia_artificial=false;
    TiXmlDocument doc_t((char*)"misc/inputs.xml");
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;

    vector<Boton> botones;
    for(TiXmlNode* input=doc->FirstChild("Input");
            input!=NULL;
            input=input->NextSibling("Input"))
    {
        if(jugador==atoi(input->ToElement()->Attribute("player")))
        {
            //Key
            if(strcmp("keyboard",input->ToElement()->Attribute("type"))==0)
            {
                for(TiXmlNode* boton=input->FirstChild("button");
                        boton!=NULL;
                        boton=boton->NextSibling("button"))
                {
                    botones.push_back(Boton(receiver,(irr::EKEY_CODE)boton->ToElement()->Attribute("input")[0],stringw(boton->ToElement()->Attribute("map"))));
                }
            }
            //Joy
            if(strcmp("joystick",input->ToElement()->Attribute("type"))==0)
            {
                for(TiXmlNode* boton=input->FirstChild("button");
                        boton!=NULL;
                        boton=boton->NextSibling("button"))
                {
                    int int_boton;
                    if(strcmp(boton->ToElement()->Attribute("input"),"up")==0)
                        int_boton=-8;
                    else if(strcmp(boton->ToElement()->Attribute("input"),"down")==0)
                        int_boton=-2;
                    else if(strcmp(boton->ToElement()->Attribute("input"),"left")==0)
                        int_boton=-4;
                    else if(strcmp(boton->ToElement()->Attribute("input"),"right")==0)
                        int_boton=-6;
                    else
                        int_boton=boton->ToElement()->Attribute("input")[0]-48;
                    botones.push_back(Boton(receiver,int_boton,input->ToElement()->Attribute("joystick_number")[0]-48,boton->ToElement()->Attribute("map")));
                }
            }
        }
    }

    tecla_arriba=true;
    for(int i=0;i<20;i++)
        buffer_inputs.push_back("5");
    for(int i=0;i<(int)botones.size();i++)
    {
        if(botones[i].getMapeo()=="2" || botones[i].getMapeo()=="4" || botones[i].getMapeo()=="6" || botones[i].getMapeo()=="8")
        {
            this->cruz.push_back(botones[i]);
        }
        else
        {
            this->botones.push_back(botones[i]);
        }
    }
}