4 This is Nibble (CircuitMess) implementation of the game front end.
6 by Miloslav Ciz (drummyfish), 2021
8 Released under CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0/)
9 plus a waiver of all other intellectual property. The goal of this work is to
10 be and remain completely in the public domain forever, available for any use
16 #include <CircuitOS.h>
19 #define PLUS_BRIGHTNESS 2 // this can be changed (max: 8)
23 #define SFG_SCREEN_RESOLUTION_X 128
24 #define SFG_SCREEN_RESOLUTION_Y 128
27 #define SFG_RAYCASTING_MAX_STEPS 20
28 #define SFG_RAYCASTING_SUBSAMPLE 2
29 #define SFG_DIMINISH_SPRITES 1
30 #define SFG_DITHERED_SHADOW 1
32 #define SFG_CAN_EXIT 0 /* If the game is compiled into loeader, this can be set
33 to 1 which will show the "exit" option in the menu. */
39 uint16_t paletteRAM[256];
41 void SFG_setPixel(uint16_t x, uint16_t y, uint8_t colorIndex)
43 sprite->drawPixel(x,y,paletteRAM[colorIndex]);
46 uint32_t SFG_getTimeMs()
51 void SFG_sleepMs(uint16_t timeMs)
55 int8_t SFG_keyPressed(uint8_t key)
57 return key < 7 ? buttons[key] : 0;
60 void SFG_getMouseOffset(int16_t *x, int16_t *y)
64 void SFG_setMusic(uint8_t value)
68 void SFG_save(uint8_t data[SFG_SAVE_SIZE])
72 void SFG_processEvent(uint8_t event, uint8_t data)
76 uint8_t SFG_load(uint8_t data[SFG_SAVE_SIZE])
81 void SFG_playSound(uint8_t soundIndex, uint8_t volume)
85 case 0: Piezo.tone(120, 45); break; // shot
86 case 1: Piezo.tone(200, 30); break; // door
87 case 2: Piezo.tone(80, 60); break; // explosion
88 case 3: Piezo.tone(220, 50); break; // click
89 case 4: Piezo.tone(180, 60); break; // plasma
90 case 5: Piezo.tone(300, 10); break; // monster
95 // create button callbacks:
97 #define cbf(b,n) void b ## _down() { buttons[n] = 255; } void b ## _up() { buttons[n] = 0; }
110 display = Nibble.getDisplay();
111 sprite = display->getBaseSprite();
115 for (uint8_t i = 0; i < 7; ++i)
118 // move palette to RAM plus increase brightness of the colors:
120 for (int i = 0; i < 256; ++i)
123 helper = (helper < 8 - PLUS_BRIGHTNESS) ? PLUS_BRIGHTNESS : (7 - helper);
124 paletteRAM[i] = pgm_read_word(paletteRGB565 + i + helper);
127 // register button callbacks:
130 Input::getInstance()->setBtnPressCallback(b,b ## _down); \
131 Input::getInstance()->setBtnReleaseCallback(b,b ## _up);
146 Input::getInstance()->loop(0);