Esempio n. 1
1
void TREnemy::moveAlongPath(){
    planRoute(false);
    if(path.empty()){
        return;
    }
    int topX = path.front().first;
    int topY = path.front().second;
    int curX = getX();
    int curY = getY();
    if(!undoed && curX != topX){
        if(std::abs(curX - topX) < vel){
            if(curX > topX){
                setDirection(TRDirectionLeft);
                curX = topX;
            }else{
                setDirection(TRDirectionRight);
                curX = topX;
            }
        }else{
            if (curX > topX) {
                setDirection(TRDirectionLeft);
                curX -= vel;
            }else{
                setDirection(TRDirectionRight);
                curX += vel;
            }
        }
        if(curX == topX && curY == topY){
            path.pop();
        }
        setX(curX);
        return;
    }
    if(curY != topY){
        undoed = false;
        if(std::abs(curY - topY) < vel){
            if(curY > topY){
                setDirection(TRDirectionUp);
                curY = topY;
            }else{
                setDirection(TRDirectionDown);
                curY = topY;
            }
        }else{
            if (curY > topY) {
                setDirection(TRDirectionUp);
                curY -= vel;
            }else{
                setDirection(TRDirectionDown);
                curY += vel;
            }
        }
        if(curX == topX && curY == topY){
            path.pop();
        }
        setY(curY);
        return;
    }
    if(curX == topX && curY == topY){
        path.pop();
    }
    return;
}
void Coordinate::operator+=(const Coordinate& coord)
{
	setX(_x + coord.x());
	setY(_y + coord.y());
}
QSizeF HelperKaraokeLabel::RenderToImage(QImage** ppimage, const QString& lyric, QList<RubyChar>& ruby, const QColor& textCol, const QColor& strokeColor)
{
    if (!ppimage)
    {
        return QSizeF();
    }
    auto pimage = *ppimage;
    if (pimage)
    {
        delete pimage;
        pimage = NULL;
        *ppimage = NULL;
    }

    auto setting = Settings::getInstance();
    _textColor = textCol;
    _strokeColor = strokeColor;

    // text
    setText(lyric);

    // set font
    QFont f;
    f.setFamily(setting->fontName());
    f.setWeight(99);
    f.setPixelSize(setting->fontSize());
    f.setLetterSpacing(QFont::SpacingType::AbsoluteSpacing, 1);
    setFont(f);

    // calc size
    QSizeF size = minimumSizeHint();

    //////////////////////////////////////////////////////////////////////////
    // ruby
    int rubyCount = ruby.size();
    _maxSubW = 0.0;
    _maxSubH = setting->rubyFontSize();
    QList<HelperKaraokeLabel*> subList;
    for (int i = 0; i < rubyCount; i++)
    {
        HelperKaraokeLabel* sub = new HelperKaraokeLabel(this);
        sub->_isRuby = true;
        sub->setRubyHidden(_isRubyHidden);
        subList.append(sub);
        sub->setText(ruby[i].ruby());
        sub->_textColor = _textColor;
        sub->_strokeColor = _strokeColor;

        // set font
        QFont f;
        f.setFamily(setting->fontName());
        f.setWeight(99);
        f.setPixelSize(setting->rubyFontSize());
        f.setLetterSpacing(QFont::SpacingType::AbsoluteSpacing, 1);
        sub->setFont(f);

        QSizeF subsize = sub->minimumSizeHint();
        if (_maxSubW < subsize.width())
        {
            _maxSubW = subsize.width();
        }
        // should be even!!
        /*
        if (_maxSubH < subsize.height())
        {
        	_maxSubH = subsize.height();
        }*/
    }

    // rearrange size
    _maxSubH += 1.0; // shadow

    //  /--/                // _rubyOffset > 0
    //      /<--->/      // _maxSubW
    //  |--|a|----|b|----|c|--|
    //  AAAAAAAAAAAAAAAAA

    //
    // |a|b|c|
    //	---A---
    // /--/                // _rubyOffset < 0

    size.setHeight(size.height() + _maxSubH + setting->rubyVSpace());
    if (rubyCount > 0)
    {
        qreal subTotalW = _maxSubW*rubyCount;
        qreal oWidth = size.width();

        if (oWidth < subTotalW)
        {
            size.setWidth(_maxSubW*rubyCount);
            _rubyOffset = (oWidth - subTotalW) / 2.0;
        }
        else
        {
            auto oMaxSubW = _maxSubW;
            /*
            _maxSubW = ((qreal)(oWidth)) / rubyCount;
            _rubyOffset = oMaxSubW/2;
            */
            _rubyOffset = (oWidth - rubyCount*oMaxSubW) / rubyCount / 2.0;
            _maxSubW = oMaxSubW + _rubyOffset * 2.0;
        }

        for (int i = 0; i < rubyCount; i++)
        {
            subList[i]->setFixedSize(QSize(_maxSubW, _maxSubH+setting->rubyVSpace()));
            subList[i]->_maxSubW = _maxSubW;
            subList[i]->_maxSubH = _maxSubH;
            auto geo = subList[i]->geometry();
            geo.setX(geo.x() + i*_maxSubW + (_rubyOffset>0 ? _rubyOffset : 0));
            subList[i]->setGeometry(geo);
        }
        /*
        auto geo = this->geometry();
        geo.setY(maxSubH + subSpaceH);
        this->setGeometry(geo);
        */
    }

    setFixedSize(size.toSize());


    // render to image
    pimage = new QImage(size.toSize(), QImage::Format_ARGB32);
    QPainter painter(pimage);
    pimage->fill(qRgba(0, 0, 0, 0));
    render(&painter, QPoint(), QRegion(), QWidget::DrawChildren);


    // assign return value
    *ppimage = pimage;

    return size;
}
void OpticalFlowTransitionModel::predict(vector<Sample>& samples, const Mat& image, const optional<Sample>& target) {
	points.clear();
	forwardPoints.clear();
	backwardPoints.clear();
	forwardStatus.clear();
	error.clear();
	squaredDistances.clear();
	correctFlowCount = 0;

	// build pyramid of the current image
	cv::buildOpticalFlowPyramid(makeGrayscale(image), currentPyramid, windowSize, maxLevel, true, BORDER_REPLICATE, BORDER_REPLICATE);
	if (previousPyramid.empty() || !target) { // optical flow cannot be computed if there is no previous pyramid or no current target
		swap(previousPyramid, currentPyramid);
		return fallback->predict(samples, image, target);
	}

	// compute grid of points at target location
	for (auto point = templatePoints.begin(); point != templatePoints.end(); ++point)
		points.push_back(Point2f(target->getWidth() * point->x + target->getX(), target->getHeight() * point->y + target->getY()));
	// compute forward and backward optical flow
	cv::calcOpticalFlowPyrLK(previousPyramid, currentPyramid, points, forwardPoints, forwardStatus, error, windowSize, maxLevel);
	cv::calcOpticalFlowPyrLK(currentPyramid, previousPyramid, forwardPoints, backwardPoints, backwardStatus, error, windowSize, maxLevel);
	swap(previousPyramid, currentPyramid);

	// compute flow and forward-backward-error
	vector<Point2f> flows;
	flows.reserve(points.size());
	squaredDistances.reserve(points.size());
	for (unsigned int i = 0; i < points.size(); ++i) {
		flows.push_back(forwardPoints[i] - points[i]);
		if (forwardStatus[i] && backwardStatus[i]) {
			Point2f difference = backwardPoints[i] - points[i];
			squaredDistances.push_back(make_pair(difference.dot(difference), i));
		}
	}
	if (squaredDistances.size() < points.size() / 2) // the flow for more than half of the points could not be computed
		return fallback->predict(samples, image, target);

	// find the flows with the least forward-backward-error (not more than 1 pixel)
	float maxError = 1 * 0.5f;
	vector<float> xs, ys;
	sort(squaredDistances.begin(), squaredDistances.end(), [](pair<float, int> lhs, pair<float, int> rhs) { return lhs.first < rhs.first; });
	xs.reserve(squaredDistances.size());
	ys.reserve(squaredDistances.size());
	for (correctFlowCount = 0; correctFlowCount < squaredDistances.size(); ++correctFlowCount) {
		if (squaredDistances[correctFlowCount].first > maxError)
			break;
		int index = squaredDistances[correctFlowCount].second;
		xs.push_back(flows[index].x);
		ys.push_back(flows[index].y);
	}
	if (correctFlowCount < points.size() / 2) // to little correct correspondences
		return fallback->predict(samples, image, target);

	// compute median flow (only change in position for now)
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	float medianX = xs[xs.size() / 2];
	float medianY = ys[ys.size() / 2];
	Point2f medianFlow(medianX, medianY);

	// compute ratios of point distances in previous and current image
	vector<float> squaredRatios;
	squaredRatios.reserve(correctFlowCount * (correctFlowCount - 1) / 2);
	for (unsigned int i = 0; i < correctFlowCount; ++i) {
		for (unsigned int j = i + 1; j < correctFlowCount; ++j) {
			Point2f point1 = points[squaredDistances[i].second];
			Point2f forwardPoint1 = forwardPoints[squaredDistances[i].second];
			Point2f point2 = points[squaredDistances[j].second];
			Point2f forwardPoint2 = forwardPoints[squaredDistances[j].second];
			Point2f differenceBefore = point1 - point2;
			Point2f differenceAfter = forwardPoint1 - forwardPoint2;
			float squaredDistanceBefore = differenceBefore.dot(differenceBefore);
			float squaredDistanceAfter = differenceAfter.dot(differenceAfter);
			squaredRatios.push_back(squaredDistanceAfter / squaredDistanceBefore);
		}
	}

	// compute median ratio to complete the median flow
	sort(squaredRatios.begin(), squaredRatios.end());
	float medianRatio = sqrt(squaredRatios[squaredRatios.size() / 2]);

	// predict samples according to median flow and random noise
	for (auto sample = samples.begin(); sample != samples.end(); ++sample) {
		int oldX = sample->getX();
		int oldY = sample->getY();
		float oldSize = sample->getSize();
		// change position according to median flow
		double newX = oldX + medianX;
		double newY = oldY + medianY;
		double newSize = oldSize * medianRatio;
		// add noise to position
		double positionDeviation = scatter * sample->getSize();
		newX += positionDeviation * generator();
		newY += positionDeviation * generator();
		newSize *= pow(2, scatter * generator());
		// round to integer
		sample->setX((int)(newX + 0.5));
		sample->setY((int)(newY + 0.5));
		sample->setSize((int)(newSize + 0.5));
		// compute change
		sample->setVx(sample->getX() - oldX);
		sample->setVy(sample->getY() - oldY);
		sample->setVSize(sample->getSize() / oldSize);
	}
}
Esempio n. 5
0
HexagonGrid::HexagonGrid()
{
    // Creating 200x200 hexagonal map
    unsigned int index = 0;
    for (unsigned int q = 0; q != 200; ++q)
    {
        for (unsigned int p = 0; p != 200; ++p, ++index)
        {
            auto hexagon = new Hexagon(index);
            int x = 48*100 + 16*(q+1) - 24*p;
            int y = (q+1)*12 + 6*p + 12;
            if (p&1)
            {
                x -= 8;
                y -= 6;
            }

            hexagon->setCubeX(q - (p + (p&1))/2);
            hexagon->setCubeZ(p);
            hexagon->setCubeY(-hexagon->cubeX() - hexagon->cubeZ());

            hexagon->setX(x);
            hexagon->setY(y);
            _hexagons.push_back(hexagon);
        }
    }

    // Creating links between hexagons
    for (index = 0; index != 200*200; ++index)
    {
        auto hexagon = _hexagons.at(index);

        unsigned int q = index/200; // hexagonal y
        unsigned int p = index%200; // hexagonal x

        unsigned index1 = (q + 1)*200 + p;
        unsigned index4 = (q-1)*200 + p;
        unsigned int index2, index3, index5, index6;
        if (index&1)
        {
            index2 = q*200 + p-1;
            index3 = (q-1)*200 + p-1;
            index5 = (q-1)*200 + p+1;
            index6 = q*200 + p+1;
        }
        else
        {
            index2 = (q+1)*200 + p-1;
            index3 = q*200 + p-1;
            index5 = q*200 + p+1;
            index6 = (q+1)*200 + p+1;
        }

        if (index1 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index1));
        if (index2 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index2));
        if (index3 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index3));
        if (index4 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index4));
        if (index5 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index5));
        if (index6 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index6));
    }
}
void BossLaser::setMissedPosition() 
{
	setPosition(VECTOR2(GAME_WIDTH/2, GAME_HEIGHT/5));
	setX(Entity::getPositionX());
	setY(Entity::getPositionY());
}
Esempio n. 7
0
Point::Point()
{
    setX(0.0);
    setY(0.0);
    setY(0.0);
}
 Location(unsigned long int _size, T _x, T _y) : size(_size) {
     setX(_x);
     setY(_y);
 }
Esempio n. 9
0
void Entity::setPosition(float x, float y)
{
    setX(x);
    setY(y);
}
Esempio n. 10
0
TextBox::TextBox(int x, int y, const Color &textColor, const std::string &text,
	FontName fontName, TextureManager &textureManager)
	: Surface(x, y, 1, 1)
{
	this->fontName = fontName;

	// Split "text" into lines of text.
	this->textLines = [&text]()
	{
		auto temp = std::vector<std::string>();

		// Add one empty string to start.
		temp.push_back(std::string());

		const char newLine = '\n';
		int textLineIndex = 0;
		for (auto &c : text)
		{
			if (c != newLine)
			{
				// std::string has push_back! Yay! Intuition + 1.
				temp.at(textLineIndex).push_back(c);
			}
			else
			{
				temp.push_back(std::string());
				textLineIndex++;
			}
		}

		return temp;
	}();

	// Calculate the proper dimensions of the text box.
	// No need for a "FontSurface" type... just do the heavy lifting in this class.
	auto font = Font(fontName);
	int upperCharWidth = font.getUpperCharacterWidth();
	int upperCharHeight = font.getUpperCharacterHeight();
	int lowerCharWidth = font.getLowerCharacterWidth();
	int lowerCharHeight = font.getLowerCharacterHeight();

	const int newWidth = [](const std::vector<std::string> &lines,
		int upperCharWidth, int lowerCharWidth)
	{
		// Find longest line (in pixels) out of all lines.
		int longestLength = 0;
		for (auto &line : lines)
		{
			// Sum of all character lengths in the current line.
			int linePixels = 0;
			for (auto &c : line)
			{
				linePixels += islower(c) ? lowerCharWidth : upperCharWidth;
			}

			// Check against the current longest line.
			if (linePixels > longestLength)
			{
				longestLength = linePixels;
			}
		}

		// In pixels.
		return longestLength;
	}(this->textLines, upperCharWidth, lowerCharWidth);

	const int newHeight = static_cast<int>(this->textLines.size()) * upperCharHeight;

	// Resize the surface with the proper dimensions for fitting all the text.
	SDL_FreeSurface(this->surface);
	this->surface = [](int width, int height, int colorBits)
	{
		return SDL_CreateRGBSurface(0, width, height, colorBits, 0, 0, 0, 0);
	}(newWidth, newHeight, Surface::DEFAULT_BPP);

	// Make this surface transparent.
	this->setTransparentColor(Color::Transparent);
	this->fill(Color::Transparent);
	
	// Blit each character surface in at the right spot.
	auto point = Int2();
	auto fontSurface = textureManager.getSurface(font.getFontTextureName());
	int upperCharOffsetWidth = font.getUpperCharacterOffsetWidth();
	int upperCharOffsetHeight = font.getUpperCharacterOffsetHeight();
	int lowerCharOffsetWidth = font.getLowerCharacterOffsetWidth();
	int lowerCharOffsetHeight = font.getLowerCharacterOffsetHeight();
	for (auto &line : this->textLines)
	{
		for (auto &c : line)
		{
			int width = islower(c) ? lowerCharWidth : upperCharWidth;
			int height = islower(c) ? lowerCharHeight : upperCharHeight;
			auto letterSurface = [&]()
			{
				auto cellPosition = Font::getCharacterCell(c);
				int offsetWidth = islower(c) ? lowerCharOffsetWidth : upperCharOffsetWidth;
				int offsetHeight = islower(c) ? lowerCharOffsetHeight : upperCharOffsetHeight;

				// Make a copy surface of the font character.
				auto pixelPosition = Int2(
					cellPosition.getX() * (width + offsetWidth),
					cellPosition.getY() * (height + offsetHeight));
				auto clipRect = Rectangle(pixelPosition.getX(), pixelPosition.getY(),
					width, height);

				auto surface = Surface(width, height);
				fontSurface.blit(surface, Int2(), clipRect);

				return surface;
			}();

			// Set the letter surface to have transparency.
			letterSurface.setTransparentColor(Color::Magenta);

			// Set the letter colors to the desired color.
			auto letterPixels = static_cast<unsigned int*>(letterSurface.getSurface()->pixels);
			auto mappedColor = SDL_MapRGBA(letterSurface.getSurface()->format, 
				textColor.getR(), textColor.getG(), textColor.getB(), textColor.getA());

			int area = letterSurface.getWidth() * letterSurface.getHeight();
			for (int i = 0; i < area; ++i)
			{
				auto pixel = &letterPixels[i];
				
				// If transparent, then color it? I dunno, but it works.
				if ((*pixel) == 0)
				{
					*pixel = mappedColor;
				}
			}

			// Draw the letter onto this texture.
			letterSurface.blit(*this, point);

			// Move drawing position to the right of the current character.
			point.setX(point.getX() + width);
		}

		// Move drawing point back to the left and down by one capital character size.
		point.setX(0);
		point.setY(point.getY() + upperCharHeight);
	}

	assert(this->surface->w > 1);
	assert(this->surface->h > 1);
	assert(this->textLines.size() > 0);
	assert(this->fontName == fontName);
}
void EllipseObject::setObjectCenterX(qreal centerX)
{
    setX(centerX);
}
void VESPERSEXAFSScanConfiguration::setPosition(QPair<double, double> pos)
{
	setX(pos.first);
	setY(pos.second);
}
Esempio n. 13
0
void Point::set(std::shared_ptr<Point> data)
{
	setX (data->getX());
	setY (data->getY());
}
void Coordinate::operator-=(const Coordinate& coord)
{
	setX(_x - coord.x());
	setY(_y - coord.y());
}
void Transform::subToX(int x)
{
	setX(getX()-x);

}
void Dynamite::onTick()
{
    setX(getX()-speed);
    setY(getY()+rand()%21-10);
}
Esempio n. 17
0
PlayerPanel::PlayerPanel() : UI::Base()
{
    auto game = Game::getInstance();
    auto renderer = game->renderer();
    auto mouse = game->mouse();

    _background = std::make_shared<Image>("art/intrface/iface.frm");
    _ui.push_back(_background);

    setX((renderer->width() - 640) / 2);
    setY(renderer->height() - _background->height());

    _background->setPosition(this->position());

    mouseInHandler().add([this, mouse](Event::Event* event)
    {
        mouse->pushState(Input::Mouse::Cursor::BIG_ARROW);
    });

    mouseOutHandler().add([this, mouse](Event::Event* event)
    {
        if (mouse->scrollState())
        {
            // this trick is needed for correct cursor type returning on scrolling
            auto state = mouse->state();
            mouse->popState();
            mouse->popState();
            mouse->pushState(state);
        }
        else
        {
            mouse->popState();
        }
    });

    // Change hand button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::BIG_RED_CIRCLE, position() + Point(218, 5)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){ this->changeHand(); });

    // Inventory button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_INVENTORY, position() + Point(211, 40)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){ this->openInventory(); });

    // Options button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_OPTIONS, position() + Point(210, 61)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){ this->openGameMenu(); });

    // Attack button
    _isAttackBtnPressed = false;
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_ATTACK, position() + Point(267, 25)));

    _ui.back()->mouseDownHandler().add([this](Event::Event* event){
        if(auto mouse = dynamic_cast<Event::Mouse*>(event))
        {
            if(mouse->leftButton())
                _isAttackBtnPressed = true;
        }
    });

    _ui.back()->mouseUpHandler().add([this](Event::Event* event){
        _isAttackBtnPressed = false;
    });


    // Hit points
    _hitPoints = std::make_shared<SmallCounter>(position() + Point(473, 40));
    _hitPoints->setType(SmallCounter::Type::SIGNED);
    _hitPoints->setNumber(game->player()->hitPoints());
    _ui.push_back(_hitPoints);

    // Armor class
    _armorClass = std::make_shared<SmallCounter>(position() + Point(473, 76));
    _armorClass->setType(SmallCounter::Type::SIGNED);
    _armorClass->setNumber(game->player()->armorClass());
    _ui.push_back(_armorClass);

    // Skilldex button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::BIG_RED_CIRCLE, position() + Point(523, 5)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){
        this->openSkilldex();
    });

    // MAP button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_MAP, position() + Point(526, 39)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){
        this->openMap();
    });

    // CHA button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_CHA, position() + Point(526, 58)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){
        this->openCharacterScreen();
    });

    // PIP button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_PIP, position() + Point(526, 77)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){
        this->openPipBoy();
    });

    // Message log
    _messageLog = std::make_shared<UI::TextArea>(position() + Point(23, 24));
    _messageLog->setSize({165, 60});
    _messageLog->setWordWrap(true);
    _messageLog->setCustomLineShifts({0, 1, 2, 3, 4, 5});
    _ui.push_back(_messageLog);

    _messageLog->mouseDownHandler().add([this](Event::Mouse* event)
        {
            _scrollingLog = 0;
            Point relPos = event->position() - _messageLog->position();
            if (relPos.y() < (_messageLog->size().height() / 2))
            {
                if (_messageLog->lineOffset() > 0)
                {
                    _scrollingLog = -1;
                }
            }
            else if (_messageLog->lineOffset() < _messageLog->numLines() - 6)
            {
                _scrollingLog = 1;
            }
            if (_scrollingLog != 0)
            {
                _messageLog->setLineOffset(_messageLog->lineOffset() + _scrollingLog);
                _scrollingLogTimer = SDL_GetTicks();
            }
        });

    _messageLog->mouseUpHandler().add([this](Event::Mouse* event)
        {
            _scrollingLog = 0;
            _scrollingLogTimer = 0;
        });

    _messageLog->mouseMoveHandler().add([this](Event::Mouse* event)
        {
            auto mouse = Game::getInstance()->mouse();
            Point relPos = event->position() - _messageLog->position();

            auto state = relPos.y() < (_messageLog->size().height() / 2)
                ? Input::Mouse::Cursor::SMALL_UP_ARROW
                : Input::Mouse::Cursor::SMALL_DOWN_ARROW;

            if (mouse->state() != state)
            {
                mouse->setState(state);
            }
        });

     _messageLog->mouseOutHandler().add([this](Event::Mouse* event)
        {
            _scrollingLog = 0;
            _scrollingLogTimer = 0;
            Game::getInstance()->mouse()->setState(Input::Mouse::Cursor::BIG_ARROW);
        });

    keyDownHandler().add([this](Event::Event* event) {
        this->onKeyDown(dynamic_cast<Event::Keyboard*>(event));
    });
}
Esempio n. 18
0
void Character::moveOnCenter() {
	setX((m_maze->getColFromX(m_x) + 0.5) * Cell::SIZE);
	setY((m_maze->getRowFromY(m_y) + 0.5) * Cell::SIZE);
}
Esempio n. 19
0
/** Initializer **/
void Wall::init(const int & x, const int & orientation)
{
	setX(x);
	setO(orientation);
}
 /** \brief Set the X, Y and Z components of the state */
 void setXYZ(double x, double y, double z)
 {
     setX(x);
     setY(y);
     setZ(z);
 }
Esempio n. 21
0
Point::Point(double _x, double _y, double _z)
{
    setX(_x);
    setY(_y);
    setZ(_z);
}
Esempio n. 22
0
/*Funcao de update logico do proprio jogo. E' executada em cada ciclo apos a checagem de colisao, antes
  do update logico das entidades do jogo.*/
void updateGameLogic(double deltaTime)
{
    int i, estadoInicial, posInicial, numVivos;
    Vetor v, p;

	/*Antes temos que criar os dois botes, sempre que der.*/
	while ( (2 - getNumBotesVivos()) > 0 ) 
	{
		/*Apenas criamos o vetor e setamos apenas 1 de suas coordenadas (a outra = 0). Assim esse valor que estamos setando
          sera igual ao modulo do vetor, que queremos que seja um numero especifico dependendo das configuracoes.
          Depois iremos atualizar (para variar) a direcao, e somente a direcao, da velocidade.*/
        v = VETORinit(getSpeed() + (getRandDouble()*10 ), 0);
		/*Inicializamos a posicao com um valor fora da tela, para que no teste a seguir nao haja nenhuma entidade para que possamos
		  criar uma.*/
		p = VETORinit(-30.0, -30.0);

        /*Agora escolhemos uma posicao aleatoria ao longo das bordas do oceano para criar o bote,
          e atualizamos a sua direcao para eles comecarem se mexendo para algum lado.*/
		while ( getEntityByPositionVector(p) != NULL || getX(p) < 0)
		{
			posInicial = rand()%4;
    	    estadoInicial = rand()%2;

	        if (posInicial == 0)
    	    {
    	    	setX(p, rand()%SCREEN_W);
				setY(p, 10);
    	        if (estadoInicial == 0)
					setEstado(7, v);
				else if (estadoInicial == 1)
					setEstado(5, v);
			}
			else if (posInicial == 1)
    	    {
				setX(p, 0);
				setY(p, rand()%SCREEN_H);
				if (estadoInicial == 0)
					setEstado(4, v);
				else if (estadoInicial == 1)
					setEstado(5, v);
			}
			else if (posInicial == 2)
    	    {
				setX(p, rand()%SCREEN_W);
				setY(p, SCREEN_H-1);
				if (estadoInicial == 0)
					setEstado(6, v);
				else if (estadoInicial == 1)
					setEstado(4, v);
			}
			else if (posInicial == 3)
    	    {
				setX(p, SCREEN_W-1);
				setY(p, rand()%SCREEN_H);
    	        if (estadoInicial == 0)
					setEstado(6, v);
				else if (estadoInicial == 1)
					setEstado(7, v);
    		}
		}
        /*Finalmente, criamos o bote.*/
        criaBote(p, v);
	}

    /*deltaTime em segundos, frequencia em ciclos por segundo (passageiros a serem criados por segundo).*/
    timeElapsed += deltaTime;
    if (timeElapsed >= 1)  /*Um segundo inteiro foi completado, criar passageiros...*/
    {
		numVivos = getNumPassageirosVivos();

        for (i=0; i<getFrequency() && numVivos < getMaxNumPassageiros(); i++)
        {
            /*Apenas criamos o vetor e setamos apenas 1 de suas coordenadas (a outra = 0). Assim esse valor que estamos setando
              sera igual ao modulo do vetor, que queremos que seja um numero especifico dependendo das configuracoes.
              Depois iremos atualizar (para variar) a direcao, e somente a direcao, da velocidade.*/
            v = VETORinit(getSpeed() + (getRandDouble()*2 - 1), 0);
			/*Inicializamos a posicao com um valor fora da tela, para que no teste a seguir nao haja nenhuma entidade para que possamos
			  criar uma.*/
			p = VETORinit(-30.0, -30.0);

            /*Agora escolhemos uma posicao aleatoria ao longo das bordas do oceano para criar o passageiro,
              e atualizamos a sua direcao para eles comecarem se mexendo ao centro do oceano.*/
			while ( getEntityByPositionVector(p) != NULL || getX(p) < 0)
			{
	            posInicial = rand()%4;
    	        estadoInicial = rand()%6;

	            if (posInicial == 0)
    	        {
    	            setX(p, rand()%SCREEN_W);
					setY(p, 10);
    	            if (estadoInicial <= 3)
    	                setEstado(1, v);
    	            else if (estadoInicial == 4)
    	                setEstado(7, v);
    	            else if (estadoInicial == 5)
    	                setEstado(5, v);
    	        }
    	        else if (posInicial == 1)
    	        {
					setX(p, 0);
    	            setY(p, rand()%SCREEN_H);
    	            if (estadoInicial <= 3)
    	                setEstado(2, v);
    	            else if (estadoInicial == 4)
    	                setEstado(4, v);
    	            else if (estadoInicial == 5)
    	                setEstado(5, v);
    	        }
    	        else if (posInicial == 2)
    	        {
    	            setX(p, rand()%SCREEN_W);
					setY(p, SCREEN_H-1);
    	            if (estadoInicial <= 3)
    	                setEstado(0, v);
    	            else if (estadoInicial == 4)
    	                setEstado(6, v);
    	            else if (estadoInicial == 5)
    	                setEstado(4, v);
    	        }
    	        else if (posInicial == 3)
    	        {
    	            setX(p, SCREEN_W-1);
					setY(p, rand()%SCREEN_H);
    	            if (estadoInicial <= 3)
    	                setEstado(3, v);
    	            else if (estadoInicial == 4)
    	                setEstado(6, v);
    	            else if (estadoInicial == 5)
    	                setEstado(7, v);
    			}
			}

            /*Finalmente, criamos o passageiro.*/
            criaPassageiro(p, v, rand()%60 + 40);

			numVivos++;
        }

        timeElapsed -= 1.0;
    }
}
Esempio n. 23
0
HesapMak::HesapMak():
        Window(LBLCALCULATOR)
{
    logger->log("hesap makinesi");
    setDefaultSize(windowContainer->getWidth() - 255, 25, 230, 200);

    setWidth(230);
    setHeight(225);
    setX(100);
    setY(100);

    mOndalik =0;
    mSayi1=0;
    mSayi2=0;
    mIslem=YOK;
    mSonuc=0;
    mIslemVar=false;

    mGosterge = new gcn::Label("0");
    mGosterge->setPosition(20,15);
    mGosterge->setSize(150,25);
    mGosterge->setForegroundColor(gcn::Color(0,0,0));
    mGosterge->setFont(boldFont);
    mGosterge->setAlignment(gcn::Graphics::CENTER);

    add(mGosterge);

    int mbutx=20, mbuty=160, mbutw=30, mbuth=28;

    mBut0 = new Button("0","0",this);
    mBut0->setPosition(mbutx,mbuty);
    mBut0->setSize(mbutw,mbuth);
    mBut0->setAlignment(gcn::Graphics::LEFT);
    add(mBut0);
    mbutx += mbutw +10;

    mButIsaret = new Button("+/-","+/-",this);
    mButIsaret->setPosition(mbutx,mbuty);
    mButIsaret->setSize(mbutw,mbuth);
    mButIsaret->setAlignment(gcn::Graphics::CENTER);
    add(mButIsaret);
    mbutx += mbutw +10;

    mButOndalik= new Button(",",".",this);
    mButOndalik->setPosition(mbutx,mbuty);
    mButOndalik->setSize(mbutw,mbuth);
    mButOndalik->setAlignment(gcn::Graphics::CENTER);
    add(mButOndalik);
    mbutx += mbutw +10;

    mButTopla= new Button("+","+",this);
    mButTopla->setPosition(mbutx,mbuty);
    mButTopla->setSize(mbutw,mbuth);
    mButTopla->setAlignment(gcn::Graphics::CENTER);
    add(mButTopla);
    mbutx =20;
    mbuty -= mbuth+10;

    mBut1 = new Button("1","1",this);
    mBut1->setPosition(mbutx,mbuty);
    mBut1->setSize(mbutw,mbuth);
    mBut1->setAlignment(gcn::Graphics::CENTER);
    add(mBut1);
    mbutx += mbutw +10;

    mBut2 = new Button("2","2",this);
    mBut2->setPosition(mbutx,mbuty);
    mBut2->setSize(mbutw,mbuth);
    mBut2->setAlignment(gcn::Graphics::CENTER);
    add(mBut2);
    mbutx += mbutw +10;

    mBut3= new Button("3","3",this);
    mBut3->setPosition(mbutx,mbuty);
    mBut3->setSize(mbutw,mbuth);
    mBut3->setAlignment(gcn::Graphics::CENTER);
    add(mBut3);
    mbutx += mbutw +10;

    mButCikar= new Button("-","-",this);
    mButCikar->setPosition(mbutx,mbuty);
    mButCikar->setSize(mbutw,mbuth);
    mButCikar->setAlignment(gcn::Graphics::CENTER);
    add(mButCikar);
    mbutx += mbutw +10;

    mButEsit= new Button("=","=",this);
    mButEsit->setPosition(mbutx,mbuty);
    mButEsit->setSize(mbutw,mbuth*2+10);
    mButEsit->setAlignment(gcn::Graphics::CENTER);
    add(mButEsit);
    mbutx =20;
    mbuty -= mbuth+10;

    mBut4 = new Button("4","4",this);
    mBut4->setPosition(mbutx,mbuty);
    mBut4->setSize(mbutw,mbuth);
    mBut4->setAlignment(gcn::Graphics::CENTER);
    add(mBut4);
    mbutx += mbutw +10;

    mBut5 = new Button("5","5",this);
    mBut5->setPosition(mbutx,mbuty);
    mBut5->setSize(mbutw,mbuth);
    mBut5->setAlignment(gcn::Graphics::CENTER);
    add(mBut5);
    mbutx += mbutw +10;

    mBut6= new Button("6","6",this);
    mBut6->setPosition(mbutx,mbuty);
    mBut6->setSize(mbutw,mbuth);
    mBut6->setAlignment(gcn::Graphics::CENTER);
    add(mBut6);
    mbutx += mbutw +10;

    mButCarp= new Button("x","x",this);
    mButCarp->setPosition(mbutx,mbuty);
    mButCarp->setSize(mbutw,mbuth);
    mButCarp->setAlignment(gcn::Graphics::CENTER);
    add(mButCarp);
    mbutx += mbutw +10;

    mbutx =20;
    mbuty -= mbuth+10;

    mBut7 = new Button("7","7",this);
    mBut7->setPosition(mbutx,mbuty);
    mBut7->setSize(mbutw,mbuth);
    mBut7->setAlignment(gcn::Graphics::CENTER);
    add(mBut7);
    mbutx += mbutw +10;

    mBut8 = new Button("8","8",this);
    mBut8->setPosition(mbutx,mbuty);
    mBut8->setSize(mbutw,mbuth);
    mBut8->setAlignment(gcn::Graphics::CENTER);
    add(mBut8);
    mbutx += mbutw +10;

    mBut9= new Button("9","9",this);
    mBut9->setPosition(mbutx,mbuty);
    mBut9->setSize(mbutw,mbuth);
    mBut9->setAlignment(gcn::Graphics::CENTER);
    add(mBut9);
    mbutx += mbutw +10;

    mButBol= new Button("/","/",this);
    mButBol->setPosition(mbutx,mbuty);
    mButBol->setSize(mbutw,mbuth);
    mButBol->setAlignment(gcn::Graphics::CENTER);
    add(mButBol);
    mbutx += mbutw +10;

    mbuty += mbuth + 10;
    mButTumSil= new Button("C","TumSil",this);
    mButTumSil->setPosition(mbutx,mbuty);
    mButTumSil->setSize(mbutw,mbuth);
    mButTumSil->setAlignment(gcn::Graphics::CENTER);
    add(mButTumSil);
    mbuty -= mbuth+10;
    mbutx =180;

    mButGeriSil= new Button("<-","GeriSil",this);
    mButGeriSil->setPosition(mbutx,mbuty);
    mButGeriSil->setSize(mbutw,mbuth);
    mButGeriSil->setAlignment(gcn::Graphics::CENTER);
    add(mButGeriSil);
    loadWindowState();
}
Esempio n. 24
0
void Arma::atirar(float theta, float time){
  setX(cos(getTheta()*M_PI/180 )*time);
  setY(sin(getTheta()*M_PI/180 )*time);
}
Esempio n. 25
0
void TentaculatBoss::onUpdate(float frametime)
{
	m_animator.updateSubRect(*this, frametime);

	m_timer += frametime;

	sf::Vector2f target_pos = m_target->getCenter();
	m_weapon.shoot(target_pos);

	sf::Vector2f pos = getPosition();
	switch (m_state)
	{
		case INIT:
			if (pos.x < MAX_X)
			{
				setX(MAX_X);
				m_state = LURK;
				m_speed = {0.f, 120.f};
			}
			break;
		case LURK:
			if ((int) pos.y < 40 || (int) pos.y > MAX_Y - 40)
			{
				if      ((int) pos.y < 40)         setY(40);
				else if ((int) pos.y > MAX_Y - 40) setY(MAX_Y - 40);
				m_speed.y *= -1;
			}
			if ((int) m_timer > 10)
			{
				m_timer = 0.f;
				m_state = IDLE;
				m_speed = {0.f, 0.f};
			}
			break;
		case IDLE:
			if ((int) m_timer > 2)
			{
				m_timer = 0.f;
				m_state = CHARGE;
				float angle = math::angle(pos, target_pos);
				m_speed.x = std::cos(angle) * 350;
				m_speed.y = -std::sin(angle) * 350;
			}
			break;
		case CHARGE:
			if ((int) pos.x < 10 || (int) pos.y < 10 || (int) pos.y > MAX_Y - 10)
			{
				if ((int) pos.x < 10)         setX(10);
				if ((int) pos.y < 10)         setY(10);
				if ((int) pos.y > MAX_Y - 10) setY(MAX_Y - 10);
				// Go back to initial position
				m_speed.x *= -1;
				m_speed.y *= -1;
			}
			else if ((int) pos.x > MAX_X)
			{
				setX(MAX_X);
				m_state = LURK;
				m_speed = {0.f, 120.f};
			}
			break;
	}
	move(m_speed.x * frametime, m_speed.y * frametime);
	updateDamageFlash(frametime);
}
Esempio n. 26
0
Point::Point(QString& str) : QPointF() {
    QStringList list = str.split(" ");
    setX(list[0].toFloat());
    setY(list[1].toFloat());
    segmentIndex = -1;
}
Esempio n. 27
0
void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
{
    // load styles used by all widgets
    for(const OTMLNodePtr& node : styleNode->children()) {
        if(node->tag() == "color")
            setColor(node->value<Color>());
        else if(node->tag() == "x")
            setX(node->value<int>());
        else if(node->tag() == "y")
            setY(node->value<int>());
        else if(node->tag() == "pos")
            setPosition(node->value<Point>());
        else if(node->tag() == "width")
            setWidth(node->value<int>());
        else if(node->tag() == "height")
            setHeight(node->value<int>());
        else if(node->tag() == "rect")
            setRect(node->value<Rect>());
        else if(node->tag() == "background")
            setBackgroundColor(node->value<Color>());
        else if(node->tag() == "background-color")
            setBackgroundColor(node->value<Color>());
        else if(node->tag() == "background-offset-x")
            setBackgroundOffsetX(node->value<int>());
        else if(node->tag() == "background-offset-y")
            setBackgroundOffsetY(node->value<int>());
        else if(node->tag() == "background-offset")
            setBackgroundOffset(node->value<Point>());
        else if(node->tag() == "background-width")
            setBackgroundWidth(node->value<int>());
        else if(node->tag() == "background-height")
            setBackgroundHeight(node->value<int>());
        else if(node->tag() == "background-size")
            setBackgroundSize(node->value<Size>());
        else if(node->tag() == "background-rect")
            setBackgroundRect(node->value<Rect>());
        else if(node->tag() == "icon")
            setIcon(stdext::resolve_path(node->value(), node->source()));
        else if(node->tag() == "icon-source")
            setIcon(stdext::resolve_path(node->value(), node->source()));
        else if(node->tag() == "icon-color")
            setIconColor(node->value<Color>());
        else if(node->tag() == "icon-offset-x")
            setIconOffsetX(node->value<int>());
        else if(node->tag() == "icon-offset-y")
            setIconOffsetY(node->value<int>());
        else if(node->tag() == "icon-offset")
            setIconOffset(node->value<Point>());
        else if(node->tag() == "icon-width")
            setIconWidth(node->value<int>());
        else if(node->tag() == "icon-height")
            setIconHeight(node->value<int>());
        else if(node->tag() == "icon-size")
            setIconSize(node->value<Size>());
        else if(node->tag() == "icon-rect")
            setIconRect(node->value<Rect>());
        else if(node->tag() == "opacity")
            setOpacity(node->value<float>());
        else if(node->tag() == "enabled")
            setEnabled(node->value<bool>());
        else if(node->tag() == "visible")
            setVisible(node->value<bool>());
        else if(node->tag() == "checked")
            setChecked(node->value<bool>());
        else if(node->tag() == "dragable")
            setChecked(node->value<bool>());
        else if(node->tag() == "on")
            setOn(node->value<bool>());
        else if(node->tag() == "focusable")
            setFocusable(node->value<bool>());
        else if(node->tag() == "phantom")
            setPhantom(node->value<bool>());
        else if(node->tag() == "size")
            setSize(node->value<Size>());
        else if(node->tag() == "fixed-size")
            setFixedSize(node->value<bool>());
        else if(node->tag() == "clipping")
            setClipping(node->value<bool>());
        else if(node->tag() == "border") {
            auto split = stdext::split(node->value(), " ");
            if(split.size() == 2) {
                setBorderWidth(stdext::safe_cast<int>(split[0]));
                setBorderColor(stdext::safe_cast<Color>(split[1]));
            } else
                throw OTMLException(node, "border param must have its width followed by its color");
        }
        else if(node->tag() == "border-width")
            setBorderWidth(node->value<int>());
        else if(node->tag() == "border-width-top")
            setBorderWidthTop(node->value<int>());
        else if(node->tag() == "border-width-right")
            setBorderWidthRight(node->value<int>());
        else if(node->tag() == "border-width-bottom")
            setBorderWidthBottom(node->value<int>());
        else if(node->tag() == "border-width-left")
            setBorderWidthLeft(node->value<int>());
        else if(node->tag() == "border-color")
            setBorderColor(node->value<Color>());
        else if(node->tag() == "border-color-top")
            setBorderColorTop(node->value<Color>());
        else if(node->tag() == "border-color-right")
            setBorderColorRight(node->value<Color>());
        else if(node->tag() == "border-color-bottom")
            setBorderColorBottom(node->value<Color>());
        else if(node->tag() == "border-color-left")
            setBorderColorLeft(node->value<Color>());
        else if(node->tag() == "margin-top")
            setMarginTop(node->value<int>());
        else if(node->tag() == "margin-right")
            setMarginRight(node->value<int>());
        else if(node->tag() == "margin-bottom")
            setMarginBottom(node->value<int>());
        else if(node->tag() == "margin-left")
            setMarginLeft(node->value<int>());
        else if(node->tag() == "margin") {
            std::string marginDesc = node->value();
            std::vector<std::string> split;
            boost::split(split, marginDesc, boost::is_any_of(std::string(" ")));
            if(split.size() == 4) {
                setMarginTop(stdext::safe_cast<int>(split[0]));
                setMarginRight(stdext::safe_cast<int>(split[1]));
                setMarginBottom(stdext::safe_cast<int>(split[2]));
                setMarginLeft(stdext::safe_cast<int>(split[3]));
            } else if(split.size() == 3) {
                int marginTop = stdext::safe_cast<int>(split[0]);
                int marginHorizontal = stdext::safe_cast<int>(split[1]);
                int marginBottom = stdext::safe_cast<int>(split[2]);
                setMarginTop(marginTop);
                setMarginRight(marginHorizontal);
                setMarginBottom(marginBottom);
                setMarginLeft(marginHorizontal);
            } else if(split.size() == 2) {
                int marginVertical = stdext::safe_cast<int>(split[0]);
                int marginHorizontal = stdext::safe_cast<int>(split[1]);
                setMarginTop(marginVertical);
                setMarginRight(marginHorizontal);
                setMarginBottom(marginVertical);
                setMarginLeft(marginHorizontal);
            } else if(split.size() == 1) {
                int margin = stdext::safe_cast<int>(split[0]);
                setMarginTop(margin);
                setMarginRight(margin);
                setMarginBottom(margin);
                setMarginLeft(margin);
            }
        }
        else if(node->tag() == "padding-top")
            setPaddingTop(node->value<int>());
        else if(node->tag() == "padding-right")
            setPaddingRight(node->value<int>());
        else if(node->tag() == "padding-bottom")
            setPaddingBottom(node->value<int>());
        else if(node->tag() == "padding-left")
            setPaddingLeft(node->value<int>());
        else if(node->tag() == "padding") {
            std::string paddingDesc = node->value();
            std::vector<std::string> split;
            boost::split(split, paddingDesc, boost::is_any_of(std::string(" ")));
            if(split.size() == 4) {
                setPaddingTop(stdext::safe_cast<int>(split[0]));
                setPaddingRight(stdext::safe_cast<int>(split[1]));
                setPaddingBottom(stdext::safe_cast<int>(split[2]));
                setPaddingLeft(stdext::safe_cast<int>(split[3]));
            } else if(split.size() == 3) {
                int paddingTop = stdext::safe_cast<int>(split[0]);
                int paddingHorizontal = stdext::safe_cast<int>(split[1]);
                int paddingBottom = stdext::safe_cast<int>(split[2]);
                setPaddingTop(paddingTop);
                setPaddingRight(paddingHorizontal);
                setPaddingBottom(paddingBottom);
                setPaddingLeft(paddingHorizontal);
            } else if(split.size() == 2) {
                int paddingVertical = stdext::safe_cast<int>(split[0]);
                int paddingHorizontal = stdext::safe_cast<int>(split[1]);
                setPaddingTop(paddingVertical);
                setPaddingRight(paddingHorizontal);
                setPaddingBottom(paddingVertical);
                setPaddingLeft(paddingHorizontal);
            } else if(split.size() == 1) {
                int padding = stdext::safe_cast<int>(split[0]);
                setPaddingTop(padding);
                setPaddingRight(padding);
                setPaddingBottom(padding);
                setPaddingLeft(padding);
            }
        }
        // layouts
        else if(node->tag() == "layout") {
            std::string layoutType;
            if(node->hasValue())
                layoutType = node->value();
            else
                layoutType = node->valueAt<std::string>("type", "");

            if(!layoutType.empty()) {
                UILayoutPtr layout;
                if(layoutType == "horizontalBox")
                    layout = UIHorizontalLayoutPtr(new UIHorizontalLayout(asUIWidget()));
                else if(layoutType == "verticalBox")
                    layout = UIVerticalLayoutPtr(new UIVerticalLayout(asUIWidget()));
                else if(layoutType == "grid")
                    layout = UIGridLayoutPtr(new UIGridLayout(asUIWidget()));
                else if(layoutType == "anchor")
                    layout = UIAnchorLayoutPtr(new UIAnchorLayout(asUIWidget()));
                else
                    throw OTMLException(node, "cannot determine layout type");
                setLayout(layout);
            }

            if(node->hasChildren())
                m_layout->applyStyle(node);
        }
        // anchors
        else if(boost::starts_with(node->tag(), "anchors.")) {
            UIWidgetPtr parent = getParent();
            if(!parent) {
                if(m_firstOnStyle)
                    throw OTMLException(node, "cannot create anchor, there is no parent widget!");
                else
                    continue;
            }

            UIAnchorLayoutPtr anchorLayout = parent->getLayout()->asUIAnchorLayout();
            if(!anchorLayout)
                throw OTMLException(node, "cannot create anchor, the parent widget doesn't use anchor layout!");

            std::string what = node->tag().substr(8);
            if(what == "fill") {
                fill(node->value());
            } else if(what == "centerIn") {
                centerIn(node->value());
            } else {
                Fw::AnchorEdge anchoredEdge = Fw::translateAnchorEdge(what);

                if(node->value() == "none") {
                    removeAnchor(anchoredEdge);
                } else {
                    std::vector<std::string> split = stdext::split(node->value(), ".");
                    if(split.size() != 2)
                        throw OTMLException(node, "invalid anchor description");

                    std::string hookedWidgetId = split[0];
                    Fw::AnchorEdge hookedEdge = Fw::translateAnchorEdge(split[1]);

                    if(anchoredEdge == Fw::AnchorNone)
                        throw OTMLException(node, "invalid anchor edge");

                    if(hookedEdge == Fw::AnchorNone)
                        throw OTMLException(node, "invalid anchor target edge");

                    addAnchor(anchoredEdge, hookedWidgetId, hookedEdge);
                }
            }
            // lua functions
        } else if(boost::starts_with(node->tag(), "@")) {
            // load once
            if(m_firstOnStyle) {
                std::string funcName = node->tag().substr(1);
                std::string funcOrigin = "@" + node->source() + "[" + node->tag() + "]";
                g_lua.loadFunction(node->value(), funcOrigin);
                luaSetField(funcName);
            }
            // lua fields value
        } else if(boost::starts_with(node->tag(), "&")) {
            std::string fieldName = node->tag().substr(1);
            std::string fieldOrigin = "@" + node->source() + "[" + node->tag() + "]";
            g_lua.evaluateExpression(node->value(), fieldOrigin);
            luaSetField(fieldName);
        }
    }
}
void Transform::addToX(int x)
{
	setX(x + getX());

}
Esempio n. 29
0
health::health(int t,int c,int initx,int inity){
	setTotalHealth(t);
	setCurrentHealth(c);
	setX(initx);
	setY(inity);
}
ep_ambipan::ep_ambipan(int nbLoudSpeaker, int baseCartOrPol, double initOffset, double initDtime){
	
	int i, hp;
	
	this->Nout = this->N = ep_clip<int>(nbLoudSpeaker, 2, Nmax);
	
	if (baseCartOrPol >= 1) this->base = 1;
	else this->base = 0;
	
	this->offset = fabs(initOffset);
	if (this->offset <= EPSILON) this->offset = OFFSET;
	
	this->dtime = (int) (initDtime * ep_MSP::get_sr()/1000.);
	if (this->dtime <= 0) this->dtime = 1;
	
	this->P = new float[Nmax];
	this->teta = new float[Nmax];
	this->dist = new float[Nmax];
	this->dP = new float[Nmax];
	this->Pstop = new float[Nmax];
	
	/*********************************************************/
	/*Initialisation des données de la classe. ***************/
	for( hp = this->N-1; hp >= 0; hp--) //Initialisation des P
		this->P[hp] = 0;
	
	this->mute= 0;             //entrées signal non mutées
	this->y   = Ydefaut;       //initialisation de y
	this->phi = Phidefaut;     //initialisation de phi
	
	//Initialisation des angles des haut-parleurs et des rayons,
	for( hp=0; hp<this->N; hp++)
	 {
		this->teta[hp] = (float)( Pi*( .5 + (1 - 2*hp )/(float)this->N) );
		this->dist[hp] = 1;
	 }
	
	/*********************************************************/
	/* Création des tableaux cosinus, cos_teta et sin_teta.  */
	/* pour l'audio.                                         */
	//this->cos_teta = (float*)getbytes( (short)((T_COS+2*this->N)*sizeof(float)) );
	this->cos_teta = new float[(T_COS+2*this->N)];
	this->sin_teta = this->cos_teta+this->N;
	
	//Précalculs des cos et sin des haut-parleurs.
	for( hp=0; hp<this->N; hp++){
		this->cos_teta[hp] = (float)cos( this->teta[hp] );
		this->sin_teta[hp] = (float)sin( this->teta[hp] );
	}
	
	//Remplissage du tableau cosinus,
	this->cosin = this->sin_teta+this->N;
	/*Pour avoir besoin de cos( phi ), on cherche:
	 cos(phi) = 
	 cosin[ (int)( phi*T_COS/360 ))&(((int)T_COS-1) ] */
	for( i=0; i<T_COS; i++) this->cosin[i] = (float)cos( i*2*Pi/T_COS );
	
	/*********************************************************/
	//initialisation de x, X, Y, W et Pn par la méthode recoit x.
	if(this->base) setX(Xdefaut);
	else           setY(Rdefaut);
	
	this->m_output = new double[this->N];
}