Beispiel #1
0
	//constructor
	Bullit :: Bullit(float xx, float yy,int dir,int ww, int hh){
		setHealth(1);
		setDirectionGoing(dir);
		setSpeed(30);
		setNumOfVertices(3);
		setDistance(0);
		width = 50;
		height = 50;
		setXPos((xx+ww/2-width/2)-(xx+ww/2));
		setYPos((yy+hh+height+10)-(yy+hh/2));
		float dist=sqrt(pow(getXPos(),2)+pow(getYPos(),2));
		setXPos(xx+ww/2-width/2+dist*cos(getDirectionGoing()*PI/180));
		setYPos(yy+hh/2-height/2+dist*sin(getDirectionGoing()*PI/180));
		x=xx;
		y=yy;
		w=ww;
		h=hh;
		setNumOfVertices(3);

		//define the bullit
		vertices[0] = getXPos();	//left x
		vertices[1] = getYPos();	//left y
		
		vertices[2] = getXPos()+width;		//right x
		vertices[3] = getYPos();		//right y
		
		vertices[4] = getXPos()+width/2;	//top x
		vertices[5] = getYPos()+height;		//top y
	}
void Entity::playSoundAfterTime(float time , const int idSound)
{
	if (time == soundBase->startSounds[idSound]) {
		Vector2f posPerson = { getXPos(), getYPos() };
		::playSound(idSound , *soundBase , soundEntity , posPerson);
	}
}
Beispiel #3
0
// -----------------------------------------------------------------
// Name : displayAt
// -----------------------------------------------------------------
void guiFrame::displayAt(int iXOffset, int iYOffset, F_RGBA cpntColor, F_RGBA docColor)
{
    if (!m_bVisible)
        return;

    guiFrameEffect * pEffect = (guiFrameEffect*) m_pEffects->getFirst(0);
    while (pEffect != NULL)
    {
        if (pEffect->isActive())
            pEffect->onBeginDisplay(iXOffset, iYOffset, &cpntColor, &docColor);
        pEffect = (guiFrameEffect*) m_pEffects->getNext(0);
    }

    guiContainer::displayAt(iXOffset, iYOffset, cpntColor, docColor);
    if (m_pStickGeo)
    {
        m_iStickX = iXOffset + getXPos() + getWidth() - 16;
        m_iStickY = iYOffset + getYPos();
        if (m_bSticked)
            m_pStickedGeo->display(CoordsScreen(m_iStickX, m_iStickY, GUIPLANE), cpntColor);
        else
            m_pStickGeo->display(CoordsScreen(m_iStickX, m_iStickY, GUIPLANE), cpntColor);
    }

    pEffect = (guiFrameEffect*) m_pEffects->getFirst(0);
    while (pEffect != NULL)
    {
        if (pEffect->isActive())
            pEffect->onEndDisplay();
        pEffect = (guiFrameEffect*) m_pEffects->getNext(0);
    }
}
bool EnemyProjectile::collidesWith(LevelObject* levelObject)
{
	if(levelObject->getLevelObjectType() == LO_RECTANGLE)
	{
		sf::Vector2f otherSize = ((LevelObjectRectangle*)levelObject)->getSize();
		float otherXPos = ((LevelObjectRectangle*)levelObject)->getXPos();
		float otherYPos = ((LevelObjectRectangle*)levelObject)->getYPos();

		return(!(otherXPos > getXPos() + m_animations->getCurrentSprite()->getGlobalBounds().width
			|| otherXPos + otherSize.x < getXPos()
			|| otherYPos > getYPos() + m_animations->getCurrentSprite()->getGlobalBounds().height
			|| otherYPos + otherSize.y < getYPos()));
	}

	return false;
}
Beispiel #5
0
void printErrorString(int errorCode) {
    int oldx = getXPos(), oldy = getYPos();
    jumpTo(0, 15);
    for (int i = 0; i < 79; i++) printf(" "); // clear line
    jumpTo(0, 15);
    switch (errorCode) {
        case 1:
            // note: N/A
            printf("You can't move to the tile you're already on!");
            break;
        case 2:
            printf("You can only move to tiles directly in line with your current tile.");
            break;
        case 3:
            printf("This tile is already occupied.");
            break;
        case 4:
            printf("Only the king can move to this tile.");
            break;
        case 5:
            printf("The path to this tile is blocked by a different piece.");
            break;
        case 6:
            printf("You must select one of your own pieces.");
            break;
        case 7:
            printf("Abort game? (Y/N)");
            break;
        case 8:
            printf("You are not allowed to select this tile.\n");
    }
    jumpTo(oldx, oldy);
}
Bateau creerBateau(Position p, char sens, int l)
{
    /*Creer un bateau de position de tete p, avec les nouvelles position qui suivent le sens de s.*/
    Bateau *Bat=malloc(sizeof(int)+ sizeof(Position)+2*sizeof(*TListe)); //Car la liste contiendra des positions et elle est constituée de 2 pointeurs suivant et précédent du type liste doublement chainée
    Bat->longueur=l;
    Position *p1=creerPosition(getXPos(p),getYPos(p));
    AjoutDebut(Bat->positions, p1);
    int i;
    for (i=1;i<l;i++){
        if (sens=='v'){
            setYPos(p1,getYPos(p1)+1);
        }
        else if (sens=='h'){
            setXPos(p1,getXPos(p1)+1);
        }
        AjoutDebut (Bat->positions, p1);
    }
    return Bat;
}
Beispiel #7
0
void Player::Move()
{
	int oldX = getXPos();
	int oldY = getYPos();

	CCharacter::MoveSpecific( movementSpeed );

	dx = getXPos()-oldX;
	dy = getYPos()-oldY;

	// if the character has moved, enable walking sound
	if( oldX != getXPos() || oldY != getYPos() )
	{
		SoundEngine::useWalkingSound( true );
	}
	else
	{
		SoundEngine::useWalkingSound( false );
	}
}
Beispiel #8
0
std::string Player::getSaveText() const
{
	std::ostringstream oss;
	std::string objectName = "thePlayer";
	oss << "-- General status attributes" << std::endl;
	oss << "local " << objectName << " = DawnInterface.getPlayer();" << std::endl;
	oss << objectName << ":setStrength( " << getStrength() << " );" << std::endl;
	oss << objectName << ":setDexterity( " << getDexterity() << " );" << std::endl;
	oss << objectName << ":setVitality( " << getVitality() << " );" << std::endl;
	oss << objectName << ":setIntellect( " << getIntellect() << " );" << std::endl;
	oss << objectName << ":setWisdom( " << getWisdom() << " );" << std::endl;
	oss << objectName << ":setMaxHealth( " << getMaxHealth() << " );" << std::endl;
	oss << objectName << ":setMaxMana( " << getMaxMana() << " );" << std::endl;
	oss << objectName << ":setMaxFatigue( " << getMaxFatigue() << " );" << std::endl;
	oss << objectName << ":setMinDamage( " << getMinDamage() << " );" << std::endl;
	oss << objectName << ":setMaxDamage( " << getMaxDamage() << " );" << std::endl;

	// don't set activity textures here. That is determined by class of Player / NPC

	oss << objectName << ":setDamageModifierPoints( " << getDamageModifierPoints() << " );" << std::endl;
	oss << objectName << ":setHitModifierPoints( " << getHitModifierPoints() << " );" << std::endl;
	oss << objectName << ":setEvadeModifierPoints( " << getEvadeModifierPoints() << " );" << std::endl;
	oss << objectName << ":setParryModifierPoints( " << getParryModifierPoints() << " );" << std::endl;
	oss << objectName << ":setBlockModifierPoints( " << getBlockModifierPoints() << " );" << std::endl;
	oss << objectName << ":setMeleeCriticalModifierPoints( " << getMeleeCriticalModifierPoints() << " );" << std::endl;
	oss << objectName << ":setResistAllModifierPoints( " << getResistAllModifierPoints() << " );" << std::endl;
	oss << objectName << ":setSpellEffectAllModifierPoints( " << getSpellEffectAllModifierPoints() << " );" << std::endl;
	for( size_t curElement=0; curElement<static_cast<size_t>(ElementType::Count); ++curElement )
	{
		ElementType::ElementType curElementType = static_cast<ElementType::ElementType>(curElement);
		oss << objectName << ":setResistElementModifierPoints( "
		            << curElementType << ", "
		            << getResistElementModifierPoints( curElementType ) << " );" << std::endl;
		oss << objectName << ":setSpellEffectElementModifierPoints( "
		            << curElementType << ", "
		            << getSpellEffectElementModifierPoints( curElementType ) << " );" << std::endl;
	}
	oss << objectName << ":setSpellCriticalModifierPoints( " << getSpellCriticalModifierPoints() << " );" << std::endl;
	oss << objectName << ":setName( \"" << getName() << "\" );" << std::endl;
	// string stream doesn't seem to have a proper overload for uint8_t and makes it the 0-character, so cast to size_t
	oss << objectName << ":setLevel( " << static_cast<size_t>(getLevel()) << " );" << std::endl;
	oss << objectName << ":setExperience( " << getExperience() << " );" << std::endl;
	oss << objectName << ":setClass( CharacterClass." << getClassName() << " );" << std::endl;

	oss << "-- coins" << std::endl;
	oss << objectName << ":setCoins( " << getCoins() << " );" << std::endl;

	oss << "-- position" << std::endl;
	oss << objectName << ":setPosition( " << getXPos() << ", " << getYPos() << " );" << std::endl;

	// no current attributes are set here because after reloading the player is completely refreshed again

	return oss.str();
}
bool LevelObjectRectangle::collidesWith(LevelObject* anotherLevelObject)
{
	if(anotherLevelObject->getLevelObjectType() == LO_RECTANGLE)
	{
		sf::Vector2f otherSize = ((LevelObjectRectangle*)anotherLevelObject)->getSize();
		float otherXPos = ((LevelObjectRectangle*)anotherLevelObject)->getXPos();
		float otherYPos = ((LevelObjectRectangle*)anotherLevelObject)->getYPos();

		if(
			otherXPos > getXPos() + getSize().x
			|| otherXPos + otherSize.x < getXPos()
			|| otherYPos > getYPos() + getSize().y
			|| otherYPos + otherSize.y < getYPos()
			)
		{return false;}
		else {return true;}
	}

	return false;
}
void
GUIDanielPerspectiveChanger::centerTo(const Position& pos, SUMOReal radius,
                                      bool applyZoom) {
    if (applyZoom) {
        myViewPort = Boundary();
        myViewPort.add(pos);
        myViewPort.grow(radius);
    } else {
        myViewPort.moveby(pos.x() - getXPos(), pos.y() - getYPos());
    }
}
Beispiel #11
0
	void Bullit:: move(){
		setXPos(getXPos()+getSpeed()*cos(getDirectionGoing()*PI/180));
		setYPos(getYPos()+getSpeed()*sin(getDirectionGoing()*PI/180));

		//glTranslatef(getX()+getW()/2,getY()+getH()/2,0.0);
		//glRotatef(getDirectionGoing()-90,0.0,0.0,1.0);
		//glTranslatef(-getX()-getW()/2,-getY()-getH()/2,0.0);

		//setYPos(getYPos()+getSpeed());

		setDistance(getDistance()+getSpeed());
		if(getDistance()>=1000){
			setAlive(false);
			setXPos(3000);
			setYPos(3000);
		}
		setVertices();

		glTranslatef(getXPos()+width/2,getYPos()+height/2,0.0);
		glRotatef(getDirectionGoing()-90,0.0,0.0,1.0);
		glTranslatef(-getXPos()-width/2,-getYPos()-height/2,0.0);
	}
Beispiel #12
0
//start move from A (curr pos) to B (to end) then stop or reverse etc.
//Pass SM_NONE to x or y to start from the current position,
//even before it has finished moving
void Sprite::startMoveTo(int xEnd, int yEnd,
                         Uint32 rate, Uint32 delay,
                         float xVel, float yVel,
                         eSprite type /*Sprite::SPR_NONE*/)	//repeat, reverse etc
{
    //direction
    //set by end x or y, or overridden by SM_ direction flags
    if ( (SPR_LEFT & type) || (xEnd < getXPos()) )
        _xDir = -1;
    else _xDir = 1;	//pos=right, neg=left
    if ( (SPR_UP & type) || (yEnd < getYPos()) )
        _yDir = -1;
    else _yDir = 1;	//pos=down, neg=up

    //end position
    //if SM_ direction flags used (ie. no end pos), then determine off
    //screen end positions from sprite size, ie. sprite must be completely
    //off screen then stop (or reverse if that flag is set
    _xEnd = xEnd;
    _yEnd = yEnd;

    if (SPR_LEFT & type)
        _xEnd = -(tileW()+1); //calc end x pos (off screen)

    if (SPR_RIGHT & type)
        _xEnd = Screen::width() + 1; //calc end x pos (off screen)

    if (SPR_UP & type)
        _yEnd = -(tileH()+1); //calc end x pos (off screen)

    if (SPR_DOWN & type)
        _yEnd = Screen::height()+1; //calc end x pos (off screen)

    //velocity
    _xVel = xVel;
    _yVel = yVel;

    //attributes
//##TODO## effects flags stuff here

//	calcWaypoints(_x, _y, xEnd, yEnd);


    //unpause movement if movement is set up correctly
    pauseMove( !canMove() );		//set false, if moving set
    setMoveLoop(true);				//repeat any timer/movement

    //finally start the timer if requested
    if (rate && canMove()) setMoveRate(rate, delay);

}
Beispiel #13
0
	void Bullit:: setVertices(){
		//redefine the ship with rap around
		if(getXPos()<0-width)
			setXPos(2000);

		else if(getXPos()>2000 && isAlive())
			setXPos(0-width);

		if(getYPos()<0-height)
			setYPos(2000);

		else if(getYPos()>2000 && isAlive())
			setYPos(0-height);

		vertices[0] = getXPos();	//left x
		vertices[1] = getYPos();	//left y
		
		vertices[2] = getXPos()+width;		//right x
		vertices[3] = getYPos();		//right y
		
		vertices[4] = getXPos()+width/2;	//top x
		vertices[5] = getYPos()+height;		//top y
	}
Beispiel #14
0
void HTMLClueH::calcSize( HTMLClue *parent )
{
    // make sure children are properly sized
    setMaxWidth( max_width );

    HTMLClue::calcSize( parent );
    
    HTMLObject *obj;
    int lmargin = 0;
    
    if ( parent )
	lmargin = parent->getLeftMargin( getYPos() );

    width = lmargin + indent;
    descent = 0;
    ascent = 0;

    int a = 0;
    int d = 0;
    for ( obj = head; obj != 0; obj = obj->next() )
    {
    	obj->fitLine( (obj == head), true, -1);
	obj->setXPos( width );
	width += obj->getWidth();
	if ( obj->getAscent() > a )
	    a = obj->getAscent();
	if ( obj->getDescent() > d )
	    d = obj->getDescent();
    }

    ascent = a+d;

    switch ( valign )
    {
	case Top:
	    for ( obj = head; obj != 0; obj = obj->next() )
		obj->setYPos( obj->getAscent() );
	    break;

	case VCenter:
	    for ( obj = head; obj != 0; obj = obj->next() )
		obj->setYPos( ascent/2 );
	    break;

	default:
	    for ( obj = head; obj != 0; obj = obj->next() )
		obj->setYPos( ascent - d );
    }
}
Beispiel #15
0
void Ship::fireBullet (GameClient *client)
{
	SharedObjectData soData;

	soData.angle = body->GetAngle();

	float xNose, yNose, angle;

	angle = soData.angle/180.0*3.1415296535;

	xNose = (1.5 * sin(angle));
	yNose = -(1.5 * cos(angle));

	soData.xPos = getXPos()+xNose;
	soData.yPos = getYPos()+yNose;
	soData.velocity = 40.0;
	soData.bullet = true;

	client->spawnObject(GameServer::SPAWN_OBJECT, "bullet01", &soData);
}
Force Robot::calculateForce(int32_t xFieldSize, int32_t yFieldSize, boost::shared_ptr<Robot> secondRobot)
{
    // liczy siłę działającą na robota

    const double A = 1500,      //odpychanie ścian
                 B = 50,        //wyjazd
                 C = 20;       //drugi robot
    const double destPosWidth = 0.75;        //0-1, określa położenie potencjału docelowego w proporcji długości ściany, przez którą robot ma przejechać
    const double destPosDepth = 0.1;         //dodatnia wartość [0;1], określa odsunięcie potencjału w głąb docelowej komórki
    const double randomForce  = 0.01;        //losowa siła mnożona przez losowe [-0.5;0.5]

    //współrzędne robotów znormalizowane w fukcji wielkości pola, aby zawsze stosunek sił był ten sam
    const double myNormX = getXPos()/xFieldSize, myNormY = getYPos()/yFieldSize;
    const double normXFieldSize = 1, normYFieldSize = 1; //double, żeby nie robić wszędzie rzutowania :)

    Force result = {0.0, 0.0};

    /* odpychanie od ścian */
    //cos(alpha)*A*R^2
    result.X += ((normXFieldSize/2)-myNormX)/(distance(myNormX, myNormY, normXFieldSize/2, normYFieldSize/2))
               * A*pow(distance(myNormX, myNormY, normXFieldSize/2, normYFieldSize/2),2);
    //sin(alpha)*A*R^2
    result.Y += ((normYFieldSize/2)-myNormY)/(distance(myNormX, myNormY, normXFieldSize/2, normYFieldSize/2))
               * A*pow(distance(myNormX, myNormY, normXFieldSize/2, normYFieldSize/2),2);

    /* wyjazd z pola */
    if(_isAllowedToLeaveField)
    {
        double destX = 0, destY = 0;

        if(_nextFieldXPos==0 && _nextFieldYPos==-1) // w górę
        {
            destX = destPosWidth*normXFieldSize;
            destY = -destPosDepth;
        }

        if(_nextFieldXPos==1 && _nextFieldYPos==0) // w prawo
        {
            destX = normXFieldSize + destPosDepth;
            destY = destPosWidth*normYFieldSize;
        }

        if(_nextFieldXPos==0 && _nextFieldYPos==1) // w dół
        {
            destX = normXFieldSize - destPosWidth*normXFieldSize;
            destY = normYFieldSize + destPosDepth;
        }

        if(_nextFieldXPos==-1 && _nextFieldYPos==0) // w lewo
        {
            destX = -destPosDepth;
            destY = normYFieldSize - destPosWidth*normYFieldSize;
        }

        //cos(alpha)*B/R^2
        result.X += ((destX-myNormX)/distance(myNormX, myNormY, destX, destY))
                   * B/pow(distance(myNormX, myNormY, destX, destY),2);
        //sin(alpha)*B/R^2
        result.Y += (destY-myNormY)/distance(myNormX, myNormY, destX, destY)
                   * B/pow(distance(myNormX, myNormY, destX, destY),2);
    }

    /* drugi robot */
    if(secondRobot)
    {
        const double secRobNormX = secondRobot->getXPos()/xFieldSize, secRobNormY = secondRobot->getYPos()/yFieldSize;

        //cos(alpha)*C/R^2
        result.X += (myNormX-secRobNormX)/(distance(myNormX, myNormY, secRobNormX, secRobNormY))
                   * C/pow(distance(myNormX, myNormY, secRobNormX, secRobNormY),2);
        //sin(alpha)*C/R^2
        result.Y += (myNormY-secRobNormY)/(distance(myNormX, myNormY, secRobNormX, secRobNormY))
                   * C/pow(distance(myNormX, myNormY, secRobNormX, secRobNormY),2);
    }

    /* losowa składowa */
    result.X += ((rand()%1000)/1000 - 0.5)*randomForce*result.X;
    result.Y += ((rand()%1000)/1000 - 0.5)*randomForce*result.Y;

    return result;
}
void Robot::calculatePosition(int32_t xFieldSize, int32_t yFieldSize, boost::shared_ptr<Robot> secondRobot, int timeDelay)
{
    // tu odpalamy calculateForce i na podstawie wyliczonych wartości
    // siły oraz bieżących prędkości wyliczamy nowe położenie
    const double timeStep = static_cast<double>(timeDelay)/1000;   //[s]

    const double robotMass = 1;     //[kg]
    const double maxVelocityX = 0.2*xFieldSize;
    const double maxVelocityY = 0.2*yFieldSize;
    const double frictionFactor = 0;
    const double brakingFactor = 0.3;

    bool         brake = false;

    Force force = calculateForce(xFieldSize, yFieldSize, secondRobot);

    /* Siła tłumiąca */
    if(force.X > abs(frictionFactor*robotMass*9.81))
        force.X += frictionFactor*(-sgn(_xVel))*robotMass*9.81;
    else
        brake = true;
    if(force.Y > abs(frictionFactor*robotMass*9.81))
        force.Y += frictionFactor*(-sgn(_yVel))*robotMass*9.81;
    else
        brake = true;

    /* Ograniczenie przemieszczenia zgodnie z maxVelocity */
    if((timeStep*_xVel + (force.X/robotMass)*pow(timeStep,2)/2) > maxVelocityX*timeStep)
    {
        _xPos = getXPos() + timeStep*maxVelocityX;
    }
    else if((timeStep*_xVel + (force.X/robotMass)*pow(timeStep,2)/2) < -maxVelocityX*timeStep)
    {
        _xPos = getXPos() - timeStep*maxVelocityX;
    }
    else
    {
        _xPos = getXPos() + timeStep*_xVel + (force.X/robotMass)*pow(timeStep,2)/2;
    }

    if(timeStep*_yVel + (force.Y/robotMass)*pow(timeStep,2)/2 > maxVelocityY*timeStep)
    {
        _yPos = getYPos() + timeStep*maxVelocityY;
    }
    else if(timeStep*_yVel + (force.Y/robotMass)*pow(timeStep,2)/2 < -maxVelocityY*timeStep)
    {
        _yPos = getYPos() - timeStep*maxVelocityY;
    }
    else
    {
        _yPos = getYPos() + timeStep*_yVel + (force.Y/robotMass)*pow(timeStep,2)/2;
    }

    _xVel += (force.X/robotMass)*timeStep;
    if(brake) _xVel *= brakingFactor;
    _yVel += (force.Y/robotMass)*timeStep;
    if(brake) _yVel *= brakingFactor;

    if(_xVel > maxVelocityX) _xVel = maxVelocityX;
    else if(_xVel < -maxVelocityX) _xVel = -maxVelocityX;
    if(_yVel > maxVelocityY) _yVel = maxVelocityY;
    else if(_yVel < -maxVelocityY) _yVel = -maxVelocityY;
}
Beispiel #18
0
// -----------------------------------------------------------------
// Name : displayAt
// -----------------------------------------------------------------
void guiButton::displayAt(int iXOffset, int iYOffset, Color cpntColor, Color docColor)
{
    if (m_bVisible)
    {
        m_pGeometry = m_pGeometryNormal;
        bool bNeedPop = false;
        bool bAddMode = false;
        if (m_bClickState)
        {
            switch (m_ClickOption)
            {
            case BCO_None:
                break;
            case BCO_ReplaceTex:
                m_pGeometry = m_pGeometryClicked;
                break;
            case BCO_AddTex:
                guiImage::displayAt(iXOffset, iYOffset, cpntColor, docColor);
                m_pGeometry = m_pGeometryClicked;
                break;
            case BCO_Decal:
                iXOffset += 3;
                iYOffset += 3;
                break;
            case BCO_Scale:
            {
                float coef = 1.2f;
                Coords3D fCenter = _display->getGUI3D(CoordsScreen(
                                       iXOffset + getXPos() + getWidth() / 2,
                                       iYOffset + getYPos() + getHeight() / 2));
                glPushMatrix();
                glTranslatef(fCenter.x * (1 - coef), fCenter.y * (1 - coef), 0.0f);
                glScalef(coef, coef, 1.0f);
                bNeedPop = true;
                break;
            }
            case BCO_Enlight:
            {
                cpntColor = (cpntColor + 1) / 2;
                bAddMode = true;
                break;
            }
            }
        }

        if (!m_bEnabled) {
        	Color c(1,1,1,0.3f);
            cpntColor.multiply(&c);
        } else if (m_bMouseOver && !m_bClickState) {
            switch (m_OverOption)
            {
            case BCO_None:
                break;
            case BCO_ReplaceTex:
                m_pGeometry = m_pGeometryOver;
                break;
            case BCO_AddTex:
                guiImage::displayAt(iXOffset, iYOffset, cpntColor, docColor);
                m_pGeometry = m_pGeometryOver;
                break;
            case BCO_Decal:
                iXOffset += 3;
                iYOffset += 3;
                break;
            case BCO_Scale:
            {
                float coef = 1.2f;
                Coords3D fCenter = _display->getGUI3D(CoordsScreen(
                                       iXOffset + getXPos() + getWidth() / 2,
                                       iYOffset + getYPos() + getHeight() / 2));
                glPushMatrix();
                glTranslatef(fCenter.x * (1 - coef), fCenter.y * (1 - coef), 0.0f);
                glScalef(coef, coef, 1.0f);
                bNeedPop = true;
                break;
            }
            case BCO_Enlight:
            {
                cpntColor = (cpntColor + 1) / 2;
                bAddMode = true;
                break;
            }
            }
        }
        bool bPrevMode = false;
        if (bAddMode) {
            bPrevMode = _display->setAdditiveMode(true);
        }
        guiImage::displayAt(iXOffset, iYOffset, cpntColor, docColor);
        m_pLabel->displayAt(iXOffset, iYOffset, cpntColor, docColor);
        if (m_pGeometryAttachedImage != NULL)
        {
            CoordsScreen coords = CoordsScreen(m_iXPxl + iXOffset, m_iYPxl + iYOffset, GUIPLANE);
            m_pGeometryAttachedImage->display(coords, cpntColor * m_DiffuseColor);
        }
        if (bAddMode) {
            _display->setAdditiveMode(bPrevMode);
        }
        if (bNeedPop) {
            glPopMatrix();
        }
    }
}
Beispiel #19
0
// -----------------------------------------------------------------
// Name : displayAt
// -----------------------------------------------------------------
void Button::displayAt(int iXOffset, int iYOffset, Color cpntColor, Color docColor)
{
    if (m_bVisible) {
    	IGeometry * pGeoToDisplay = m_pGeometryBase;
        bool bNeedPop = false;
        bool bAddMode = false;
        if (m_bClickState)
        {
            switch (m_ClickedOption)
            {
            case None:
                break;
            case ReplaceTex:
            	pGeoToDisplay = m_pGeometryClicked;
                break;
            case AddTex:
            	pGeoToDisplay->display(iXOffset, iYOffset, cpntColor * docColor);
            	pGeoToDisplay = m_pGeometryClicked;
                break;
            case Decal:
                iXOffset += 3;
                iYOffset += 3;
                break;
            case Scale:
            {
                float coef = 1.2f;
                Vertex fCenter = Jogy::interface->screenTransform(
                        iXOffset + getXPos() + getWidth() / 2,
                        iYOffset + getYPos() + getHeight() / 2);
                Jogy::interface->pushMatrix();
                Jogy::interface->translate(fCenter.x * (1 - coef), fCenter.y * (1 - coef), 0.0f);
                Jogy::interface->scale(coef, coef, 1.0f);
                bNeedPop = true;
                break;
            }
            case Enlight:
            {
                cpntColor = (cpntColor + 1) / 2;
                bAddMode = true;
                break;
            }
            }
        }

        if (!m_bEnabled) {
        	Color c(1,1,1,0.3f);
            cpntColor.multiply(&c);
        } else if (m_bMouseOver && !m_bClickState) {
            switch (m_HoverOption)
            {
            case None:
                break;
            case ReplaceTex:
            	pGeoToDisplay = m_pGeometryHover;
                break;
            case AddTex:
            	pGeoToDisplay->display(iXOffset, iYOffset, cpntColor * docColor);
            	pGeoToDisplay = m_pGeometryHover;
                break;
            case Decal:
                iXOffset += 3;
                iYOffset += 3;
                break;
            case Scale:
            {
                float coef = 1.2f;
                Vertex fCenter = Jogy::interface->screenTransform(
                        iXOffset + getXPos() + getWidth() / 2,
                        iYOffset + getYPos() + getHeight() / 2);
                Jogy::interface->pushMatrix();
                Jogy::interface->translate(fCenter.x * (1 - coef), fCenter.y * (1 - coef), 0.0f);
                Jogy::interface->scale(coef, coef, 1.0f);
                bNeedPop = true;
                break;
            }
            case Enlight:
            {
                cpntColor = (cpntColor + 1) / 2;
                bAddMode = true;
                break;
            }
            }
        }
        bool bPrevMode = false;
        if (bAddMode) {
            bPrevMode = Jogy::interface->setAdditiveMode(true);
        }
        pGeoToDisplay->display(iXOffset, iYOffset, cpntColor * docColor);
        m_pLabel->displayAt(iXOffset, iYOffset, cpntColor, docColor);
        if (m_pGeometryAttachedImage != NULL) {
            m_pGeometryAttachedImage->display(m_iXPxl + iXOffset, m_iYPxl + iYOffset, cpntColor * m_DiffuseColor);
        }
        if (bAddMode) {
        	Jogy::interface->setAdditiveMode(bPrevMode);
        }
        if (bNeedPop) {
        	Jogy::interface->popMatrix();
        }
    }
}
Beispiel #20
0
//set up move to without specifying velocities (just time, ie speed to get there)
//so we need to call calcXYRate to return the values required
void Sprite::startMoveTo(int xEnd, int yEnd, Uint32 time, Uint32 delay)
{
    float xVel, yVel;
    Uint32 rate = calcXYRate(time, xEnd, yEnd, (int)getXPos(), (int)getYPos(), xVel, yVel);
    startMoveTo(xEnd, yEnd, rate, delay, xVel, yVel, SPR_NONE);
}
Beispiel #21
0
// MRJ - 26/10/97:  I've given this a rewrite so that its layout is done
// correctly, i.e. break ONLY on separators and newlines instead of breaking
// after any object.  This is much nicer and smaller code now also.  Sorry
// if I broke something.
// 
void HTMLClueFlow::calcSize( HTMLClue *parent )
{
//    HTMLClue::calcSize( parent );

    HTMLObject *obj = head;
    HTMLObject *line = head;
    HTMLVSpace::Clear clear = HTMLVSpace::CNone;;
    int lmargin, rmargin;

    ascent = 0;
    descent = 0;
    width = 0;
    lmargin = parent->getLeftMargin( getYPos() );
    if ( indent > lmargin )
	lmargin = indent;
    rmargin = parent->getRightMargin( getYPos() );
    int w = lmargin;
    int a = 0;
    int d = 0;

    bool newLine = false;

    while ( obj != 0 )
    {
	// If we get a newline object, set newLine=true so that the current
	// line will be aligned, and the next line prepared.
	if ( obj->isNewline() )
	{
// WABA: Only update the height if this line has no height already
	    if ( !a )
		a = obj->getAscent();
	    if ( !a && (obj->getDescent() > d) )
		d = obj->getDescent();
	    newLine = true;
	    HTMLVSpace *vs = (HTMLVSpace *)obj;
	    clear = vs->clear();
	    obj = obj->next();
	}
	// add a separator
	else if ( obj->isSeparator() )
	{
	    obj->setXPos( w );

	    // skip a space at the start of a line
	    if ( w != lmargin )
	    {
		w += obj->getWidth();
	        if ( obj->getAscent() > a )
	            a = obj->getAscent();

	    	if ( obj->getDescent() > d )
		    d = obj->getDescent();
	    }
	    
	    obj = obj->next();
	}
	// a left or right aligned object is not added in this line.  It
	// is added to our parent's list of aligned objects and will be
	// taken into account in subsequent get*Margin() calls.
	else if ( obj->isAligned() )
	{
	    HTMLClueAligned *c = (HTMLClueAligned *)obj;

	    if ( !parent->appended( c ) )
	    {
	        obj->calcSize();

	        if ( c->getHAlign() == Left )
	        {
		    c->setPos( lmargin,
		        ascent + c->getAscent() );

  		    parent->appendLeftAligned( c );
	        }
	        else
	        {
		    c->setPos( rmargin - c->getWidth(),
		        ascent + c->getAscent() );

  		    parent->appendRightAligned( c );
	        }
	    }
	    obj = obj->next();
	}
	// This is a normal object.  We must add all objects upto the next
	// separator/newline/aligned object.
	else
	{
	    // By setting "newLine = true" we move the complete run to
	    // a new line.
	    // We shouldn't set newLine if we are at the start of a line. 
		
	    int runWidth = 0;
	    HTMLObject *run = obj;
	    while ( run && !run->isSeparator() && !run->isNewline() &&
		    !run->isAligned() )
	    {
		HTMLFitType fit;
		run->setMaxWidth( rmargin - lmargin );
		fit = run->fitLine( (w+runWidth == lmargin), // Start of line
				    (obj == line), // first run
				    rmargin-runWidth-w);
		
		if ( fit == HTMLNoFit)
		{
		    newLine = true;
		    break;		
		}
		//run->calcSize(parent);
		// Lars: the above gives wrong lmargins, since run 
		// run->setSize() usually calls 
		// parent->getLeftMargin( getYSize() ) to determine the
		// left margin. But y is relative to the clues parent,
		// not absolute... So this should fix it.
		run->calcSize(this);
		runWidth += run->getWidth();

		// If this run cannot fit in the allowed area, break it
		// on a non-seperator. 
		// Don't break here, if it is the first object.
		if (( run != obj) && (runWidth > rmargin - lmargin ))
		{
		     break;
		}    

	 	if ( run->getAscent() > a )
		    a = run->getAscent();
		if ( run->getDescent() > d )
		    d = run->getDescent();

		run = run->next();
		
		if (fit == HTMLPartialFit)
		{
		    // We encountered an implicit separator
		    break;
		}

		// If this is the first object but it doesn't fit the 
		// allowed area, break directly after it.
		if (runWidth > rmargin - lmargin)
		{
		     break;
		}    
	    }

	    // if these objects do not fit in the current line and we are
	    // not at the start of a line then end the current line in
	    // preparation to add this run in the next pass.
	    if ( w > lmargin && w + runWidth > rmargin )
	    {
		newLine = true;
	    }
	    
	    if (!newLine)
	    {
	    	int new_y, new_lmargin, new_rmargin;

		// Check whether this run still fits the current flow area, 
		// especially with respect to its height.
 		// If not, find a rectangle with height a+b. The size of
 		// the rectangle will be rmargin-lmargin.

		parent->findFreeArea(y, line->getWidth(),
			a+d, indent, &new_y, &new_lmargin, &new_rmargin);

		if (
		    (new_y != y) || 
		    (new_lmargin > lmargin) || 
		    (new_rmargin < rmargin)
		   )
		{
		    // We did not get the location we expected.
		    // We start building our current line again

 		    // We got shifted downwards by "new_y - y"
		    // add this to both "y" and "ascent"
		    new_y -= y;
		    y += new_y;
		    ascent += new_y;

		    lmargin = new_lmargin;
		    if ( indent > lmargin )
			lmargin = indent;
		    rmargin = new_rmargin;
		    obj = line;

		    // Reset this line
		    w = lmargin;
		    d = 0;
		    a = 0;

		    newLine = false;
		    clear = HTMLVSpace::CNone;
		}	
		else
		{
  		    while ( obj != run )
		    {
		        obj->setXPos( w );
		        w += obj->getWidth();
		        obj = obj->next();
		    }
		}
	    }
	}

	// if we need a new line, or all objects have been processed
	// and need to be aligned.
	if ( newLine || !obj )
	{
	    int extra = 0;
	    ascent += a + d;
	    y += a + d;

	    if ( w > width )
		width = w;

	    if ( halign == HCenter )
	    {
		extra = ( rmargin - w ) / 2;
		if ( extra < 0 )
		    extra = 0;
	    }
	    else if ( halign == Right )
	    {
	        extra = rmargin - w;
		if ( extra < 0 )
		    extra = 0;
	    }

	    while ( line != obj )
	    {
		if ( !line->isAligned() )
		{
		    line->setYPos( ascent - d );
		    line->setMaxAscent( a );
		    line->setMaxDescent( d );
		    if ( halign == HCenter || halign == Right )
		    {
			line->setXPos( line->getXPos() + extra );
		    }
		}
		line = line->next();
	    }

	    int oldy = y;
	    
	    if ( clear == HTMLVSpace::All )
	    {
	    	int new_lmargin, new_rmargin;

		parent->findFreeArea(oldy, max_width,
			1, 0, &y, &new_lmargin, &new_rmargin);
	    }
	    else if ( clear == HTMLVSpace::Left)
	    {
		y = parent->getLeftClear( oldy );
	    }
	    else if ( clear == HTMLVSpace::Right)
	    {
		y = parent->getRightClear( oldy );
	    }

	    ascent += y-oldy;

	    lmargin = parent->getLeftMargin( y );
	    if ( indent > lmargin )
		lmargin = indent;
	    rmargin = parent->getRightMargin( y );

	    w = lmargin;
	    d = 0;
	    a = 0;

	    newLine = false;
	    clear = HTMLVSpace::CNone;
	}
    }

    if ( width < max_width )
	    width = max_width;
}
Beispiel #22
0
void HTMLClueV::calcSize( HTMLClue *parent )
{
	int lmargin = parent ? parent->getLeftMargin( getYPos() ) + padding : padding;

	// If we have already called calcSize for the children, then just
	// continue from the last object done in previous call.
	if ( curr )
	{
	    ascent = padding;
	    // get the current ascent not including curr
	    HTMLObject *obj = head;
	    while ( obj != curr )
	    {
		ascent += obj->getHeight();
		obj = obj->next();
	    }
	    // remove any aligned objects previously added by the current
	    // object.
	    removeAlignedByParent( curr );
	}
	else
	{
	    ascent = padding;
        descent = 0;
	    curr = head;
	}

	while ( curr != 0 )
	{
	    // Set an initial ypos so that the alignment stuff knows where
	    // the top of this object is
	    curr->setYPos( ascent );
	    curr->calcSize( this );
	    if ( curr->getWidth() > width - ( padding << 1) )
		    width = curr->getWidth() + ( padding << 1 );
	    ascent += curr->getHeight();
	    curr->setPos( lmargin, ascent - curr->getDescent() );
	    curr = curr->next();
	}

    ascent += padding;

	// remember the last object so that we can start from here next time
	// we are called.
	curr = tail;

	if ((max_width != 0) && (width > max_width))
		width = max_width;

	HTMLObject *obj;

	if ( halign == HCenter )
	{
	    for ( obj = head; obj != 0; obj = obj->next() )
		obj->setXPos( lmargin + (width - obj->getWidth()) / 2 );
	}
	else if ( halign == Right )
	{
	    for ( obj = head; obj != 0; obj = obj->next() )
		obj->setXPos( lmargin + width - obj->getWidth() );
	}

	HTMLClueAligned *clue;
	for ( clue = alignLeftList; clue != 0; clue = clue->nextClue() )
	{
	    if ( clue->getYPos() + clue->parent()->getYPos() -
		    clue->parent()->getAscent() > ascent )
		ascent = clue->getYPos() + clue->parent()->getYPos() -
			    clue->parent()->getAscent();
	}
	for ( clue = alignRightList; clue != 0; clue = clue->nextClue() )
	{
	    if ( clue->getYPos() + clue->parent()->getYPos() -
		    clue->parent()->getAscent() > ascent )
		ascent = clue->getYPos() + clue->parent()->getYPos() -
			    clue->parent()->getAscent();
	}
}
Beispiel #23
0
// -----------------------------------------------------------------
// Name : update
// -----------------------------------------------------------------
void guiFrame::update(double delta)
{
    if (!m_bVisible)
        return;

    // Update effects
    guiFrameEffect * pEffect = (guiFrameEffect*) m_pEffects->getFirst(0);
    while (pEffect != NULL)
    {
        if (pEffect->isActive())
        {
            pEffect->update(delta);
            if (pEffect->isFinished() && pEffect->getOnFinished() == EFFECT_REMOVE_ON_FINISHED)
            {
                pEffect = (guiFrameEffect*) m_pEffects->deleteCurrent(0, true);
                continue;
            }
        }
        pEffect = (guiFrameEffect*) m_pEffects->getNext(0);
    }

    // Retract?
    if (!m_bSticked && m_uRetractBorder != 0 && m_fRetractTimer > 0)
    {
        m_fRetractTimer -= delta;
        if (m_fRetractTimer < RETRACT_DELAY)
        {
            if (m_fRetractTimer < 0)
                m_fRetractTimer = 0;
            switch (m_uRetractBorder)
            {
            case 1: // retract to top
            {
                if (m_iRetractState == 1)
                    moveTo(getXPos(), (m_fRetractTimer / RETRACT_DELAY) * (RETRACT_MARGIN - getHeight()));
                else
                    moveTo(getXPos(), (1 - (m_fRetractTimer / RETRACT_DELAY)) * (RETRACT_MARGIN - getHeight()));
                break;
            }
            case 2: // retract to right
            {
                if (m_iRetractState == 1)
                    moveTo(getDisplay()->getParameters()->screenXSize - ((m_fRetractTimer / RETRACT_DELAY) * (RETRACT_MARGIN - getWidth()) + getWidth()), getYPos());
                else
                    moveTo(getDisplay()->getParameters()->screenXSize - ((m_fRetractTimer / RETRACT_DELAY) * (getWidth() - RETRACT_MARGIN) + RETRACT_MARGIN), getYPos());
                break;
            }
            case 3: // retract to bottom
            {
                if (m_iRetractState == 1)
                    moveTo(getXPos(), getDisplay()->getParameters()->screenYSize - ((m_fRetractTimer / RETRACT_DELAY) * (RETRACT_MARGIN - getHeight()) + getHeight()));
                else
                    moveTo(getXPos(), getDisplay()->getParameters()->screenYSize - ((m_fRetractTimer / RETRACT_DELAY) * (getHeight() - RETRACT_MARGIN) + RETRACT_MARGIN));
                break;
            }
            case 4: // retract to left
            {
                if (m_iRetractState == 1)
                    moveTo((m_fRetractTimer / RETRACT_DELAY) * (RETRACT_MARGIN - getWidth()), getYPos());
                else
                    moveTo((1 - (m_fRetractTimer / RETRACT_DELAY)) * (RETRACT_MARGIN - getWidth()), getYPos());
                break;
            }
            }
            if (m_fRetractTimer == 0)
                m_iRetractState *= 2;
        }
    }

    if (!m_bSticked && !m_bIsPointed && m_uRetractBorder != 0 && m_iRetractState == 2)
    {
        m_fRetractTimer = RETRACT_DELAY + RETRACT_TEMP_DELAY;
        m_iRetractState = -1;
    }

    m_bIsPointed = false;
    guiContainer::update(delta);
}
/**
    This method loads the units specified by the [Units] section.
*/
void INIMapEditorLoader::loadUnits()
{
    INIFile::KeyIterator iter;

    for(iter = inifile->begin("UNITS"); iter != inifile->end("UNITS"); ++iter) {
        if(iter->getKeyName().find("ID") == 0) {
            int unitID = 0;
            parseString(iter->getKeyName().substr(2), unitID);

            std::string HouseStr, UnitStr, health, PosStr, rotation, mode;
            splitString(iter->getStringValue(),6,&HouseStr,&UnitStr,&health,&PosStr,&rotation,&mode);

            HOUSETYPE houseID = getHouseID(HouseStr);
            if(houseID == HOUSE_UNUSED) {
                // skip unit for unused house
                continue;
            } else if(houseID == HOUSE_INVALID) {
                logWarning(iter->getLineNumber(), "Invalid house string for '" + UnitStr + "': '" + HouseStr + "'!");
                continue;
            }

            int pos;
            if(!parseString(PosStr, pos) || (pos < 0)) {
                logWarning(iter->getLineNumber(), "Invalid position string for '" + UnitStr + "': '" + PosStr + "'!");
                continue;
            }

            int angle;
            if(!parseString(rotation, angle) || (angle < 0) || (angle > 255)) {
                logWarning(iter->getLineNumber(), "Invalid rotation string: '" + rotation + "'!");
                angle = 64;
            }
            angle = (angle+16)/32;
            angle = ((NUM_ANGLES - angle) + 2) % NUM_ANGLES;


            int itemID = getItemIDByName(UnitStr);
            if((itemID == ItemID_Invalid) || !isUnit(itemID)) {
                logWarning(iter->getLineNumber(), "Invalid unit string: '" + UnitStr + "'!");
                continue;
            }

            int iHealth;
            if(!parseString(health, iHealth) || (iHealth < 0) || (iHealth > 256)) {
                logWarning(iter->getLineNumber(), "Invalid health string: '" + health + "'!");
                iHealth = 256;
            }

            ATTACKMODE attackmode = getAttackModeByName(mode);
            if(attackmode == ATTACKMODE_INVALID) {
                logWarning(iter->getLineNumber(), "Invalid attackmode string: '" + mode + "'!");
                attackmode = AREAGUARD;
            }

            if(itemID == Unit_Soldier || itemID == Unit_Saboteur || itemID == Unit_Trooper || itemID == Unit_Infantry || itemID == Unit_Troopers) {
                if(angle == UP) {
                    angle = UP;
                } else if (angle == DOWN) {
                    angle = DOWN;
                } else if (angle == LEFTUP || angle == LEFTDOWN || angle == LEFT) {
                    angle = LEFT;
                } else /*(angle == RIGHT)*/ {
                    angle = RIGHT;
                }
            }

            pMapEditor->units.push_back(MapEditor::Unit(unitID, houseID, itemID, iHealth, Coord(getXPos(pos),getYPos(pos)), (unsigned char) angle, attackmode));

        } else {
            logWarning(iter->getLineNumber(), "Invalid unit key: '" + iter->getKeyName() + "'!");
            continue;
        }
	}
}
/**
    This method loads the structures specified by the [Structures] section.
*/
void INIMapEditorLoader::loadStructures()
{
    int genID = -2;

    INIFile::KeyIterator iter;

    for(iter = inifile->begin("STRUCTURES"); iter != inifile->end("STRUCTURES"); ++iter) {
		std::string tmpkey = iter->getKeyName();
		std::string tmp = iter->getStringValue();

		if(tmpkey.find("GEN") == 0) {
			// Gen Object/Structure
			std::string PosStr = tmpkey.substr(3,tmpkey.size()-3);
            int pos;
            if(!parseString(PosStr, pos) || (pos < 0)) {
                logWarning(iter->getLineNumber(), "Invalid position string: '" + PosStr + "'!");
                continue;
            }

			std::string HouseStr, BuildingStr;
			splitString(tmp,2,&HouseStr,&BuildingStr);

			HOUSETYPE houseID = getHouseID(HouseStr);
			if(houseID == HOUSE_UNUSED) {
                // skip structure for unused house
                continue;
            } else if(houseID == HOUSE_INVALID) {
				logWarning(iter->getLineNumber(), "Invalid house string for '" + BuildingStr + "': '" + HouseStr + "'!");
				continue;
			}

			int itemID = getItemIDByName(BuildingStr);

			if((itemID == Structure_Slab1) || (itemID == Structure_Slab4) || (itemID == Structure_Wall)) {
			    pMapEditor->structures.push_back(MapEditor::Structure(genID, houseID, itemID, 256, Coord(getXPos(pos),getYPos(pos))));
			    genID--;
			} else {
			    logWarning(iter->getLineNumber(), "Invalid building string: '" + BuildingStr + "' for GEN-Placement!");
			    continue;
			}

		} else if(tmpkey.find("ID") == 0) {
		    // other structure
			int structureID = 0;
            parseString(tmpkey.substr(2), structureID);

			std::string HouseStr, BuildingStr, health, PosStr;
			splitString(tmp,6,&HouseStr,&BuildingStr,&health,&PosStr);

            int pos;
            if(!parseString(PosStr, pos) || (pos < 0)) {
                logWarning(iter->getLineNumber(), "Invalid position string for '" + BuildingStr + "': '" + PosStr + "'!");
                continue;
            }

			HOUSETYPE houseID = getHouseID(HouseStr);
            if(houseID == HOUSE_UNUSED) {
                // skip structure for unused house
                continue;
            } else if(houseID == HOUSE_INVALID) {
				logWarning(iter->getLineNumber(), "Invalid house string for '" + BuildingStr + "': '" + HouseStr + "'!");
				continue;
			}

            int iHealth;
            if(!parseString(health, iHealth) || (iHealth < 0) || (iHealth > 256)) {
                logWarning(iter->getLineNumber(), "Invalid health string: '" + health + "'!");
                iHealth = 256;
            }

			int itemID = getItemIDByName(BuildingStr);

			if((itemID == ItemID_Invalid) || !isStructure(itemID)) {
			    logWarning(iter->getLineNumber(), "Invalid building string: '" + BuildingStr + "'!");
			    continue;
			}

			pMapEditor->structures.push_back(MapEditor::Structure(structureID, houseID, itemID, iHealth, Coord(getXPos(pos),getYPos(pos))));
		} else {
            logWarning(iter->getLineNumber(), "Invalid structure key: '" + tmpkey + "'!");
            continue;
		}
	}
}
/**
    This method loads the game map. This is based on the [MAP] section in the INI file.
*/
void INIMapEditorLoader::loadMap() {

    version = inifile->getIntValue("BASIC", "Version", 1);

    if(version < 2) {
        // we have all houses fixed
        std::vector<MapEditor::Player>& players = pMapEditor->getPlayers();

        std::vector<MapEditor::Player>::iterator iter;
        for(iter = players.begin(); iter != players.end(); ++iter) {
            iter->bAnyHouse = false;
        }
    }


    pMapEditor->mapInfo.author = inifile->getStringValue("BASIC", "Author");
    pMapEditor->mapInfo.license = inifile->getStringValue("BASIC", "License");

    pMapEditor->mapInfo.winFlags = inifile->getIntValue("BASIC", "WinFlags", 3);
    pMapEditor->mapInfo.loseFlags = inifile->getIntValue("BASIC", "LoseFlags", 1);

    pMapEditor->mapInfo.losePicture = inifile->getStringValue("BASIC", "LosePicture");
    pMapEditor->mapInfo.winPicture = inifile->getStringValue("BASIC", "WinPicture");
    pMapEditor->mapInfo.briefPicture = inifile->getStringValue("BASIC", "BriefPicture");

    pMapEditor->mapInfo.timeout = inifile->getIntValue("BASIC", "TimeOut", 0);
    pMapEditor->mapInfo.techLevel = inifile->getIntValue("BASIC", "TechLevel", 0);


    if(version < 2) {
        int mapscale = inifile->getIntValue("BASIC", "MapScale", 0);

        pMapEditor->mapInfo.mapSeed = inifile->getIntValue("MAP", "Seed", 0);

        pMapEditor->map = createMapWithSeed(pMapEditor->mapInfo.mapSeed, mapscale);

	    switch(mapscale) {
            case 0: {
                sizeX = 62;
                sizeY = 62;
                logicalOffsetX = 1;
                logicalOffsetY = 1;
            } break;

            case 1: {
                sizeX = 32;
                sizeY = 32;
                logicalOffsetX = 16;
                logicalOffsetY = 16;
            } break;

            case 2: {
                sizeX = 21;
                sizeY = 21;
                logicalOffsetX = 11;
                logicalOffsetY = 11;
            } break;

            default: {
                 logError(inifile->getKey("BASIC", "MapScale")->getLineNumber(), "Unknown MapScale '" + stringify(mapscale) + "'!");
            } break;
	    }

	    logicalSizeX = 64;
	    logicalSizeY = 64;




        int cursorPos = inifile->getIntValue("BASIC", "CursorPos", 0);
        pMapEditor->mapInfo.cursorPos = Coord(getXPos(cursorPos), getYPos(cursorPos));
        int tacticalPos = inifile->getIntValue("BASIC", "TacticalPos", 0);
        pMapEditor->mapInfo.tacticalPos = Coord(getXPos(tacticalPos), getYPos(tacticalPos));



	    // field, spice bloom and special bloom

	    std::string BloomString = inifile->getStringValue("MAP","Bloom");
        if(BloomString != "") {
            std::vector<std::string> BloomPositions  = splitString(BloomString);

            for(unsigned int i=0; i < BloomPositions.size();i++) {
                // set bloom
                int BloomPos;
                if(parseString(BloomPositions[i], BloomPos)) {
                    int xpos = getXPos(BloomPos);
                    int ypos = getYPos(BloomPos);
                    pMapEditor->getSpiceBlooms().push_back(Coord(xpos,ypos));
                } else {
                    logWarning(inifile->getKey("MAP", "Bloom")->getLineNumber(), "Invalid spice bloom position: '" + BloomPositions[i] + "'");
                }
            }

        }

        std::string SpecialString = inifile->getStringValue("MAP","Special");
        if(SpecialString != "") {
            std::vector<std::string> SpecialPositions  = splitString(SpecialString);

            for(unsigned int i=0; i < SpecialPositions.size();i++) {
                // set special
                int SpecialPos;
                if(parseString(SpecialPositions[i], SpecialPos)) {
                    int xpos = getXPos(SpecialPos);
                    int ypos = getYPos(SpecialPos);
                    pMapEditor->getSpecialBlooms().push_back(Coord(xpos,ypos));
                } else {
                    logWarning(inifile->getKey("MAP", "Special")->getLineNumber(), "Invalid special bloom position: '" + SpecialPositions[i] + "'");
                }
            }

        }

        std::string FieldString = inifile->getStringValue("MAP","Field");
        if(FieldString != "") {
            std::vector<std::string> FieldPositions  = splitString(FieldString);

            for(unsigned int i=0; i < FieldPositions.size();i++) {
                // set bloom
                int FieldPos;
                if(parseString(FieldPositions[i], FieldPos)) {
                    int xpos = getXPos(FieldPos);
                    int ypos = getYPos(FieldPos);
                    pMapEditor->getSpiceFields().push_back(Coord(xpos,ypos));
                } else {
                    logWarning(inifile->getKey("MAP", "Field")->getLineNumber(), "Invalid spice field position: '" + FieldPositions[i] + "'");
                }
            }

        }

	} else {
        // new map format with saved map


        pMapEditor->mapInfo.cursorPos = Coord::Invalid();
        pMapEditor->mapInfo.tacticalPos = Coord::Invalid();
        pMapEditor->mapInfo.mapSeed = INVALID;

        int sizeX = inifile->getIntValue("MAP", "SizeX", 0);
        int sizeY = inifile->getIntValue("MAP", "SizeY", 0);

        pMapEditor->map = MapData(sizeX, sizeY);

        logicalSizeX = sizeX;
        logicalSizeY = sizeY;
	    logicalOffsetX = 0;
	    logicalOffsetY = 0;

        for(int y=0;y<sizeY;y++) {
            std::string rowKey = strprintf("%.3d", y);

            if(inifile->hasKey("MAP", rowKey) == false) {
                logWarning(inifile->getSection("MAP")->getLineNumber(), "Map row " + stringify(y) + " does not exist!");
                continue;
            }

            std::string rowString = inifile->getStringValue("MAP",rowKey);

            int rowLength = rowString.size();

            if(rowLength < sizeX) {
                logWarning(inifile->getKey("MAP", rowKey)->getLineNumber(), "Map row " + stringify(y) + " is not long enough!");
            } else if(rowLength > sizeX) {
                logWarning(inifile->getKey("MAP", rowKey)->getLineNumber(), "Map row " + stringify(y) + " is too long!");
                rowLength = sizeX;
            }

            for(int x=0;x<rowLength;x++) {
                TERRAINTYPE type = Terrain_Sand;

                switch(rowString.at(x)) {
                    case '-': {
                        // Normal sand
                        type = Terrain_Sand;
                    } break;

                    case '^': {
                        // Sand dunes
                        type = Terrain_Dunes;
                    } break;

                    case '~': {
                        // Spice
                        type = Terrain_Spice;
                    } break;

                    case '+': {
                        // Thick spice
                        type = Terrain_ThickSpice;
                    } break;

                    case '%': {
                        // Rock
                        type = Terrain_Rock;
                    } break;

                    case '@': {
                        // Mountain
                        type = Terrain_Mountain;
                    } break;

                    case 'O': {
                        // Spice Bloom
                        type = Terrain_SpiceBloom;
                    } break;

                    case 'Q': {
                        // Special Bloom
                        type = Terrain_SpecialBloom;
                    } break;

                    default: {
                        logWarning(inifile->getKey("MAP", rowKey)->getLineNumber(), std::string("Unknown map tile type '") + rowString.at(x) + "' in map tile (" + stringify(x) + ", " + stringify(y) + ")!");
                        type = Terrain_Sand;
                    } break;
                }

                pMapEditor->map(x,y) = type;
            }
        }
	}

	screenborder->adjustScreenBorderToMapsize(pMapEditor->map.getSizeX(), pMapEditor->map.getSizeY());

}
void Entity::update(const float deltaTime)
{

	soundEntity.setPosition(getXPos() , getYPos() , 1.f);

	damage.updateInputDamage(deltaTime);
	mana.update(deltaTime);
	stamina.update(deltaTime , directions.directionWalk , step);
	health.update(deltaTime , isDeath);
	hungry.update(deltaTime , health.needMinusHealth);
	thirst.update(deltaTime , health.needMinusHealth);

	if (currenMode == idEntityMode::walk
			|| currenMode == idEntityMode::fight
			|| currenMode == idEntityMode::panic) {
		switch (directions.directionWalk) {
		case UP_LEFT:
			directions.directionLook = UP_LEFT;
			movement.y = -step.stepCurrent;
			movement.x = -step.stepCurrent;
			break;
		case UP_RIGHT:
			directions.directionLook = UP_RIGHT;
			movement.y = -step.stepCurrent;
			movement.x = step.stepCurrent;
			break;
		case UP:
			directions.directionLook = UP;
			movement.y = -step.stepCurrent;
			break;
		case DOWN_LEFT:
			directions.directionLook = DOWN_LEFT;
			movement.y = step.stepCurrent;
			movement.x = -step.stepCurrent;
			break;
		case DOWN_RIGHT:
			directions.directionLook = DOWN_RIGHT;
			movement.y = step.stepCurrent;
			movement.x = step.stepCurrent;
			break;
		case DOWN:
			directions.directionLook = DOWN;
			movement.y = step.stepCurrent;
			break;
		case LEFT:
			directions.directionLook = LEFT;
			movement.x = -step.stepCurrent;
			break;
		case RIGHT:
			directions.directionLook = RIGHT;
			movement.x = step.stepCurrent;
			break;
		case NONE_DIRECTION:
			movement.x = 0;
			movement.y = 0;
			break;
		default:
			break;
		}

		if (directions.directionWalk >= Direction::UP_LEFT) {
			movement.x *= DIAGONAL_SCALE_SPEED * deltaTime;
			movement.y *= DIAGONAL_SCALE_SPEED * deltaTime;
		}
		else {
			movement.x *= deltaTime;
			movement.y *= deltaTime;
		}

		updateDirectionLook();
		playAnimationWalk(deltaTime);

	}

	if (currenMode == idEntityMode::atack) {
		animation.updateFight(deltaTime , giveDamage , currenMode);
		playAnimationAtack(deltaTime);
	}
}
Beispiel #28
0
int Player::getTileY(){
	return ((getYPos()) / 8);
}