-
Notifications
You must be signed in to change notification settings - Fork 7
/
matrixman.ino
94 lines (77 loc) · 2.32 KB
/
matrixman.ino
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
#include "matrixman-gamefile.h"
#include <SmartMatrix_32x32.h>
SmartMatrix matrix;
/*------------------Display Specific Funcions----------------------------*/
void initDisplay(void) {
matrix.begin();
matrix.setBrightness(128);
}
void displayClear(uint8_t color) {
matrix.fillScreen({colors[color][0],colors[color][1],colors[color][2]});
displayLatch();
}
void displayGameOver(void) {
matrix.setScrollOffsetFromEdge(13);
matrix.setScrollMode(wrapForward);
matrix.scrollText("Game Over", 1);
while(matrix.getScrollStatus() > 0) { }
}
void displayPixel(uint8_t x, uint8_t y, char color) {
matrix.drawPixel(x,y-2,{colors[color][0],colors[color][1],colors[color][2]});
}
void displayClose(void) {
}
void displayLatch(void) {
matrix.swapBuffers();
}
/*---------------------Control Specific Funcitons ----------------------*/
#define JOYUP 24
#define JOYDOWN 25
#define JOYLEFT 26
#define JOYRIGHT 27
#define JOYBUT 28
void initControl(void) {
pinMode(JOYUP, INPUT_PULLUP);
pinMode(JOYDOWN, INPUT_PULLUP);
pinMode(JOYLEFT, INPUT_PULLUP);
pinMode(JOYRIGHT, INPUT_PULLUP);
pinMode(JOYBUT, INPUT_PULLUP);
}
uint8_t getControl(void) {
if (digitalRead(JOYUP) == LOW) { return UP; }
if (digitalRead(JOYDOWN) == LOW) { return DOWN; }
if (digitalRead(JOYLEFT) == LOW) { return LEFT; }
if (digitalRead(JOYRIGHT) == LOW) { return RIGHT; }
if (digitalRead(JOYBUT) == LOW) { return BUTTON; }
/*--------------Need to implement this for teensy --------------------
if (SDL_PollEvent(&event)) {
if (event.type == SDL_KEYDOWN) {
SDL_Keycode keyPressed = event.key.keysym.sym;
switch (keyPressed)
{
case SDLK_ESCAPE:
return ESCAPE;
case SDLK_UP:
return UP;
case SDLK_DOWN:
return DOWN;
case SDLK_LEFT:
return LEFT;
case SDLK_RIGHT:
return RIGHT;
}
}
}
--------------------------------------------------------------------*/
return NOINPUT;
}
void controlDelayMs(uint16_t ms) {
delay(ms);
}
void setup() {
// put your setup code here, to run once:
}
void loop() {
//Everything is handled in the matrixman.c loop
playMatrixman();
}