Beispiel #1
0
void Scene::Generate() {
    vector<SceneElement*>::iterator i;
    float ratio = 0.f, width = -1024.f;
    vector<SceneElement*>_backgroundSeed;

    // Creating Background;
    for(i = _dynamic.begin(); i != _dynamic.end(); ++i)
        if ( (*i)->_cat == Scene::Background ) { _backgroundSeed.push_back(*i); ratio += (*i)->_ratio; }

    while( width < _width ) {
            float r = (rand()%static_cast<int>(ratio*100));
            r /= 100.0;
            float finder = 0.0f;
            for(i = _backgroundSeed.begin(); i != _backgroundSeed.end(); ++i) {
                finder += (*i)->_ratio;
                if ( r < finder ) {
                    Sprite * tmp = new Sprite( *(*i)->_image );
                    tmp->SetX( width );
                    tmp->SetY( 600 - tmp->GetSize().y );
                    width += tmp->GetSize().x + ( rand()%200 - 100);
                    _background.push_back(tmp);
                    break;
                }
            }
    }
}
Beispiel #2
0
    bool click(int x1, int y1, bool leftclicked)
    {
        if(leftclicked && x1>x-sprite.GetSize().x/2 && x1<x+sprite.GetSize().x/2
                && y1>y-sprite.GetSize().y/2 && y1<y+sprite.GetSize().y/2)return true;

        return false;
    }
Beispiel #3
0
 void SetCursorImage(string FileName, Vector2f Center = Vector2f(-500, -500))
 {
     OwnCursor = true;
     CursorSprite = LoadSprite(CursorImage, FileName);
     if(Center == Vector2f(-500, -500))
         CursorSprite.SetCenter(CursorSprite.GetSize().x/2, CursorSprite.GetSize().y/2);
     else
         CursorSprite.SetCenter(Center);
 }
Beispiel #4
0
bool SimpleCollision(Sprite s1, Sprite s2)
{
    if(s1.GetPosition().x - s1.GetCenter().x < s2.GetPosition().x + s2.GetSize().x  - s2.GetCenter().x
            && s1.GetPosition().x + s1.GetSize().x - s1.GetCenter().x > s2.GetPosition().x - s2.GetCenter().x
            && s1.GetPosition().y - s1.GetCenter().y < s2.GetPosition().y + s2.GetSize().y - s2.GetCenter().y
            && s1.GetPosition().y + s1.GetSize().y - s1.GetCenter().y > s2.GetPosition().y - s2.GetCenter().y)
        return true;
    else
        return false;
}
Beispiel #5
0
bool ownCollision(Sprite& s1, Sprite& s2, int n)
{
    if(s1.GetPosition().x < s2.GetPosition().x+s2.GetSize().x
            && s1.GetPosition().x+s1.GetSize().x > s2.GetPosition().x
            && s1.GetPosition().y < s2.GetPosition().y+s2.GetSize().y
            && s1.GetPosition().y+s1.GetSize().y+n > s2.GetPosition().y)
        return true;
    else
        return false;
}
Beispiel #6
0
bool PPCollision(Vector2f point, Sprite & s, float AlphaLimit = 20.f)
{
    point -= s.GetPosition() - s.GetCenter();

    if(point.x >= 0 && point.x < s.GetSize().x
            && point.y >= 0 && point.y < s.GetSize().y
            && s.GetPixel((int)point.x, (int)point.y).a > AlphaLimit)
        return true;
    else
        return false;
}
Beispiel #7
0
    BackgroundObject(string fileName, float distance, Vector2f position, Vector2f speed = Vector2f(0.f, 0.f))
    {
        bSprite = LoadSprite(bImage, fileName);
        Distance = distance;
        Origin = position;
        MinCorner = Vector2f(-1000.f, -1000.f);
        MaxCorner = Vector2f(1000.f, 1000.f);
        Speed = speed;

        bSprite.SetCenter(bSprite.GetSize().x/2, bSprite.GetSize().y/2);
        bSprite.SetPosition(Origin + Position);
    }
Beispiel #8
0
void Scene::SetGrass(Image * img) {
    int nbimg = _width/img->GetWidth();
    nbimg += 2;

    // TODO: Clear old scene (if any?)
    for(int i = 0; i < nbimg; ++i) {
        Sprite * tmp = new Sprite( *img);
        tmp->SetX((i-1) * tmp->GetSize().x );
        tmp->SetY(600 - img->GetHeight());
        _grass.push_back(tmp);
    }
}
Beispiel #9
0
void Scene::SetSky(Image *img) {
    int nbimg = _width/img->GetWidth();
    nbimg += 2;

    // TODO: Clear old scene (if any?)
    for(int i = 0; i < nbimg; ++i) {
        Sprite * tmp = new Sprite( *img);
        tmp->SetX((i-1) * tmp->GetSize().x );
        tmp->SetCenter(0, tmp->GetSize().y );
        tmp->SetY(600);
        tmp->SetScaleY(2.0);
        _sky.push_back(tmp);
    }
}
Beispiel #10
0
bool PPCollisionWR(Sprite Sprite1,Sprite Sprite2,float AlphaLimit = 50.f)
{
    float xmin1 = Sprite1.GetPosition().x - Sprite1.GetCenter().x;
    float ymin1 = Sprite1.GetPosition().y - Sprite1.GetCenter().y;
    float xmin2 = Sprite2.GetPosition().x - Sprite2.GetCenter().x;
    float ymin2 = Sprite2.GetPosition().y - Sprite2.GetCenter().y;

    float xmax1 = xmin1 + Sprite1.GetSize().x;
    float ymax1 = ymin1 + Sprite1.GetSize().y;
    float xmax2 = xmin2 + Sprite2.GetSize().x;
    float ymax2 = ymin2 + Sprite2.GetSize().y;

    float xmin = max(xmin1, xmin2);
    float ymin = max(ymin1, ymin2);
    float xmax = min(xmax1, xmax2);
    float ymax = min(ymax1, ymax2);

    //if(xmax <= xmin || ymax <= ymin) { return false; }

    for(int y = int(ymin); y < ymax; ++y)
    {
        for(int x = int(xmin); x < xmax; ++x)
        {
            float x1 = x - xmin1, y1 = y - ymin1;
            float x2 = x - xmin2, y2 = y - ymin2;

            Vector2f Point1 =
                RotatePoint(Vector2f(x1,y1),
                            Sprite1.GetCenter(),
                            -Sprite1.GetRotation());

            Vector2f Point2 =
                RotatePoint(Vector2f(x2,y2),
                            Sprite2.GetCenter(),
                            -Sprite2.GetRotation());

            if(Point1.x > 0 && Point1.y > 0 && Point2.x > 0 && Point2.y > 0
                    && Point1.x < Sprite1.GetSize().x && Point1.y < Sprite1.GetSize().y
                    && Point2.x < Sprite2.GetSize().x && Point2.y < Sprite2.GetSize().y)
            {
                Color color1 = Sprite1.GetPixel(int(Point1.x),int(Point1.y));
                Color color2 = Sprite2.GetPixel(int(Point2.x),int(Point2.y));

                if (color1.a >= AlphaLimit && color2.a >= AlphaLimit)
                {
                    return true;
                }
            }
        }
    }

    return false;
}
Beispiel #11
0
bool EngineInput::hoversprite( Sprite &s )
{
    F32 x, y, w, h;

    x = s.GetPosition().x;
    y = s.GetPosition().y;
    w = x + s.GetSize().x;
    h = y + s.GetSize().y;

    if( x <= mouse.x && mouse.x <= w ) {
        if( y < mouse.y && mouse.y <= h ) {
            return true;
        }
    }


    return false;
}
Beispiel #12
0
bool PPCollision(Sprite Sprite1,Sprite Sprite2,float AlphaLimit = 50.f)
{
    float xmin1 = Sprite1.GetPosition().x - Sprite1.GetCenter().x;
    float ymin1 = Sprite1.GetPosition().y - Sprite1.GetCenter().y;
    float xmin2 = Sprite2.GetPosition().x - Sprite2.GetCenter().x;
    float ymin2 = Sprite2.GetPosition().y - Sprite2.GetCenter().y;

    float xmax1 = xmin1 + Sprite1.GetSize().x;
    float ymax1 = ymin1 + Sprite1.GetSize().y;
    float xmax2 = xmin2 + Sprite2.GetSize().x;
    float ymax2 = ymin2 + Sprite2.GetSize().y;

    float xmin = max(xmin1, xmin2);
    float ymin = max(ymin1, ymin2);
    float xmax = min(xmax1, xmax2);
    float ymax = min(ymax1, ymax2);

    if(xmax <= xmin || ymax <= ymin) {
        return false;
    }

    for(int y = int(ymin); y < ymax; y += 5)
    {
        for(int x = int(xmin); x < xmax; x += 5)
        {
            float x1 = x - xmin1, y1 = y - ymin1;
            float x2 = x - xmin2, y2 = y - ymin2;

            if(x1 > 0 && y1 > 0 && x2 > 0 && y2 > 0
                    && x1 < Sprite1.GetSize().x && y1 < Sprite1.GetSize().y
                    && x2 < Sprite2.GetSize().x && y2 < Sprite2.GetSize().y)
            {
                Color color1 = Sprite1.GetPixel(int(x1),int(y1));
                Color color2 = Sprite2.GetPixel(int(x2),int(y2));

                if (color1.a >= AlphaLimit && color2.a >= AlphaLimit)
                {
                    return true;
                }
            }
        }
    }

    return false;
}
bool Colision::colisionSimple(Sprite s1, Sprite s2) {
	
	///Obtengo el tamaño y la posicion de los sprites a comparar
	Vector2f tam_s1 = s1.GetSize();
	Vector2f tam_s2 = s2.GetSize();
	Vector2f pos_s1 = s1.GetPosition();
	Vector2f pos_s2 = s2.GetPosition();
	
	///Comparo si la esquina superior izquierda se S1 estra dentro del area ocupada por s2
	if( ((pos_s1.x >= pos_s2.x) and (pos_s1.x <= pos_s2.x + tam_s2.x))
		and ((pos_s1.y >= pos_s2.y) and (pos_s1.y <= pos_s2.y + tam_s2.y))
		) {
			return true;
		}
	
	///Comparo si la esquina superior dercha de S1 esta dentro del area ocupada por S2
	if( ((pos_s1.x + tam_s1.x >= pos_s2.x) and (pos_s1.x + tam_s1.x <= pos_s2.x + tam_s2.x))
		and ((pos_s1.y >= pos_s2.y) and (pos_s1.y <= pos_s2.y + tam_s2.y))
		) {
			return true;
		}
	
	///Comparo si la esquina inferior derecha de S1 esta dentro del area ocupada por S2
	if( ((pos_s1.x + tam_s1.x >= pos_s2.x) and (pos_s1.x + tam_s1.x <= pos_s2.x + tam_s2.x))
		and ((pos_s1.y + tam_s2.y>= pos_s2.y) and (pos_s1.y + tam_s2.y <= pos_s2.y + tam_s2.y))
		) {
			return true;
		}
	
	///Comparo si la esquina inferior izquierda de S1 esta dentro del area ocupada por S2
	if( ((pos_s1.x >= pos_s2.x) and (pos_s1.x <= pos_s2.x + tam_s2.x))
		and ((pos_s1.y + tam_s2.y>= pos_s2.y) and (pos_s1.y + tam_s2.y <= pos_s2.y + tam_s2.y))
		) {
			return true;
		}
	///s2 con s1
	///Comparo si la esquina superior izquierda se S1 estra dentro del area ocupada por s2
	if( ((pos_s2.x >= pos_s1.x) and (pos_s2.x <= pos_s1.x + tam_s1.x))
		and ((pos_s2.y >= pos_s1.y) and (pos_s2.y <= pos_s1.y + tam_s1.y))
		) {
			return true;
		}
	
	///Comparo si la esquina superior dercha de S1 esta dentro del area ocupada por S2
	if( ((pos_s2.x + tam_s2.x >= pos_s1.x) and (pos_s2.x + tam_s2.x <= pos_s1.x + tam_s1.x))
		and ((pos_s2.y >= pos_s1.y) and (pos_s2.y <= pos_s1.y + tam_s1.y))
		) {
			return true;
		}
	
	///Comparo si la esquina inferior derecha de S1 esta dentro del area ocupada por S2
	if( ((pos_s2.x + tam_s2.x >= pos_s1.x) and (pos_s2.x + tam_s2.x <= pos_s1.x + tam_s1.x))
		and ((pos_s2.y + tam_s1.y>= pos_s1.y) and (pos_s2.y + tam_s1.y <= pos_s1.y + tam_s1.y))
		) {
			return true;
		}
	
	///Comparo si la esquina inferior izquierda de S1 esta dentro del area ocupada por S2
	if( ((pos_s2.x >= pos_s1.x) and (pos_s2.x <= pos_s1.x + tam_s1.x))
		and ((pos_s2.y + tam_s1.y>= pos_s1.y) and (pos_s2.y + tam_s1.y <= pos_s1.y + tam_s1.y))
		) {
			return true;
		}
	
	return false;
}
Beispiel #14
0
void SetCenterInCenter(Sprite & s)
{
    s.SetCenter(s.GetSize().x/2.f, s.GetSize().y/2.f);
}
Beispiel #15
0
 Obstacle(string fileName, Vector2f pos)
 {
     oSprite = LoadSprite(oImage, fileName);
     oSprite.SetCenter(oSprite.GetSize().x/2.f, oSprite.GetSize().y/2.f);
     Position = pos;
 }
Beispiel #16
0
 Vector2f GetSize()
 {
     return oSprite.GetSize();
 }
Beispiel #17
0
Vector2f LowerRight(Sprite & sprite)
{
    return sprite.GetPosition() + sprite.GetSize() - sprite.GetCenter();
}