Example #1
0
cxAtlas *cxAtlas::SetCoords(const cxArray *coords,const cxFrames *frames)
{
    CX_ASSERT(!Size().IsZero(), "size not set");
    cxInt size = frames->Num();
    SetCapacity(size);
    const cxInt *map = frames->Map();
    for(cxInt i = 0;i < size;i++){
        cxInt mapIdx = map[i];
        CX_ASSERT(mapIdx < coords->Size(), "map idx error");
        //get map tex
        cxTexCoord *coord = coords->At(mapIdx)->To<cxTexCoord>();
        if(coord->IsEmpty()){
            continue;
        }
        //trimmed box
        cxBoxPoint3F bp = coord->Trimmed(BoxPoint(), Size(), FlipX(), FlipY());
        if(bp.Size().IsZero()){
            continue;
        }
        //add render
        cxBoxRender &render = renders.Inc();
        render.SetVertices(bp);
        render.SetColor(Color());
        //get coord box
        const cxBoxCoord2F &tbox = coord->BoxCoord(Pixel(), FlipX(), FlipY());
        render.SetCoords(tbox);
    }
    return this;
}
Example #2
0
void SHero::DrawIt() {
	if(GetPosition().y>480) SetPosition(GetPosition().x,-24);
	if(sf::Keyboard::IsKeyPressed(sf::Keyboard::LShift)) power=1.0F;
	else power=3.0F;

	if(sf::Keyboard::IsKeyPressed(sf::Keyboard::A)) {
		FlipX(true);
		xSpeed=-power;
	}
	else if(sf::Keyboard::IsKeyPressed(sf::Keyboard::D)) {
		FlipX(false);
		xSpeed=power;
	}
	else xSpeed=0;

	if(Collide(GetPosition().x,GetPosition().y+1)) {
		ySpeed=0;
		if(sf::Keyboard::IsKeyPressed(sf::Keyboard::W)) ySpeed-=jumpPower;
	}
	else ySpeed+=gravity;

	AdjustXPosition();
	AdjustYPosition();

	float oldx=GetPosition().x;
	float oldy=GetPosition().y;
	Move(SGame::GetInstance().camera_x,SGame::GetInstance().camera_y);
	SGame::GetInstance().Draw(*this);
	SetPosition(oldx,oldy);
}
Example #3
0
cxAtlas *cxAtlas::SetCoords(const cxArray *coords)
{
    cxInt size = coords->Size();
    SetCapacity(size);
    for(cxInt i = 0;i < size;i++){
        cxBoxRender &render = renders.Inc();
        cxTexCoord *coord = coords->At(i)->To<cxTexCoord>();
        cxBoxPoint3F bp = coord->Trimmed(BoxPoint(), Size(), FlipX(), FlipY());
        const cxBoxCoord2F &tbox = coord->BoxCoord(Pixel(), FlipX(), FlipY());
        render.SetVertices(bp);
        render.SetColor(Color());
        render.SetCoords(tbox);
    }
    return this;
}
Example #4
0
void Player::Turn(bool left, bool right){

    if(left&&!right){
        m_moving=true;
        m_direction=GAUCHE;
        m_velx=-100;
    }
    else if(!left&&right){
        m_moving=true;
        m_direction=DROITE;
        m_velx=100;
    }
    else{
        m_moving=false;
        m_velx*=0.8;
    }
    FlipX(m_direction);
}
Example #5
0
void TransForm(POS *P, int Np, TRANS *T, ARGS *A, int Nc)
{
	int i;
	for (i=0;i<Nc;i++)
	{
		switch (T[i])
		{
			case MOVE:
				Move(P, Np, A[i].P0);
				break;
			case ROT:
				Rotate(P, Np, A[i].P0, A[i].f);
				break;
			case FLIPY:
				FlipY(P, Np);
				break;
			case FLIPX:
				FlipX(P, Np);
				break;
			case SCALE:
				Scale(P, Np, A[i].f);
				break;	
			case SCALEX:
				ScaleX(P, Np, A[i].f);
				break;	
			case SCALEY:
				ScaleY(P, Np, A[i].f);
				break;	
			case BB:
				MoveBB(P, Np, A[i].P0, A[i].P1);
				break;	
			case BBFIXR:
				MoveBBFixR(P, Np, A[i].P0, A[i].P1);
				break;			
		}
	
	}
}
Example #6
0
bool
HdrImage::Load(const char* fn)
{
	mFlipX = false;
	mFlipY = false;

	FILE* fp = fopen(fn, "rb");
	if (!fp) {
		setSize(16, 16);
		Clear();
		return false;
	}

	char buf[128];

	fgets(buf, sizeof(buf), fp);
	if (strcmp(buf, "#?RADIANCE\n") != 0) {
		fclose(fp);
		setSize(16, 16);
		Clear();
		return false;
	}
	while (!feof(fp)) {
		fgets(buf, sizeof(buf), fp);
		if (strcmp(buf, "\n") == 0) {
			break;
		}

		if (buf[0] != '#') {
			if (char* nameEnd = strchr(buf, '=')) {
				*nameEnd++ = '\0';
				size_t valLen = strlen(nameEnd);
				if (nameEnd[valLen-1] == '\n') {
					nameEnd[valLen-1] = '\0';
				}
				setProperty(buf, strdup(nameEnd));
			}
		}
	}

	char flip[2];
	char dim[2];
	int size[2];
	fgets(buf, sizeof(buf), fp);
	sscanf(buf, "%c%c %d %c%c %d", &flip[0], &dim[0], &size[0], &flip[1], &dim[1], &size[1]);

	int width = 0;
	int height = 0;
	bool flipX = false;
	bool flipY = false;
	for (int i = 0; i < 2; i++) {
		switch(dim[i]) {
		case 'X':
		case 'x':
			width = size[i];
			flipX = (flip[i]=='-');
			break;
		case 'Y':
		case 'y':
			height = size[i];
			flipY = (flip[i]=='-');
			break;
		}
	}

	if (width <= 0  || height <= 0) {
		fclose(fp);
		setSize(16, 16);
		Clear();
		return false;
	} else {
		setSize(width, height);
		const bool result = ReadDataRLE(fp, (float*)mData, mWidth, mHeight);
		fclose(fp);
		if (result) {
			if (flipX && flipY) {
				FlipXY();
			} else if (flipY) {
				FlipY();
			} else if (flipX) {
				FlipX();
			}
		}
		return result;
	}
}
Example #7
0
void Anim_Sprite::set_flipX(bool flip)
{
	FlipX(flip);
	Xflipped=flip;
}