added star highlighting, progress saving
This commit is contained in:
parent
650ef4f460
commit
8b2950f9fb
1
.gitignore
vendored
1
.gitignore
vendored
@ -76,3 +76,4 @@ iOSInjectionProject/
|
||||
*.db
|
||||
*.opendb
|
||||
/proj.android-studio/app/release/
|
||||
assets/levels/user_progress.json
|
@ -26,7 +26,8 @@
|
||||
"paddingLeft": 10,
|
||||
"paddingRight": 10,
|
||||
"itemSpacing": 20,
|
||||
"children" : [{
|
||||
"children" : [
|
||||
{
|
||||
"type": "HorizontalLinearLayout",
|
||||
"name": "row1",
|
||||
"paddingBottom": 15,
|
||||
|
16
assets/shaders/hoverable-button.fragment
Executable file
16
assets/shaders/hoverable-button.fragment
Executable file
@ -0,0 +1,16 @@
|
||||
precision highp float;
|
||||
|
||||
uniform sampler2D Texture;
|
||||
uniform bool Hover;
|
||||
varying vec2 texCoord;
|
||||
varying vec4 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texColor = texture2D(Texture,texCoord).rgba;
|
||||
gl_FragColor = color * texColor.rgba;
|
||||
if (Hover)
|
||||
{
|
||||
gl_FragColor.xyz *= 1.5;
|
||||
}
|
||||
}
|
@ -28,7 +28,6 @@ bool GalaxyMenu::InitGalaxyMenu(std::string config_json, float scale) {
|
||||
boost::property_tree::ptree error_pt;
|
||||
error_pt.put("error", "something goes wrong at InitGalaxyMenu");
|
||||
|
||||
int levelIndex = 1;
|
||||
|
||||
/*..Init Menu..*/
|
||||
BOOST_FOREACH(auto menu_pt, config_pt.get_child("Space", error_pt)) {
|
||||
@ -39,6 +38,9 @@ bool GalaxyMenu::InitGalaxyMenu(std::string config_json, float scale) {
|
||||
galax.texture = menu_pt.second.get<std::string>("texture", "error");
|
||||
galax.position = Eigen::Vector2f(menu_pt.second.get<float>("position.x_coord", 0.0f), menu_pt.second.get<float>("position.y_coord", 0.0f));
|
||||
//boost::property_tree::ptree stars = menu_pt.second.get<boost::property_tree::ptree>("Stars", error_pt);
|
||||
|
||||
int levelStar = 0;
|
||||
|
||||
BOOST_FOREACH(auto stars_pt, menu_pt.second.get_child("Stars", error_pt)) {
|
||||
StarObject star;
|
||||
|
||||
@ -51,17 +53,23 @@ bool GalaxyMenu::InitGalaxyMenu(std::string config_json, float scale) {
|
||||
|
||||
star.position = Eigen::Vector2f(stars_pt.second.get<float>("position.x_coord", 0.0f), stars_pt.second.get<float>("position.y_coord", 0.0f));
|
||||
|
||||
int levelIndex = 0;
|
||||
|
||||
/*..Levels..*/
|
||||
BOOST_FOREACH(auto levels_pt, stars_pt.second.get_child("levels")) {
|
||||
|
||||
std::string levelName = levels_pt.second.get<std::string>("name", "empty");
|
||||
|
||||
std::shared_ptr<TGameLevel> lvl = std::make_shared<TGameLevel>();
|
||||
std::shared_ptr<TGameLevel> lvl = std::make_shared<TGameLevel>(levelStar, levelIndex);
|
||||
lvl->FillWithFile(ST::PathToResources + levelName + ".txt");
|
||||
|
||||
star.selectionMenu.gameLevels.push_back(lvl);
|
||||
|
||||
++levelIndex;
|
||||
}
|
||||
galax.Stars.push_back(star);
|
||||
|
||||
++levelStar;
|
||||
}
|
||||
galaxies.push_back(galax);
|
||||
}
|
||||
@ -203,12 +211,15 @@ void GalaxyMenu::DrawGalaxyMenu() {
|
||||
); // DrawRect
|
||||
|
||||
/*..Draw stars..*/
|
||||
Renderer->PushShader("HoverableButtonShader");
|
||||
if (stars_params.size() >= i) {
|
||||
for (int j = 0; j < stars_params[i].size(); j++) {
|
||||
if (planetHoverIndex == j) {
|
||||
RenderUniform1i("Hover", 1);
|
||||
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList[galaxies[i].Stars[j].textureName]);
|
||||
}
|
||||
else {
|
||||
RenderUniform1i("Hover", 0);
|
||||
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList[galaxies[i].Stars[j].textureName]);
|
||||
}
|
||||
SE::Renderer->DrawRect(
|
||||
@ -223,6 +234,7 @@ void GalaxyMenu::DrawGalaxyMenu() {
|
||||
); // DrawRect
|
||||
}
|
||||
}
|
||||
Renderer->PopShader();
|
||||
|
||||
/*..Draw level selection menu..*/
|
||||
//drawSelectionMenu(starIndex);
|
||||
@ -494,16 +506,32 @@ int GalaxyMenu::negativeV(float val) {
|
||||
}
|
||||
|
||||
int GalaxyMenu::findPlanetByPos(Eigen::Vector2f pos) {
|
||||
for (int i = 0; i < stars_params.size(); i++) {
|
||||
for (int j = 0; j < stars_params[i].size(); j++) {
|
||||
if (pos(0) >= (stars_params[i][j].first(0) - stars_params[i][j].second(0) / 2) && pos(0) <= (stars_params[i][j].first(0) + stars_params[i][j].second(0) / 2)) {
|
||||
if (pos(1) >= (stars_params[i][j].first(1) - stars_params[i][j].second(1) / 2) && pos(1) <= (stars_params[i][j].first(1) + stars_params[i][j].second(1) / 2)) {
|
||||
return j;
|
||||
|
||||
float minimalDistance = std::numeric_limits<float>::max();
|
||||
int index = -1;
|
||||
|
||||
for (int i = 0; i < stars_params.size(); i++)
|
||||
{
|
||||
for (int j = 0; j < stars_params[i].size(); j++)
|
||||
{
|
||||
if (pos(0) >= (stars_params[i][j].first(0) - stars_params[i][j].second(0) / 2) && pos(0) <= (stars_params[i][j].first(0) + stars_params[i][j].second(0) / 2))
|
||||
{
|
||||
if (pos(1) >= (stars_params[i][j].first(1) - stars_params[i][j].second(1) / 2) && pos(1) <= (stars_params[i][j].first(1) + stars_params[i][j].second(1) / 2))
|
||||
{
|
||||
float dx = pos(0) - stars_params[i][j].first(0);
|
||||
float dy = pos(1) - stars_params[i][j].first(1);
|
||||
float distance = dx * dx + dy * dy;
|
||||
|
||||
if (distance < minimalDistance)
|
||||
{
|
||||
minimalDistance = distance;
|
||||
index = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
bool GalaxyMenu::checkMenuBound(Eigen::Vector2f pos) {
|
||||
|
@ -439,8 +439,10 @@ void TBall::Update(size_t dt)
|
||||
//===========================================
|
||||
|
||||
|
||||
TGameLevel::TGameLevel()
|
||||
TGameLevel::TGameLevel(int levelStar, int levelIndex)
|
||||
{
|
||||
this->levelStar = levelStar;
|
||||
this->levelIndex = levelIndex;
|
||||
|
||||
BkgTexture = "";
|
||||
|
||||
@ -463,6 +465,16 @@ TGameLevel::~TGameLevel()
|
||||
{
|
||||
}
|
||||
|
||||
int TGameLevel::getStarIndex()
|
||||
{
|
||||
return levelStar;
|
||||
}
|
||||
|
||||
int TGameLevel::getLevelIndex()
|
||||
{
|
||||
return levelIndex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TGameLevel::ReloadBlockInstansingList(int screenWidth)
|
||||
@ -1319,6 +1331,8 @@ void TGameLevel::Update(size_t dt)
|
||||
|
||||
if (noMoreBlocks && LevelState != CONST_LEVELSTATE_FINISH_FREEZE)
|
||||
{
|
||||
Application->SaveUserProgress(levelStar, levelIndex);
|
||||
|
||||
Application->fireworkEffect(); // Firework start
|
||||
|
||||
Application->OpenNextLevel();
|
||||
|
@ -130,6 +130,9 @@ protected:
|
||||
//std::string LevelScreenTexture;
|
||||
std::string LevelFileName;
|
||||
|
||||
int levelIndex;
|
||||
int levelStar;
|
||||
|
||||
GLuint prerenderedImage;
|
||||
|
||||
Vector2f ReflectorPos;
|
||||
@ -190,7 +193,7 @@ protected:
|
||||
void ReloadLevel();
|
||||
|
||||
public:
|
||||
TGameLevel();
|
||||
TGameLevel(int levelStar, int levelIndex);
|
||||
~TGameLevel();
|
||||
|
||||
void FillWithFile(const std::string& filename);
|
||||
@ -199,6 +202,9 @@ public:
|
||||
//void SetLevelScale();
|
||||
//Vector2f GetLevelScale();
|
||||
|
||||
int getStarIndex();
|
||||
int getLevelIndex();
|
||||
|
||||
void SetStandBy();
|
||||
void SetLoading();
|
||||
bool IsLoaded();
|
||||
|
@ -54,9 +54,73 @@ const float CONST_CREDITS_SHOW_TIME = 150.f;
|
||||
TMyApplication* Application;
|
||||
|
||||
|
||||
int currentStar;
|
||||
std::vector<int> finishedLevels;
|
||||
|
||||
void TMyApplication::LoadUserProgress()
|
||||
{
|
||||
boost::property_tree::ptree userProgressJson;
|
||||
|
||||
try
|
||||
{
|
||||
boost::property_tree::json_parser::read_json(ST::PathToResources + "levels/user_progress.json", userProgressJson);
|
||||
currentStar = userProgressJson.get<int>("currentStar");
|
||||
for (auto& index : userProgressJson.get_child("finishedLevels"))
|
||||
{
|
||||
finishedLevels.push_back(index.second.get_value<int>());
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
currentStar = 0;
|
||||
finishedLevels.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void TMyApplication::SaveUserProgress(int levelStar, int levelIndex)
|
||||
{
|
||||
if (levelStar < currentStar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto iter = std::find(finishedLevels.begin(), finishedLevels.end(), levelIndex);
|
||||
if (iter != finishedLevels.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
finishedLevels.push_back(levelIndex);
|
||||
|
||||
if (finishedLevels.size() == Menu.GalaxMenu.galaxies[0].Stars[currentStar].selectionMenu.gameLevels.size())
|
||||
{
|
||||
finishedLevels.clear();
|
||||
|
||||
if (currentStar < Menu.GalaxMenu.galaxies[0].Stars.size() - 1)
|
||||
{
|
||||
currentStar += 1;
|
||||
}
|
||||
}
|
||||
|
||||
boost::property_tree::ptree userProgressJson;
|
||||
|
||||
userProgressJson.put("currentStar", currentStar);
|
||||
|
||||
boost::property_tree::ptree finishedLevelsTree;
|
||||
for (int index : finishedLevels)
|
||||
{
|
||||
boost::property_tree::ptree finishedLevel;
|
||||
finishedLevel.put_value(index);
|
||||
finishedLevelsTree.push_back(std::make_pair("", finishedLevel));
|
||||
}
|
||||
|
||||
userProgressJson.put_child("finishedLevels", finishedLevelsTree);
|
||||
boost::property_tree::json_parser::write_json(ST::PathToResources + "levels/user_progress.json", userProgressJson);
|
||||
}
|
||||
|
||||
|
||||
void TMyApplication::InnerInit()
|
||||
{
|
||||
|
||||
Application = this;
|
||||
|
||||
#ifdef TARGET_WIN32
|
||||
@ -76,6 +140,8 @@ void TMyApplication::InnerInit()
|
||||
ST::PathToResources = "";
|
||||
#endif
|
||||
|
||||
LoadUserProgress();
|
||||
|
||||
if (Console != NULL)
|
||||
{
|
||||
*Console<<"APP INIT\n";
|
||||
@ -93,6 +159,7 @@ void TMyApplication::InnerInit()
|
||||
|
||||
//ResourceManager->ShaderManager.AddShader("DefaultShader", "shaders/texture-shader.vertex", "shaders/texture-shader.fragment");
|
||||
ResourceManager->ShaderManager.AddShader("DefaultShader", "shaders/gui_transparent.vertex", "shaders/gui_transparent.fragment");
|
||||
ResourceManager->ShaderManager.AddShader("HoverableButtonShader", "shaders/gui_transparent.vertex", "shaders/hoverable-button.fragment");
|
||||
ResourceManager->ShaderManager.AddShader("BlackAndWhiteShader", "shaders/gui_transparent_blackandwhite.vertex", "shaders/gui_transparent_blackandwhite.fragment");
|
||||
ResourceManager->ShaderManager.AddShader("ColorShader", "shaders/color-shader.vertex", "shaders/color-shader.fragment");
|
||||
ResourceManager->ShaderManager.AddShader("FrameShader", "shaders/frameshader_vertex.txt", "shaders/frameshader_fragment.txt");
|
||||
@ -137,7 +204,6 @@ void TMyApplication::InnerInit()
|
||||
std::cout << "menu error" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TMyApplication::InnerDeinit()
|
||||
@ -403,9 +469,7 @@ void TMyApplication::InnerDraw()
|
||||
{
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
|
||||
Renderer->PushShader("DefaultShader");
|
||||
OnDrawSignal();
|
||||
Renderer->PopShader();
|
||||
|
||||
|
||||
}
|
||||
@ -755,17 +819,7 @@ void TMyApplication::InnerOnMouseMove(TMouseState& mouseState) {
|
||||
|
||||
bool TMyApplication::IsLevelOpened(int levelStar, int levelIndex)
|
||||
{
|
||||
if (levelStar == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (levelStar == 1 && levelIndex < 3)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return levelStar <= currentStar;
|
||||
}
|
||||
|
||||
|
||||
|
@ -138,6 +138,9 @@ public:
|
||||
|
||||
TMyApplication() : TApplication(), Loaded(false), Inited(false) { }
|
||||
|
||||
void LoadUserProgress();
|
||||
void SaveUserProgress(int levelStar, int levelIndex);
|
||||
|
||||
virtual void InnerInit();
|
||||
|
||||
virtual void InnerDeinit();
|
||||
|
Loading…
Reference in New Issue
Block a user