-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGame.h
145 lines (119 loc) · 2.87 KB
/
Game.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma once
#include "core.h"
#include "Arduboy.h"
#include "Maths.h"
#define SCREEN_WIDTH (WIDTH)
#define SCREEN_HEIGHT (HEIGHT)
#define BTN_U (UP_BUTTON)
#define BTN_D (DOWN_BUTTON)
#define BTN_L (LEFT_BUTTON)
#define BTN_R (RIGHT_BUTTON)
#define BTN_B (B_BUTTON)
#define BTN_A (A_BUTTON)
struct GameCore
{
Arduboy arduboy;
byte nowInput;
byte prevInput;
char qx, qy;
void setup(void)
{
arduboy.setup();
arduboy.setFrameRate(60);
nowInput = 0x00;
prevInput = 0xff;
}
void updateInput(void)
{
prevInput = nowInput;
nowInput = arduboy.getInput();
}
bool pressed(byte button) const
{
return (nowInput & button) != 0;
}
bool pushed(byte button) const
{
return (nowInput & button) != 0 && (prevInput & button) == 0;
}
bool released(byte button) const
{
return (nowInput & button) == 0 && (prevInput & button) != 0;
}
// functions nicked from gamemaker.they're handyish.
float lengthdirX(float len, float dir)
{
return(len * cos(dir));
}
float lengthdirY(float len, float dir)
{
return(len * sin(dir));
}
// found at http:// xoax.net / cpp / ref / cpp_examples / incl / distance_points_plane/
float Distance(int dX0, int dY0, int dX1, int dY1)
{
return sqrt((dX1 - dX0) * (dX1 - dX0) + (dY1 - dY0) * (dY1 - dY0));
}
// delegation time!
inline int cpuLoad(void)
{
return arduboy.cpuLoad();
}
inline bool nextFrame(void)
{
return arduboy.nextFrame();
}
inline void clearDisplay(void)
{
arduboy.clearDisplay();
}
inline void fillScreen(byte c)
{
arduboy.fillScreen(c);
}
inline void display(void)
{
arduboy.display();
}
inline int frameCount(void)
{
return arduboy.frameCount;
}
// draws
inline void drawPixel(int x, int y, byte c)
{
arduboy.drawPixel(x + qx, y + qy, c);
}
inline void drawLine(int x0, int y0, int x1, int y1, uint8_t c)
{
arduboy.drawLine(x0, y0, x1, y1, c);
}
inline void drawBitmap(int x, int y, const byte * bitmap, byte c)
{
arduboy.drawBitmap(x + qx, y + qy, bitmap + 2, pgm_read_byte(bitmap), pgm_read_byte(bitmap + 1), c);
}
inline void drawBitmapSlow(int x, int y, const byte * bitmap, byte c)
{
arduboy.drawSlowXYBitmap(x + qx, y + qy, bitmap + 2, pgm_read_byte(bitmap), pgm_read_byte(bitmap + 1), c);
}
inline void drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint8_t color)
{
arduboy.fillTriangle (x0, y0, x1, y1, x2, y2, color);
}
inline void fillRect(int x, int y, int w, int h, byte c)
{
arduboy.fillRect(x + qx, y + qy, w, h, c);
}
inline void drawCircle(int x, int y, int r, byte c)
{
arduboy.drawCircle(x + qx, y + qy, r, c);
}
inline void setCursor(int x, int y)
{
arduboy.setCursor(x, y);
}
inline void print(const char * text)
{
arduboy.print(text);
}
};