Exemple #1
0
void DrawSprite ( const std::string& sheetname, int sheet_x, int sheet_y, vec2 position, vec2 size, float rotation, colour col )
{
	SetShader("Sprite");
	EnableTexturing();
	EnableBlending();
	ClearColour();
	SetColour(col);
	SpriteSheet* sheet;
	SheetMap::iterator iter = spriteSheets.find(sheetname);
	if (iter == spriteSheets.end())
	{
		// load it
		sheet = new SpriteSheet(sheetname);
		spriteSheets[sheetname] = sheet;
	}
	else
	{
		sheet = iter->second;
	}
	Matrices::SetViewMatrix(matrix2x3::Translate(position));
	Matrices::SetModelMatrix(matrix2x3::Identity());
	if (sheet->IsRotational())
	{
		assert(sheet_x == 0);
		assert(sheet_y == 0);
		sheet->DrawRotation(size, rotation);
	}
	else
	{
		glRotatef(RAD2DEG(rotation), 0.0f, 0.0f, 1.0f);
		sheet->Draw(sheet_x, sheet_y, size);
	}
}
Exemple #2
0
void DrawSpriteFrame ( const std::string& sheetname, vec2 position, vec2 size, int index, float rotation, colour col )
{
	SetShader("Sprite");
	EnableTexturing();
	EnableBlending();
	ClearColour();
	SetColour(col);
	SpriteSheet* sheet;
	SheetMap::iterator iter = spriteSheets.find(sheetname);
	if (iter == spriteSheets.end())
	{
		sheet = new SpriteSheet(sheetname);
		spriteSheets[sheetname] = sheet;
	}
	else
	{
		sheet = iter->second;
	}
	Matrices::SetViewMatrix(matrix2x3::Translate(position));
	Matrices::SetModelMatrix(matrix2x3::Identity());
	glRotatef(RAD2DEG(rotation), 0.0f, 0.0f, 1.0f);
	
	int x = index % sheet->SheetTilesX();
	int y = (index - x) / sheet->SheetTilesX();
	sheet->Draw(x, y, size);
}
Exemple #3
0
Sprite::Sprite(SpriteSheet& spriteSheet, std::string spriteKey, float scale) :
	texture_(spriteSheet.texture()),
	source_(spriteSheet.getRegion(spriteKey))
{
	width_ = (int)(source_->w * scale);
	height_ = (int)(source_->h * scale);
}
std::vector<Halley::Path> Halley::SpriteSheetImporter::import(const ImportingAsset& asset, Path dstDir, ProgressReporter reporter, AssetCollector collector)
{
	SpriteSheet sheet;
	Path dstFile = asset.inputFiles[0].name.replaceExtension("");
	sheet.loadJson(gsl::as_bytes(gsl::span<const Byte>(asset.inputFiles.at(0).data)));
	FileSystem::writeFile(dstDir / dstFile, Serializer::toBytes(sheet));
	return { dstFile };
}
Exemple #5
0
SpriteSheet* SpriteSheet::CloneTo( std::string Filename )
{
	SpriteSheet* result = new SpriteSheet( Filename );

	for( int i = 0; i < frames.size(); i++ )
	{
		SpriteSheetRegion* r = frames.at( i );
		result->AddSprite( r->X, r->Y, r->Width, r->Height );
	}

	return result;
}
Exemple #6
0
SpriteSheet* RenderManager::createSpriteSheet(
	int _layer, std::wstring _filename, int _width, int _height, int _delay)
{
	SpriteSheet *isheet = new SpriteSheet( _filename, _width, _height, _delay );
	isheet->setLayer(_layer);

	isheet->m_prev = NULL;
	isheet->m_next = m_rendlist;
	if (m_rendlist)
		m_rendlist->m_prev = isheet;
	m_rendlist = isheet;
	return isheet;
}
SpriteSheet* GerenciadorDeRecursos::carregarSpriteSheet(const string& nome, const string& caminho, int num_animacoes, int num_max_frames)
{
	SpriteSheet* sheet = new SpriteSheet;
	if(sheet->carregar(caminho, num_animacoes, num_max_frames))
	{
		mSpriteSheets.insert(pair<string, SpriteSheet*>(nome, sheet));
	}
	else
	{
		delete sheet;
		sheet = NULL;
	}

	return sheet;
}
std::unique_ptr<Image> SpriteImporter::makeAtlas(const std::vector<BinPackResult>& result, Vector2i origSize, SpriteSheet& spriteSheet)
{
	Vector2i size = shrinkAtlas(result);

	auto image = std::make_unique<Image>(Image::Format::RGBA, size);
	image->clear(0);

	for (auto& packedImg: result) {
		ImageData* img = reinterpret_cast<ImageData*>(packedImg.data);
		image->blitFrom(packedImg.rect.getTopLeft(), *img->img, img->clip, packedImg.rotated);

		const auto borderTL = img->clip.getTopLeft();
		const auto borderBR = img->img->getSize() - img->clip.getSize() - borderTL;

		const auto offset = Vector2f(0.0001f, 0.0001f);

		SpriteSheetEntry entry;
		entry.size = Vector2f(img->clip.getSize());
		entry.rotated = packedImg.rotated;
		entry.pivot = Vector2f(img->pivot - img->clip.getTopLeft()) / entry.size;
		entry.origPivot = img->pivot;
		entry.coords = (Rect4f(Vector2f(packedImg.rect.getTopLeft()) + offset, Vector2f(packedImg.rect.getBottomRight()) + offset)) / Vector2f(size);
		entry.trimBorder = Vector4s(short(borderTL.x), short(borderTL.y), short(borderBR.x), short(borderBR.y));
		entry.slices = img->slices;

		for (auto& filename: img->filenames) {
			spriteSheet.addSprite(filename, entry);
		}
	}

	return image;
}
Exemple #9
0
bool Haste::load(File* file){
	static SpriteSheet ssHaste;
	static bool loaded = false;
	if (!loaded){
		ssHaste = SpriteSheet(Vec2i(1, 1));
		if (!ssHaste.load("haste.png")){
			return false;
		}
		loaded = true;
	}
	m_sprite.setSpriteSheet(&ssHaste);
	m_sprite.loadAnimation(&ssHaste, 0, 0, 1);
	m_duration = 5.0f;
	m_timeRemaining = m_duration;

	return true;
}
Exemple #10
0
vec2 SpriteDimensions ( const std::string& sheetname )
{
	SpriteSheet* sheet;
	SheetMap::iterator iter = spriteSheets.find(sheetname);
	if (iter == spriteSheets.end())
	{
		// load it
		sheet = new SpriteSheet(sheetname);
		spriteSheets[sheetname] = sheet;
	}
	else
	{
		sheet = iter->second;
	}
	assert(sheet);
	return vec2(sheet->TileSizeX(), sheet->TileSizeY());
}
bool Jelly::Load(File* file)
{
	static SpriteSheet mySpriteSheet;
	if (!mySpriteSheet.Load("jelly.png"))
	{
		return false;
	}
	mySpriteSheet.SetNumCells(2, 1);
	m_sprite.SetSpriteSheet(&mySpriteSheet);
	m_sprite.SetMaxCellTime(0.1f);
	m_sprite.SetStartCell(0);
	m_sprite.SetEndCell(1);
	m_sprite.SetPos(Vec2f(ThePlatformManager::Instance()->m_posX, ThePlatformManager::Instance()->m_posY));
	m_sprite.SetVel(Vec2f(-70, 0));
	
	return true;
}
bool BossBullet::Load(File* file)
{
	static SpriteSheet mySpriteSheet;
	if (!mySpriteSheet.Load("bossbullet.png"))
	{
		return false;
	}
	mySpriteSheet.SetNumCells(2, 1);
	m_sprite.SetSpriteSheet(&mySpriteSheet);
    
	m_sprite.SetCurrentCell(0);
    m_sprite.SetStartCell(0);
    m_sprite.SetEndCell(1);
	m_sprite.SetPos(Vec2f(TheBulletManager::Instance()->GetBulletPos().GetX(), TheBulletManager::Instance()->GetBulletPos().GetY() + rand() % 100));
	m_sprite.SetVel(Vec2f(-100, 0));

	return true;
}
Exemple #13
0
Particle::Particle(const AABB2& boundingBox, const Vector2& position, float orientation, float duration, const RGBA& color, const SpriteSheet& m_spriteSheet)
: m_spriteSheet(m_spriteSheet)
, m_animation(m_spriteSheet, duration, AnimMode::ONE_SHOT, 0, m_spriteSheet.GetNumSprites() - 1)
, m_position(position)
, m_orientation(orientation)
, m_boundingBox (boundingBox)
, m_color(color)
{

}
Exemple #14
0
SpriteSheet TexturePacker::createSpriteSheet(SpriteArray& sprites)
{
    SpriteSheet sheet;

    QImage& image = sheet.newImage(2048, 2048);
    QPainter painter(&image);
    QPoint border(1, 1);

    const int baselength = Project::getActiveProject().getImagePath().length() + 1;

    for ( const Sprite& sprite : sprites )
    {
        QImage image(sprite.mName);
        assert(!image.isNull());

        Sprite newSprite;
        newSprite.mName = sprite.mName.right(sprite.mName.length() - baselength);
        newSprite.mCoordinates = sprite.mCoordinates;
        newSprite.mOriginalSize = sprite.mOriginalSize;
        newSprite.mRotated = sprite.mRotated;
        newSprite.translate(border);
        sheet.addSprite(newSprite);

        if ( newSprite.mRotated )
        {
            RotateImagePainter rpainter(painter);
            rpainter.drawImage(newSprite.mCoordinates.topLeft(),
                               90,
                               image.width(),
                               image.height(),
                               newSprite.mCoordinates.width(),
                               newSprite.mCoordinates.height(),
                               image);
        }
        else
        {
            painter.drawImage(newSprite.mCoordinates, image);
        }
    }

    return sheet;
}
    void SpriteAnimationRepository::initialize(std::string filename) {
        LOG(INFO) << "Loading sprite animation repository from " << filename;
        string animationContent = FILESYS.getFileContent(filename);

        string parseError;
        auto json = Json::parse(animationContent, parseError);
        if (!parseError.empty()) {
            LOG(FATAL) << "Error while parsing JSON content from " << filename << ". Error: " << parseError;
        } else {
            for (auto& k : json["spriteSheets"].array_items()) {
                SpriteSheet* sheet = new SpriteSheet();
                sheet->texture = GFXSYS.loadTexture(k["texture"].string_value());
                sheet->autoAdd(k["spriteWidth"].int_value(), k["spriteHeight"].int_value());
                spriteSheets[k["name"].string_value()] = sheet;
            }

            for (auto& k : json["animations"].array_items()) {
                AnimationData* animData = new AnimationData();
                animationData[k["name"].string_value()] = animData;

                animData->frameTimeInMilliseconds = (float) k["frameTimeInMilliseconds"].number_value();
                animData->loopType = animationLoopType(k["loopType"].string_value());

                for (auto& f : k["frames"].array_items()) {
                    string spriteSheetName = f["spriteSheet"].string_value();
                    if (spriteSheets.find(spriteSheetName) == spriteSheets.end())
                        LOG(FATAL) << "Animation " << k["name"].string_value() << " refers to unexistent spritesheet \"" << spriteSheetName << "\"";

                    int index = f["index"].int_value();
                    int indexTo = f["indexTo"].int_value();

                    if (indexTo > index) {
                        for (int i = index; i <= indexTo; i++)
                            animData->frames.push_back(Sprite(spriteSheets[spriteSheetName], i));
                    } else {
                        animData->frames.push_back(Sprite(spriteSheets[spriteSheetName], index));
                    }
                }
            }
        }
    }
SpriteSheet* GerenciadorDeRecursos::carregarSpriteSheet(const string& nome, const string& caminho, int num_animacoes, int num_max_frames, TipoQualidadeEscala qualidade_escala)
{
	if(carregouSpriteSheet(nome))
	{
		uniErro("Recurso '" + nome + "' nao pode ser carregado, pois um SpriteSheet com esse nome ja existe.");
		return NULL;
	}

	SpriteSheet* sheet = new SpriteSheet;
	if(sheet->carregar(caminho, num_animacoes, num_max_frames, qualidade_escala))
	{
		mSpriteSheets.insert(pair<string, SpriteSheet*>(nome, sheet));
	}
	else
	{
		delete sheet;
		sheet = NULL;
	}

	return sheet;
}
Exemple #17
0
bool SceneObject::pointIn(double _x, double _y) 
{
	// Return false if we do not live in the world
	if (!hasComponent("Transform"))
		return false;
	double x = ((TransformComponent*)m_Components["Transform"])->getPositionX();
	double y = ((TransformComponent*)m_Components["Transform"])->getPositionY();
	double width, height;
	
	// Are we visible?
	if (hasComponent("Renderable")) {
		Camera& cam = RenderManager::getCurrentContext()->camera();
		int layer;
		if (((RenderComponent*)m_Components["Renderable"])->hasSprite()) {
			Sprite *spr = ((RenderComponent*)m_Components["Renderable"])->getSprite();
			width = spr->width();
			height = spr->height();
			layer = spr->layer();
		}
		if (((RenderComponent*)m_Components["Renderable"])->hasSpriteSheet()) {
			SpriteSheet *spr = ((RenderComponent*)m_Components["Renderable"])->getSpriteSheet();
			width = spr->width();
			height = spr->height();
			layer = spr->layer();
		}

		CameraTransform ctrans = cam.screenToWorld(width, height, layer);
		CameraTransform ctrans2 = cam.screenToWorld(0.0, 0.0, layer);
		width = ctrans.x - ctrans2.x;
		height = ctrans.y - ctrans2.y;
	}else// If we aren't visible, do we have a shape?
	if (hasComponent("Physics")) {

	}else{
		width = 0.5;
		height = 0.5;
	}
}
void AnimatedSpriteRenderer::DrawSprite(SpriteSheet &sheet, glm::vec2 position, glm::vec2 size, GLfloat rotate, glm::vec3 color, int frame)
{
	// Prepare transformations
	this->shader.Use();
	glm::mat4 model;
	model = glm::translate(model, glm::vec3(position, 0.0f));  // First translate (transformations are: scale happens first, then rotation and then finall translation happens; reversed order)

	model = glm::translate(model, glm::vec3(0.5f * size.x, 0.5f * size.y, 0.0f)); // Move origin of rotation to center of quad
	model = glm::rotate(model, rotate, glm::vec3(0.0f, 0.0f, 1.0f)); // Then rotate
	model = glm::translate(model, glm::vec3(-0.5f * size.x, -0.5f * size.y, 0.0f)); // Move origin back

	model = glm::scale(model, glm::vec3(size, 1.0f)); // Last scale

	this->shader.SetMatrix4("model", model);

	// Render textured quad
	this->shader.SetVector3f("spriteColor", color);

	glActiveTexture(GL_TEXTURE0);

	GLuint VBO;
	GLfloat vertices[] = {
		// Pos      // Tex
		0.0f, 1.0f, sheet.minu[frame], sheet.maxv[frame],
		1.0f, 0.0f, sheet.maxu[frame], sheet.minv[frame],
		0.0f, 0.0f, sheet.minu[frame], sheet.minv[frame],

		0.0f, 1.0f, sheet.minu[frame], sheet.maxv[frame],
		1.0f, 1.0f, sheet.maxu[frame], sheet.maxv[frame],
		1.0f, 0.0f, sheet.maxu[frame], sheet.minv[frame]
	};
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glGenBuffers(1, &VBO);

	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

	sheet.Bind();

	glBindVertexArray(this->quadVAO);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid*)0);

	glDrawArrays(GL_TRIANGLES, 0, 6);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindVertexArray(0);
}
Exemple #19
0
Player::Player(PlatformState& platformState, BoxWorld* world, sf::Vector2f& size, sf::Vector2f& position, ResourceCollection& resource, LightSolver* lightSolver, StatManager& stats)
: Entity(world, size, position)
, mPlatformState(platformState)
, groundCallBack(nullptr)
, leftButton(false)
, rightButton(false)
, downButton(false)
, mResource(resource)
, flashLight(lightSolver->createLight(FLASHLIGHT_SIZE.x, FLASHLIGHT_SIZE.y))
, maskRight(&resource.getTexture("Assets/Shader/mask.png"))
, maskLeft(flipTexture(maskRight))
, activeStreetLight(nullptr)
, collisionFixture(body->GetFixtureList())
, mStats(stats)
, flashLightBody(world->createEntityBody(sf::Vector2f(0.0f, 0.0f), static_cast<sf::Vector2f>(FLASHLIGHT_SIZE), false))
{
	flashLight->setColor(sf::Color(255, 255, 0, 150));
	int group = flashLight->getFilterGroup();
	group |= (1 << 8);
	flashLight->setFilterGroup(group);
	setFilterGroup(getFilterGroup() | (1 << 8));

	setState(PLAYER_STATE::NORMAL);

	/* Walking/run animation */
	auto &walking = mResource.getTexture("Assets/Characters/Stella Left.png");
	sf::Vector2i walkingSize = static_cast<sf::Vector2i>(walking.getSize());
	sf::Vector2i frameSize(256, 256);
	SpriteSheet spritesheet1(frameSize, walkingSize);
	std::vector<sf::IntRect> frames = spritesheet1.getAllFrames();
	mWalking = new Animation(frames,walking);
	
	/* Idle animation */
	auto &idle = mResource.getTexture("Assets/Characters/Stella idle.png");
	sf::Vector2i idleSize = static_cast<sf::Vector2i>(idle.getSize());
	SpriteSheet idleSheet(frameSize,idleSize);
	std::vector<sf::IntRect> idleFrames = idleSheet.getAllFrames();
	mIdle = new Animation(idleFrames,idle);
	
	/* Jump animation */
	auto &jump = mResource.getTexture("Assets/Characters/Stella jump.png");
	sf::Vector2i jumpSize = static_cast<sf::Vector2i>(jump.getSize());
	SpriteSheet jumpSheet(frameSize,jumpSize);
	std::vector<sf::IntRect> jumpFrames = jumpSheet.getAllFrames();
	mJump = new Animation(jumpFrames,jump);

	/* Grab animation */
	auto &grab = mResource.getTexture("Assets/Characters/Stella grab.png");
	sf::Vector2i grabSize = static_cast<sf::Vector2i>(grab.getSize());
	SpriteSheet grabSheet (frameSize, grabSize);
	std::vector<sf::IntRect> grabFrames = grabSheet.getAllFrames();
	mGrab = new Animation(grabFrames,grab);

	/* Fall Animation*/
	auto &fall = mResource.getTexture("Assets/Characters/Stella fall.png");
	sf::Vector2i fallSize = static_cast<sf::Vector2i>(fall.getSize());
	SpriteSheet fallSheet(frameSize, fallSize);
	std::vector<sf::IntRect> fallFrames = jumpSheet.getAllFrames();
	mFall = new Animation(fallFrames,fall);

	/* Hit Animation*/
	auto &hit = mResource.getTexture("Assets/Characters/Stella hit.png");
	sf::Vector2i hitSize = static_cast<sf::Vector2i>(hit.getSize());
	SpriteSheet hitSheet(frameSize, hitSize);
	std::vector<sf::IntRect> hitFrames = hitSheet.getAllFrames();
	mHit = new Animation(hitFrames,hit);

	anime.setAnimation(*mIdle);
	
	updateSpriteOrigin();

	mJumpSound = new sf::Sound;
	mJumpSound->setBuffer(*mResource.getSound("Assets/Sound/Jump.wav"));

	mWalkSound = new sf::Sound;
	mWalkSound->setBuffer(*mResource.getSound("Assets/Sound/Stella_Run_Loop_1.wav"));
	mWalkSound->setVolume(40);

	mHurtSound = new sf::Sound;
	mHurtSound->setBuffer(*mResource.getSound("Assets/Sound/Stella get hurt.wav"));

	setupSensors(position, size);
	body->SetLinearDamping(1.0f);
	/* Set filter for collisions */
	b2Filter filter = collisionFixture->GetFilterData();
	filter.categoryBits = PLAYER;
	//filter.maskBits =ALL, ENEMY_CHASE, ENEMY_ATTACK;
	filter.groupIndex = ALL, ENEMY_CHASE, ENEMY_ATTACK;
	collisionFixture->SetFilterData(filter);
	knockForce = 35;
	toggle = false;
}
void SpriteImporter::import(const ImportingAsset& asset, IAssetCollector& collector)
{
	String atlasName = asset.assetId;
	String spriteSheetName = Path(asset.assetId).replaceExtension("").string();
	std::vector<ImageData> totalFrames;

	Maybe<Metadata> startMeta;

	Maybe<String> palette;

	for (auto& inputFile: asset.inputFiles) {
		auto fileInputId = Path(inputFile.name).dropFront(1);
		const String spriteName = fileInputId.replaceExtension("").string();

		// Meta
		Metadata meta = inputFile.metadata;
		if (!startMeta) {
			startMeta = meta;
		}
		Vector2i pivot;
		pivot.x = meta.getInt("pivotX", 0);
		pivot.y = meta.getInt("pivotY", 0);
		Vector4s slices;
		slices.x = gsl::narrow<short, int>(meta.getInt("slice_left", 0));
		slices.y = gsl::narrow<short, int>(meta.getInt("slice_top", 0));
		slices.z = gsl::narrow<short, int>(meta.getInt("slice_right", 0));
		slices.w = gsl::narrow<short, int>(meta.getInt("slice_bottom", 0));
		bool trim = meta.getBool("trim", true);

		// Palette
		auto thisPalette = meta.getString("palette", "");
		if (palette) {
			if (thisPalette != palette.get()) {
				throw Exception("Incompatible palettes in atlas \"" + atlasName + "\". Previously using \"" + palette.get() + "\", now trying to use \"" + thisPalette + "\"", HalleyExceptions::Tools);
			}
		} else {
			palette = thisPalette;
		}

		// Import image data
		std::vector<ImageData> frames;
		if (inputFile.name.getExtension() == ".ase" || inputFile.name.getExtension() == ".aseprite") {
			// Import Aseprite file
			frames = AsepriteReader::importAseprite(spriteName, gsl::as_bytes(gsl::span<const Byte>(inputFile.data)), trim);
		} else {
			// Bitmap
			auto span = gsl::as_bytes(gsl::span<const Byte>(inputFile.data));
			auto image = std::make_unique<Image>(span, fromString<Image::Format>(meta.getString("format", "undefined")));

			frames.emplace_back();
			auto& imgData = frames.back();
			imgData.clip = trim ? image->getTrimRect() : image->getRect(); // Be careful, make sure this is done before the std::move() below
			imgData.img = std::move(image);
			imgData.duration = 100;
			imgData.filenames.emplace_back(":img:" + fileInputId.toString());
			imgData.frameNumber = 0;
			imgData.sequenceName = "";
		}

		// Update frames with pivot and slices
		for (auto& f: frames) {
			f.pivot = pivot;
			f.slices = slices;
		}

		// Split into a grid
		const Vector2i grid(meta.getInt("tileWidth", 0), meta.getInt("tileHeight", 0));
		if (grid.x > 0 && grid.y > 0) {
			frames = splitImagesInGrid(frames, grid);
		}

		// Write animation
		Animation animation = generateAnimation(spriteName, spriteSheetName, meta.getString("material", "Halley/Sprite"), frames);
		collector.output(spriteName, AssetType::Animation, Serializer::toBytes(animation));

		std::move(frames.begin(), frames.end(), std::back_inserter(totalFrames));
	}

	// Generate atlas + spritesheet
	SpriteSheet spriteSheet;
	auto atlasImage = generateAtlas(atlasName, totalFrames, spriteSheet);
	spriteSheet.setTextureName(atlasName);

	// Image metafile
	auto size = atlasImage->getSize();
	Metadata meta;
	if (startMeta) {
		meta = startMeta.get();
	}
	if (palette) {
		meta.set("palette", palette.get());
	}
	meta.set("width", size.x);
	meta.set("height", size.y);
	meta.set("compression", "raw_image");

	// Write atlas image
	ImportingAsset image;
	image.assetId = atlasName;
	image.assetType = ImportAssetType::Image;
	image.inputFiles.emplace_back(ImportingAssetFile(atlasName, Serializer::toBytes(*atlasImage), meta));
	collector.addAdditionalAsset(std::move(image));

	// Write spritesheet
	collector.output(spriteSheetName, AssetType::SpriteSheet, Serializer::toBytes(spriteSheet));
}
Exemple #21
0
void Entity::Draw(ShaderProgram* program, Matrix& gameMatrix, SpriteSheet& sprite) {
    sprite.Draw(program, gameMatrix, x, y);
}
Exemple #22
0
// TODO: find a cleaner way that this massive mess ?
SpriteSheet* SpriteSheetManager::load(const std::string& textureName)
{
	sf::Texture* t = new sf::Texture();
	if (!t->loadFromFile(textureName))
	{
		// BAD!
	}

	SpriteSheet* s = new SpriteSheet(*t);
	if (textureName == "Castle2.png")
	{

	}
	else if (textureName == "wood_tileset_3.png")
	{
		sf::Sprite* sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(0,0,32,32)); // only grass
		tiles[TileGame::Grass][TileGame::Grass][TileGame::Grass][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(64,0,32,32));// grass top left
		tiles[TileGame::Grass][TileGame::Grass][TileGame::Earth][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(64,32,32,32)); // horizontal separation (grass left)
		tiles[TileGame::Grass][TileGame::Grass][TileGame::Earth][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(64,64,32,32)); // grass bottom left
		tiles[TileGame::Grass][TileGame::Grass][TileGame::Grass][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(96,0,32,32)); // vertical separation (grass top)
		tiles[TileGame::Grass][TileGame::Earth][TileGame::Earth][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(96,32,32,32));// only earth
		tiles[TileGame::Earth][TileGame::Earth][TileGame::Earth][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(96,64,32,32));// vertical separation (grass bottom)
		tiles[TileGame::Earth][TileGame::Grass][TileGame::Grass][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(128,0,32,32));// grass right top
		tiles[TileGame::Grass][TileGame::Earth][TileGame::Grass][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(128,32,32,32));// horizontal separation (grass right)
		tiles[TileGame::Earth][TileGame::Earth][TileGame::Grass][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(128,64,32,32)); // grass bottom right
		tiles[TileGame::Earth][TileGame::Grass][TileGame::Grass][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(256,192,32,32)); // grass bottom left, top right
		tiles[TileGame::Earth][TileGame::Grass][TileGame::Earth][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(160,224,32,32)); // grass top left, bottom right
		tiles[TileGame::Grass][TileGame::Earth][TileGame::Grass][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(192,224,32,32)); // minimum grass bottom right
		tiles[TileGame::Earth][TileGame::Earth][TileGame::Grass][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(224,224,32,32)); // minimum grass bottom left
		tiles[TileGame::Earth][TileGame::Grass][TileGame::Earth][TileGame::Earth] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(192,256,32,32)); // minimum grass top right
		tiles[TileGame::Earth][TileGame::Earth][TileGame::Earth][TileGame::Grass] = sprite;

		sprite = new sf::Sprite(*t, sf::IntRect(224,256,32,32)); // minimum grass top left
		tiles[TileGame::Grass][TileGame::Earth][TileGame::Earth][TileGame::Earth] = sprite;
	}
	else if (textureName == "BODY_male.png")
	{
		Animation* anim = new Animation();
		anim->setSpriteSheet(*t);
		anim->addFrame(sf::IntRect(0,0,64,64));
		s->addAnimation("idleUp",anim);
		anim = new Animation();
		anim->setSpriteSheet(*t);
		anim->addFrame(sf::IntRect(0,64,64,64));
		s->addAnimation("idleLeft",anim);
		anim = new Animation();
		anim->setSpriteSheet(*t);
		anim->addFrame(sf::IntRect(0,128,64,64));
		s->addAnimation("idleDown",anim);
		anim = new Animation();
		anim->setSpriteSheet(*t);
		anim->addFrame(sf::IntRect(0,192,64,64));
		s->addAnimation("idleRight",anim);

		anim = new Animation();
		anim->setSpriteSheet(*t);
		for (int i = 1; i < 8; ++i)
			anim->addFrame(sf::IntRect(i * 64,0,64,64));
		s->addAnimation("walkUp",anim);
		anim = new Animation();
		anim->setSpriteSheet(*t);
		for (int i = 1; i < 8; ++i)
			anim->addFrame(sf::IntRect(i * 64,64,64,64));
		s->addAnimation("walkLeft",anim);
				anim = new Animation();
		anim->setSpriteSheet(*t);
		for (int i = 1; i < 8; ++i)
			anim->addFrame(sf::IntRect(i * 64,128,64,64));
		s->addAnimation("walkDown",anim);
				anim = new Animation();
		anim->setSpriteSheet(*t);
		for (int i = 1; i < 8; ++i)
			anim->addFrame(sf::IntRect(i * 64,192,64,64));
		s->addAnimation("walkRight",anim);
	}
	textures[textureName] = s;
	return s;
}
Exemple #23
0
void TextTestApp::setup()
{
	hideBackground = false;
	activeUserPresent = false;
	// SET UP BLUR STUFF
	// setup our scene Fbo
	mFboScene = gl::Fbo( getWindowWidth(), getWindowHeight() );

	// setup our blur Fbo's, smaller ones will generate a bigger blur
	mFboBlur1 = gl::Fbo(getWindowWidth()/8, getWindowHeight()/8);
	mFboBlur2 = gl::Fbo(getWindowWidth()/8, getWindowHeight()/8);

	
	OutlineParams::getInstance()->init();

	// load and compile the shaders
	try { 
		mShaderBlur = gl::GlslProg( 
			loadFile("../shaders/blur_vert.glsl"),
			loadFile("../shaders/blur_frag.glsl")); 
	} catch(...) {
		console() << "Can't load/compile blur shader" << endl;
		quit();
	}

	try { 
		mShaderPhong = gl::GlslProg( 
			loadFile("../shaders/phong_vert.glsl"),
			loadFile("../shaders/phong_frag.glsl")); 
	} catch(...) {
		console() << "Can't load/compile phong shader" << endl;
		quit();
	}


	mTransform.setToIdentity();

	gestureTracker = GestureTracker::getInstance();

	gl::Texture::Format format;
	format.enableMipmapping(true);

	mCamera.setEyePoint( Vec3f(2.5f, 5.0f, 5.0f) );
	mCamera.setCenterOfInterestPoint( Vec3f(0.0f, 2.0f, 0.0f) );
	mCamera.setPerspective( 60.0f, getWindowAspectRatio(), 1.0f, 1000.0f );

	for (int i=0; i<40; i++)
	{
		CinderClip cinderClip = CinderClip();
		cinderClip.x = -200;
		cinderClip.y = -200;
		repelClips.push_back(cinderClip);

		////
	//	TweenParticle userParticle = TweenParticle(cinderClip.x, cinderClip.y,10,true);
		//userParticles.push_back(userParticle);
	}

	mbackground.setup();
	mbackground.setRepelClips( repelClips ); // I KNOW THEY ON SCREEN

	//load store config
	cinder::XmlTree configXml(ci::app::loadAsset( "shopconfig.xml" ) );
	ShopConfig::getInstance()->parseConfig(configXml);

	ci::gl::Texture bubbleManWaveTexture = cinder::loadImage(ci::app::loadResource(BUBBLEMAN_WAVE));

	mBubbleManWave = new SpriteSheet();
	mBubbleManWave->init(bubbleManWaveTexture, "./spritesheetdata/bubbleman_wave.xml", SpriteSheet::FORMAT_TEXTUREPACKER_GENERIC_XML);

	ci::gl::Texture bubbleManRunTexture = cinder::loadImage(ci::app::loadResource(BUBBLEMAN_RUN));
	mBubbleManRun = new SpriteSheet();
	mBubbleManRun->init(bubbleManRunTexture, "./spritesheetdata/bubbleman_run.xml", SpriteSheet::FORMAT_TEXTUREPACKER_GENERIC_XML);
	
	TextureGlobals::getInstance()->setSpriteSheet(mBubbleManRun,TextureGlobals::SPRITE_BUBBLEMAN_RUN);
	TextureGlobals::getInstance()->setSpriteSheet(mBubbleManWave,TextureGlobals::SPRITE_BUBBLEMAN_WAVE);

	gl::Texture particleTexture0 = loadImage(loadAsset( "ParticleFullON.png" ) ); 
	TextureGlobals::getInstance()->setParticleTexture(particleTexture0,0);

	gl::Texture particleTexture1 = loadImage(loadAsset( "ParticlePatial01.png" ) ); 
	TextureGlobals::getInstance()->setParticleTexture(particleTexture1,1);

	gl::Texture particleTexture2 = loadImage(loadAsset( "ParticlePatial02.png" ) ); 
	TextureGlobals::getInstance()->setParticleTexture(particleTexture2,2);

	gl::Texture particleTexture3 = loadImage(loadAsset( "ParticlePatial03.png" ) ); 
	TextureGlobals::getInstance()->setParticleTexture(particleTexture3,3);

	gl::Texture particleTexture4 = loadImage(loadAsset( "ParticlePatial04.png" ) ); 
	TextureGlobals::getInstance()->setParticleTexture(particleTexture4,4);

	gl::Texture particleTexture5 = loadImage(loadAsset( "ParticlePatial05.png" ) ); 
	TextureGlobals::getInstance()->setParticleTexture(particleTexture5,5);

	gl::Texture particleTexture6 = loadImage(loadAsset( "background-particle.png" ) ); 
	TextureGlobals::getInstance()->setParticleTexture(particleTexture6,6);

	gl::Texture particleTexture7 = loadImage(loadAsset( "ParticleFullONYellow.png" ) ); 
	TextureGlobals::getInstance()->setParticleTexture(particleTexture6,7);


	
	gl::Texture terms1Texture = loadImage(loadAsset( "terms1.png" ) ); 
	TextureGlobals::getInstance()->setParticleTexture(terms1Texture,8);

	
	gl::Texture terms2Texture = loadImage(loadAsset( "terms2.png" ) ); 
	TextureGlobals::getInstance()->setParticleTexture(terms2Texture,9);

	//gl::Texture terms2Texture = loadImage(loadAsset( "terms2.png" ) ); 
	//TextureGlobals::getInstance()->setParticleTexture(particleTexture6,9);

	myFont = FontRenderer();

	fgParticles.setup( 100 );
	fgParticles.setRepelClips(repelClips);

	// TO VIEW ACTIVE SCENE
	//currentScene = new ActiveScene1();
	//currentScene->getSignal()->connect( boost::bind(&TextTestApp::onPassiveSceneComplete, this, ::_1 ));
	//currentScene->setup( myFont, iconFactory, fgParticles );

	currentScene = new PassiveScene1();
	currentScene->getSignal()->connect( boost::bind(&TextTestApp::onPassiveSceneComplete, this ));
	currentScene->setup( myFont, iconFactory, fgParticles, mbackground.gridLayer1 );

	iconFactory.init();
	
	bgAnimationTimer = Timer();
	significantInteractionTimer = Timer();	
	setupSkeletonTracker();
}