Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitwise trophy states #5

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 101 additions & 110 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,16 @@ typedef struct
#define MAX_COINS 130
coin coins[MAX_COINS] = {0};

uint trophies[6] = {0};
// Bit flag based method for storing trophie states,
// 0b0000_0000 where the last bit denotes 1, second last denotes 2 etc like so:
// 0b0000_0001 = trophie 1
// 0b0000_0101 = trophie 1 and 3
char trophies_bits = 0;
#define trophies_set(x) trophies_bits |= (0b1 << x)
#define trophies_clear() trophies_bits = 0
#define trophies_get(x) (trophies_bits >> x) & 0b1
#define trophies_all() trophies_bits


//*************************************
// game functions
Expand Down Expand Up @@ -418,13 +427,13 @@ uint stepCollisions()
{
if(j >= 0 && j <= 3)
{
if(trophies[coins[j].color-1] == 1) // already have? then reward coins!
if(trophies_get(coins[j].color-1)) // already have? then reward coins!
{
gold_stack += 6.f;
silver_stack += 6.f;
}
else
trophies[coins[j].color-1] = 1;
trophies_set(coins[j].color-1);
}
else
{
Expand All @@ -443,13 +452,13 @@ uint stepCollisions()
{
if(j >= 0 && j <= 3)
{
if(trophies[coins[j].color-1] == 1) // already have? then reward coins!
if(trophies_get(coins[j].color-1)) // already have? then reward coins!
{
gold_stack += 6.f;
silver_stack += 6.f;
}
else
trophies[coins[j].color-1] = 1;
trophies_set(coins[j].color-1);
}
else
{
Expand All @@ -469,13 +478,13 @@ uint stepCollisions()
{
if(j >= 0 && j <= 3)
{
if(trophies[coins[j].color-1] == 1) // already have? then reward coins!
if(trophies_get(coins[j].color-1)) // already have? then reward coins!
{
gold_stack += 6.f;
silver_stack += 6.f;
}
else
trophies[coins[j].color-1] = 1;
trophies_set(coins[j].color-1);
}
else
{
Expand All @@ -491,13 +500,13 @@ uint stepCollisions()
{
if(j >= 0 && j <= 3)
{
if(trophies[coins[j].color-1] == 1) // already have? then reward coins!
if(trophies_get(coins[j].color-1)) // already have? then reward coins!
{
gold_stack += 6.f;
silver_stack += 6.f;
}
else
trophies[coins[j].color-1] = 1;
trophies_set(coins[j].color-1);
}
else
silver_stack += 1.f;
Expand All @@ -524,12 +533,7 @@ void newGame()
active_coin = 0;
inmotion = 0;
gameover = 0.f;
trophies[0] = 0;
trophies[1] = 0;
trophies[2] = 0;
trophies[3] = 0;
trophies[4] = 0;
trophies[5] = 0;
trophies_clear();
for(int i=0; i < MAX_COINS; i++)
{
coins[i].color = -1;
Expand Down Expand Up @@ -994,101 +998,88 @@ void main_loop()

//

if(trophies[0] == 1)
{
mIdent(&model);
mTranslate(&model, 3.92732f, 1.0346f, 0.f);
mRotZ(&model, t*0.3f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);

glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);
}

if(trophies[1] == 1)
{
mIdent(&model);
mTranslate(&model, 3.65552f, -1.30202f, 0.f);
mRotZ(&model, t*0.3f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);

glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);

glUniform1f(opacity_id, 0.5f);
modelBind3(&mdlEvil);
glDrawElements(GL_TRIANGLES, evil_numind, GL_UNSIGNED_BYTE, 0);
}

if(trophies[2] == 1)
{
mIdent(&model);
mTranslate(&model, 3.01911f, -3.23534f, 0.f);
mRotZ(&model, t*0.3f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);

glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);

glUniform1f(opacity_id, 0.6f);
modelBind3(&mdlKing);
glDrawElements(GL_TRIANGLES, king_numind, GL_UNSIGNED_BYTE, 0);
}

if(trophies[3] == 1)
{
mIdent(&model);
mTranslate(&model, -3.92732f, 1.0346f, 0.f);
mRotZ(&model, t*0.3f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);

glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);

modelBind3(&mdlNinja);
glDrawElements(GL_TRIANGLES, ninja_numind, GL_UNSIGNED_BYTE, 0);
}

if(trophies[4] == 1)
{
mIdent(&model);
mTranslate(&model, -3.65552f, -1.30202f, 0.f);
mRotZ(&model, t*0.3f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);

glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);

glUniform1f(opacity_id, 0.4f);
modelBind3(&mdlSurf);
glDrawElements(GL_TRIANGLES, surf_numind, GL_UNSIGNED_SHORT, 0);
}

if(trophies[5] == 1)
{
mIdent(&model);
mTranslate(&model, -3.01911f, -3.23534f, 0.f);
mRotZ(&model, t*0.3f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);

glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);

glUniform1f(opacity_id, 0.5f);
modelBind3(&mdlTrip);
glDrawElements(GL_TRIANGLES, trip_numind, GL_UNSIGNED_SHORT, 0);
if (trophies_all()) // Are there any trophies that need to be rendered?
{
if(trophies_get(0))
{
mIdent(&model);
mTranslate(&model, 3.92732f, 1.0346f, 0.f);
mRotZ(&model, t*0.3f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);
glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);
}
if(trophies_get(1))
{
mIdent(&model);
mTranslate(&model, 3.65552f, -1.30202f, 0.f);
mRotZ(&model, t*0.3f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);
glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);
glUniform1f(opacity_id, 0.5f);
modelBind3(&mdlEvil);
glDrawElements(GL_TRIANGLES, evil_numind, GL_UNSIGNED_BYTE, 0);
}
if(trophies_get(2))
{
mIdent(&model);
mTranslate(&model, 3.01911f, -3.23534f, 0.f);
mRotZ(&model, t*0.3f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);
glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);
glUniform1f(opacity_id, 0.6f);
modelBind3(&mdlKing);
glDrawElements(GL_TRIANGLES, king_numind, GL_UNSIGNED_BYTE, 0);
}
if(trophies_get(3))
{
mIdent(&model);
mTranslate(&model, -3.92732f, 1.0346f, 0.f);
mRotZ(&model, t*0.3f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);
glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);
modelBind3(&mdlNinja);
glDrawElements(GL_TRIANGLES, ninja_numind, GL_UNSIGNED_BYTE, 0);
}
if(trophies_get(4))
{
mIdent(&model);
mTranslate(&model, -3.65552f, -1.30202f, 0.f);
mRotZ(&model, t*0.3f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);
glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);
glUniform1f(opacity_id, 0.4f);
modelBind3(&mdlSurf);
glDrawElements(GL_TRIANGLES, surf_numind, GL_UNSIGNED_SHORT, 0);
}
if(trophies_get(5))
{
mIdent(&model);
mTranslate(&model, -3.01911f, -3.23534f, 0.f);
mRotZ(&model, t*0.3f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);
glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);
glUniform1f(opacity_id, 0.5f);
modelBind3(&mdlTrip);
glDrawElements(GL_TRIANGLES, trip_numind, GL_UNSIGNED_SHORT, 0);
}
}

// render scene props
Expand Down