summaryrefslogtreecommitdiff
path: root/src/game.h
blob: 1b8f95754ecb6d93f455bc3bf362343c5601ae3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef GAME_H

#include "entity.h"

#include <stdint.h>

#define TITLE "Obsolete Human Space Pilot"
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define BYTES_PER_PIXEL 4

#define SECOND 1000.0f
#define FPS 60
#define MS_PER_FRAME (SECOND / FPS)
#define UPDATES_PER_SECOND 120
#define MS_PER_UPDATE (SECOND / UPDATES_PER_SECOND)

#ifndef M_PI
#define M_PI (3.14159265358979323846264338327950288)
#endif

#define COLOR_BACKGROUND 0x000000

struct GameBounds
{
    float center_x;
    float center_y;
    float side_length_x;
    float side_length_y;
};

struct GameControllerInput
{
    uint8_t controller_index;
    float left_stick_x;
    float left_stick_y;
    float right_stick_x;
    float right_stick_y;
};

struct GameView
{
    float dx;
    float dy;
    float zoom;
};

struct GameState
{
    struct Entity player;
    struct GameView view;
};

struct OffscreenBuffer
{
    // NOTE(amin): pixels are always 32-bits wide. Memory order: BB GG RR XX.
    void *memory;
    unsigned int width;
    unsigned int height;
    unsigned int pitch;
};

void game_init(struct GameState *game_state, int field_width, int field_height);
void game_update(struct GameState *game_state, struct GameControllerInput game_input, int field_width, int field_height);
void game_render(struct OffscreenBuffer *buffer, float dt, struct GameState *game_state);
void game_render_circle(struct OffscreenBuffer *buffer, float x, float y, float radius, uint32_t color);
float game_calc_render_offset(float zoom, float delta, float pos, float center);
void game_set_pixel(struct OffscreenBuffer *buffer, uint32_t x, uint32_t y, uint32_t color);
void game_cleanup(struct GameState *game_state);

#define GAME_H
#endif