void onExit(Scene::Enum) override { RENDERING(textToReadContainer)->show = false; TEXT(textToRead)->show = false; for (int i=0; i<3; i++) { TEXT(boutonText[i])->show = false; RENDERING(boutonContainer[i])->show = false; BUTTON(boutonContainer[i])->enabled = false; } }
void onExit(Scene::Enum) override { for (int i=0; i<Text::Count; i++) { TEXT(texts[i])->show = false; } for (int i=0; i<Button::Count; i++) { RENDERING(buttons[i])->show = BUTTON(buttons[i])->enabled = false; } for (int i=0; i<Image::Count; i++) { RENDERING(images[i])->show = false; } }
void onEnter(Scene::Enum) override { Entity menufg = theEntityManager.getEntityByName(HASH("mainmenu/foreground", 0x0)); Entity menubg = theEntityManager.getEntityByName(HASH("mainmenu/background", 0x0)); RENDERING(menubg)->show = RENDERING(menufg)->show = true; RENDERING(textToReadContainer)->show = true; TEXT(textToRead)->show = true; for (int i=0; i<3; i++) { RENDERING(boutonContainer[i])->show = true; TEXT(boutonText[i])->show = true; BUTTON(boutonContainer[i])->enabled = true; } }
void GameModeManager::Enter() { PROFILE("GameModeManager", "Enter", BeginEvent); RENDERING(herisson)->show = true; RENDERING(herisson)->color.a = 1; RENDERING(branch)->show = true; SCROLLING(decor2nd)->show = true; SCROLLING(decor1er)->show = true; LoadHerissonTexture(bonus+1); uiHelper.show(); theHeriswapGridSystem.ShowAll(true); TRANSFORM(herisson)->position.x = initialHerissonPosition(herisson); PROFILE("GameModeManager", "Enter", EndEvent); }
void ScrollingSystem::initScrolling(Entity e, ScrollingComponent* sc) { ScrollingElement se; TransformationComponent* ptc = TRANSFORM(e); for (int i=0; i<2; i++) { se.e[i] = theEntityManager.CreateEntity(HASH("scroll/e", 0x4ab48dfd)); ADD_COMPONENT(se.e[i], Transformation); ADD_COMPONENT(se.e[i], Rendering); ADD_COMPONENT(se.e[i], Anchor); TRANSFORM(se.e[i])->size = sc->displaySize; auto* tc = ANCHOR(se.e[i]); tc->parent = e; tc->position = -glm::vec2(sc->direction.x * ptc->size.x, sc->direction.y * ptc->size.y) * (float)i; tc->z = i * 0.001f; RenderingComponent* rc = RENDERING(se.e[i]); se.imageIndex[i] = i % sc->images.size(); rc->texture = sc->images[se.imageIndex[i]]; // rc->color = debugColors[se.imageIndex[i]]; se.hasBeenVisible[i] = false; rc->flags = sc->renderingFlags; } elements[e] = se; }
void GameModeManager::toggleDebugDisplay() { _debug = !_debug; for(int i=0; i<8; i++) { RENDERING(debugEntities[2*i])->show = _debug; TEXT(debugEntities[2*i+1])->show = _debug; } }
void GameModeManager::TogglePauseDisplay(bool paused) { theHeriswapGridSystem.ShowAll(!paused); //show levelbig score BUTTON(uiHelper.pauseButton)->enabled = !paused; RENDERING(uiHelper.pauseButton)->show = !paused; }
void GameModeManager::showGameDecor(bool onlyBg) { SCROLLING(decor2nd)->show = true; SCROLLING(decor1er)->show = true; RENDERING(herisson)->show = !onlyBg; RENDERING(branch)->show = !onlyBg; if (onlyBg) uiHelper.hide(); else uiHelper.show(); // delete leaves for (unsigned int az=0;az<branchLeaves.size();az++) { RENDERING(branchLeaves[az].e)->show = !onlyBg; } }
void GameModeManager::Exit() { RENDERING(herisson)->show = false; RENDERING(branch)->show = false; SCROLLING(decor2nd)->show = false; SCROLLING(decor1er)->show = false; uiHelper.game->stopInGameMusics(); uiHelper.hide(); // delete leaves for (unsigned int az=0;az<branchLeaves.size();az++) { theEntityManager.DeleteEntity(branchLeaves[az].e); } branchLeaves.clear(); theHeriswapGridSystem.DeleteAll(); PROFILE("GameModeManager", "Exit", InstantEvent); }
Entity GameModeManager::createAndAddLeave(int type, const glm::vec2& position, float rotation) { Entity e = theEntityManager.CreateEntity(HASH("branch/leave", 0x6ac1ed8f)); ADD_COMPONENT(e, Transformation); ADD_COMPONENT(e, Rendering); ADD_COMPONENT(e, Twitch); RENDERING(e)->texture = theRenderingSystem.loadTextureFile(HeriswapGame::cellTypeToTextureNameAndRotation(type, 0)); RENDERING(e)->show = true; RENDERING(e)->flags = RenderingFlags::NonOpaque; TRANSFORM(e)->size = HeriswapGame::CellSize(8, type) * HeriswapGame::CellContentScale(); TRANSFORM(e)->position = position; TRANSFORM(e)->rotation = rotation; TRANSFORM(e)->z = glm::lerp(DL_LeafMin, DL_LeafMax, glm::linearRand(0.f, 1.f)); return e; }
void PrivateData::Setup() { soundButton = theEntityManager.CreateEntityFromTemplate("general/soundButton"); if (storageAPI->isOption("sound", "on")) RENDERING(soundButton)->texture = theRenderingSystem.loadTextureFile("sound_on"); else RENDERING(soundButton)->texture = theRenderingSystem.loadTextureFile("sound_off"); for (int i=0; i<3; ++i) { Entity e = theEntityManager.CreateEntityFromTemplate("general/cloud"); theBackgroundSystem.initCloud(e, i); } for(auto it : mode2Manager) it.second->Setup(); menu = theEntityManager.CreateEntityFromTemplate("music/menuTrack"); inGameMusic.masterTrack = theEntityManager.CreateEntityFromTemplate("music/masterTrack"); for (int i=0; i<3; i++) { std::stringstream a; a << "" << "secondaryTracks_" << i; inGameMusic.secondaryTracks[i] = theEntityManager.CreateEntityFromTemplate("music/secondaryTrack"); MUSIC(inGameMusic.secondaryTracks[i])->master = MUSIC(inGameMusic.masterTrack); } inGameMusic.accessoryTrack = theEntityManager.CreateEntityFromTemplate("music/accessoryTrack"); MUSIC(inGameMusic.accessoryTrack)->master = MUSIC(inGameMusic.masterTrack); inGameMusic.stressTrack = theEntityManager.CreateEntityFromTemplate("music/stressTrack"); MUSIC(inGameMusic.stressTrack)->master = MUSIC(inGameMusic.masterTrack); const float MusicFadeOut = 1; theMusicSystem.forEachECDo([&MusicFadeOut] (Entity, MusicComponent *mc) -> void { mc->fadeOut = MusicFadeOut; }); (static_cast<NormalGameModeManager*> (mode2Manager[Normal]))->stressTrack = inGameMusic.stressTrack; // PauseStateManager* pause = static_cast<PauseStateManager*> (state2Manager[Pause]); // pause->helpMgr = static_cast<HelpStateManager*> (state2Manager[Help]); // static_cast<ModeMenuStateManager*>(state2Manager[ModeMenu])->helpMgr = pause->helpMgr; }
void ScrollingSystem::DoUpdate(float dt) { FOR_EACH_ENTITY_COMPONENT(Scrolling, a, sc) EltIt iter = elements.find(a); if (iter == elements.end()) { if ( glm::abs(glm::length(sc->direction) - 1) <= 0.001) { initScrolling(a, sc); iter = elements.find(a); } continue; } if (!sc->show) { ScrollingElement& se = iter->second; for (int i=0; i<2; i++) { RENDERING(se.e[i])->show = false; } continue; } LOGF_IF(sc->speed < 0, "Scrolling component '" << sc << "' has a speed < 0"); ScrollingElement& se = iter->second; for (int i=0; i<2; i++) { RENDERING(se.e[i])->show = true; AnchorComponent* tc = ANCHOR(se.e[i]); tc->position += sc->direction * (sc->speed * dt); bool isVisible = theRenderingSystem.isVisible(se.e[i]); if (!se.hasBeenVisible[i] && isVisible) { se.hasBeenVisible[i] = true; } else if (se.hasBeenVisible[i] && !isVisible) { se.imageIndex[i] = (se.imageIndex[i] + 2) % sc->images.size(); RENDERING(se.e[i])->texture = sc->images[se.imageIndex[i]]; const auto* ptc = TRANSFORM(a); tc->position = ANCHOR(se.e[(i+1)%2])->position - glm::vec2(sc->direction.x * ptc->size.x, sc->direction.y * ptc->size.y); se.hasBeenVisible[i] = false; } } END_FOR_EACH() }
void TouchInputManager::activateDebug(Entity camera) { for (int i=0; i<MAX_TOUCH_POINT; i++) { debugState[i] = theEntityManager.CreateEntity(HASH("debug_input", 0x0)); ADD_COMPONENT(debugState[i], Transformation); ADD_COMPONENT(debugState[i], Anchor); ANCHOR(debugState[i])->parent = camera; ANCHOR(debugState[i])->z = 0.9999f - TRANSFORM(camera)->z; ADD_COMPONENT(debugState[i], Rendering); RENDERING(debugState[i])->show = 1; } }
///----------------------------------------------------------------------------// ///--------------------- UPDATE SECTION ---------------------------------------// ///----------------------------------------------------------------------------// Scene::Enum update(float dt) override { Entity animLogo = e(HASH("logo/logo_anim", 0xed78c546)); if (timeAccum > 0.8 + 0.05 + 0.25 + 0.05) { RENDERING(animLogo)->show = false; return Scene::Menu; } else if (timeAccum > 0.8 + 0.05 + 0.25) { RENDERING(animLogo)->texture = theRenderingSystem.loadTextureFile("soupe_logo2_365_331"); } else if (timeAccum > 0.8 + 0.05) { if (!soundPlayed) { SOUND(animLogo)->sound = theSoundSystem.loadSoundFile("sounds/logo_blink.ogg"); soundPlayed = true; } RENDERING(animLogo)->texture = theRenderingSystem.loadTextureFile("soupe_logo3_365_331"); } else if (timeAccum > 0.8) { RENDERING(animLogo)->show = true; } timeAccum += dt; return Scene::Logo; }
void GameModeManager::Setup() { herisson = theEntityManager.CreateEntityFromTemplate("gamemode/herisson"); branch = theEntityManager.CreateEntityFromTemplate("gamemode/branch"); decor2nd = theEntityManager.CreateEntityFromTemplate("gamemode/decor2nd"); // HACK TRANSFORM(decor2nd)->size.x = PlacementHelper::ScreenSize.x; SCROLLING(decor2nd)->images.push_back(HASH("decor2nd_0", 0x2da4a4da)); SCROLLING(decor2nd)->images.push_back(HASH("decor2nd_3", 0xb93314de)); SCROLLING(decor2nd)->images.push_back(HASH("decor2nd_2", 0xc2edcdae)); SCROLLING(decor2nd)->images.push_back(HASH("decor2nd_1", 0xe8c9a7d4)); decor1er = theEntityManager.CreateEntityFromTemplate("gamemode/decor1er"); TRANSFORM(decor1er)->size.x = PlacementHelper::ScreenSize.x; SCROLLING(decor1er)->images.push_back(HASH("decor1er_0", 0x3a3efebf)); SCROLLING(decor1er)->images.push_back(HASH("decor1er_1", 0x5ba415d2)); SCROLLING(decor1er)->images.push_back(HASH("decor1er_2", 0x68f8263e)); SCROLLING(decor1er)->images.push_back(HASH("decor1er_3", 0x4d7b9af)); fillVec(); uiHelper.build(); #if SAC_DEBUG _debug = false; for(int i=0; i<8; i++) { debugEntities[2*i] = theEntityManager.CreateEntity(HASH("debug/Entities", 0x15df1b7c)); ADD_COMPONENT(debugEntities[2*i], Rendering); ADD_COMPONENT(debugEntities[2*i], Transformation); RENDERING(debugEntities[2*i])->texture = theRenderingSystem.loadTextureFile(HeriswapGame::cellTypeToTextureNameAndRotation(i, 0)); TRANSFORM(debugEntities[2*i])->z = DL_DebugLayer; TRANSFORM(debugEntities[2*i])->size = glm::vec2((float)PlacementHelper::GimpWidthToScreen(80)); debugEntities[2*i + 1] = theEntityManager.CreateEntity(HASH("debug/Entities", 0x15df1b7c)); ADD_COMPONENT(debugEntities[2*i + 1], Text); TEXT(debugEntities[2*i + 1])->positioning = TextComponent::CENTER; ADD_COMPONENT(debugEntities[2*i + 1], Transformation); TRANSFORM(debugEntities[2*i + 1])->position = TRANSFORM(debugEntities[2*i])->position; TRANSFORM(debugEntities[2*i+1])->z = DL_DebugLayer + 0.01f; TEXT(debugEntities[2*i + 1])->fontName = HASH("typo", 0x5a18f4a9); TEXT(debugEntities[2*i + 1])->charHeight = PlacementHelper::GimpHeightToScreen(25); } #endif }
static Entity createCell(Feuille& f, bool assignGridPos) { Entity e = theEntityManager.CreateEntityFromTemplate("spawn/cell"); ADD_COMPONENT(e, HeriswapGrid); ADD_COMPONENT(e, Twitch); TRANSFORM(e)->position = HeriswapGame::GridCoordsToPosition(f.X, f.Y, theHeriswapGridSystem.GridSize); TRANSFORM(e)->z = DL_Cell + Random::Float(0.f, 1.f) * 0.001f; RenderingComponent* rc = RENDERING(e); rc->show = true; TRANSFORM(e)->size = glm::vec2(0.f); ADSR(e)->idleValue = HeriswapGame::CellSize(theHeriswapGridSystem.GridSize, f.type).x * HeriswapGame::CellContentScale(); HERISWAPGRID(e)->type = f.type; if (assignGridPos) { HERISWAPGRID(e)->i = f.X; HERISWAPGRID(e)->j = f.Y; } rc->texture = theRenderingSystem.loadTextureFile(HeriswapGame::cellTypeToTextureNameAndRotation(f.type, &TRANSFORM(e)->rotation)); return e; }
void removeEntitiesInCombination() { std::vector<Combinais> c; unsigned int ite = 0; //remove direct combinations but keep combinations to do (give up at 100 try) do { c = theHeriswapGridSystem.LookForCombination(false,true); // change type from cells in combi for(unsigned int i=0; i<c.size(); i++) { int j = Random::Int(0, c[i].points.size()-1); Entity e = theHeriswapGridSystem.GetOnPos(c[i].points[j].x, c[i].points[j].y); int type, iter = 0; do { type = Random::Int(0, theHeriswapGridSystem.Types-1); iter++; } while (theHeriswapGridSystem.GridPosIsInCombination(c[i].points[j].x, c[i].points[j].y, type, 0) && iter < 100); HERISWAPGRID(e)->type = type; RenderingComponent* rc = RENDERING(e); rc->texture = theRenderingSystem.loadTextureFile(HeriswapGame::cellTypeToTextureNameAndRotation(type, &TRANSFORM(e)->rotation)); } ite++; } while((!c.empty() || !theHeriswapGridSystem.StillCombinations()) && ite<100); }
cairo_surface_t * console_render_to_cairo_surface () { uint32_t timer, fast_blink_on, slow_blink_on; int width, height; cairo_surface_t *surf; uint32_t *data; int stride; int tile_j, tile_i, delta_tile_i, delta_tile_j; int map_index; uint32_t index, c; int glyph_bpd, glyph_stride, glyph_width, glyph_height, glyph_xoffset, glyph_yoffset; uint8_t *glyph_bitmap; timer = SDL_GetTicks (); fast_blink_on = (timer / FAST_BLINK_TIME) % 2; slow_blink_on = (timer / SLOW_BLINK_TIME) % 2; width = CONSOLE_COLS; height = CONSOLE_ROWS; surf = xcairo_image_surface_create (CAIRO_FORMAT_ARGB32, width * FIXED8x12_MAXWIDTH, height * FIXED8x12_MAXHEIGHT); data = xcairo_image_surface_get_argb32_data (surf); stride = xcairo_image_surface_get_argb32_stride (surf); xcairo_surface_flush (surf); for (int r = 0; r < height; r++) { for (int c = 0; c < width; c++) { uint32_t cell = cells[r * CONSOLE_COLS + c]; uint16_t rendering = RENDERING (cell); uint16_t codepoint = CODEPOINT (cell); uint16_t fg_color_index = (rendering & COLOR_FG_MASK) >> COLOR_FG_OFFSET; uint16_t bg_color_index = (rendering & COLOR_BG_MASK) >> COLOR_BG_OFFSET; uint16_t intensity_index = (rendering & INTENSITY_MASK) >> INTENSITY_OFFSET; uint16_t polarity = rendering & POLARITY_MASK; uint16_t blink = rendering & BLINK_MASK; uint16_t underline = rendering & UNDERLINE_MASK; uint32_t fg_argb = fg_palette[fg_color_index * CONSOLE_NUM_INTENSITIES + intensity_index]; uint32_t bg_argb = bg_palette[bg_color_index]; // Xor the inverse and blink states to see if we're inverse now. if ((polarity == POLARITY_NEGATIVE) != (((blink == BLINK_FAST) && (fast_blink_on)) || (blink == BLINK_SLOW) && (slow_blink_on))) { uint32_t temp_argb = fg_argb; fg_argb = bg_argb; bg_argb = temp_argb; } /* Swap again if we're the cursor and the cursor is visible */ if (r == row && c == col && cursor_visible) { uint32_t temp_argb = fg_argb; fg_argb = bg_argb; bg_argb = temp_argb; } glyph_bitmap = get_glyph (0, codepoint, &glyph_bpd, &glyph_stride, &glyph_width, &glyph_height, &glyph_xoffset, &glyph_yoffset); for (int j = 0; j < glyph_height; j++) { for (int i = 0; i < glyph_width; i++) { uint32_t pixel_argb; if ((underline == UNDERLINE_SINGLY || underline == UNDERLINE_DOUBLY) && (j == glyph_height - 1)) pixel_argb = fg_argb; else if ((underline == UNDERLINE_DOUBLY) && (j == glyph_height - 2)) pixel_argb = fg_argb; else if (glyph_bitmap && glyph_bitmap[j] & (1 << (glyph_width - i - 1))) pixel_argb = fg_argb; else pixel_argb = bg_argb; data[(r * FIXED8x12_MAXHEIGHT + j) * stride + c * FIXED8x12_MAXWIDTH + i] = pixel_argb; } } xcairo_surface_mark_dirty (surf); } } return surf; }
void TouchInputManager::Update() { if (!camera) { LOGW_EVERY_N(60, "No camera defined -> no input handling"); return; } TransformationComponent* tc = TRANSFORM(camera); const glm::vec2 windowSize(theRenderingSystem.screenW, theRenderingSystem.screenH); glm::vec2 coords; const unsigned pointers = ptr->maxTouchingCount(); for (unsigned i=0; i<pointers; i++) { wasTouching[i] = touching[i]; touching[i] = ptr->isTouching(i, &coords); if (touching[i]) { // convert window coordinates -> world coords lastTouchedPositionScreen[i] = windowToScreen(coords); lastTouchedPosition[i] = windowToWorld(coords, tc); if (!wasTouching[i]) { onTouchPosition[i] = lastTouchedPositionScreen[i]; } } #if !SAC_MOBILE { lastOverPositionScreen[i] = windowToScreen(coords); lastOverPosition[i] = windowToWorld(coords, tc); } #endif // first click condition: was touched + is released if (!touching[i] && wasTouching[i]) { // click is valid if ~no move between on touch and on release event clicked[i] = (glm::distance2(lastTouchedPositionScreen[i], onTouchPosition[i]) < 0.005); if (clicked[i]) { float t = TimeUtil::GetTime(); glm::vec2 pos = lastTouchedPositionScreen[i]; if ((t - lastClickTime[i] < 0.3) && glm::distance2(pos, lastClickPosition[i]) < 0.005) { doubleclicked[i] = true; LOGV(1, "DOUBLE CLICKED("<< i << ") TOO!"); } else { lastClickPosition[i] = pos; doubleclicked[i] = false; LOGV(1, "CLICK(" << i << ") at " << t << ": " << pos); } lastClickTime[i] = t; } else { doubleclicked[i] = false; } } else { clicked[i] = doubleclicked[i] = false; } if (theReplayManager.isReplayModeEnabled()) { theReplayManager.saveIsTouching(i, touching[i], coords); } } #if SAC_DEBUG if (!debugState[0]) return; const auto* cam = TRANSFORM(ANCHOR(debugState[0])->parent); for (int i=0; i<MAX_TOUCH_POINT; i++) { TRANSFORM(debugState[i])->size = glm::vec2(0.05 * cam->size.y); ANCHOR(debugState[i])->position = AnchorSystem::adjustPositionWithCardinal( cam->size * glm::vec2(-0.5, 0.5) - glm::vec2(0, TRANSFORM(debugState[i])->size.y * i), TRANSFORM(debugState[i])->size, Cardinal::NW); if (touching[i]) RENDERING(debugState[i])->color = Color(0, 1, 0); else RENDERING(debugState[i])->color = Color(1, 0, 0); } #endif }
void PlatformerSystem::DoUpdate(float) { FOR_EACH_ENTITY_COMPONENT(Platformer, entity, pltf) PhysicsComponent* pc = PHYSICS(entity); TransformationComponent* tc = TRANSFORM(entity); glm::vec2 newPosition(tc->position + glm::rotate(pltf->offset, tc->rotation)); // if going down if (pc->linearVelocity.y < 0) { TransformationComponent* tc = TRANSFORM(entity); // did we intersect a platform ? for (std::map<Entity, bool>::const_iterator it=pltf->platforms.begin(); it != pltf->platforms.end(); ++it) { if (!it->second) continue; TransformationComponent* pltfTC = TRANSFORM(it->first); if (IntersectionUtil::lineLine( pltf->previousPosition, newPosition, pltfTC->position + glm::rotate(glm::vec2(pltfTC->size.x * 0.5, pltfTC->size.y * 0.5), pltfTC->rotation), pltfTC->position + glm::rotate(glm::vec2(-pltfTC->size.x * 0.5, pltfTC->size.y * 0.5), pltfTC->rotation), 0)) { // We did intersect... pc->gravity.y = 0; pc->linearVelocity = glm::vec2(0.0f); tc->position.y = pltfTC->position.y + tc->size.y * 0.5; ANIMATION(entity)->name = HASH("jumptorunL2R", 0x9bdaadc5); if (RUNNER(entity)->speed < 0) RENDERING(entity)->flags |= RenderingFlags::MirrorHorizontal; else RENDERING(entity)->flags &= ~(RenderingFlags::MirrorHorizontal); newPosition = tc->position + glm::rotate(pltf->offset, tc->rotation); pltf->onPlatform = it->first; break; } } } else if (pc->linearVelocity.y == 0) { if (pltf->onPlatform) { if (!onPlatform(newPosition, 0.5, pltf->onPlatform)) { bool foundNew = false; for (std::map<Entity, bool>::const_iterator it=pltf->platforms.begin(); it != pltf->platforms.end(); ++it) { if (it->first == pltf->onPlatform || !it->second) continue; if (onPlatform(newPosition, 0.5, it->first)) { pltf->onPlatform = it->first; foundNew = true; } } if (!foundNew) { pltf->onPlatform = 0; pc->gravity.y= -150; LOGV(1, "No on a platform anymore"); } } else if (!pltf->platforms[pltf->onPlatform]) { pltf->onPlatform = 0; pc->gravity.y = -150; } } } else { pltf->onPlatform = 0; } pltf->previousPosition = newPosition; }