generated from 32blit/32blit-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
track.hpp
115 lines (81 loc) · 2.12 KB
/
track.hpp
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
110
111
112
113
114
115
#pragma once
#include <cstdint>
#include <vector>
#include "graphics/surface.hpp"
#include "types/point.hpp"
#include "types/rect.hpp"
#include "types/vec2.hpp"
#include "sprite3d.hpp"
#include "surface-helper.hpp"
class Camera;
class Kart;
class Track;
namespace blit {
struct TileMap;
}
enum class ObjectType : uint8_t {
Removed,
Static, // obstacle
Item,
DroppedItem, // usualy an obstacale, removed when hit
Projectile, // moving obstacle
};
class TrackObjectInfo final {
public:
ObjectType type;
uint8_t scale; //*16
uint16_t pos_x, pos_y;
uint8_t sprite_x, sprite_y, sprite_w, sprite_h; // spritesheet coords
uint8_t origin_x, origin_y;
};
class TrackInfo final {
public:
const char *name;
blit::Point finish_line[2];
const blit::Point *route;
size_t route_len;
const blit::Rect *collision_rects;
size_t num_collision_rects;
const float *tile_friction;
size_t tile_friction_len;
const TrackObjectInfo *sprites;
size_t num_sprites;
const uint8_t *map_asset, *tiles_asset;
blit::Pen background_col;
};
class TrackObject final {
public:
TrackObject(ObjectType type);
TrackObject(const TrackObjectInfo &info, blit::Surface *spritesheet);
void update();
void collide(Kart &kart);
bool is_active() const;
ObjectType type;
uint16_t respawn_timer = 0;
Sprite3D sprite;
blit::Vec3 vel;
Track *track = nullptr;
};
class Track final {
public:
Track(const TrackInfo &info);
~Track();
void render(const Camera &cam);
const TrackInfo &get_info() const;
blit::Surface *get_tiles();
blit::TileMap &get_map();
void reset_objects();
std::vector<TrackObject> &get_objects();
void add_object(TrackObject object);
unsigned int find_closest_route_segment(blit::Vec2 pos, float &segment_t) const;
float get_friction(blit::Vec2 pos);
blit::Vec2 get_starting_dir() const;
void set_fog(float fog);
private:
void load_tilemap();
const TrackInfo &info;
OwnedSurface tiles;
blit::TileMap *map;
std::vector<TrackObject> objects;
float fog = 170.0f;
};