1 #ifndef INCLUDED_JUMPNRUN_TILES_H
2 #define INCLUDED_JUMPNRUN_TILES_H
4 #include "../util/fixed_point.h"
5 #include "../util/rectangle.h"
6 #include "../ui/sprite.h"
11 JUMPNRUN_TILE_TOP
= 1,
12 JUMPNRUN_TILE_BOTTOM
= 2,
13 JUMPNRUN_TILE_LEFT
= 4,
14 JUMPNRUN_TILE_RIGHT
= 8
15 } jumpnrun_tile_sides
;
18 JUMPNRUN_TILE_PIXEL_WIDTH
= 5,
19 JUMPNRUN_TILE_PIXEL_HEIGHT
= 5
22 typedef struct jumpnrun_tile_position
{
25 } jumpnrun_tile_position
;
27 typedef struct jumpnrun_tile_type
{
32 typedef struct jumpnrun_tile
{
33 jumpnrun_tile_position pos
;
37 typedef struct jumpnrun_tile_range
{
39 size_t last
; // actually one past last.
40 } jumpnrun_tile_range
;
42 static inline fixed_point
tile_left (jumpnrun_tile
const *tile
) { return FIXED_POINT(tile
->pos
.x
* JUMPNRUN_TILE_PIXEL_WIDTH
, 0); }
43 static inline fixed_point
tile_top (jumpnrun_tile
const *tile
) { return FIXED_POINT(tile
->pos
.y
* JUMPNRUN_TILE_PIXEL_HEIGHT
, 0); }
44 static inline fixed_point
tile_right (jumpnrun_tile
const *tile
) { return fixed_point_add(tile_left(tile
), FIXED_POINT(JUMPNRUN_TILE_PIXEL_WIDTH
, 0)); }
45 static inline fixed_point
tile_bottom(jumpnrun_tile
const *tile
) { return fixed_point_add(tile_top (tile
), FIXED_POINT(JUMPNRUN_TILE_PIXEL_HEIGHT
, 0)); }
47 /************************************/
50 JUMPNRUN_TILE_TYPE_BRICK
,
51 JUMPNRUN_TILE_TYPE_SQUARE
,
52 JUMPNRUN_TILE_TYPE_TUBE_TOP_LEFT
,
53 JUMPNRUN_TILE_TYPE_TUBE_TOP_RIGHT
,
54 JUMPNRUN_TILE_TYPE_TUBE_LEFT
,
55 JUMPNRUN_TILE_TYPE_TUBE_RIGHT
,
57 JUMPNRUN_TILE_TYPE_COUNT
60 extern jumpnrun_tile_type
const jumpnrun_tile_type_data
[JUMPNRUN_TILE_TYPE_COUNT
];
62 static inline jumpnrun_tile_type
const *tile_type(jumpnrun_tile
const *tile
) {
63 return &jumpnrun_tile_type_data
[tile
->type
];
66 static inline rectangle
rect_from_tile(jumpnrun_tile
const *tile
) {
72 FIXED_POINT(tile_type(tile
)->sprite
.width
, 0),
73 FIXED_POINT(tile_type(tile
)->sprite
.height
, 0)