ohsp

Prototype for a game with dual thruster controls.
git clone git://git.amin.space/ohsp.git
Log | Files | Refs | LICENSE

game.h (2322B)


      1 #ifndef GAME_H
      2 
      3 #include "entity.h"
      4 #include "vector.h"
      5 
      6 #include <stdint.h>
      7 
      8 #define TITLE "Obsolete Human Space Pilot"
      9 #define SCREEN_WIDTH 640
     10 #define SCREEN_HEIGHT 480
     11 #define BYTES_PER_PIXEL 4
     12 
     13 #define SECOND 1000.0f
     14 #define FPS 60
     15 #define MS_PER_FRAME (SECOND / FPS)
     16 #define UPDATES_PER_SECOND 120
     17 #define MS_PER_UPDATE (SECOND / UPDATES_PER_SECOND)
     18 
     19 #ifndef M_PI
     20 #define M_PI 3.14159265358979f
     21 #endif
     22 
     23 #define COLOR_BACKGROUND 0x000000
     24 
     25 struct GameBounds
     26 {
     27     float center_x;
     28     float center_y;
     29     float side_length_x;
     30     float side_length_y;
     31 };
     32 
     33 struct GameControllerInput
     34 {
     35     uint8_t controller_index;
     36     float left_stick_x;
     37     float left_stick_y;
     38     float right_stick_x;
     39     float right_stick_y;
     40 };
     41 
     42 struct GameView
     43 {
     44     // TODO: Use a vec2d here
     45     float dx;
     46     float dy;
     47     float zoom;
     48 };
     49 
     50 struct GameState
     51 {
     52     struct Entity player;
     53     struct Vec2d thrust_vector01;
     54     struct Vec2d thrust_vector02;
     55     struct Vec2d thrust_vector_sum;
     56     struct GameView view;
     57     struct Entities *entities;
     58 };
     59 
     60 struct OffscreenBuffer
     61 {
     62     // NOTE(amin): pixels are always 32-bits wide. Memory order: BB GG RR XX.
     63     void *memory;
     64     unsigned int width;
     65     unsigned int height;
     66     unsigned int pitch;
     67 };
     68 
     69 // TODO: Consider using the #define trick from HMH
     70 typedef void (game_update_t)(struct GameState*, struct GameControllerInput, int, int);
     71 typedef void (game_render_t)(struct OffscreenBuffer*, float, struct GameState*);
     72 
     73 void game_init(struct GameState *game_state, int field_width, int field_height);
     74 void game_update(struct GameState *game_state, struct GameControllerInput game_input, int field_width, int field_height);
     75 void game_render(struct OffscreenBuffer *buffer, float dt, struct GameState *game_state);
     76 void game_render_circle(struct OffscreenBuffer *buffer, float x, float y, float radius, uint32_t color);
     77 void game_render_line(struct OffscreenBuffer *buffer, float x0, float y0, float x1, float y1, uint32_t color);
     78 void game_render_vector(struct OffscreenBuffer *buffer, struct Vec2d *v, float x0, float y0, float radius, uint32_t color);
     79 float game_calc_render_offset(float zoom, float delta, float pos, float center);
     80 void game_set_pixel(struct OffscreenBuffer *buffer, uint32_t x, uint32_t y, uint32_t color);
     81 void game_cleanup(struct GameState *game_state);
     82 
     83 #define GAME_H
     84 #endif