예제 #1
0
bool GameLayer::init() {
    
    CCLayer::init();
    
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    
    screenW = size.width;
    screenH = size.height;
    
    createBox2DWorld();
    
    generateBackground();
    
    setTerrain(Terrain::terrainWithWorld(world));
    
    addChild(getTerrain());
    
    setHero(Hero::heroWithWorld(world));
    getTerrain()->addChild(getHero());
    
    setTouchEnabled(true);
    
    tapDown = false;
    
    scheduleUpdate();
    return true;
}
예제 #2
0
GameState::GameState(Tmx::Map const* map, hgeResourceManager* res) {
	env = new Environment(map, res);

	for (Tmx::ObjectGroup const* ob : map->GetObjectGroups()) {
		if (ob->GetName() != "BodyLayer")
			continue;
		for (Tmx::Object const* o : ob->GetObjects()) {
			if (o->GetType() == "Body") {
				addBody(new IBody(o, res));
			} else if (o->GetType() == "Hero") {
				setHero(new IBody(o, res));
			}
		}
	}
	rData.target1 = res->GetTarget("GameStateTarget1");
	if (rData.target1 == 0) {
		std::cerr << "Can't find GameStateTarget1\n";
		exit(0);
	}

	rData.target2 = res->GetTarget("GameStateTarget2");
	if (rData.target2 == 0) {
		std::cerr << "Can't find GameStateTarget2\n";
		exit(0);
	}

	rData.target3 = res->GetTarget("GameStateTarget3");
	if (rData.target3 == 0) {
		std::cerr << "Can't find GameStateTarget3\n";
		exit(0);
	}

	rData.blurShader = res->GetShader("BlurShader");
	if (rData.blurShader == NULL) {
		std::cerr << "Can't find BlurShader\n";
		exit(0);
	}

	rData.kSize = 9;
	rData.dirX[0] = 0.002f, rData.dirX[1] = 0.f;
	rData.dirY[0] = 0.f, rData.dirY[1] = 0.002f;
	rData.sigma = 3.f;
	for (int i = -rData.kSize/2; i <= rData.kSize/2; ++i) {
		rData.kernel[i+rData.kSize/2] = rData.gaussian(rData.dirX[0]*i, rData.sigma);
	}

}
bool GameLayer::init() {
    
    CCLayer::init();
    
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    
    screenW = size.width;
    screenH = size.height;
    
    createBox2DWorld();
    
    //setBackground(CCSprite::spriteWithFile("background.png"));
    //setBackground(generateBackground());
    //getBackground()->setPosition(ccp(screenW/2, screenH/2));
    
    //getBackground()->setScaleX(screenW/getBackground()->getTextureRect().size.width);
    //getBackground()->setScaleY(screenH/getBackground()->getTextureRect().size.height);
    
    //CCLog("sw = %f, sh = %f, bw = %f, bh = %f", screenW, screenH, getBackground()->getTextureRect().size.width, getBackground()->getTextureRect().size.height);
    
    //ccTexParams tp = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};
    //getBackground()->getTexture()->setTexParameters(&tp);
    //addChild(getBackground());
    
    generateBackground();
    
    setTerrain(Terrain::terrainWithWorld(world));
    
    addChild(getTerrain());
    
    setHero(Hero::heroWithWorld(world));
    getTerrain()->addChild(getHero());
    
    setIsTouchEnabled(true);
    
    tapDown = false;
    
    scheduleUpdate();

    return true;
}