a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

game.h (1714B)


      1 #ifndef GAME_H
      2 #define GAME_H
      3 
      4 #include <limits.h>
      5 #include <stdalign.h>
      6 #include <stdbool.h>
      7 #include <stddef.h>
      8 #include <stdint.h>
      9 
     10 #if !defined(PLATFORM_WASM)
     11 #include <math.h>
     12 #endif
     13 
     14 #if !defined(PLATFORM_WASM)
     15 #include <assert.h>
     16 #include <stdio.h>
     17 #include <stdlib.h>
     18 #include <string.h>
     19 #endif // !PLATFORM_WASM
     20 
     21 #include "platform_info.h"
     22 
     23 #if defined(PLATFORM_WASM)
     24 #include "webgl.h"
     25 #else
     26 #include "am_gl.h"
     27 #endif
     28 
     29 #include "types.h"
     30 #include "intrinsics.h"
     31 #include "am_math.h"
     32 #include "shader.h"
     33 #include "memory.h"
     34 #include "render.h"
     35 #include "world.h"
     36 #include "input.h"
     37 #include "image.h"
     38 
     39 #include "platform.h"
     40 
     41 static_assert(-1 == ~0, "Implementation doesn't use two's complement");
     42 
     43 // One tile is one square meter
     44 #define TILE_SIZE 1.0f
     45 #define JUMP_ALLOWANCE_MS 100
     46 
     47 // TODO: Move this to world.h
     48 struct AbsolutePos
     49 {
     50     v2i room;
     51     v2 local;
     52 };
     53 
     54 enum MoveMode
     55 {
     56     MOVE_MODE_FALLING,
     57     MOVE_MODE_GROUNDED,
     58     MOVE_MODE_CLIMBING,
     59     MOVE_MODE_JUMPING,
     60     MOVE_MODE_FLOATING,
     61 };
     62 
     63 enum Direction
     64 {
     65     DIR_RIGHT,
     66     DIR_LEFT,
     67     DIR_UP,
     68     DIR_DOWN,
     69 };
     70 
     71 struct Entity
     72 {
     73     struct AbsolutePos pos;
     74     v2 acceleration;
     75     v2 velocity;
     76     v2 dimensions;
     77     enum Direction facing;
     78     enum MoveMode move_mode;
     79     f32 jump_timeout;
     80 };
     81 
     82 struct Timer
     83 {
     84     i64 elapsed_ms;
     85     i64 limit_ms;
     86 };
     87 
     88 struct GameState
     89 {
     90     struct RendererState renderer;
     91     struct Entity player;
     92     struct StackAllocator temp_allocator;
     93     struct StackAllocator world_allocator;
     94     struct Timer jump_allowance_timer;
     95     struct World *world;
     96 };
     97 
     98 internal void game_init(struct GameMemory *game_memory, v2u framebuffer);
     99 internal void game_cleanup(struct GameMemory *game_memory);
    100 
    101 #endif //GAME_H