-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.hh
109 lines (92 loc) · 2.51 KB
/
main.hh
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef _main_hh_
#define _main_hh_
namespace rl {
#include "raylib.h"
}
#include <cmath>
static const int W = 800;
static const int H = 500;
// Scenes
class scene {
public:
virtual void update() {}
virtual void draw() {}
virtual void pton(float, float) {}
virtual void ptmove(float, float) {}
virtual void ptoff(float, float) {}
#ifdef SHOWCASE
virtual const char *scr() { return nullptr; }
#endif
virtual ~scene() { }
};
scene *scene_startup();
scene *scene_text(int text_id);
scene *scene_game(int level_id);
void replace_scene(scene *s);
// Maths
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
struct vec2 {
float x, y;
vec2(float x = 0, float y = 0) : x(x), y(y) { }
inline vec2 operator + (const vec2 &b) const { return vec2(x + b.x, y + b.y); }
inline vec2 operator - (const vec2 &b) const { return vec2(x - b.x, y - b.y); }
inline vec2 operator - () const { return vec2(-x, -y); }
inline vec2 operator * (const float k) const { return vec2(x * k, y * k); }
inline vec2 operator / (const float k) const { return vec2(x / k, y / k); }
inline float dot(const vec2 &b) const { return x * b.x + y * b.y; }
inline float det(const vec2 &b) const { return x * b.y - y * b.x; }
inline vec2 operator * (const vec2 &b) const { return vec2(x * b.x, y * b.y); }
inline vec2 rot(const float a) const {
float sin_a = sinf(a), cos_a = cosf(a);
return vec2(x * cos_a - y * sin_a, x * sin_a + y * cos_a);
}
inline float norm() const { return sqrtf(x * x + y * y); }
};
struct tint4 {
float r, g, b, a;
tint4(float r = 0, float g = 0, float b = 0, float a = 1)
: r(r), g(g), b(b), a(a) { }
};
// Painter
class painter {
public:
static void init();
static void text(
const char *s, int size,
vec2 pos, vec2 anchor,
tint4 tint);
static void image(
const char *name,
vec2 pos,
tint4 tint);
static void image(
const char *name,
vec2 pos, vec2 dims,
tint4 tint);
static void image(
const char *name,
vec2 pos, vec2 anchor, vec2 scale,
tint4 tint);
static void image(
const char *name,
vec2 pos, vec2 dims,
vec2 src_pos, vec2 src_dims,
vec2 anchor, float rot,
tint4 tint);
};
// Sound
class sound {
public:
static void init();
static void play(const char *name, float pan = 0.5);
static float bellflowers_pan(float x, float x_cen);
static const char *bellflower_pop_zero(int cur, int total);
};
// Translation
extern char lang;
template <typename T> T _(const T a, const T b) {
return (lang == 0 ? a : b);
}
#endif