void PlayScene::removeCoin(cpSpace * space, void * key, void * data) { PlayScene *This = static_cast<PlayScene *>(data); BackgroundLayer *backgroundLayer = This->m_gameLayer->getChildByTag<BackgroundLayer *>(LAYER_BACKGROUND); backgroundLayer->removeObjectByShape(static_cast<cpShape *>(key)); }
void BuyLifeLayer::onCommandBuy130(CCObject * pSender) { SimpleAudioEngine::sharedEngine()->playEffect(g_sSelectedSound); BackgroundLayer* layer = (BackgroundLayer*)GameScene::sharedGameScene()->getBackgroundLayer(); if (layer->subGoldCount(500)) addLifeCount(130); else GameScene::sharedGameScene()->showBuyGoldLayer(); }
bool HeroSprite::onContactBegin(PhysicsContact& contact) { if (mState == STATE_DEAD) { return false; } if (hitTest(contact, TAG_HERO_PHYS_BODY|TAG_GROUND1_PHYS_BODY)) { Vec2 v = getPhysicsBody()->getVelocity(); getPhysicsBody()->setVelocity(Vec2(0, 0)); getPhysicsBody()->resetForces(); getPhysicsBody()->setContactTestBitmask(1<<1); if ((mState == STATE_JUMP1) || (mState == STATE_JUMP2) || (mState == STATE_IDLE)) { if (v.y < -200) stand(); else mState = STATE_STAND; CallFunc *callback = CallFunc::create([&]() { run(); }); auto delay = DelayTime::create(0.05f); auto seq = Sequence::create(delay, callback, nullptr); runAction(seq); } } if (hitTest(contact, TAG_HERO_PHYS_BODY|TAG_BARRIER_PHYS_BODY)) { BackgroundLayer * bg = (BackgroundLayer *)(getScene() ->getChildByName("gamelayer") ->getChildByName("background")); bg->stopMove(); auto scale1 = ScaleTo::create(0.1, 0.9, 0.9); auto scale2 = ScaleTo::create(0.1, 1.0, 1.0); auto seq1 = Sequence::create(scale1, scale2, nullptr); getNodeByTag(contact, TAG_BARRIER_PHYS_BODY)->runAction(seq1); getPhysicsBody()->setContactTestBitmask(1<<1 | 1<<0); dead(); CallFunc *callback = CallFunc::create([]() { Director::getInstance()->replaceScene(GameOverScene::create()); }); auto seq = Sequence::create(DelayTime::create(1), callback, nullptr); runAction(seq); EventCustom event("EVENT_GameOver"); _eventDispatcher->dispatchEvent(&event); } return true; }
BackgroundLayer* BackgroundLayer::create(BgLayerDef* bgLayerDef) { BackgroundLayer* backgroundLayer = new (std::nothrow) BackgroundLayer(); if (backgroundLayer && backgroundLayer->init(bgLayerDef)) { backgroundLayer->autorelease(); return backgroundLayer; } CC_SAFE_DELETE(backgroundLayer); return nullptr; }
void BackgroundLayer::cullEmptyLayers() { BackgroundLayer *next; for (BackgroundLayer *p = this; p; p = next) { next = p->m_next; if (next && !next->isBackgroundImageSet() && !next->isBackgroundXPositionSet() && !next->isBackgroundYPositionSet() && !next->isBackgroundAttachmentSet() && !next->isBackgroundClipSet() && !next->isBackgroundCompositeSet() && !next->isBackgroundOriginSet() && !next->isBackgroundRepeatSet() && !next->isBackgroundSizeSet()) { delete next; p->m_next = 0; break; } } }
void CristalWaveApp::draw() { //glClear(GL_COLOR_BUFFER_BIT); // A virer // -------------------------------------------------------- // Set Camera for background setCameraOrtho(Vec3f(0, 0, 500.0f)); gl::setMatrices(mCamera); // Draw Background mBackground.draw(); // -------------------------------------------------------- // Set Camera for wave //setCameraOrtho(Vec3f(0, 140, 1000.0f)); setCameraOrtho(Vec3f(0, mCameraAltitude, 1000.0f)); gl::setMatrices(mCamera); // -------------------------------------------------------- // Draw Wave mWave.draw(); // -------------------------------------------------------- // Draw particules mParticuleInTheWindManager.drawBatch(); // -------------------------------------------------------- // Fade in effect fadeLayer(1.0f - mOpacity); }
BackgroundLayer *BackgroundLayer::create( std::string baseBackgroundImgFilename, std::string baseMaskImgFilename, int rStart, int rEnd, int cStart, int cEnd) { BackgroundLayer *pRet = new(std::nothrow) BackgroundLayer( baseBackgroundImgFilename, baseMaskImgFilename, rStart, rEnd, cStart, cEnd); if (pRet && pRet->init()) { pRet->autorelease(); return pRet; } else { delete pRet; pRet = nullptr; } return nullptr; }
/** * @brief Map::initScene creates the scene with a margin around the background image. Requires * BackgroundLayer to be initiated * @param tileStep */ void Map::initScene(int tileStep) { int sceneHeight, sceneWidth; BackgroundLayer *bgLayer = dynamic_cast<BackgroundLayer *>( m_Layers->getLayer(LayerCodes::LAYER_BACKGROUND) ); if (tileStep < 5) { tileStep = 5; } sceneHeight = bgLayer->getBackground()->rect().height() + BG_OFFSET * tileStep; sceneWidth = bgLayer->getBackground()->rect().width() + BG_OFFSET * tileStep; initScene(sceneWidth, sceneHeight); }
bool MainScene::init() { CCScene::init(); BackgroundLayer* background = BackgroundLayer::create(); background->setTag(LAYER_BACKGROUND); addChild(background); LandsLayer* lands = LandsLayer::create(); lands->setTag(LAYER_LANDS); addChild(lands); PlayerLayer* playerLayer = PlayerLayer::create(lands); playerLayer->setTag(LAYER_PLAYER); addChild(playerLayer); this->landsLayer = lands; lands->retain(); this->playerLayer = playerLayer; playerLayer->retain(); return true; }
bool LevelReader::readBackgroundLayers(XMLElement* _property, LevelData& data) const { // we've found the property "backgroundlayers" const char* textAttr = nullptr; textAttr = _property->Attribute("value"); if (textAttr == nullptr) { g_logger->logError("LevelReader", "XML file could not be read, no value attribute found (map->properties->property->name=backgroundlayer)."); return false; } std::string backgroundLayerText = textAttr; size_t pos = 0; float distance = 0.f; std::string backgroundLayer = ""; while ((pos = backgroundLayerText.find(",")) != std::string::npos) { distance = static_cast<float>(atof(backgroundLayerText.substr(0, pos).c_str())); backgroundLayerText.erase(0, pos + 1); if ((pos = backgroundLayerText.find(",")) != std::string::npos) { backgroundLayer = backgroundLayerText.substr(0, pos); backgroundLayerText.erase(0, pos + 1); } else { backgroundLayer = backgroundLayerText; backgroundLayerText.clear(); } BackgroundLayer layer; layer.load(backgroundLayer, distance); data.backgroundLayers.push_back(layer); } return true; }
void CristalWaveApp::setup() { float sizeW = getWindowWidth() * 0.5f; float sizeH = getWindowHeight() * 0.5f; float x = 0.0f, z = 0.0f, y = 0.0f; ///////////////////////////////////////////////// int numRows = PARAM_WAVE_NB_ROWS; int gap = PARAM_WAVE_GAP + getWindowWidth() / 2000; int numLines = getWindowWidth() / gap + 1; ///////////////////////////////////////////////// mOpacity = 0.0f; mOffsetCameratH = 60; // Global amplitude // Init BackgroundLayer mBackground.setup(getWindowWidth(), getWindowHeight(), mOffsetCameratH); // Init Wave Model mWave.setup(getWindowWidth(), getWindowHeight(), numRows, numLines, -mOffsetCameratH); // set a random offset Rand rnd; rnd.seed((unsigned long)GetTickCount()); mOffsetTime = rnd.nextFloat(0.0f, 100.0f); // Set the Shader program mFresnelShader.load(); mpWaveShader = &mFresnelShader; mWave.setShader(mpWaveShader); // -------------------------------------------------------- // Set Particule manager int nbParticule = PARAM_NB_PARTICULES; mEmitter.radius = PARAM_EMITTER_RADIUS; mParticuleInTheWindManager.attrPosition = Vec3f::zero(); mParticuleInTheWindManager.attrFactor = PARAM_FORCE_FACTOR; ParticuleManager::PARTICULE_LIFE particule_life; particule_life.minTTL = 0.5f; particule_life.maxTTL = 3.5f; particule_life.minTTH = 1.0f; particule_life.minTTH = 4.0f; mParticuleInTheWindManager.init(nbParticule, particule_life, getWindowWidth()); }
void CristalWaveApp::update() { float elapsedTime = (float)getElapsedSeconds() * 0.1f + mOffsetTime; mOpacity += (mOpacity < 1.0f) ? 0.005f : 0.0f; // -------------------------------------------------------- // Update Background Color topColor; mBackground.update(elapsedTime * 0.2f, topColor); // Change color mpWaveShader->setAmbiantColor(topColor); mpWaveShader->setDiffuseColor(topColor); // -------------------------------------------------------- // Update Wave float speedFactor = (10 - (float)getElapsedSeconds()) * 0.1f; if (speedFactor < 0){ speedFactor = 0.0f; } // Smooth factor speedFactor = speedFactor * speedFactor * (3 - 2 * speedFactor); mWave.update(elapsedTime, speedFactor * 0.25f); // -------------------------------------------------------- // Change light position mpWaveShader->setLightPosition(Vec3f(0.0f, 10.0f, -10.0f + sin(elapsedTime) * 2)); // -------------------------------------------------------- // Update particules system int vId = static_cast<int>(randFloat(mWave.getNumRows() * 0.2f * mWave.getNumLines(), mWave.getNumRows() * 0.8f * mWave.getNumLines())); Vec3f point = mWave.getVertices()[vId].position; // Move Particles Emitter mEmitter.position = point; // Update Particles manager parameters mParticuleInTheWindManager.setRepulsion(true, Vec3f(point.x, point.y, 0.0f)); mParticuleInTheWindManager.setColor(topColor); mParticuleInTheWindManager.update(); // Move Camera mCameraAltitude = cos(elapsedTime * 0.25f) * 300 + 200; }
void BackgroundLayer::fillUnsetProperties() { BackgroundLayer* curr; for (curr = this; curr && curr->isBackgroundImageSet(); curr = curr->next()); if (curr && curr != this) { // We need to fill in the remaining values with the pattern specified. for (BackgroundLayer* pattern = this; curr; curr = curr->next()) { curr->m_image = pattern->m_image; pattern = pattern->next(); if (pattern == curr || !pattern) pattern = this; } } for (curr = this; curr && curr->isBackgroundXPositionSet(); curr = curr->next()); if (curr && curr != this) { // We need to fill in the remaining values with the pattern specified. for (BackgroundLayer* pattern = this; curr; curr = curr->next()) { curr->m_xPosition = pattern->m_xPosition; pattern = pattern->next(); if (pattern == curr || !pattern) pattern = this; } } for (curr = this; curr && curr->isBackgroundYPositionSet(); curr = curr->next()); if (curr && curr != this) { // We need to fill in the remaining values with the pattern specified. for (BackgroundLayer* pattern = this; curr; curr = curr->next()) { curr->m_yPosition = pattern->m_yPosition; pattern = pattern->next(); if (pattern == curr || !pattern) pattern = this; } } for (curr = this; curr && curr->isBackgroundAttachmentSet(); curr = curr->next()); if (curr && curr != this) { // We need to fill in the remaining values with the pattern specified. for (BackgroundLayer* pattern = this; curr; curr = curr->next()) { curr->m_bgAttachment = pattern->m_bgAttachment; pattern = pattern->next(); if (pattern == curr || !pattern) pattern = this; } } for (curr = this; curr && curr->isBackgroundClipSet(); curr = curr->next()); if (curr && curr != this) { // We need to fill in the remaining values with the pattern specified. for (BackgroundLayer* pattern = this; curr; curr = curr->next()) { curr->m_bgClip = pattern->m_bgClip; pattern = pattern->next(); if (pattern == curr || !pattern) pattern = this; } } for (curr = this; curr && curr->isBackgroundOriginSet(); curr = curr->next()); if (curr && curr != this) { // We need to fill in the remaining values with the pattern specified. for (BackgroundLayer* pattern = this; curr; curr = curr->next()) { curr->m_bgOrigin = pattern->m_bgOrigin; pattern = pattern->next(); if (pattern == curr || !pattern) pattern = this; } } for (curr = this; curr && curr->isBackgroundRepeatSet(); curr = curr->next()); if (curr && curr != this) { // We need to fill in the remaining values with the pattern specified. for (BackgroundLayer* pattern = this; curr; curr = curr->next()) { curr->m_bgRepeat = pattern->m_bgRepeat; pattern = pattern->next(); if (pattern == curr || !pattern) pattern = this; } } for (curr = this; curr && curr->isBackgroundSizeSet(); curr = curr->next()); if (curr && curr != this) { // We need to fill in the remaining values with the pattern specified. for (BackgroundLayer* pattern = this; curr; curr = curr->next()) { curr->m_backgroundSize = pattern->m_backgroundSize; pattern = pattern->next(); if (pattern == curr || !pattern) pattern = this; } } }
void MainGameLayer3::addBackground() { BackgroundLayer* bgLayer = BackgroundLayer::create(); addChild(bgLayer, 0, kTagBackground); bgLayer->incrementBlue(3); }
void BuyLifeLayer::addLifeCount(int count) { BackgroundLayer* layer = (BackgroundLayer*)GameScene::sharedGameScene()->getBackgroundLayer(); layer->addLifeCount(count); }
void Renderer::init() { for (int i = 0;i < 10;i++) { effectList[i].duration = 0; } if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Impossible d'initialiser SDL: %s\n", SDL_GetError()); exit(1); } //atexit(SDL_Quit); SDL_Init(SDL_INIT_VIDEO); // Version d'OpenGL SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); // Double Buffer SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); displayWindow = SDL_CreateWindow("Test SDL 2.0", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Renderer::screenWidth, Renderer::screenHeight, SDL_WINDOW_OPENGL); // Création du contexte OpenGL contexteOpenGL = SDL_GL_CreateContext(displayWindow); if(contexteOpenGL == 0) { std::cout << SDL_GetError() << std::endl; //// >> AFFICHE : " the specified window isn't an OpenGL window" SDL_DestroyWindow(displayWindow); SDL_Quit(); exit(-1); //// >> PLANTE ICI : return -1 .. } if (TTF_Init() < 0) { puts("ERROR : unable to initialize font library"); exit(1); } //this->font = TTF_OpenFont( "INSPIRAT.ttf", 28 ); this->font = TTF_OpenFont( "digital display tfb.ttf",28); if (this->font == NULL) { puts("ERROR : unable to load font"); exit(1); } #if SDL_BYTEORDER == SDL_BIG_ENDIAN unsigned int rmask = 0xff000000; unsigned int gmask = 0x00ff0000; unsigned int bmask = 0x0000ff00; unsigned int amask = 0x000000ff; #else unsigned int rmask = 0x000000ff; unsigned int gmask = 0x0000ff00; unsigned int bmask = 0x00ff0000; unsigned int amask = 0xff000000; #endif this->textSurface = SDL_CreateRGBSurface( 0, Renderer::screenWidth, Renderer::screenHeight, 32, rmask, gmask, bmask, amask); OGLRenderableFactory factory = OGLRenderableFactory(); this->game = GameFactory::loadGame("game.xml"); this->game->loadCurrentLevel(&factory); bExit = false; soundManager = new SoundManager(); soundManager->init(); //soundManager->loadMusic("A991Project.ogg"); //soundManager->playCurrentMusic(); //soundManager->loadExplosionSound("Grenade-SoundBible.com-1777900486.wav"); particleManager = new ParticleManager(); /* drawthread = SDL_CreateThread(thread_func, this); if ( drawthread == NULL ) { fprintf(stderr, "Unable to create draw thread: %s\n", SDL_GetError()); exit(0); } */ this->game->setOnDestroyCallback(onDestroyCallback,this); this->game->setOnHitCallback(onHitCallback,this); this->fbAccumulation = NULL; this->fbDrawing = NULL; this->fbHalfRes1 = NULL; this->fbHalfRes2 = NULL; shaderTexturing = new Shader(); shaderTexturing->load_fragment("fragment_texturing.gl"); shaderTexturing->load_vertex("test.gl"); shaderDistort = new Shader(); shaderDistort->load_fragment("fragment_distort.gl"); shaderDistort->load_vertex("test.gl"); shaderGaussianBlurVertical = new Shader(); shaderGaussianBlurVertical->load_fragment("fragment_gaussian_vertical.gl"); shaderGaussianBlurVertical->load_vertex("test02.gl"); shaderGaussianBlurHorizontal = new Shader(); shaderGaussianBlurHorizontal->load_fragment("fragment_gaussian_horizontal.gl"); shaderGaussianBlurHorizontal->load_vertex("test02.gl"); Texture * texture = new Texture(2,2,(unsigned char*)g_texdata); unsigned int * pixels = (unsigned int *)malloc(sizeof(unsigned int)*30*30); TextureGenerator::generateTriangle(10,4,pixels,30,0xffffffff); this->spriteAccumulation = new Sprite(texture,100.f,100.f,0,0,1,1); this->spriteBullet = new Sprite(texture,5.f,5.f,1,1,0,0); this->spriteDrawing = new Sprite(texture,100.f,100.f,0,0,1,1); this->spriteDummy = new Sprite(texture,100.f,100.f,0,0,1,1); this->spriteCovering = new Sprite(texture,Renderer::screenWidth,Renderer::screenHeight,0,0,1,1); this->spriteRectangle = new Sprite(texture,10.f,1.f,0,0,1,1); unsigned int * pixels2 = (unsigned int *)malloc(sizeof(unsigned int)*30*30); TextureGenerator::generateCircle(0,0,pixels2,30,0xffffffff); this->spriteCircle = new Sprite(new Texture(30,30,(unsigned char*)pixels2),10.f,10.f,1,1,0,0); //this->spriteCircle = this->spriteBullet; Texture * textSurfaceTexture = new Texture(Renderer::screenWidth,Renderer::screenHeight,(unsigned char*)this->textSurface->pixels); this->spriteTextSurface = new Sprite(textSurfaceTexture,Renderer::screenWidth,Renderer::screenHeight,0,1,1,0); this->spriteShip = new Sprite(new Texture(30,30,(unsigned char*)pixels),30.f,30.f,1,1,0,0); unsigned int * pixelsgrid = (unsigned int*)malloc(sizeof(unsigned int)* 100 * 100); TextureGenerator::generateGrid(pixelsgrid,100,100,20,0xff0909aa); this->spriteGrid = new Sprite(new Texture(100,100,(unsigned char*)pixelsgrid),100.f,100.f,0,0,1,1); BackgroundLayer * backgroundLayer = new BackgroundLayer(Renderer::screenWidth,Renderer::screenHeight); backgroundLayer->addElement(this->spriteGrid,100,100); this->backgroundManager.addLayer(backgroundLayer); unsigned int * pixelsStarfield = (unsigned int*)calloc(sizeof(unsigned int), 100 * 100); TextureGenerator::generateStarfield(pixelsStarfield,100,100,10); backgroundLayer = new BackgroundLayer(Renderer::screenWidth,Renderer::screenHeight,0.0,-1.5f); backgroundLayer->addElement(new Sprite(new Texture(100,100,(unsigned char*)pixelsStarfield),100.f,100.f,0,0,1,1),100,100); this->backgroundManager.addLayer(backgroundLayer); unsigned int * pixelsStarfield2 = (unsigned int*)calloc(sizeof(unsigned int), 100 * 100); TextureGenerator::generateStarfield(pixelsStarfield2,100,100,10); backgroundLayer = new BackgroundLayer(Renderer::screenWidth,Renderer::screenHeight,0.0,-1.0f); backgroundLayer->addElement(new Sprite(new Texture(100,100,(unsigned char*)pixelsStarfield2),100.f,100.f,0,0,1,1),100,100); this->backgroundManager.addLayer(backgroundLayer); }