4 This is Ringo (MAKERphone) implementation of the game front end, using the
5 official library and Arduino libraries.
7 by Miloslav Ciz (drummyfish), 2020
9 For some reason makerphone display accepts 565 RGB values but displays them
10 as 332, so the colors are a little distorted.
12 Compile with -O1 (-O3 breaks the libraries).
14 Released under CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0/)
15 plus a waiver of all other intellectual property. The goal of this work is to
16 be and remain completely in the public domain forever, available for any use
21 #include <MAKERphone.h>
22 #include <utility/soundLib/MPWavLib.h>
24 #define SFG_SCREEN_RESOLUTION_X LCDWIDTH
25 #define SFG_SCREEN_RESOLUTION_Y LCDHEIGHT
28 #define SFG_RAYCASTING_MAX_STEPS 20
29 #define SFG_RAYCASTING_SUBSAMPLE 2
30 #define SFG_DIMINISH_SPRITES 1
31 #define SFG_CAN_EXIT 0
32 #define SFG_DITHERED_SHADOW 1
34 #define SAVE_FILE_NAME "/Anarch/anarch.sav"
40 void SFG_setPixel(uint16_t x, uint16_t y, uint8_t colorIndex)
42 mp.display.drawPixel(x,y,paletteRGB565[colorIndex]);
45 uint32_t SFG_getTimeMs()
50 void SFG_sleepMs(uint16_t timeMs)
56 int8_t SFG_keyPressed(uint8_t key)
60 #define b(button) (mp.buttons.timeHeld(button) > 0)
61 #define r(button) return b(button); break;
63 case SFG_KEY_UP: return (arrows & 0x04) || b(BTN_2); break;
64 case SFG_KEY_DOWN: return (arrows & 0x08) || b(BTN_5); break;
65 case SFG_KEY_RIGHT: return (arrows & 0x01) || b(BTN_6); break;
66 case SFG_KEY_LEFT: return (arrows & 0x02) || b(BTN_4); break;
67 case SFG_KEY_STRAFE_RIGHT: r(BTN_3)
68 case SFG_KEY_STRAFE_LEFT: r(BTN_1)
69 case SFG_KEY_JUMP: r(BTN_HASHTAG)
70 case SFG_KEY_MAP: r(BTN_ASTERISK)
71 case SFG_KEY_PREVIOUS_WEAPON: r(BTN_FUN_LEFT)
72 case SFG_KEY_NEXT_WEAPON: r(BTN_FUN_RIGHT)
73 case SFG_KEY_A: return b(BTN_A) || b(BTN_8); break;
74 case SFG_KEY_B: return b(BTN_B) || b(BTN_9); break;
75 case SFG_KEY_C: r(BTN_7);
76 case SFG_KEY_MENU: r(BTN_0);
77 default: return 0; break;
86 void SFG_getMouseOffset(int16_t *x, int16_t *y)
90 void SFG_setMusic(uint8_t value)
94 void SFG_save(uint8_t data[SFG_SAVE_SIZE])
96 SD.remove(SAVE_FILE_NAME);
97 File f = SD.open(SAVE_FILE_NAME,FILE_WRITE);
98 f.write(data,SFG_SAVE_SIZE);
102 void SFG_processEvent(uint8_t event, uint8_t data)
106 case SFG_EVENT_PLAYER_DIES: FastLED.showColor(CRGB::Red); break;
107 case SFG_EVENT_PLAYER_TAKES_ITEM: FastLED.showColor(CRGB::Green); break;
108 case SFG_EVENT_LEVEL_WON: FastLED.showColor(CRGB::Yellow); break;
113 uint8_t SFG_load(uint8_t data[SFG_SAVE_SIZE])
115 if (SD.exists(SAVE_FILE_NAME))
117 File f = SD.open(SAVE_FILE_NAME,FILE_READ);
118 f.read(data,SFG_SAVE_SIZE);
127 void SFG_playSound(uint8_t soundIndex, uint8_t volume)
130 uint16_t freq = 1000;
132 uint8_t vol = (((uint16_t) volume) * 64) / 256;
136 case 0: freq = 120; dur = 0.025; wave = SAW; break; // shot
137 case 1: freq = 200; dur = 0.03; wave = TRIANGLE; break; // door
138 case 2: freq = 80; dur = 0.02; wave = SAW; break; // explosion
139 case 3: freq = 220; dur = 0.005; wave = SAW; vol /= 4; break; // click
140 case 4: freq = 180; dur = 0.06; wave = TRIANGLE; break; // plasma
141 case 5: freq = 300; dur = 0.1; wave = SQUARE; vol /= 2; break; // monster
146 osc->setWaveform(wave);
153 osc = new Oscillator(SINE);
161 ((mp.buttons.getJoystickX() < 200)) << 0 |
162 ((mp.buttons.getJoystickX() > 900)) << 1 |
163 ((mp.buttons.getJoystickY() < 200)) << 2 |
164 ((mp.buttons.getJoystickY() > 900)) << 3;