Skip to content

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMoroz committed Jul 20, 2019
1 parent d650190 commit e857eb2
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 252 deletions.
Binary file added game_folder/game_folder.rar
Binary file not shown.
Empty file added game_folder/levels/scores.bin
Empty file.
98 changes: 46 additions & 52 deletions game_folder/shaders/frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,11 @@ float de_marble(vec4 p) {
}
vec4 col_marble(vec4 p) {
vec4 col = vec4(0, 0, 0, de_sphere(p - vec4(iMarblePos, 0), iMarbleRad));
if(REFL_REFR_ENABLED)
{
col.xyz = vec3(0,0,0);
}
else
if(!REFL_REFR_ENABLED)
{
col.xyz = vec3(0.7,0.7,0.7);
}
return vec4(0, 0, 0, de_sphere(p - vec4(iMarblePos, 0), iMarbleRad));
return vec4(col.x, col.y, col.z, de_sphere(p - vec4(iMarblePos, 0), iMarbleRad));
}
float de_flag(vec4 p) {
vec3 f_pos = iFlagPos + vec3(1.5, 4, 0)*iFlagScale;
Expand Down Expand Up @@ -486,55 +482,53 @@ void main() {
vec4 col_r = scene(p, ray, vignette);

//Check if this is the glass marble
if (col_r.w > 0.5) {
if(REFL_REFR_ENABLED)
if (col_r.w > 0.5 && REFL_REFR_ENABLED)
{
//Calculate refraction
vec3 n = normalize(iMarblePos - p.xyz);
vec3 q = refraction(r, n, 1.0 / 1.5);
vec3 p2 = p.xyz + (dot(q, n) * 2.0 * iMarbleRad) * q;
n = normalize(p2 - iMarblePos);
q = (dot(q, r) * 2.0) * q - r;
vec4 p_temp = vec4(p2 + n * (MIN_DIST * 10), 1.0);
vec4 r_temp = vec4(q, 0.0);
vec3 refr = scene(p_temp, r_temp, 0.8).xyz;

//Calculate reflection
n = normalize(p.xyz - iMarblePos);
q = r - n*(2*dot(r,n));
p_temp = vec4(p.xyz + n * (MIN_DIST * 10), 1.0);
r_temp = vec4(q, 0.0);
vec3 refl = scene(p_temp, r_temp, 0.8).xyz;

//PBR reflections/refractions
vec3 V = -r;
vec3 N = n;

//Combine for final marble color
if(MARBLE_MODE == 0)
{
//Calculate refraction
vec3 n = normalize(iMarblePos - p.xyz);
vec3 q = refraction(r, n, 1.0 / 1.5);
vec3 p2 = p.xyz + (dot(q, n) * 2.0 * iMarbleRad) * q;
n = normalize(p2 - iMarblePos);
q = (dot(q, r) * 2.0) * q - r;
vec4 p_temp = vec4(p2 + n * (MIN_DIST * 10), 1.0);
vec4 r_temp = vec4(q, 0.0);
vec3 refr = scene(p_temp, r_temp, 0.8).xyz;

//Calculate reflection
n = normalize(p.xyz - iMarblePos);
q = r - n*(2*dot(r,n));
p_temp = vec4(p.xyz + n * (MIN_DIST * 10), 1.0);
r_temp = vec4(q, 0.0);
vec3 refl = scene(p_temp, r_temp, 0.8).xyz;
//glass
vec3 F0 = vec3(0.03);
vec3 L = normalize(q.xyz);
vec3 H = normalize(V + L);
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);

//PBR reflections/refractions
vec3 V = -r;
vec3 N = n;
vec3 kS = F;
vec3 kD = vec3(1.0) - kS;
col += kS*refl + kD*refr + col_r.xyz;
}
else
{
//metal
vec3 F0 = vec3(0.6);
vec3 L = normalize(q.xyz);
vec3 H = normalize(V + L);
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);

//Combine for final marble color
if(MARBLE_MODE == 0)
{
//glass
vec3 F0 = vec3(0.03);
vec3 L = normalize(q.xyz);
vec3 H = normalize(V + L);
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);

vec3 kS = F;
vec3 kD = vec3(1.0) - kS;
col += kS*refl + kD*refr + col_r.xyz;
}
else
{
//metal
vec3 F0 = vec3(0.6);
vec3 L = normalize(q.xyz);
vec3 H = normalize(V + L);
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);

vec3 kS = F;
vec3 kD = vec3(1.0) - kS;
col += kS*refl + col_r.xyz;
}
vec3 kS = F;
vec3 kD = vec3(1.0) - kS;
col += kS*refl + col_r.xyz;
}
} else {
col += col_r.xyz;
Expand Down
59 changes: 40 additions & 19 deletions src/Gamemodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,26 @@ void OpenMainMenu(Scene * scene, Overlays * overlays)
scene->SetMode(Scene::INTRO);
sf::Vector2f wsize = default_view.getSize();

MenuBox mainmenu(700, wsize.y*0.6f, wsize.x*0.025, wsize.y*0.3f);
MenuBox mainmenu(1000, wsize.y*0.8f, wsize.x*0.025, wsize.y*0.025f);
mainmenu.SetBackgroundColor(sf::Color::Transparent);
//make the menu static
mainmenu.static_object = true;

//TITLE
Text ttl(LOCAL["Marble_Marcher"], LOCAL("default"), 120, sf::Color::White);
ttl.SetBorderColor(sf::Color::Black);
ttl.SetBorderWidth(4);
mainmenu.AddObject(&ttl, Object::Allign::LEFT);

Text CE("Community Edition", LOCAL("default"), 60, sf::Color::White);
CE.SetBorderColor(sf::Color::Black);
CE.SetBorderWidth(4);
mainmenu.AddObject(&CE, Object::Allign::LEFT);

Box margin(800, 80);
margin.SetBackgroundColor(sf::Color::Transparent);
mainmenu.AddObject(&margin, Object::Allign::LEFT);

//PLAY
Box playbtn(600, 50);
Text button1(LOCAL["Play"], LOCAL("default"), 40, sf::Color::White);
Expand All @@ -37,7 +52,7 @@ void OpenMainMenu(Scene * scene, Overlays * overlays)
{
PlayNewGame(scene, window, 0);
overlays->sound_click.play();
});
}, true);
playbtn.AddObject(&button1, Object::Allign::CENTER);
mainmenu.AddObject(&playbtn, Object::Allign::LEFT);

Expand All @@ -49,7 +64,7 @@ void OpenMainMenu(Scene * scene, Overlays * overlays)
{
OpenLevelMenu(scene, overlays);
overlays->sound_click.play();
});
}, true);
lvlsbtn.AddObject(&button2, Object::Allign::CENTER);
mainmenu.AddObject(&lvlsbtn, Object::Allign::LEFT);

Expand All @@ -61,7 +76,7 @@ void OpenMainMenu(Scene * scene, Overlays * overlays)
{
OpenControlMenu(scene, overlays);
overlays->sound_click.play();
});
}, true);
cntrlbtn.AddObject(&button3, Object::Allign::CENTER);
mainmenu.AddObject(&cntrlbtn, Object::Allign::LEFT);

Expand All @@ -73,7 +88,7 @@ void OpenMainMenu(Scene * scene, Overlays * overlays)
{
OpenScreenSaver(scene, overlays);
overlays->sound_click.play();
});
}, true);
ssbtn.AddObject(&button4, Object::Allign::CENTER);
mainmenu.AddObject(&ssbtn, Object::Allign::LEFT);

Expand All @@ -85,10 +100,16 @@ void OpenMainMenu(Scene * scene, Overlays * overlays)
{
overlays->sound_click.play();
window->close();
});
}, true);
exitbtn.AddObject(&button5, Object::Allign::CENTER);
mainmenu.AddObject(&exitbtn, Object::Allign::LEFT);

Text about(LOCAL["About"], LOCAL("mono"), 30, sf::Color::White);
about.SetBorderColor(sf::Color::Black);
about.SetBorderWidth(3);
mainmenu.AddObject(&about, Object::Allign::LEFT);


AddGlobalObject(mainmenu);
}

Expand Down Expand Up @@ -142,7 +163,7 @@ void PlayNewGame(Scene * scene, sf::RenderWindow * window, int level)
LockMouse(*window);
}

void OpenTestWindow(sf::Font & font)
void OpenTestWindow()
{
Window test(200, 200, 500, 500, sf::Color(0, 0, 0, 128), LOCAL["Window"], LOCAL("default"));
Text button(LOCAL["Button"], LOCAL("default"), 30, sf::Color::White);
Expand All @@ -169,21 +190,22 @@ void OpenLevelMenu(Scene* scene, Overlays* overlays)
sf::Vector2f wsize = default_view.getSize();

MenuBox levels(wsize.x*0.95f, wsize.y*0.95f, wsize.x*0.025f, wsize.y*0.025f);
levels.SetBackgroundColor(sf::Color(64,64,64,128));
levels.SetBackgroundColor(sf::Color(32,32,32,160));
//make the menu static
levels.static_object = true;

scene->SetExposure(0.5f);
scene->SetExposure(0.7f);
scene->SetMode(Scene::INTRO);
game_mode = LEVELS;

std::vector<std::string> names = scene->levels.getLevelNames();
std::vector<std::string> desc = scene->levels.getLevelDesc();
std::map<int, std::string> names = scene->levels.getLevelNames();
std::map<int, std::string> desc = scene->levels.getLevelDesc();
std::vector<int> ids = scene->levels.getLevelIds();
std::map<int, Score> scores = scene->levels.getLevelScores();
Text lvl(LOCAL["Levels"], LOCAL("default"), 60, sf::Color::White);
levels.AddObject(&lvl, Object::Allign::CENTER);
Box Bk2Menu(600, 50);
Bk2Menu.SetBackgroundColor(sf::Color(128, 128, 128, 128));
Text button(LOCAL["Back2Main"], LOCAL("default"), 40, sf::Color::White);
Bk2Menu.hoverstate.color_main = sf::Color(200, 40, 0, 255);
Bk2Menu.SetCallbackFunction([scene, overlays](sf::RenderWindow * window, InputState & state)
Expand All @@ -195,6 +217,7 @@ void OpenLevelMenu(Scene* scene, Overlays* overlays)
levels.AddObject(&Bk2Menu, Object::Allign::LEFT);

Box Newlvl(600, 50);
Newlvl.SetBackgroundColor(sf::Color(128, 128, 128, 128));
Text newlvl(LOCAL["CreateNewLvl"], LOCAL("default"), 40, sf::Color::White);
Newlvl.hoverstate.color_main = sf::Color(200, 40, 0, 255);
Newlvl.SetCallbackFunction([scene, overlays](sf::RenderWindow * window, InputState & state)
Expand All @@ -216,14 +239,15 @@ void OpenLevelMenu(Scene* scene, Overlays* overlays)
for (int i = 0; i < scene->levels.GetLevelNum(); i++)
{
Box lvlbtton(wsize.x*0.95f - 60, 60);
lvlbtton.SetBackgroundColor(sf::Color(128, 128, 128, 128));
lvlbtton.hoverstate.border_thickness = 3;

Box lvltext(500, 60);
lvltext.SetBackgroundColor(sf::Color::Transparent);
Box lvltitle(500, 40);
lvltitle.SetBackgroundColor(sf::Color::Transparent);
Text lvlname(utf8_to_wstring(names[i]), LOCAL("default"), 35, sf::Color::White);
Text lvldescr(utf8_to_wstring(desc[i]), LOCAL("default"), 18, sf::Color::White);
Text lvlname(utf8_to_wstring(names[ids[i]]), LOCAL("default"), 35, sf::Color::White);
Text lvldescr(utf8_to_wstring(desc[ids[i]]), LOCAL("default"), 18, sf::Color::White);
lvlname.hoverstate.color_main = sf::Color(255, 0, 0, 255);
lvlname.SetCallbackFunction([scene, overlays, selected = ids[i]](sf::RenderWindow * window, InputState & state)
{
Expand All @@ -235,7 +259,6 @@ void OpenLevelMenu(Scene* scene, Overlays* overlays)
lvltext.AddObject(&lvldescr, Object::Allign::LEFT);
lvlbtton.AddObject(&lvltext, Object::Allign::LEFT);


Box lvlscore(500, 40);
lvlscore.SetBackgroundColor(sf::Color::Transparent);
std::string score_text = "--:--:--";
Expand Down Expand Up @@ -281,7 +304,6 @@ void OpenLevelMenu(Scene* scene, Overlays* overlays)
overlays->sound_click.play();
}, true);


Box bremove(60, 60);
bremove.defaultstate.color_main = sf::Color(255, 255, 255, 255);
bremove.hoverstate.color_main = sf::Color(255, 0, 0, 255);
Expand All @@ -295,9 +317,7 @@ void OpenLevelMenu(Scene* scene, Overlays* overlays)

buttons.AddObject(&bremove, Object::Allign::RIGHT);
buttons.AddObject(&bedit, Object::Allign::RIGHT);

lvlbtton.AddObject(&buttons, Object::Allign::RIGHT);

levels.AddObject(&lvlbtton, Object::Allign::LEFT);
}

Expand Down Expand Up @@ -326,11 +346,12 @@ void ConfirmLevelDeletion(int lvl, Scene* scene, Overlays* overlays)

int id = AddGlobalObject(confirm);

get_glob_obj(id).objects[1].get()->objects[0].get()->objects[1].get()->SetCallbackFunction([scene, overlays, id](sf::RenderWindow * window, InputState & state)
get_glob_obj(id).objects[1].get()->objects[0].get()->objects[1].get()->SetCallbackFunction([scene, overlays, id, lvl](sf::RenderWindow * window, InputState & state)
{
//remove lvl
Add2DeleteQueue(id);
scene->levels.DeleteLevel(lvl);
overlays->sound_click.play();
OpenLevelMenu(scene, overlays);
});

get_glob_obj(id).objects[1].get()->objects[0].get()->objects[2].get()->SetCallbackFunction([scene, overlays, id](sf::RenderWindow * window, InputState & state)
Expand Down
3 changes: 2 additions & 1 deletion src/Gamemodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void OpenScreenSaver(Scene * scene, Overlays * overlays);

void PlayNewGame(Scene * scene, sf::RenderWindow * window, int level);

void OpenTestWindow(sf::Font & font);
void OpenTestWindow();

void OpenLevelMenu(Scene* scene, Overlays* overlays);
void ConfirmLevelDeletion(int lvl, Scene* scene, Overlays* overlays);

Expand Down
Loading

0 comments on commit e857eb2

Please sign in to comment.