Exemple #1
0
/*
 * The ground class constructor
 */
Ground::Ground() : collisionBoxes_(34), collisionBoxes_Loop_(34)
{
    //Randomly initialize the type of the ground
    srand(time(0));
    type_ = (Type)(rand() % 4);

    //Set the initial location of the ground
    setOffsetX(INITIAL_OFFSET_X);
    setOffsetY(INITIAL_OFFSET_Y);

    //Initialize the ground's velocity
    setVelocityX(GROUND_VELOCITY_X);
    setVelocityY(GROUND_VELOCITY_Y);

    //Initialize the width and height of the collision boxes
    for (int i = 0; i < collisionBoxes_.size(); i++)
    {

        collisionBoxes_[i].w = COLLISION_BOX_W[i];
        collisionBoxes_[i].h = COLLISION_BOX_H[i];
    }


    for (int i = 0; i < collisionBoxes_Loop_.size(); i++)
    {

        collisionBoxes_Loop_[i].w = COLLISION_BOX_W[i];
        collisionBoxes_Loop_[i].h = COLLISION_BOX_H[i];
    }

}
Exemple #2
0
/*
 * This is the plane's constructor
 */
Plane::Plane() : collisionBoxes_(7) {
    //Randomly select color of the plane from the start
    srand(time(0));
    color_ = (Color)(rand() % 4);

    //Initialize the motion of the plane
    motion_ = MOTION_Falling;
    //Initialize the frame counter
    frameCounter_ = 0;

    //Initialize the offset x and offset y of the plane
    //The offset x of the plane is constant
    setOffsetX(INITIAL_OFFSET_X);
    setOffsetY(INITIAL_OFFSET_Y);

    //Set the width and height of the plane
    //Width and height are constant
    setSourceWidth(SPRITE_WIDTH);
    setSourceHeight(SPRITE_HEIGHT);

    //Velocity of plane on the x axis is constant and does not change
    setVelocityX(0.0f);
    setVelocityY(0.0f);

    elapseTime_ = 0;

    puffCloud_.setOffsetY(getOffsetY() + 10.0f);


    //Initialize the collision boxes width and height
    for (int i = 0; i < collisionBoxes_.size(); i++) {
        collisionBoxes_[i].w = COLLISION_BOX_W[i];
        collisionBoxes_[i].h = COLLISION_BOX_H[i];
    }
}
Exemple #3
0
	int32_t LuaDrawable::setOffsetY(lua_State *L)
	{
		auto drawable = Lua::getObject<Drawable>(L, 1, LuaType::Drawable);
		auto offsetY = static_cast<float>(Lua::getNumber(L, 2));
		drawable->setOffsetY(offsetY);
		return 0;
	}
Exemple #4
0
Background::Background()
{
    setOffsetX(INITIAL_OFFSET_X);
    setOffsetY(INITIAL_OFFSET_Y);

    setSourceWidth(BACKGROUND_WIDTH);
    setSourceHeight(BACKGROUND_HEIGHT);
}
Exemple #5
0
void Plane::update(int deltaTime, bool gameOver)
{
    //If the game is over continue to make the plane fall
    if (gameOver)
    {

        setVelocityY(getVelocityY() + GRAVITY * (deltaTime/1000.0f));
        setOffsetY(getOffsetY() + getVelocityY());

        //Check if the plane has reach the bottom maximum bounds
        if (getOffsetY() >= SPRITE_MAX_BOTTOM)
        {
            setOffsetY(getOffsetY() - getVelocityY());

        }
    }

    elapseTime_ += deltaTime;
    if (elapseTime_ > FPS)
    {
        frameCounter_++;
        if (frameCounter_ == 3)
        {
            frameCounter_ = 0;
        }
        elapseTime_ = 0;
    }

    //Update the puff cloud
    puffCloud_.setOffsetY(getOffsetY() + 10.0f);
    puffCloud_.update(deltaTime);


    //Shift the collision boxes
    shiftCollisionBoxes();

}
Exemple #6
0
/**
 * Slot for vertical scroll events.
 */
void QG_GraphicView::slotVScrolled(int value) {
    // Scrollbar behaviour tends to change with every Qt version..
    // so let's keep old code in here for now

    //static int running = false;
    //if (!running) {
    //running = true;
    ////RS_DEBUG->print("value y: %d\n", value);
    if (vScrollBar->maximum()==vScrollBar->minimum()) {
        centerOffsetY();
    } else {
        setOffsetY(value);
    }
    //if (isUpdateEnabled()) {
  //  updateGrid();
    redraw();
}
/**
 * Slot for vertical scroll events.
 */
void QG_GraphicView::slotVScrolled(int value) {
    // Scrollbar behaviour tends to change with every Qt version..
    // so let's keep old code in here for now

    //static int running = false;
    //if (!running) {
    //running = true;
//    DEBUG_HEADER();
    RS_DEBUG->print(/*RS_Debug::D_WARNING,*/ "%s %s(): set vertical offset from %d to %d\n", __FILE__, __FUNCTION__, getOffsetY(), value);
    if (vScrollBar->maximum()==vScrollBar->minimum()) {
        centerOffsetY();
    } else {
        setOffsetY(value);
    }
    //if (isUpdateEnabled()) {
  //  updateGrid();
    redraw();
}
int Tiled::Internal::ResizeHelper::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: offsetChanged((*reinterpret_cast< const QPoint(*)>(_a[1]))); break;
        case 1: offsetXChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 2: offsetYChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 3: offsetBoundsChanged((*reinterpret_cast< const QRect(*)>(_a[1]))); break;
        case 4: setOldSize((*reinterpret_cast< const QSize(*)>(_a[1]))); break;
        case 5: setNewSize((*reinterpret_cast< const QSize(*)>(_a[1]))); break;
        case 6: setOffset((*reinterpret_cast< const QPoint(*)>(_a[1]))); break;
        case 7: setOffsetX((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 8: setOffsetY((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 9: setNewWidth((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 10: setNewHeight((*reinterpret_cast< int(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 11;
    }
    return _id;
}
Exemple #9
0
void RS_GraphicView::setOffset(int ox, int oy) {
	//    DEBUG_HEADER
	//    RS_DEBUG->print(/*RS_Debug::D_WARNING, */"set offset from (%d, %d) to (%d, %d)", getOffsetX(), getOffsetY(), ox, oy);
	setOffsetX(ox);
	setOffsetY(oy);
}
Exemple #10
0
void File::_initialize()
{
    if (_initialized) return;
    Dat::Item::_initialize();
    Dat::Item::setPosition(0);

    _version = uint32();
    _framesPerSecond = uint16();
    _actionFrame = uint16();
    _framesPerDirection = uint16();

    uint16_t shiftX[6];
    uint16_t shiftY[6];
    uint32_t dataOffset[6];
    for (unsigned int i = 0; i != 6; ++i) shiftX[i] = uint16();
    for (unsigned int i = 0; i != 6; ++i) shiftY[i] = uint16();
    for (unsigned int i = 0; i != 6; ++i)
    {
        dataOffset[i] = uint32();
        if (i > 0 && dataOffset[i-1] == dataOffset[i])
        {
            continue;
        }

        auto direction = new Direction();
        direction->setDataOffset(dataOffset[i]);
        direction->setShiftX(shiftX[i]);
        direction->setShiftY(shiftY[i]);
        _directions.push_back(direction);
    }

    // for each direction
    for (auto direction : _directions)
    {
        // jump to frames data at frames area
        Dat::Item::setPosition(direction->dataOffset() + 62);

        // read all frames
        for (unsigned i = 0; i != _framesPerDirection; ++i)
        {            
            uint16_t width = uint16();
            uint16_t height = uint16();
            auto frame = new Frame(width, height);

            // Number of pixels for this frame
            // We don't need this, because we already have width*height
            uint32();

            frame->setOffsetX(int16());
            frame->setOffsetY(int16());

            // Pixels data
            for (unsigned y = 0; y != frame->height(); ++y)
            {
                for (unsigned x = 0; x != frame->width(); ++x)
                {
                    frame->setIndex(x, y, uint8());
                }
            }
            direction->frames()->push_back(frame);
        }
    }
}
Exemple #11
0
/*
 * This updates the planes offsets and frame
 *
 * @param input is used to check for player input
 * @param deltaTime is used to update the frame of the plane
 */
void Plane::update(Input* input, int deltaTime)
{

    //std::cout << "Delta is: " << deltaTime << std::endl;
    //If player press the space key then make the plane jump
    if (input->isKeyHit(SDLK_SPACE))
    {
        startJump();
    }

    //If plane is falling
    if (motion_ == MOTION_Falling)
    {
        setVelocityY(getVelocityY() + GRAVITY * (deltaTime/1000.0f));
        setOffsetY(getOffsetY() + getVelocityY());
        //Check if the plane has reach the bottom maximum bounds
        if (getOffsetY() >= SPRITE_MAX_BOTTOM)
        {
            setOffsetY(getOffsetY() - getVelocityY());

        }

    }

    //Else if plane is jumping
    else if (motion_ == MOTION_Jumping)
    {
        jump_.update(deltaTime);

        if (jump_.getJumpTimeRemaining() > 0)
        {
            //Set the velocity
            setVelocityY( getVelocityY() + JUMP_VELOCITY);
            setOffsetY(getOffsetY() - getVelocityY());

            //Check if the plane has reach the top maximum bounds
            if (getOffsetY() <= SPRITE_MAX_TOP) {
                setOffsetY(getOffsetY() + getVelocityY());
                //Stop jumping
                stopJump();
            }
        }
        //Max jump is reach
        else
        {

            stopJump();
        }
    }

    elapseTime_ += deltaTime;
    if (elapseTime_ > FPS)
    {
        frameCounter_++;
        if (frameCounter_ == 3)
        {
            frameCounter_ = 0;
        }
        elapseTime_ = 0;
    }

    //Update the puff cloud
    puffCloud_.setOffsetY(getOffsetY() + 10.0f);
    puffCloud_.update(deltaTime);

    //Shift the collision boxes
    shiftCollisionBoxes();
}