changed Color struct to 4 floats

GetRandomValue returns floats
added GetRandomInt
added Color4ub rgba 0-255
edited examples to work
colour palette values could bare a double check!
This commit is contained in:
Chris 2019-10-21 20:17:48 +01:00
commit b4d8f0b5d1
30 changed files with 475 additions and 359 deletions

View file

@ -44,10 +44,10 @@ int main(void)
{ {
circles[i].alpha = 0.0f; circles[i].alpha = 0.0f;
circles[i].radius = GetRandomValue(10, 40); circles[i].radius = GetRandomValue(10, 40);
circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius); circles[i].position.x = GetRandomInt(circles[i].radius, screenWidth - circles[i].radius);
circles[i].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius); circles[i].position.y = GetRandomInt(circles[i].radius, screenHeight - circles[i].radius);
circles[i].speed = (float)GetRandomValue(1, 100)/2000.0f; circles[i].speed = (float)GetRandomInt(1, 100)/2000.0f;
circles[i].color = colors[GetRandomValue(0, 13)]; circles[i].color = colors[(int)GetRandomInt(0, 13)];
} }
Music music = LoadMusicStream("resources/mini1111.xm"); Music music = LoadMusicStream("resources/mini1111.xm");
@ -97,11 +97,11 @@ int main(void)
if (circles[i].alpha <= 0.0f) if (circles[i].alpha <= 0.0f)
{ {
circles[i].alpha = 0.0f; circles[i].alpha = 0.0f;
circles[i].radius = GetRandomValue(10, 40); circles[i].radius = GetRandomInt(10, 40);
circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius); circles[i].position.x = GetRandomInt(circles[i].radius, screenWidth - circles[i].radius);
circles[i].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius); circles[i].position.y = GetRandomInt(circles[i].radius, screenHeight - circles[i].radius);
circles[i].color = colors[GetRandomValue(0, 13)]; circles[i].color = colors[(int)GetRandomInt(0, 13)];
circles[i].speed = (float)GetRandomValue(1, 100)/2000.0f; circles[i].speed = (float)GetRandomInt(1, 100)/2000.0f;
} }
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------

View file

@ -62,7 +62,7 @@ int main(void)
if (!inhibitOgg) PlaySoundMulti(fxOgg); if (!inhibitOgg) PlaySoundMulti(fxOgg);
frame = 0; frame = 0;
maxFrame = GetRandomValue(6,12); maxFrame = GetRandomInt(6,12);
} }
soundsCounter = GetSoundsPlaying(); soundsCounter = GetSoundsPlaying();

View file

@ -30,14 +30,14 @@ int main(void)
for (int i = 0; i < MAX_BUILDINGS; i++) for (int i = 0; i < MAX_BUILDINGS; i++)
{ {
buildings[i].width = GetRandomValue(50, 200); buildings[i].width = GetRandomInt(50, 200);
buildings[i].height = GetRandomValue(100, 800); buildings[i].height = GetRandomInt(100, 800);
buildings[i].y = screenHeight - 130 - buildings[i].height; buildings[i].y = screenHeight - 130 - buildings[i].height;
buildings[i].x = -6000 + spacing; buildings[i].x = -6000 + spacing;
spacing += buildings[i].width; spacing += buildings[i].width;
buildColors[i] = (Color){ GetRandomValue(200, 240), GetRandomValue(200, 240), GetRandomValue(200, 250), 255 }; buildColors[i] = (Color){ GetRandomValue(.8, .95), GetRandomValue(.8, .95), GetRandomValue(.8, .95), 1 };
} }
Camera2D camera = { 0 }; Camera2D camera = { 0 };

View file

@ -37,9 +37,9 @@ int main(void)
for (int i = 0; i < MAX_COLUMNS; i++) for (int i = 0; i < MAX_COLUMNS; i++)
{ {
heights[i] = (float)GetRandomValue(1, 12); heights[i] = (float)GetRandomInt(1, 12);
positions[i] = (Vector3){ GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15) }; positions[i] = (Vector3){ GetRandomInt(-15, 15), heights[i]/2, GetRandomInt(-15, 15) };
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 }; colors[i] = (Color){ GetRandomValue(.1, 1), GetRandomValue(.1, .3), .1, 1 };
} }
SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode

View file

@ -22,7 +22,7 @@ int main(void)
int framesCounter = 0; // Variable used to count frames int framesCounter = 0; // Variable used to count frames
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included) int randValue = GetRandomInt(-8, 5); // Get a random integer number between -8 and 5 (both included)
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -37,7 +37,7 @@ int main(void)
// Every two seconds (120 frames) a new random value is generated // Every two seconds (120 frames) a new random value is generated
if (((framesCounter/120)%2) == 1) if (((framesCounter/120)%2) == 1)
{ {
randValue = GetRandomValue(-8, 5); randValue = GetRandomInt(-8, 5);
framesCounter = 0; framesCounter = 0;
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------

View file

@ -37,8 +37,8 @@ int main(void)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_R)) if (IsKeyPressed(KEY_R))
{ {
score = GetRandomValue(1000, 2000); score = GetRandomInt(1000, 2000);
hiscore = GetRandomValue(2000, 4000); hiscore = GetRandomInt(2000, 4000);
} }
if (IsKeyPressed(KEY_ENTER)) if (IsKeyPressed(KEY_ENTER))

View file

@ -34,7 +34,7 @@ int main(void)
SetTextureFilter(target.texture, FILTER_BILINEAR); // Texture scale filter to use SetTextureFilter(target.texture, FILTER_BILINEAR); // Texture scale filter to use
Color colors[10] = { 0 }; Color colors[10] = { 0 };
for (int i = 0; i < 10; i++) colors[i] = (Color){ GetRandomValue(100, 250), GetRandomValue(50, 150), GetRandomValue(10, 100), 255 }; for (int i = 0; i < 10; i++) colors[i] = (Color){ GetRandomValue(.5, .95), GetRandomValue(.2, .6), GetRandomValue(.05, .4), 1 };
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -50,7 +50,7 @@ int main(void)
if (IsKeyPressed(KEY_SPACE)) if (IsKeyPressed(KEY_SPACE))
{ {
// Recalculate random colors for the bars // Recalculate random colors for the bars
for (int i = 0; i < 10; i++) colors[i] = (Color){ GetRandomValue(100, 250), GetRandomValue(50, 150), GetRandomValue(10, 100), 255 }; for (int i = 0; i < 10; i++) colors[i] = (Color){ GetRandomValue(.5, .95), GetRandomValue(.2, .6), GetRandomValue(.05, .4), 1 };
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------

View file

@ -35,7 +35,7 @@ int main(void)
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
// Get map image data to be used for collision detection // Get map image data to be used for collision detection
Color *mapPixels = GetImageData(imMap); Color4ub *mapPixels = GetImageData(imMap);
UnloadImage(imMap); // Unload image from RAM UnloadImage(imMap); // Unload image from RAM
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position

View file

@ -51,14 +51,14 @@ int main(void)
MeshTangents(&model.meshes[0]); MeshTangents(&model.meshes[0]);
UnloadMaterial(model.materials[0]); // get rid of default material UnloadMaterial(model.materials[0]); // get rid of default material
model.materials[0] = LoadMaterialPBR((Color){ 255, 255, 255, 255 }, 1.0f, 1.0f); model.materials[0] = LoadMaterialPBR((Color){ 1, 1, 1, 1 }, 1.0f, 1.0f);
// Create lights // Create lights
// NOTE: Lights are added to an internal lights pool automatically // NOTE: Lights are added to an internal lights pool automatically
CreateLight(LIGHT_POINT, (Vector3){ LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 0, 255 }, model.materials[0].shader); CreateLight(LIGHT_POINT, (Vector3){ LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 1, 0, 0, 1 }, model.materials[0].shader);
CreateLight(LIGHT_POINT, (Vector3){ 0.0f, LIGHT_HEIGHT, LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 255, 0, 255 }, model.materials[0].shader); CreateLight(LIGHT_POINT, (Vector3){ 0.0f, LIGHT_HEIGHT, LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 1, 0, 1 }, model.materials[0].shader);
CreateLight(LIGHT_POINT, (Vector3){ -LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 0, 255, 255 }, model.materials[0].shader); CreateLight(LIGHT_POINT, (Vector3){ -LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 0, 1, 1 }, model.materials[0].shader);
CreateLight(LIGHT_DIRECTIONAL, (Vector3){ 0.0f, LIGHT_HEIGHT*2.0f, -LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 255, 255 }, model.materials[0].shader); CreateLight(LIGHT_DIRECTIONAL, (Vector3){ 0.0f, LIGHT_HEIGHT*2.0f, -LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 1, 0, 1, 1 }, model.materials[0].shader);
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
@ -223,7 +223,7 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
// Set up material properties color // Set up material properties color
mat.maps[MAP_ALBEDO].color = albedo; mat.maps[MAP_ALBEDO].color = albedo;
mat.maps[MAP_NORMAL].color = (Color){ 128, 128, 255, 255 }; mat.maps[MAP_NORMAL].color = (Color){ 0.5, 0.5, 1, 1 };
mat.maps[MAP_METALNESS].value = metalness; mat.maps[MAP_METALNESS].value = metalness;
mat.maps[MAP_ROUGHNESS].value = roughness; mat.maps[MAP_ROUGHNESS].value = roughness;
mat.maps[MAP_OCCLUSION].value = 1.0f; mat.maps[MAP_OCCLUSION].value = 1.0f;

View file

@ -252,7 +252,7 @@ void DrawSphereBasic(Color color)
int slices = 16; int slices = 16;
rlBegin(RL_TRIANGLES); rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4f(color.r, color.g, color.b, color.a);
for (int i = 0; i < (rings + 2); i++) for (int i = 0; i < (rings + 2); i++)
{ {

View file

@ -137,7 +137,7 @@ void DrawSphereBasic(Color color)
int slices = 16; int slices = 16;
rlBegin(RL_TRIANGLES); rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4f(color.r, color.g, color.b, color.a);
for (int i = 0; i < (rings + 2); i++) for (int i = 0; i < (rings + 2); i++)
{ {

View file

@ -168,7 +168,7 @@ void UpdateLightValues(Shader shader, Light light)
SetShaderValue(shader, light.targetLoc, target, UNIFORM_VEC3); SetShaderValue(shader, light.targetLoc, target, UNIFORM_VEC3);
// Send to shader light color values // Send to shader light color values
float diff[4] = { (float)light.color.r/(float)255, (float)light.color.g/(float)255, (float)light.color.b/(float)255, (float)light.color.a/(float)255 }; float diff[4] = { light.color.r, light.color.g, light.color.b, light.color.a };
SetShaderValue(shader, light.colorLoc, diff, UNIFORM_VEC4); SetShaderValue(shader, light.colorLoc, diff, UNIFORM_VEC4);
} }

View file

@ -53,9 +53,9 @@
#include <GLFW/glfw3.h> // Windows/Context and inputs management #include <GLFW/glfw3.h> // Windows/Context and inputs management
#define RED (Color){ 230, 41, 55, 255 } // Red #define RED (Color){ 0.89844, 0.16667, 0.21484, 1.0 } // Red
#define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo) #define DARKGRAY (Color){ 0.3125 , 0.3125 , 0.3125 , 1.0 } // Dark Gray
#define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray #define RAYWHITE (Color){ 0.96078, 0.96078, 0.96078, 1.0 } // My own White (raylib logo)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module specific Functions Declaration // Module specific Functions Declaration
@ -128,7 +128,7 @@ int main(void)
rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix
rlLoadIdentity(); // Reset current matrix (MODELVIEW) rlLoadIdentity(); // Reset current matrix (MODELVIEW)
rlClearColor(245, 245, 245, 255); // Define clear color rlClearColor(.95, .95, .95, 1); // Define clear color
rlEnableDepthTest(); // Enable DEPTH_TEST for 3D rlEnableDepthTest(); // Enable DEPTH_TEST for 3D
Camera camera = { 0 }; Camera camera = { 0 };
@ -232,7 +232,7 @@ static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, i
static void DrawRectangleV(Vector2 position, Vector2 size, Color color) static void DrawRectangleV(Vector2 position, Vector2 size, Color color)
{ {
rlBegin(RL_TRIANGLES); rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4f(color.r, color.g, color.b, color.a);
rlVertex2i(position.x, position.y); rlVertex2i(position.x, position.y);
rlVertex2i(position.x, position.y + size.y); rlVertex2i(position.x, position.y + size.y);
@ -292,7 +292,7 @@ static void DrawCube(Vector3 position, float width, float height, float length,
//rlRotatef(45, 0, 1, 0); //rlRotatef(45, 0, 1, 0);
rlBegin(RL_TRIANGLES); rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4f(color.r, color.g, color.b, color.a);
// Front Face ----------------------------------------------------- // Front Face -----------------------------------------------------
rlVertex3f(x-width/2, y-height/2, z+length/2); // Bottom Left rlVertex3f(x-width/2, y-height/2, z+length/2); // Bottom Left
@ -364,7 +364,7 @@ static void DrawCubeWires(Vector3 position, float width, float height, float len
//rlRotatef(45, 0, 1, 0); //rlRotatef(45, 0, 1, 0);
rlBegin(RL_LINES); rlBegin(RL_LINES);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4f(color.r, color.g, color.b, color.a);
// Front Face ----------------------------------------------------- // Front Face -----------------------------------------------------
// Bottom Line // Bottom Line

View file

@ -77,8 +77,8 @@ int main(void)
} }
// Physics body creation inputs // Physics body creation inputs
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) CreatePhysicsBodyPolygon(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(3, 8), 10); if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) CreatePhysicsBodyPolygon(GetMousePosition(), GetRandomInt(20, 80), GetRandomInt(3, 8), 10);
else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) CreatePhysicsBodyCircle(GetMousePosition(), GetRandomValue(10, 45), 10); else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) CreatePhysicsBodyCircle(GetMousePosition(), GetRandomInt(10, 45), 10);
// Destroy falling physics bodies // Destroy falling physics bodies
int bodiesCount = GetPhysicsBodiesCount(); int bodiesCount = GetPhysicsBodiesCount();

View file

@ -41,7 +41,7 @@ int main(void)
SetPhysicsGravity(0, 0); SetPhysicsGravity(0, 0);
// Create random polygon physics body to shatter // Create random polygon physics body to shatter
CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomInt(80, 200), GetRandomInt(3, 8), 10);
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -57,7 +57,7 @@ int main(void)
if (needsReset) if (needsReset)
{ {
// Create random polygon physics body to shatter // Create random polygon physics body to shatter
CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomInt(80, 200), GetRandomInt(3, 8), 10);
needsReset = false; needsReset = false;
} }

View file

@ -179,8 +179,7 @@ void UpdateLightValues(Shader shader, Light light)
SetShaderValue(shader, light.targetLoc, target, UNIFORM_VEC3); SetShaderValue(shader, light.targetLoc, target, UNIFORM_VEC3);
// Send to shader light color values // Send to shader light color values
float color[4] = { (float)light.color.r/(float)255, (float)light.color.g/(float)255, float color[4] = { light.color.r, light.color.g, light.color.b, light.color.a };
(float)light.color.b/(float)255, (float)light.color.a/(float)255 };
SetShaderValue(shader, light.colorLoc, color, UNIFORM_VEC4); SetShaderValue(shader, light.colorLoc, color, UNIFORM_VEC4);
} }

View file

@ -132,7 +132,7 @@ int main(void)
EndMode3D(); EndMode3D();
DrawText(TextFormat("Use KEY_UP/KEY_DOWN to change fog density [%.2f]", fogDensity), 10, 10, 20, RAYWHITE); DrawText(TextFormat("Use KEY_UP/KEY_DOWN to change fog density [%.2f]", fogDensity), 10, 10, 20, BLACK);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------

View file

@ -121,7 +121,7 @@ int main(void)
{ {
// Draw horizontal screen-wide rectangles with increasing "palette index" // Draw horizontal screen-wide rectangles with increasing "palette index"
// The used palette index is encoded in the RGB components of the pixel // The used palette index is encoded in the RGB components of the pixel
DrawRectangle(0, lineHeight*i, GetScreenWidth(), lineHeight, (Color){ i, i, i, 255 }); DrawRectangle(0, lineHeight*i, GetScreenWidth(), lineHeight, (Color){ (float)i/255, 0, 0, 1 });
} }
EndShaderMode(); EndShaderMode();

View file

@ -303,18 +303,18 @@ int main(int argc, char **argv)
static void RandomizeEmoji(void) static void RandomizeEmoji(void)
{ {
hovered = selected = -1; hovered = selected = -1;
int start = GetRandomValue(45, 360); int start = GetRandomInt(45, 360);
for (int i = 0; i < SIZEOF(emoji); ++i) for (int i = 0; i < SIZEOF(emoji); ++i)
{ {
// 0-179 emoji codepoints (from emoji char array) each 4bytes + null char // 0-179 emoji codepoints (from emoji char array) each 4bytes + null char
emoji[i].index = GetRandomValue(0, 179)*5; emoji[i].index = GetRandomInt(0, 179)*5;
// Generate a random color for this emoji // Generate a random color for this emoji
Vector3 hsv = {(start*(i + 1))%360, 0.6f, 0.85f}; Vector3 hsv = {(start*(i + 1))%360, 0.6f, 0.85f};
emoji[i].color = Fade(ColorFromHSV(hsv), 0.8f); emoji[i].color = Fade(ColorFromHSV(hsv), 0.8f);
// Set a random message for this emoji // Set a random message for this emoji
emoji[i].message = GetRandomValue(0, SIZEOF(messages) - 1); emoji[i].message = GetRandomInt(0, SIZEOF(messages) - 1);
} }
} }

View file

@ -57,11 +57,11 @@ int main(void)
if (bunniesCount < MAX_BUNNIES) if (bunniesCount < MAX_BUNNIES)
{ {
bunnies[bunniesCount].position = GetMousePosition(); bunnies[bunniesCount].position = GetMousePosition();
bunnies[bunniesCount].speed.x = (float)GetRandomValue(-250, 250)/60.0f; bunnies[bunniesCount].speed.x = (float)GetRandomInt(-250, 250)/60.0f;
bunnies[bunniesCount].speed.y = (float)GetRandomValue(-250, 250)/60.0f; bunnies[bunniesCount].speed.y = (float)GetRandomInt(-250, 250)/60.0f;
bunnies[bunniesCount].color = (Color){ GetRandomValue(50, 240), bunnies[bunniesCount].color = (Color){ GetRandomValue(0.5, .9),
GetRandomValue(80, 240), GetRandomValue(.8, .9),
GetRandomValue(100, 240), 255 }; GetRandomValue(.5, .9), 1 };
bunniesCount++; bunniesCount++;
} }
} }

Some files were not shown because too many files have changed in this diff Show more