Drei Extraleben, x 0 auch noch spielbar. Anzeigeschirm besser formatiert.
[hackover2013-badge-firmware.git] / badge / jumpnrun / tiles.h
1 #ifndef INCLUDED_JUMPNRUN_TILES_H
2 #define INCLUDED_JUMPNRUN_TILES_H
3
4 #include "../util/fixed_point.h"
5 #include "../util/rectangle.h"
6 #include "../ui/sprite.h"
7
8 #include <stdint.h>
9
10 enum {
11 JUMPNRUN_COLLISION_TOP = 1,
12 JUMPNRUN_COLLISION_BOTTOM = 2,
13 JUMPNRUN_COLLISION_LEFT = 4,
14 JUMPNRUN_COLLISION_RIGHT = 8
15 };
16
17 enum {
18 JUMPNRUN_TILE_PIXEL_WIDTH = 5,
19 JUMPNRUN_TILE_PIXEL_HEIGHT = 5
20 };
21
22 typedef struct jumpnrun_tile_position {
23 int16_t x;
24 int8_t y;
25 } jumpnrun_tile_position;
26
27 typedef struct jumpnrun_tile_type {
28 uint8_t lethal_sides;
29 badge_sprite sprite;
30 } jumpnrun_tile_type;
31
32 typedef struct jumpnrun_tile {
33 jumpnrun_tile_position pos;
34 uint8_t type;
35 } jumpnrun_tile;
36
37 typedef struct jumpnrun_tile_range {
38 size_t first;
39 size_t last; // actually one past last.
40 } jumpnrun_tile_range;
41
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)); }
46
47 /************************************/
48
49 enum {
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,
60
61 JUMPNRUN_TILE_TYPE_COUNT
62 };
63
64 extern jumpnrun_tile_type const jumpnrun_tile_type_data[JUMPNRUN_TILE_TYPE_COUNT];
65
66 static inline jumpnrun_tile_type const *tile_type(jumpnrun_tile const *tile) {
67 return &jumpnrun_tile_type_data[tile->type];
68 }
69
70 static inline rectangle rect_from_tile(jumpnrun_tile const *tile) {
71 rectangle r = {
72 {
73 tile_left(tile),
74 tile_top(tile)
75 }, {
76 FIXED_POINT(tile_type(tile)->sprite.width , 0),
77 FIXED_POINT(tile_type(tile)->sprite.height, 0)
78 }
79 };
80 return r;
81 }
82
83 #endif
This page took 0.046791 seconds and 5 git commands to generate.