forked from lexus2k/ssd1306
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_basic.h
79 lines (62 loc) · 2.59 KB
/
game_basic.h
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
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "ssd1306.h"
#include "nano_engine.h"
typedef NanoEngine<TILE_16x16_RGB8> GraphicsEngine;
extern uint8_t gameField[];
extern GraphicsEngine engine;
static inline bool isWalkable(uint8_t type) { return (type == 0) || (type == 2) || (type == 3) || (type == 4); }
static inline bool isSolid(uint8_t type) { return (type == 1) || (type == 2) || (type == 5); }
static inline bool isPipe(uint8_t type) { return type == 3; }
static inline bool isGold(uint8_t type) { return type == 4; }
static inline bool isStair(uint8_t type) { return type == 2; }
static inline uint16_t block_index(const NanoPoint& block)
{
return block.x + block.y * 24;
}
static inline NanoPoint pos_to_block(const NanoPoint& pos)
{
return pos >> 3;
}
static inline NanoPoint block_to_pos(const NanoPoint& block)
{
return block << 3;
}
static inline NanoRect rect_to_blocks(const NanoRect& rect)
{
return rect >> 3;
}
static inline uint8_t block_value(const NanoPoint& block)
{
uint16_t index = block_index(block);
if (index >= 24*14) index = 0;
return gameField[index];
}
static inline uint8_t block_at(const NanoPoint& p)
{
return block_value(pos_to_block(p));
}
static inline void set_block_at(const NanoPoint& p, uint8_t v)
{
uint16_t index = block_index(pos_to_block(p));
if (index >= 24*14) index = 0;
gameField[index] = v;
}