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_COLLISION_TOP
= 1,
12 JUMPNRUN_COLLISION_BOTTOM
= 2,
13 JUMPNRUN_COLLISION_LEFT
= 4,
14 JUMPNRUN_COLLISION_RIGHT
= 8
18 JUMPNRUN_TILE_PIXEL_WIDTH
= 5,
19 JUMPNRUN_TILE_PIXEL_HEIGHT
= 5
22 typedef struct jumpnrun_tile_position
{
25 } __attribute__((packed
)) jumpnrun_tile_position
;
27 typedef struct jumpnrun_tile_type
{
32 typedef struct jumpnrun_tile
{
33 jumpnrun_tile_position pos
;
35 } __attribute__((packed
)) jumpnrun_tile
;
37 typedef struct jumpnrun_tile_range
{
39 uint16_t last
; // actually one past last.
40 } jumpnrun_tile_range
;
42 static inline fixed_point
tile_left (jumpnrun_tile
const *tile
) { return FIXED_INT(tile
->pos
.x
* JUMPNRUN_TILE_PIXEL_WIDTH
); }
43 static inline fixed_point
tile_top (jumpnrun_tile
const *tile
) { return FIXED_INT(tile
->pos
.y
* JUMPNRUN_TILE_PIXEL_HEIGHT
); }
44 static inline fixed_point
tile_right (jumpnrun_tile
const *tile
) { return fixed_point_add(tile_left(tile
), FIXED_INT(JUMPNRUN_TILE_PIXEL_WIDTH
)); }
45 static inline fixed_point
tile_bottom(jumpnrun_tile
const *tile
) { return fixed_point_add(tile_top (tile
), FIXED_INT(JUMPNRUN_TILE_PIXEL_HEIGHT
)); }
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
,
56 JUMPNRUN_TILE_TYPE_SPIKE_UP
,
57 JUMPNRUN_TILE_TYPE_SPIKE_RIGHT
,
58 JUMPNRUN_TILE_TYPE_SPIKE_DOWN
,
59 JUMPNRUN_TILE_TYPE_SPIKE_LEFT
,
61 JUMPNRUN_TILE_TYPE_COUNT
64 extern jumpnrun_tile_type
const jumpnrun_tile_type_data
[JUMPNRUN_TILE_TYPE_COUNT
];
66 static inline jumpnrun_tile_type
const *tile_type(jumpnrun_tile
const *tile
) {
67 return &jumpnrun_tile_type_data
[tile
->type
];
70 static inline rectangle
rect_from_tile(jumpnrun_tile
const *tile
) {
76 FIXED_POINT(tile_type(tile
)->sprite
.width
, 0),
77 FIXED_POINT(tile_type(tile
)->sprite
.height
, 0)