| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #include "cglm/types.h"
- #include "scufeng/engine.h"
- #include "scufeng/text.h"
- #include "screen.h"
- #include "MainMenu.h"
- #include "SinglePlayer.h"
- #include "MultiPlayer.h"
- static const unsigned int screen_w = 1200;
- static const unsigned int screen_h = 600;
- static const float paddles_w = 0.01f;
- static const float paddles_h = 0.10f;
- static const float paddle_l_x = (1.0f / 16);
- static const float ball_w = paddles_w * 0.5f;
- static vec2 ball_pos = { 0.5f, 0.5f };
- static const float paddle_speed = 0.7f;
- static const float ball_speed = 0.7f;
- int main() {
- se_init(true);
- se_window_create(screen_w, screen_h, "Pong", -1);
- se_swap_interval(0);
- se_fps_lock_set_fps(60);
- se_font_load(FONT_PATH, 0, 48);
- se_clear_color(0.0f, 0.0f, 0.0f, 1.0f);
- MainMenu mm = MainMenu_alloc(screen_w, screen_h);
- SinglePlayer sp;
- double last_frame_time = 0.0;
- while (!se_window_should_close()) {
- const double current_time = se_get_time();
- const double delta = current_time - last_frame_time;
- last_frame_time = current_time;
- se_fps_lock_frame_start_s(current_time);
- se_clear();
- se_handle_events();
- switch (current_screen) {
- case PONG_MAIN_MENU:
- current_screen = MainMenu_tick(&mm);
- if (current_screen == PONG_SINGLEPLAYER) {
- sp = SinglePlayer_alloc(
- screen_w,
- screen_h,
- paddles_w,
- paddles_h,
- paddle_l_x,
- paddle_speed,
- ball_w,
- ball_pos,
- ball_speed
- );
- }
- break;
- case PONG_SINGLEPLAYER:
- current_screen = SinglePlayer_tick(&sp, delta);
- if (current_screen == PONG_MAIN_MENU) {
- SinglePlayer_free(&sp);
- }
- break;
- case PONG_MULTIPLAYER:
- MultiPlayer_tick();
- break;
- }
- // printf("%u %u\n", sp.state.score_l, sp.state.score_r);
- se_fps_lock_wait();
- se_swap_buffers();
- // printf("FT: %lf FPS: %lf\n", se_get_time() - current_time, 1.0 / (se_get_time() - current_time));
- }
- return 0;
- }
|