aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2016-03-05 15:40:08 +0100
committerraysan5 <raysan5@gmail.com>2016-03-05 15:40:08 +0100
commit5ea18b9426823e92f1fc16e686702f2caadf83c9 (patch)
treec668cd3dd6b4d80c6f521ab3b080ebf27216e81d /examples
parentd8bd8634ab7d5179cb1481206176af1f8e592e75 (diff)
downloadraylib-5ea18b9426823e92f1fc16e686702f2caadf83c9.tar.gz
raylib-5ea18b9426823e92f1fc16e686702f2caadf83c9.zip
Support 2d camera system -IN PROGRESS-
Diffstat (limited to 'examples')
-rw-r--r--examples/core_2d_camera.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/examples/core_2d_camera.c b/examples/core_2d_camera.c
new file mode 100644
index 00000000..71c474f0
--- /dev/null
+++ b/examples/core_2d_camera.c
@@ -0,0 +1,71 @@
+/*******************************************************************************************
+*
+* raylib [core] example - 2d camera
+*
+* This example has been created using raylib 1.5 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2016 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera");
+
+ Camera2D camera;
+
+ camera.position = (Vector2){ 0, 0 };
+ camera.origin = (Vector2){ 100, 100 };
+ camera.rotation = 0.0f;
+ camera.zoom = 1.0f;
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ if (IsKeyDown(KEY_RIGHT)) camera.position.x--;
+ else if (IsKeyDown(KEY_LEFT)) camera.position.x++;
+ else if (IsKeyDown(KEY_UP)) camera.position.y++;
+ else if (IsKeyDown(KEY_DOWN)) camera.position.y--;
+
+ if (IsKeyDown(KEY_R)) camera.rotation--;
+ else if (IsKeyDown(KEY_F)) camera.rotation++;
+
+ if (IsKeyDown(KEY_W)) camera.zoom += 0.005f;
+ if (IsKeyDown(KEY_S)) camera.zoom -= 0.005f;
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawingEx(camera);
+
+ ClearBackground(RAYWHITE);
+
+ DrawText("2D CAMERA TEST", 20, 20, 20, GRAY);
+
+ DrawRectangle(0, 300, screenWidth, 50, GRAY);
+ DrawRectangle(400, 250, 40, 40, RED);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file