Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <raylib.h>
- #define RAYGUI_IMPLEMENTATION
- #include <raygui.h>
- #include <stdint.h>
- #include <iostream>
- #include <vector>
- const int DEFAULT_WIDTH = 800;
- const int DEFAULT_HEIGHT = 600;
- const int BOUNDS_ASSERTIONS = false;
- static void todoImpl(uint64_t line, const char* file) {
- std::cerr << file << ":" << line << " is todo" << std::endl;
- exit(1);
- }
- #define TODO() \
- todoImpl(__LINE__, __FILE__)
- void initWindow() {
- SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
- InitWindow(DEFAULT_WIDTH, DEFAULT_HEIGHT, "sand experiment 3");
- BeginDrawing();
- {
- ClearBackground(BLACK);
- DrawText("Loading sand...", 10, 10, 20, RAYWHITE);
- }
- EndDrawing();
- }
- const int COLUMN_WIDTH = 800;
- const int ROW_HEIGHT = 600;
- // class Grid {
- // public:
- // std::vector<bool> cellIsSand = std::vector<bool>();
- // uint64_t grid_width = 0;
- // uint64_t grid_height = 0;
- // inline uint64_t cellPosV(Vector2 pos) {
- // uint64_t pos = (pos.y * COLUMN_WIDTH) + pos.x;
- // return pos;
- // }
- // inline bool cellHasSandV(Vector2 cellPos) {
- // }
- // inline Grid() {
- // }
- // };
- static int CAMERA_ZOOM = 1;
- float screen_ratio(int current_size, int default_size) {
- return (float)current_size / (float)default_size;
- }
- int main() {
- initWindow();
- Rectangle menu_bounds = Rectangle{0, 0, COLUMN_WIDTH, 50};
- Rectangle sim_bounds = Rectangle {0, 60, COLUMN_WIDTH, ROW_HEIGHT-60};
- Camera2D camera = Camera2D {};
- camera.offset = Vector2{0, 60};
- camera.rotation = 0;
- camera.target = Vector2{0, 60};
- // camera.target = Vector2{COLUMN_WIDTH/2, ROW_HEIGHT/2};
- camera.zoom = 1;
- bool firstRun = true;
- while (!WindowShouldClose())
- {
- BeginDrawing();
- {
- ClearBackground(BLACK);
- DrawRectangleRec(menu_bounds, BROWN);
- for (int i = 0; i < 3; i++) {
- Rectangle bounds = menu_bounds;
- bounds.y += 5;
- bounds.x += 5;
- bounds.width = 50;
- bounds.height = 40;
- bounds.x = (60* i) + 10;
- GuiButton(bounds, "meow");
- }
- BeginMode2D(camera);
- {
- DrawRectangleRec(sim_bounds, GREEN);
- }
- EndMode2D();
- }
- EndDrawing();
- // update camera if window resized
- if (IsWindowResized() || firstRun) {
- int new_h = GetScreenHeight();
- int new_w = GetScreenWidth();
- float ratio_h = screen_ratio(new_h, ROW_HEIGHT); // (float)new_h / (float)HEIGHT;
- float ratio_w = screen_ratio(new_w, COLUMN_WIDTH); // (float)new_w / (float)WIDTH;
- // smallest ratio means window is smallest along that dimension
- if (ratio_w < ratio_h) {
- camera.zoom = ratio_w * 0.99;
- } else {
- camera.zoom = ratio_h * 0.99;
- }
- CAMERA_ZOOM = camera.zoom;
- }
- PollInputEvents();
- firstRun = false;
- }
- CloseWindow();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement