Add christmas edition
This commit is contained in:
parent
2f1c7d9e82
commit
b62af486a7
74 changed files with 3422 additions and 1 deletions
74
christmas/AdAstra/src/mediator/mediator.c
Normal file
74
christmas/AdAstra/src/mediator/mediator.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#include "mediator.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "../hardware_access/hardware_access.h"
|
||||
#include "../objects/object_container/object_container.h"
|
||||
#include "../objects/event_generator/event_generator.h"
|
||||
#include "../objects/commands/commands.h"
|
||||
#include "../objects/ai/ai.h"
|
||||
#include "../driver/display/display.h"
|
||||
#include "../driver/infra/infra.h"
|
||||
#include "../driver/sleep/sleep.h"
|
||||
|
||||
#define TARGET_FRAME_DURATION 20 // ms
|
||||
#define DEATH_SCREEN_LENGTH 50 // frames
|
||||
#define SAVE_INTERVAL 50 // every x frames
|
||||
|
||||
static struct {
|
||||
uint8_t contrast;
|
||||
uint8_t framesSinceLastSave;
|
||||
uint8_t deathDownCounter;
|
||||
uint8_t receivedWakeUpBitCount;
|
||||
} state = {
|
||||
.contrast = 255
|
||||
};
|
||||
|
||||
static inline bool handleDeathAnimation() {
|
||||
if (isSpaceshipDestroyed()) {
|
||||
setDisplayContrast(state.contrast * (state.deathDownCounter / DEATH_SCREEN_LENGTH));
|
||||
if (state.deathDownCounter-- == 0) {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool frameFunction(uint8_t previousFrameTime) {
|
||||
tickObjects(previousFrameTime);
|
||||
handleCommands();
|
||||
handleAI();
|
||||
generateEvents();
|
||||
drawFrame();
|
||||
return handleDeathAnimation();
|
||||
}
|
||||
|
||||
static inline void initializeGame() {
|
||||
state.deathDownCounter = DEATH_SCREEN_LENGTH;
|
||||
setDisplayContrast(state.contrast);
|
||||
initializeBackground();
|
||||
initializeObjectContainer();
|
||||
}
|
||||
|
||||
void setupConnections() {
|
||||
initializeHardwareAccess();
|
||||
initializeInfra(addCommand);
|
||||
initializeDisplay(drawObjects);
|
||||
}
|
||||
|
||||
void startGame() {
|
||||
while (true) {
|
||||
initializeGame();
|
||||
startFrameLoop(frameFunction, TARGET_FRAME_DURATION);
|
||||
}
|
||||
}
|
||||
|
||||
void changeDisplayContrast(int8_t by) {
|
||||
if (by < 0) {
|
||||
state.contrast = (state.contrast < -by) ? 0 : (state.contrast + by);
|
||||
} else {
|
||||
state.contrast = (state.contrast > 255 - by) ? 255 : (state.contrast + by);
|
||||
}
|
||||
|
||||
setDisplayContrast(state.contrast);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue