Exemple #1
0
void Enemy::logic(int stage_velocity, string stage_name, int global_iteration, string username)
{
    animationControl();
    spellControl(stage_velocity);

    for (std::list<Pattern*>::iterator pattern = active_patterns->begin(); pattern != active_patterns->end(); pattern++) {
        Pattern* p =  (Pattern*)*pattern;
        double distance_x= player->getHitbox().getX() - p->getX();
        double distance_y= player->getHitbox().getY() - p->getY();

        if (p->getHoming() != 0)
        {
            p->setAngle(-atan2(distance_y,distance_x)*180/PI);
        }
        else if(p->getAimPlayer())
        {
            p->setAngle(p->getAngle()-atan2(distance_y,distance_x)*180/PI);
        }


    }


    if(this->hp>0)
        modifiersControl();
    else
    {
        if(orientation!="destroyed" && flag_begin_upload)
        {
            orientation="destroyed";
            if(this->sonido->soundExists(name+".destroyed"))
                this->sonido->playSound(name+".destroyed");

            this->hitbox.setValues(0,0,0,0,0);

            //Delete bullets
            std::list<Pattern*>* active_patterns=getActivePatterns();
            std::list<Pattern*>::iterator i = active_patterns->begin();
            while (i != active_patterns->end())
            {
                Pattern*p=(Pattern*)*i;
                active_patterns->erase(i++);
                delete p;
            }

//            RosalilaNetwork network(painter);
//            //score_upload_message = network.runTcpClientSendScore(31716, "108.59.1.187",stage_name, username, global_iteration);
//            score_upload_message = network.runTcpClientSendScore(31716, "localhost",stage_name, username, global_iteration);
        }
    }

    this->angle+=this->angle_change / getSlowdown();

    this->x += cos (angle*PI/180) * velocity / getSlowdown() + stage_velocity;
    this->y -= sin (angle*PI/180) * velocity / getSlowdown();

    getIterateSlowdownFlag();
}
Exemple #2
0
void Explosion::logic()
{
    if (this->fuel > 0)
    {
        for (int i = 0; i < NUM_PARTICLES; i++)
        {
            this->particles[i]->position[0] += (this->particles[i]->speed[0] * 0.2) / getSlowdown();
            this->particles[i]->position[1] += (this->particles[i]->speed[1] * 0.2) / getSlowdown();
            this->particles[i]->position[2] += (this->particles[i]->speed[2] * 0.2) / getSlowdown();

//            this->particles[i]->color[0] -= (5.0 / 500.0)/getSlowdown();
//            if (this->particles[i]->color[0] < 0.0)
//            {
//                this->particles[i]->color[0] = 0.0;
//            }
//
//            this->particles[i]->color[1] -= (5.0 / 100.0)/getSlowdown();
//            if (this->particles[i]->color[1] < 0.0)
//            {
//                this->particles[i]->color[1] = 0.0;
//            }
//
//            this->particles[i]->color[2] -= (5.0 / 50.0)/getSlowdown();
//            if (this->particles[i]->color[2] < 0.0)
//            {
//                this->particles[i]->color[2] = 0.0;
//            }
        }

        for (int i = 0; i < NUM_DEBRIS; i++)
        {
            this->debris[i]->position[0] += this->debris[i]->speed[0] * 0.5;
            this->debris[i]->position[1] += this->debris[i]->speed[1] * 0.5;
            this->debris[i]->position[2] += this->debris[i]->speed[2] * 0.5;

            this->debris[i]->orientation[0] += this->debris[i]->orientationSpeed[0] * 10;
            this->debris[i]->orientation[1] += this->debris[i]->orientationSpeed[1] * 10;
            this->debris[i]->orientation[2] += this->debris[i]->orientationSpeed[2] * 10;
        }

//        --this->fuel;
    }

    iteration+=1/getSlowdown();
}
void Player::inputControl()
{
    if(receiver->isKeyDown(SDL_SCANCODE_DOWN)
       || receiver->isJoyDown(-2,0))
    {
        if(orientation!="down" && this->sonido->soundExists(name+".down"))
            this->sonido->playSound(name+".down");
        orientation="down";
    }
    else if(receiver->isKeyDown(SDL_SCANCODE_UP)
       || receiver->isJoyDown(-8,0))
    {
        if(orientation!="up" && this->sonido->soundExists(name+".up"))
            this->sonido->playSound(name+".up");
        orientation="up";
    }
    else if(receiver->isKeyDown(SDL_SCANCODE_LEFT)
       || receiver->isJoyDown(-4,0))
    {
        if(orientation!="left" && this->sonido->soundExists(name+".left"))
            this->sonido->playSound(name+".left");
        orientation="left";
    }
    else if(receiver->isKeyDown(SDL_SCANCODE_RIGHT)
       || receiver->isJoyDown(-6,0))
    {
        if(orientation!="right" && this->sonido->soundExists(name+".right"))
            this->sonido->playSound(name+".right");
        orientation="right";
    }
    else
    {
        if(orientation!="idle" && this->sonido->soundExists(name+".idle"))
            this->sonido->playSound(name+".idle");
        orientation="idle";
    }

    if(receiver->isKeyDown(SDL_SCANCODE_DOWN)
       || receiver->isJoyDown(-2,0))
    {
        this->y+=velocity/getSlowdown();
    }
    if(receiver->isKeyDown(SDL_SCANCODE_UP)
       || receiver->isJoyDown(-8,0))
    {
        this->y-=velocity/getSlowdown();
    }
    if(receiver->isKeyDown(SDL_SCANCODE_LEFT)
       || receiver->isJoyDown(-4,0))
    {
        this->x-=velocity/getSlowdown();
    }
    if(receiver->isKeyDown(SDL_SCANCODE_RIGHT)
       || receiver->isJoyDown(-6,0))
    {
       this->x+=velocity/getSlowdown();
    }

    if(receiver->isKeyDown(SDLK_z)
       || receiver->isJoyDown(0,0))
    {
        this->shooting=true;
    }
    else
    {
        this->shooting=false;
    }
}