eco2d/code/apps/client/source/platform_raylib.c

63 lines
1.6 KiB
C
Raw Normal View History

2021-01-11 20:11:03 +00:00
#include "platform.h"
2021-01-10 16:42:01 +00:00
#include "raylib.h"
2021-05-05 09:25:05 +00:00
#include "network.h"
2021-05-04 20:44:55 +00:00
#include "game.h"
2021-05-05 09:25:05 +00:00
#include "entity_view.h"
2021-05-05 10:14:52 +00:00
#include "camera.h"
2021-01-10 16:42:01 +00:00
2021-01-10 16:52:20 +00:00
const uint16_t screenWidth = 800;
const uint16_t screenHeight = 450;
2021-01-10 16:42:01 +00:00
2021-05-05 10:14:52 +00:00
static Camera2D render_camera;
2021-01-11 20:11:03 +00:00
void platform_init() {
2021-01-11 13:47:14 +00:00
InitWindow(screenWidth, screenHeight, "eco2d - client");
2021-01-10 16:42:01 +00:00
SetTargetFPS(60);
2021-05-05 10:14:52 +00:00
render_camera.target = (Vector2){0.0f,0.0f};
render_camera.offset = (Vector2){screenWidth/2.0f, screenHeight/2.0f};
render_camera.rotation = 0.0f;
render_camera.zoom = 1.0f;
2021-01-10 16:42:01 +00:00
}
2021-01-11 20:11:03 +00:00
void platform_shutdown() {
2021-01-10 16:42:01 +00:00
CloseWindow();
}
2021-01-11 20:11:03 +00:00
uint8_t platform_is_running() {
2021-01-11 20:08:16 +00:00
return !WindowShouldClose();
}
2021-05-04 20:44:55 +00:00
void display_conn_status();
2021-05-05 09:25:05 +00:00
void DEBUG_draw_entities(uint64_t key, entity_view data);
2021-01-11 20:11:03 +00:00
void platform_render() {
2021-05-05 10:14:52 +00:00
camera game_camera = camera_get();
render_camera.target = (Vector2){game_camera.x, game_camera.y};
2021-01-10 16:42:01 +00:00
BeginDrawing();
2021-05-04 20:44:55 +00:00
ClearBackground(BLACK);
2021-05-05 10:14:52 +00:00
BeginMode2D(render_camera);
2021-05-05 13:14:02 +00:00
DrawRectangleV((Vector2){0,0}, (Vector2){40,40}, RED);
2021-05-06 15:30:38 +00:00
entity_view_map(&game_world_view_get_active()->entities, DEBUG_draw_entities);
2021-05-05 10:14:52 +00:00
EndMode2D();
2021-05-05 09:25:05 +00:00
display_conn_status();
2021-01-10 16:42:01 +00:00
EndDrawing();
}
2021-05-04 20:44:55 +00:00
void display_conn_status() {
if (game_is_networked()) {
if (network_client_is_connected()) {
DrawText("Connection: online", 5, 5, 12, GREEN);
} else {
DrawText("Connection: offline", 5, 5, 12, RED);
}
} else {
DrawText("Connection: single-player", 5, 5, 12, BLUE);
}
2021-05-05 09:25:05 +00:00
}
void DEBUG_draw_entities(uint64_t key, entity_view data) {
2021-05-05 10:14:52 +00:00
DrawCircle(data.x, data.y, 15.0f, RAYWHITE);
2021-05-04 20:44:55 +00:00
}