summaryrefslogtreecommitdiffhomepage
path: root/examples/ex06a_color_select.c
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2013-12-27 00:17:39 +0100
committerraysan5 <[email protected]>2013-12-27 00:17:39 +0100
commita0d719d95f60d0b2109cebff29603625c3c3cbe1 (patch)
tree1fdf93b234be458b1d25ad372ed7106878c71bf9 /examples/ex06a_color_select.c
parentcfb42dc251d5cbadb76f5fdab010a389989228d2 (diff)
downloadraylib-a0d719d95f60d0b2109cebff29603625c3c3cbe1.tar.gz
raylib-a0d719d95f60d0b2109cebff29603625c3c3cbe1.zip
Updated examples
Diffstat (limited to 'examples/ex06a_color_select.c')
-rw-r--r--examples/ex06a_color_select.c52
1 files changed, 48 insertions, 4 deletions
diff --git a/examples/ex06a_color_select.c b/examples/ex06a_color_select.c
index 3a243e8f..febec407 100644
--- a/examples/ex06a_color_select.c
+++ b/examples/ex06a_color_select.c
@@ -16,9 +16,30 @@ int main()
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
- int screenHeight = 450;
+ int screenHeight = 400;
- InitWindow(screenWidth, screenHeight, "raylib example 06a - color selection");
+ Color colors[21] = { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN,
+ GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW,
+ GREEN, SKYBLUE, PURPLE, BEIGE };
+
+ Rectangle recs[21]; // Rectangles array
+
+ // Fills recs data (for every rectangle)
+ for (int i = 0; i < 21; i++)
+ {
+ recs[i].x = 20 + 100*(i%7) + 10*(i%7);
+ recs[i].y = 40 + 100*(i/7) + 10*(i/7);
+ recs[i].width = 100;
+ recs[i].height = 100;
+ }
+
+ bool selected[21] = { false }; // Selected rectangles indicator
+
+ Vector2 mousePoint;
+
+ InitWindowEx(screenWidth, screenHeight, "raylib example 06a - color selection", false, "resources/mouse.png");
+
+ SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
@@ -26,7 +47,18 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
- // TODO: Update your variables here
+ mousePoint = GetMousePosition();
+
+ for (int i = 0; i < 21; i++) // Iterate along all the rectangles
+ {
+ if (CheckCollisionPointRec(mousePoint, recs[i]))
+ {
+ colors[i].a = 120;
+
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selected[i] = !selected[i];
+ }
+ else colors[i].a = 255;
+ }
//----------------------------------------------------------------------------------
// Draw
@@ -35,7 +67,19 @@ int main()
ClearBackground(RAYWHITE);
- // TODO: Comming soon...
+ for (int i = 0; i < 21; i++) // Draw all rectangles
+ {
+ DrawRectangleRec(recs[i], colors[i]);
+
+ // Draw four rectangles around selected rectangle
+ if (selected[i])
+ {
+ DrawRectangle(recs[i].x, recs[i].y, 100, 10, RAYWHITE); // Square top rectangle
+ DrawRectangle(recs[i].x, recs[i].y, 10, 100, RAYWHITE); // Square left rectangle
+ DrawRectangle(recs[i].x + 90, recs[i].y, 10, 100, RAYWHITE); // Square right rectangle
+ DrawRectangle(recs[i].x, recs[i].y + 90, 100, 10, RAYWHITE); // Square bottom rectangle
+ }
+ }
EndDrawing();
//----------------------------------------------------------------------------------