Example #1
0
void MainMenuScene::draw(CL_GraphicContext &p_gc)
{
    CL_Draw::fill(p_gc, 0.0f, 0.0f, get_width(), get_height(), CL_Colorf::white);

    const float w = Gfx::Stage::getWidth();
    const float h = w / m_logoSprite.get_width() * m_logoSprite.get_height();

    CL_Rectf spriteRect(0, 0, w, h);
    m_logoSprite.draw(p_gc, spriteRect);
}
//animation is assumed to be a 1 frame tall and {numFrames} wide image
//the planned source frame images are taller, might edit, might not
//TODO credit sprites (from Pokemon Zeta/Omicron) or find orig source
void addAnimation(string animName, sf::Vector2i frameDim, int numFrames, string texFile){

	addTexture(animName, texFile);

	Animation a;
	a.setSpriteSheet(getTexture(animName));

	//add each 'frame' (box) from image to animation
	for (int i = 0; i < numFrames; i++){
		sf::IntRect spriteRect(i*frameDim.x, 0, frameDim.x, frameDim.y);
		a.addFrame(spriteRect);
	}

	animMap.insert(make_pair(animName, a));


}
Example #3
0
TechTree *TechTree::fromJSONObject(const JSONObject &tree,
                                   ImageManager *imgMgr)
{
    TechTree *that = new TechTree();

    JSONObject::const_iterator tree_it;
    for (tree_it = tree.begin(); tree_it != tree.end(); tree_it++) {
        std::string type = wstrToStr(tree_it->first);
        const JSONObject &obj = tree_it->second->AsObject();

        JSONObject::const_iterator it;
        for (it = obj.begin(); it != obj.end(); it++) {
            const std::string &className = wstrToStr(it->first);
            const JSONObject &content = it->second->AsObject();
            const std::wstring &displayName = content.find(L"displayName")->second->AsString();
            const JSONArray &rectVect = content.find(L"spriteRect")->second->AsArray();
            int size = content.find(L"size")->second->AsNumber();

            sf::IntRect spriteRect(rectVect[0]->AsNumber(), rectVect[1]->AsNumber(),
                                   rectVect[2]->AsNumber(), rectVect[3]->AsNumber());

            if (type == "units") {
                that->units[className] = new Unit(className,
                                                  wstrToStr(displayName),
                                                  spriteRect,
                                                  size,
                                                  imgMgr);
            }
            else if (type == "buildings") {
                that->buildings[className] = new Building(className,
                        wstrToStr(displayName),
                        spriteRect,
                        size,
                        imgMgr);
            }
            else
                break;
        }
    }

    log("Successfully loaded the technology tree");
    return that;
}