Ejemplo n.º 1
0
void Player::advance(int phase)
{
    if(!phase) return;

    qreal xa = 0, ya =0;

    if(pSpriteMove->getIsRunning()){
        setSpeedWalking(DEFAULT_SPEED_WALKING *3);
    }else{
        setSpeedWalking(DEFAULT_SPEED_WALKING);
    }

    setAnimDelta(getAnimDelta()+1);
    setAnimTime(getAnimTime()+ getSpeedWalking());
    /* On gère l'animation de déplacement */
    if(getAnimDelta() >= getAnimTime()){
        setAnimFrame(getAnimFrame()+1);
        setAnimDelta(0);

        if(getAnimFrame() > DEFAULT_ANIME_FRAME){
            setAnimFrame(0);
        }
    }

    /*On définie les coordonnées de déplacement
     *par rapport au sens où le player doit aller.*/
    if(pSpriteMove->getIsLookingUp()){
        ya -= getSpeedWalking();
    }else if(pSpriteMove->getIsLookingDown()){
        ya += getSpeedWalking();
    }else if(pSpriteMove->getIsLookingLeft()){
        xa -= getSpeedWalking();
    }else if(pSpriteMove->getIsLookingRight()){
        xa += getSpeedWalking();
    }

    /* On effectue le déplacement du player*/

    if(xa != 0 || ya != 0){
        pSpriteMove->setIsWalking(true);
        move(xa,ya);
    }else{
        pSpriteMove->setIsWalking(false);
    }


    setAnimTime(DEFAULT_ANIME_TIME);
}
Ejemplo n.º 2
0
    void MovieSprite::clear()
    {
        _clear();

        _dirty = false;
        _playing = false;
        _paused = false;
        _ready = false;

        if (_textureUV)
            _textureUV->release();
        _textureUV = 0;

        if (_textureYA)
            _textureYA->release();
        _textureYA = 0;

        _movieRect = Rect(0, 0, 0, 0);

        setAnimFrame(0);

        _initialized = false;

        {
            MutexAutoLock m(_mutex);

            _mtUV.cleanup();
            _mtYA.cleanup();
        }
    }
Ejemplo n.º 3
0
 void Sprite::setColumn(int column, int row)
 {
     const ResAnim* rs = getResAnim();
     if (row == -1)
         row = getRow();
     setAnimFrame(rs, column, row);
 }
    void TreeInspectorPreview::init(spActor item)
    {
        //_item = item;
        STDRenderer r(&_videoCache);
        RenderState rs;
        rs.renderer = &r;
        rs.transform = item->getTransform();
        r.begin(0);
        //r.setTransform(rs.transform);
        item->doRender(rs);
        r.end();
        r.drawBatch();

        setSize(30, 30);

        RectF itemRect = _videoCache._bounds;
        if (itemRect.isEmpty())
        {
            itemRect = item->getDestRect();
            if (itemRect.isEmpty())
                itemRect.setSize(Vector2(10, 4));
        }

        Vector2 ns = fitSize(Vector2(50.0f, 50.0f), itemRect.size);
        float scale = ns.x / itemRect.size.x;

        _cacheTransform.identity();

        _cacheTransform.scale(Vector2(scale, scale));
        _cacheTransform.translate(-itemRect.pos);



        AnimationFrame fr = _tree->_resSystem->getResAnim("checker")->getFrame(0, 0);
        //Point itemSize(30, 30);// = _getItemRect().size;

        RectF srcRect = fr.getSrcRect();
        const Diffuse& df = fr.getDiffuse();
        srcRect.size.x = ns.x / (float)df.base->getWidth();
        srcRect.size.y = ns.y / (float)df.base->getHeight();
        RectF destRect = fr.getDestRect();
        destRect.size = ns;

        AnimationFrame cfr;
        cfr.init(0, df, srcRect, destRect, ns);

        setAnimFrame(cfr);


        /*
        spEventHandler bh = new EventHandler();

        bh->setCallbackEnter(CLOSURE(this, &TreeInspectorPreview::_onEvent));
        bh->setCallbackExit(CLOSURE(this, &TreeInspectorPreview::_onEvent));
        bh->setCallbackPressDown(CLOSURE(this, &TreeInspectorPreview::_onEvent));
        bh->setCallbackPressUp(CLOSURE(this, &TreeInspectorPreview::_onEvent));
        addEventHandler(bh);
        */
    }
Ejemplo n.º 5
0
    void Sprite::setRow(int row, int column)
    {
        const ResAnim* rs = getResAnim();
        if (column == -1)
            column = getColumn();
        setAnimFrame(rs, column, row);

    }
Ejemplo n.º 6
0
	void Sprite::setResAnim(const ResAnim *resanim)
	{
		if (resanim)
		{
			if (resanim->getTotalFrames()) 
				setAnimFrame(resanim);
			else
			{
				AnimationFrame fr;

				fr.init(0, Diffuse(), RectF(0,0,0,0), RectF(0,0,0,0), getSize());
				setAnimFrame(fr);
			}
		}
		else
			setAnimFrame(AnimationFrame());
	}
Ejemplo n.º 7
0
void NcpEnnemy::advance(int phase)
{
    if(!phase) return;

    if(!chasingMode){
        targetInAgressiveZone();
    }else{
        setAnimDelta(getAnimDelta()+1);
        setAnimTime(getAnimTime()+ getSpeedWalking());
        if(getAnimDelta() >= getAnimTime()){
            setAnimFrame(getAnimFrame()+1);
            setAnimDelta(0);

            if(getAnimFrame() > DEFAULT_ANIME_FRAME){
                setAnimFrame(0);
            }
            findPathToTarget();
        }
        setAnimTime(DEFAULT_ANIME_E_TIME);
    }

}
Ejemplo n.º 8
0
    void MovieSprite::initPlayer()
    {
        if (_initialized)
            return;

        _initialized = true;

        _initPlayer();

        Point sz = _bufferSize;
        //sz = Point(nextPOT(sz.x), nextPOT(sz.y));

        Point uvSize = _bufferSize / 2;
        //uvSize = Point(nextPOT(uvSize.x), nextPOT(uvSize.y));
        //uvSize = sz;

        _mtUV.init(uvSize.x, uvSize.y, TF_A8L8);
        _mtUV.fill_zero();
        _textureUV = IVideoDriver::instance->createTexture();
        _textureUV->init(uvSize.x, uvSize.y, _mtUV.getFormat(), false);

        _mtYA.init(sz.x, sz.y, _hasAlphaChannel ? TF_A8L8 : TF_L8);
        _mtYA.fill_zero();
        _textureYA = IVideoDriver::instance->createTexture();
        _textureYA->init(sz.x, sz.y, _mtYA.getFormat(), false);

        if (_hasAlphaChannel)
            setBlendMode(blend_premultiplied_alpha);
        else
            setBlendMode(blend_disabled);

        Diffuse d;
        d.base = _textureYA;
        d.alpha = _textureUV;
        d.premultiplied = true;

        AnimationFrame frame;
        RectF mr = _movieRect.cast<RectF>();

        Vector2 szf = sz.cast<Vector2>();
        RectF tcYA = RectF(mr.pos.div(szf), mr.size.div(szf));
        frame.init(0, d, tcYA, mr, mr.size);

        _yaScale = Vector2(uvSize.x / szf.x, uvSize.y / szf.y);
        _yaScale = Vector2(0.5f, 0.5f);
        _yaScale = Vector2(1, 1);
        Vector2 s = getSize();
        setAnimFrame(frame);
        setSize(s);
    }
Ejemplo n.º 9
0
void Spaceship::nextAnimFrame()
{
  if (_reverse)
  {
    if (_current_frame > 0)
      setAnimFrame(_current_frame - 1);
    else
    {
      _reverse = false;
      setAnimFrame(_current_frame + 1);
    }
  }
  else
  {
    if (_current_frame < 4)
      setAnimFrame(_current_frame + 1);
    else
    {
      _reverse = true;
      setAnimFrame(_current_frame - 1);
    }
  }
}
Ejemplo n.º 10
0
    void Sprite::deserialize(const deserializedata* data)
    {
        inherited::deserialize(data);

        pugi::xml_node node = data->node;
        const char* res = node.attribute("resanim").as_string(0);
        if (res && *res)
        {
            int col = node.attribute("column").as_int(0);
            int row = node.attribute("row").as_int(0);
            AnimationFrame frame = data->factory->getFrame(res, col, row);
            setAnimFrame(frame);
        }

        setFlipped(node.attribute("flipX").as_bool(false), node.attribute("flipY").as_bool(false));
    }
Ejemplo n.º 11
0
 void Sprite::setResAnim(const ResAnim* resanim, int col, int row)
 {
     setAnimFrame(resanim, col, row);
 }
Ejemplo n.º 12
0
 void Sprite::setColumnRow(int column, int row)
 {
     const ResAnim* rs = getResAnim();
     setAnimFrame(rs, column, row);
 }
Ejemplo n.º 13
0
    void Sprite::setRow(int row)
    {
        const ResAnim* rs = getResAnim();
        setAnimFrame(rs, getColumn(), row);

    }
Ejemplo n.º 14
0
 void Sprite::setColumn(int column)
 {
     const ResAnim* rs = getResAnim();
     setAnimFrame(rs, column, getRow());
 }