summaryrefslogtreecommitdiffhomepage
path: root/src/main.cpp
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2022-11-05 02:04:30 -0400
committerrealtradam <[email protected]>2022-11-05 02:04:30 -0400
commit3c8e6238ebed92691dac9393893ca6214ab060ab (patch)
treea6bcb9ddca6608a39b70e667231e73bb2ce19472 /src/main.cpp
parente35ff8879409dae845371be867ca76a1cf78cf7f (diff)
downloadorbital_game-3c8e6238ebed92691dac9393893ca6214ab060ab.tar.gz
orbital_game-3c8e6238ebed92691dac9393893ca6214ab060ab.zip
implemented rough physics system
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp92
1 files changed, 50 insertions, 42 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 7af702a..50ccd47 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,51 +1,59 @@
#include "raylib.h"
+#include "raymath.h"
#include "resources.hpp"
#include "renderer.hpp"
+#include "physics.hpp"
+#include <iostream>
+
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main(void)
{
- // Initialization
- //--------------------------------------------------------------------------------------
- const int screenWidth = 800;
- const int screenHeight = 800;
-
- InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
-
- SetTargetFPS(60); // Set our game to run at 60 frames-per-second
- //--------------------------------------------------------------------------------------
-
- auto ship = Renderer::Sprite("kenneySpaceShooter", (Rectangle){1365,1696,198,188}, (Vector2){19.80/2,18.80/2});
- auto rock = Renderer::Sprite("kenneySpaceShooter", (Rectangle){0,800,440,442}, (Vector2){44.00/2, 44.20/2});
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- // TODO: Update your variables here
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- BeginDrawing();
-
- ClearBackground(BLACK);
-
- DrawText("Space!", 190, 200, 20, LIGHTGRAY);
- //DrawTexture(Resources::useTexture("ship"), 0, 0, WHITE);
- ship.draw(100,100, 0.1);
- rock.draw(750,750, 0.1);
-
- EndDrawing();
- //----------------------------------------------------------------------------------
- }
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 800;
+
+ InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
+ auto ship_sprite = Renderer::Sprite("kenneySpaceShooter", (Rectangle){1365,1696,198,188}, (Vector2){19.80/2,18.80/2});
+ auto rock_sprite = Renderer::Sprite("kenneySpaceShooter", (Rectangle){0,800,440,442}, (Vector2){44.00/2, 44.20/2});
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ // TODO: Update your variables here
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ for (int i = 0; i < 50000; i++) {
+ Physics::step(0.001);
+ }
+ std::cout << std::to_string(Vector2Distance(Physics::ship.position, Physics::rock.position)) << std::endl;
+ BeginDrawing();
+
+ ClearBackground(BLACK);
+
+ DrawText("Space!", 190, 200, 20, LIGHTGRAY);
+ //DrawTexture(Resources::useTexture("ship"), 0, 0, WHITE);
+ ship_sprite.draw(Physics::ship.position.x,Physics::ship.position.y, 0.1);
+ rock_sprite.draw(Physics::rock.position.x,Physics::rock.position.y, 0.1);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
}