Add documentation
This commit is contained in:
parent
62853bcedc
commit
c6063e28a4
47 changed files with 1011 additions and 148750 deletions
|
|
@ -9,12 +9,12 @@
|
|||
|
||||
|
||||
static uint8_t const configuration[] PROGMEM = {
|
||||
0xD5, 0xF0, // set clock frequency
|
||||
0x8D, 0x14, // enable charge pump
|
||||
0x20, 0x00, // horizontal addressing mode
|
||||
0xD6, 0x01, // 2 times vertical zoom
|
||||
0x22, 0x00, 0x03, // only draw to the top half of the screen
|
||||
0xAF // display on
|
||||
0xD5, 0xF0, /// set clock frequency
|
||||
0x8D, 0x14, /// enable charge pump
|
||||
0x20, 0x00, /// horizontal addressing mode
|
||||
0xD6, 0x01, /// 2 times vertical zoom
|
||||
0x22, 0x00, 0x03, /// only draw to the top half of the screen
|
||||
0xAF /// display on
|
||||
};
|
||||
|
||||
static struct {
|
||||
|
|
@ -43,8 +43,8 @@ void initializeDisplay(DrawFunction drawEverything) {
|
|||
setOutputPin(DISPLAY_RESET_OUTPUT_PIN, false);
|
||||
for (volatile uint8_t i = 0; i != 255; i++)
|
||||
;
|
||||
// some time has to elapse before the next line gets called,
|
||||
// otherwise the display wont turn on
|
||||
/// some time has to elapse before the next line gets called,
|
||||
/// otherwise the display wont turn on
|
||||
setOutputPin(DISPLAY_RESET_OUTPUT_PIN, true);
|
||||
|
||||
for (uint8_t i = 0; i < sizeof(configuration); i++) {
|
||||
|
|
|
|||
|
|
@ -7,51 +7,51 @@
|
|||
#include "../../util/rectangle/rectangle.h"
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
SPI driver for D096-12864
|
||||
*/
|
||||
|
||||
#define DISPLAY_RESET_OUTPUT_PIN PB0
|
||||
#define DISPLAY_DC_OUTPUT_PIN PB4
|
||||
|
||||
// A two-times downscaling is used for greater performance
|
||||
/// A two-times downscaling is used for greater performance
|
||||
#define DISPLAY_WIDTH_IN_PIXELS 64
|
||||
#define DISPLAY_HEIGHT_IN_PIXELS 32
|
||||
|
||||
// To easily access the window size
|
||||
/// To easily access the window size
|
||||
#define WINDOW ((Rectangle){(Vec2){0, 0}, (Vec2){DISPLAY_WIDTH_IN_PIXELS, DISPLAY_HEIGHT_IN_PIXELS}})
|
||||
|
||||
// To conserve RAM, drawing is done in chunks of DEFAULT_COMPOSITING_WINDOW size
|
||||
// instead of buffering the whole display and writing it out at once
|
||||
/// To conserve RAM, drawing is done in chunks of DEFAULT_COMPOSITING_WINDOW size
|
||||
/// instead of buffering the whole display and writing it out at once
|
||||
#define DEFAULT_COMPOSITING_WINDOW ((Rectangle){(Vec2){0, 0}, (Vec2){DISPLAY_WIDTH_IN_PIXELS, 8}})
|
||||
|
||||
typedef void (*DrawFunction)(Rectangle);
|
||||
|
||||
// Call DrawFunction n times after a call to drawFrame has been made
|
||||
/// Call DrawFunction n times after a call to drawFrame has been made
|
||||
void initializeDisplay(DrawFunction drawEverything);
|
||||
|
||||
// Set a the brightness of the display
|
||||
// Value can be any number between 0 and 255.
|
||||
/// Set a the brightness of the display
|
||||
/// Value can be any number between 0 and 255.
|
||||
void setDisplayContrast(uint8_t value);
|
||||
|
||||
// To conserve program memory, pixel based intersection test
|
||||
// is implemented here.
|
||||
// Calling draw functions after calling startIntersectionTest
|
||||
// will set a wasIntersection bit appropriately.
|
||||
/// To conserve program memory, pixel based intersection test
|
||||
/// is implemented here.
|
||||
/// Calling draw functions after calling startIntersectionTest
|
||||
/// will set a wasIntersection bit appropriately.
|
||||
|
||||
// Clear buffer and wasIntersection bit
|
||||
/// Clear buffer and wasIntersection bit
|
||||
void startIntersectionTest();
|
||||
|
||||
// Return wasIntersection bit
|
||||
/// Return wasIntersection bit
|
||||
bool endIntersectionTest();
|
||||
|
||||
// Initiate a draw sequence
|
||||
/// Initiate a draw sequence
|
||||
void drawFrame();
|
||||
|
||||
// Draw a sprite of size boundingBox.size at boundingBox.position from bitmap
|
||||
// if isMirrored then mirror around the vertical axis
|
||||
// Bitmap's data is interpreted the following way:
|
||||
/*
|
||||
/// Draw a sprite of size boundingBox.size at boundingBox.position from bitmap
|
||||
/// if isMirrored then mirror around the vertical axis
|
||||
/// Bitmap's data is interpreted the following way:
|
||||
/**
|
||||
Each 16 bit word corresponds to an 8 pixel high column.
|
||||
(These columns are laid out horizontally from left to right. Unfortunately,
|
||||
the display uses this addressing mode.) The higher 8 bits of the word is the
|
||||
|
|
@ -63,9 +63,9 @@ void drawFrame();
|
|||
*/
|
||||
void drawBitmapFromProgMem(Rectangle boundingBox, uint16_t const bitmap[boundingBox.size.x][(boundingBox.size.y + 7) / 8], bool isMirrored);
|
||||
|
||||
// Draw a one byte repeated texture covering the parameter box
|
||||
// for a white rectangle use these arguments: invertedMask: don't care, fill: 0xFF
|
||||
// for a black rectangle use these arguments: invertedMask: 0xFF, fill: 0x00
|
||||
/// Draw a one byte repeated texture covering the parameter box
|
||||
/// for a white rectangle use these arguments: invertedMask: don't care, fill: 0xFF
|
||||
/// for a black rectangle use these arguments: invertedMask: 0xFF, fill: 0x00
|
||||
void drawFilledRectangle(Rectangle box, uint8_t invertedMask, uint8_t fill);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@
|
|||
#include "../uart/receive.h"
|
||||
|
||||
|
||||
// (0.5625 + (0.5625 + 1.6875) / 2) / 1000 / timer interval
|
||||
/// (0.5625 + (0.5625 + 1.6875) / 2) / 1000 / timer interval
|
||||
#define MEAN_OF_0_1_BIT_TIMES 53
|
||||
// 9 / 2 / 1000 / timer interval
|
||||
/// 9 / 2 / 1000 / timer interval
|
||||
#define MAYBE_ONE_CHECK_TIME 141
|
||||
// some large value
|
||||
/// some large value
|
||||
#define TIMEOUT 254
|
||||
|
||||
typedef enum {
|
||||
|
|
@ -139,8 +139,8 @@ ISR(TIM0_COMPB_vect) {
|
|||
}
|
||||
|
||||
void initializeInfra(OnCommandReceived onCommandReceived) {
|
||||
setBit(PORTB, IR_PIN); // enable pull-up
|
||||
setBit(PCMSK, IR_PIN); // specific pin change interrupt enable
|
||||
setBit(GIMSK, PCIE); // global on pin change interrupt enable;
|
||||
setBit(PORTB, IR_PIN); /// enable pull-up
|
||||
setBit(PCMSK, IR_PIN); /// specific pin change interrupt enable
|
||||
setBit(GIMSK, PCIE); /// global on pin change interrupt enable;
|
||||
infra.onCommandReceived = onCommandReceived;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include <avr/io.h>
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
Custom NEC implementation using a TSOP4838
|
||||
*/
|
||||
|
||||
|
|
@ -15,9 +15,9 @@
|
|||
|
||||
typedef void (*OnCommandReceived)(uint8_t);
|
||||
|
||||
// Initialize infra and call onCommandReceived with every received byte
|
||||
// Call onCommandReceived with the argument REPEAT_CODE if a repeat code
|
||||
// has been received.
|
||||
/// Initialize infra and call onCommandReceived with every received byte
|
||||
/// Call onCommandReceived with the argument REPEAT_CODE if a repeat code
|
||||
/// has been received.
|
||||
void initializeInfra(OnCommandReceived onCommandReceived);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
#include <stdbool.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
// FrameFunction gets previousFrameTime (in milliseconds) as argument
|
||||
/// FrameFunction gets previousFrameTime (in milliseconds) as argument
|
||||
typedef bool (*FrameFunction)(uint8_t);
|
||||
|
||||
// Call function every frameLengthInMilliseconds while it returns true
|
||||
/// Call function every frameLengthInMilliseconds while it returns true
|
||||
void startFrameLoop(FrameFunction function, uint8_t frameLengthInMilliseconds);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
static struct {
|
||||
uint16_t message;
|
||||
uint8_t bitPosition; // goes from 0 to 9
|
||||
uint8_t bitPosition; /// goes from 0 to 9
|
||||
bool previousValue;
|
||||
uint8_t previousTimestamp;
|
||||
OnCommandReceived onCommandReceived;
|
||||
|
|
@ -17,8 +17,8 @@ static struct {
|
|||
};
|
||||
|
||||
void initializeUartReceive(OnCommandReceived onCommandReceived) {
|
||||
setBit(PORTB, RECEIVE_PIN); // setup pull-up
|
||||
setBit(PCMSK, RECEIVE_PIN); // enable interrupt on pin
|
||||
setBit(PORTB, RECEIVE_PIN); /// setup pull-up
|
||||
setBit(PCMSK, RECEIVE_PIN); /// enable interrupt on pin
|
||||
uartReceive.onCommandReceived = onCommandReceived;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +1,24 @@
|
|||
#ifndef RECEIVE_H
|
||||
#define RECEIVE_H
|
||||
|
||||
/*
|
||||
/**
|
||||
Custom UART receive implementation with a baud rate of 2400
|
||||
*/
|
||||
|
||||
|
||||
// 8*10^6 / 128 / 2400
|
||||
/// 8*10^6 / 128 / 2400
|
||||
#define BIT_TIME 26
|
||||
#define RECEIVE_PIN PB3
|
||||
|
||||
typedef void (*OnCommandReceived)(uint8_t);
|
||||
|
||||
// Initialize UART and call onCommandReceived with every byte received
|
||||
/// Initialize UART and call onCommandReceived with every byte received
|
||||
void initializeUartReceive(OnCommandReceived onCommandReceived);
|
||||
|
||||
// Check for change on the UART receive pin
|
||||
// This function exist so we can use a single interrupt
|
||||
// handler for both the UART receive and infra pins.
|
||||
// Unfortunately, it's not possible to use more than one handler.
|
||||
/// Check for change on the UART receive pin
|
||||
/// This function exist so we can use a single interrupt
|
||||
/// handler for both the UART receive and infra pins.
|
||||
/// Unfortunately, it's not possible to use more than one handler.
|
||||
void handlePinChangeForUartReceive();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ static struct {
|
|||
char bytes[ASYNC_BUFFER_SIZE];
|
||||
uint8_t start;
|
||||
uint8_t end;
|
||||
// 0 - start bit, 1-8 word bits, 9 - end bit
|
||||
/// 0 - start bit, 1-8 word bits, 9 - end bit
|
||||
uint8_t currentMaskPosition;
|
||||
} uartTransmitter;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,30 +4,30 @@
|
|||
#include <avr/io.h>
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
Custom UART trasnmit implementation with a baud rate of 2400
|
||||
*/
|
||||
|
||||
// 8*10^6 / 128 / 2400
|
||||
/// 8*10^6 / 128 / 2400
|
||||
#define BIT_TIME 26
|
||||
|
||||
// Messages cannot be longer than this many characters (including trailing zero)
|
||||
/// Messages cannot be longer than this many characters (including trailing zero)
|
||||
#define ASYNC_BUFFER_SIZE 20
|
||||
|
||||
#define UART_OUTPUT_PIN 2
|
||||
|
||||
// Start pulling-up the transmit line
|
||||
/// Start pulling-up the transmit line
|
||||
void initializeUartTransmit();
|
||||
|
||||
// Send a single byte over on UART
|
||||
// It's done in an asynchronous fashion using a circular buffer.
|
||||
/// Send a single byte over on UART
|
||||
/// It's done in an asynchronous fashion using a circular buffer.
|
||||
void sendByteOnUartAsync(char byte);
|
||||
|
||||
// Send a string over on UART
|
||||
// It's done in an asynchronous fashion using a circular buffer.
|
||||
/// Send a string over on UART
|
||||
/// It's done in an asynchronous fashion using a circular buffer.
|
||||
void sendTextOnUartAsync(char text[]);
|
||||
|
||||
// Send the decimal form of unsigned integer over UART
|
||||
/// Send the decimal form of unsigned integer over UART
|
||||
void sendUintOnUartAsync(uint8_t number);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -12,40 +12,40 @@
|
|||
#include "output_pins/output_pins.h"
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
This module contains the lowest level functions to manipulate the hardware.
|
||||
You only have to include this header file which serves as a facade.
|
||||
The sub-modules' implementation can be freely changed as long as they
|
||||
still implement these functions.
|
||||
*/
|
||||
|
||||
// Initialize every hardware element at once
|
||||
/// Initialize every hardware element at once
|
||||
void initializeHardwareAccess();
|
||||
|
||||
// Enable interrupt OCCRA for TIMER0 with a modulo of triggerInterruptInXTicks
|
||||
/// Enable interrupt OCCRA for TIMER0 with a modulo of triggerInterruptInXTicks
|
||||
void enableTimerA(uint8_t triggerInterruptInXTicks);
|
||||
|
||||
// Enable interrupt OCCRB for TIMER0B with a modulo of triggerInterruptInXTicks
|
||||
/// Enable interrupt OCCRB for TIMER0B with a modulo of triggerInterruptInXTicks
|
||||
void enableTimerB(uint8_t triggerInterruptInXTicks);
|
||||
void disableTimerB();
|
||||
|
||||
// Enable interrupt OCCRA for TIMER1 with a modulo of triggerInterruptInXTicks
|
||||
/// Enable interrupt OCCRA for TIMER1 with a modulo of triggerInterruptInXTicks
|
||||
void enableFastTimerA(uint8_t triggerInterruptInXTicks);
|
||||
void disableFastTimerA();
|
||||
|
||||
// Return TCNT1
|
||||
/// Return TCNT1
|
||||
uint8_t getTimestampFromFastTimer();
|
||||
|
||||
// Return the time since a timestamp returned by getTimestampFromFastTimer
|
||||
// Accounts for overflow.
|
||||
/// Return the time since a timestamp returned by getTimestampFromFastTimer
|
||||
/// Accounts for overflow.
|
||||
uint8_t getTimeSince(uint8_t timestamp);
|
||||
|
||||
// Send a single byte on the built-in SPI interface
|
||||
// The transfer is done in a serial manner to achieve
|
||||
// greater throughput.
|
||||
/// Send a single byte on the built-in SPI interface
|
||||
/// The transfer is done in a serial manner to achieve
|
||||
/// greater throughput.
|
||||
void sendByteOnSPI(uint8_t byte);
|
||||
|
||||
// Set the value of an output pin
|
||||
/// Set the value of an output pin
|
||||
void setOutputPin(uint8_t id, bool value);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#define CLK_ST_PIN PB0
|
||||
|
||||
// Uses a 74HC595 to extend the number of digital outputs
|
||||
/// Uses a 74HC595 to extend the number of digital outputs
|
||||
void sendCurrentValue();
|
||||
|
||||
inline void initializeOutputPins() {
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
|
||||
inline void initializePowerSaving() {
|
||||
setBit(ACSR, ACD); // disable ADC to save power
|
||||
PRR = BV(PRADC); // disable power to ADC (again?)
|
||||
setBit(ACSR, ACD); /// disable ADC to save power
|
||||
PRR = BV(PRADC); /// disable power to ADC (again?)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
#define USCK_PIN PB2
|
||||
|
||||
inline void initializeSPI() {
|
||||
DDRB |= BV(DO_PIN) | BV(USCK_PIN); // set pin directions for MOSI and SCK
|
||||
DDRB |= BV(DO_PIN) | BV(USCK_PIN); /// set pin directions for MOSI and SCK
|
||||
}
|
||||
|
||||
// This function can be used from other sibling sub-modules
|
||||
// it's required for the current outpu_pins implementation.
|
||||
/// This function can be used from other sibling sub-modules
|
||||
/// it's required for the current outpu_pins implementation.
|
||||
void sendByteOnSPI(uint8_t byte);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
#include "bitwise.h"
|
||||
|
||||
inline void initializeTiming() {
|
||||
TCCR0B = BV(CS02); // CLK / 256
|
||||
TCCR1 = BV(CS13); // CLK / 128
|
||||
TIMSK = BV(OCIE0A) | BV(OCIE1A); // enable compare interrupts
|
||||
TCCR0B = BV(CS02); /// CLK / 256
|
||||
TCCR1 = BV(CS13); /// CLK / 128
|
||||
TIMSK = BV(OCIE0A) | BV(OCIE1A); /// enable compare interrupts
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
#include "mediator/mediator.h"
|
||||
|
||||
|
||||
// Stemming from the module oriented nature of the project
|
||||
// there is a module responsible for setting up and orchestrating
|
||||
// the other modules.
|
||||
//
|
||||
// From the main function we only have to instruct the afromentioned
|
||||
// mediator module to do its job.
|
||||
/// Stemming from the module oriented nature of the project
|
||||
/// there is a module responsible for setting up and orchestrating
|
||||
/// the other modules.
|
||||
///
|
||||
/// From the main function we only have to instruct the aforementioned
|
||||
/// mediator module to do its job.
|
||||
|
||||
int main(void) {
|
||||
setupConnections();
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@
|
|||
#include "../driver/uart/receive.h"
|
||||
|
||||
|
||||
#define TARGET_FRAME_DURATION 20 // ms
|
||||
#define DEATH_SCREEN_LENGTH 50 // frames
|
||||
#define REPORT_INTERVAL 50 // every x frames
|
||||
#define TARGET_FRAME_DURATION 20 /// ms
|
||||
#define DEATH_SCREEN_LENGTH 50 /// frames
|
||||
#define REPORT_INTERVAL 50 /// every x frames
|
||||
|
||||
static struct {
|
||||
uint8_t contrast;
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@
|
|||
#include <avr/io.h>
|
||||
|
||||
|
||||
// Setup the drivers, and business layer objects and their relations
|
||||
// It is kind of a very basic dependency injection.
|
||||
/// Setup the drivers, and business layer objects and their relations
|
||||
/// It is kind of a very basic dependency injection.
|
||||
void setupConnections();
|
||||
|
||||
// Start drawing frames and ticking objects
|
||||
/// Start drawing frames and ticking objects
|
||||
void startGame();
|
||||
|
||||
// Increase or decrease the contrast (brightness) of the display
|
||||
// by the given value
|
||||
// The contrast can be any number between 0 and 255.
|
||||
// The function automatically clamps the contrast.
|
||||
/// Increase or decrease the contrast (brightness) of the display
|
||||
/// by the given value
|
||||
/// The contrast can be any number between 0 and 255.
|
||||
/// The function automatically clamps the contrast.
|
||||
void changeDisplayContrast(int8_t by);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ static AIAction actions[AI_ACTION_COUNT];
|
|||
|
||||
|
||||
static Vec2 whichDirectionToMove(Object* astronaut, Vec2 position) {
|
||||
bool const isTargetOnUpperFloor = isOnUpperFloor((Rectangle){position, (Vec2){0, 0}}); // else it's on the lower floor
|
||||
bool const isTargetOnUpperFloor = isOnUpperFloor((Rectangle){position, (Vec2){0, 0}}); /// else it's on the lower floor
|
||||
|
||||
Vec2 const ladder = add(LADDER_BOUNDING_BOX.position, spaceshipObject->position);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
#ifndef AI_H
|
||||
#define AI_H
|
||||
|
||||
// Between AI astronauts do actions
|
||||
// there has to be at least this many frames
|
||||
/// Between AI astronauts do actions
|
||||
/// there has to be at least this many frames
|
||||
#define AI_ACTION_INTERVAL 15
|
||||
|
||||
// If there are non player controlled astronauts
|
||||
// control them according to some basic rule set
|
||||
/// If there are non player controlled astronauts
|
||||
/// control them according to some basic rule set
|
||||
void handleAI();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
#ifndef COMMANDS_H
|
||||
#define COMMANDS_H
|
||||
|
||||
// There can be no more than COMMAND_BUFFER_SIZE commands
|
||||
// waiting for processing simultaneously
|
||||
/// There can be no more than COMMAND_BUFFER_SIZE commands
|
||||
/// waiting for processing simultaneously
|
||||
#define COMMAND_BUFFER_SIZE 8
|
||||
|
||||
// increaseContrast and decreaseContrast changes the contrast
|
||||
// with this value
|
||||
/// increaseContrast and decreaseContrast changes the contrast
|
||||
/// with this value
|
||||
#define CONTRAST_STEP 15
|
||||
|
||||
// The possible inputs of the system
|
||||
// Coincidentally these are the codes of the IR remote
|
||||
// controller's buttons.
|
||||
/// The possible inputs of the system
|
||||
/// Coincidentally these are the codes of the IR remote
|
||||
/// controller's buttons.
|
||||
typedef enum {
|
||||
noCommand = 0,
|
||||
repeat = 1,
|
||||
|
|
@ -24,11 +24,11 @@ typedef enum {
|
|||
action = 199,
|
||||
} Command;
|
||||
|
||||
// Add a new command to the buffer
|
||||
// It will not be processed immediately.
|
||||
/// Add a new command to the buffer
|
||||
/// It will not be processed immediately.
|
||||
void addCommand(Command command);
|
||||
|
||||
// Process every command in the buffer at once in a FIFO manner
|
||||
/// Process every command in the buffer at once in a FIFO manner
|
||||
void handleCommands();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@
|
|||
|
||||
#define MAX_ASTEROID_COUNT 2
|
||||
|
||||
// For minimizing code size the position of generated objects is
|
||||
// decided randomly. If it fits then it stays. For each generated object
|
||||
// can be a maximum of TRY_COUNT tries.
|
||||
/// For minimizing code size the position of generated objects is
|
||||
/// decided randomly. If it fits then it stays. For each generated object
|
||||
/// can be a maximum of TRY_COUNT tries.
|
||||
#define TRY_COUNT 16
|
||||
|
||||
// Create the necessary objects in order to start the game
|
||||
// These include the background, spaceship and the player's character.
|
||||
/// Create the necessary objects in order to start the game
|
||||
/// These include the background, spaceship and the player's character.
|
||||
void createObjects();
|
||||
|
||||
// Generate asteroids and astronaut randomly based on a set of conditions
|
||||
/// Generate asteroids and astronaut randomly based on a set of conditions
|
||||
void generateEvents();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ void drawObject(Object* object, Rectangle compositingWindow) {
|
|||
}
|
||||
|
||||
Vec2 getSizeFromPrototype(Prototype const* prototype) {
|
||||
// required for casting
|
||||
/// required for casting
|
||||
uint16_t read = pgm_read_word(&prototype->size);
|
||||
Vec2* v = (Vec2*) &read;
|
||||
return *v;
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@
|
|||
#include "prototype.h"
|
||||
|
||||
|
||||
// Objects (they could have been called GameObjects) have a simple
|
||||
// hierarchy. A prototype/flyweight motivated system is used.
|
||||
// Each type has some common data and methods which are stored
|
||||
// in their respective prototype.
|
||||
// This module provides us with the methods to easily and mostly
|
||||
// transparently access an object's prototype.
|
||||
/// Objects (they could have been called GameObjects) have a simple
|
||||
/// hierarchy. A prototype/flyweight motivated system is used.
|
||||
/// Each type has some common data and methods which are stored
|
||||
/// in their respective prototype.
|
||||
/// This module provides us with the methods to easily and mostly
|
||||
/// transparently access an object's prototype.
|
||||
|
||||
|
||||
typedef union {
|
||||
|
|
@ -39,30 +39,30 @@ struct _object_t {
|
|||
object_specific_data_t as;
|
||||
};
|
||||
|
||||
// Set the prototype of the holder and initialize all the holder's
|
||||
// vale to zero. Return the freshly updated holder
|
||||
/// Set the prototype of the holder and initialize all the holder's
|
||||
/// vale to zero. Return the freshly updated holder
|
||||
Object* createObject(Prototype const* prototype, Object* holder);
|
||||
|
||||
// Call the tick function referenced in the object's prototype
|
||||
// on the object itself
|
||||
// Object might react to the elapsed time.
|
||||
// Does nothing when called with NULL.
|
||||
/// Call the tick function referenced in the object's prototype
|
||||
/// on the object itself
|
||||
/// Object might react to the elapsed time.
|
||||
/// Does nothing when called with NULL.
|
||||
void tickObject(Object* object, uint8_t previousFrameTime);
|
||||
|
||||
// Call the draw function referenced in the object's prototype
|
||||
// on the object itself.
|
||||
// Does nothing when called with NULL.
|
||||
/// Call the draw function referenced in the object's prototype
|
||||
/// on the object itself.
|
||||
/// Does nothing when called with NULL.
|
||||
void drawObject(Object* object, Rectangle compositingWindow);
|
||||
|
||||
// Find out the prototype of the object and return the size of that
|
||||
/// Find out the prototype of the object and return the size of that
|
||||
Vec2 getSize(Object const* object);
|
||||
Vec2 getSizeFromPrototype(Prototype const* prototype);
|
||||
|
||||
// Move the position of the object by a vector
|
||||
/// Move the position of the object by a vector
|
||||
void move(Object* object, Vec2 value);
|
||||
|
||||
// Get a new rectangle from the objects position and its
|
||||
// prototype's size
|
||||
/// Get a new rectangle from the objects position and its
|
||||
/// prototype's size
|
||||
Rectangle getBoundingBox(Object const* object);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@
|
|||
#include "../../util/vec2/vec2.h"
|
||||
|
||||
|
||||
// Contain up to OBJECT_COUNT objects.
|
||||
// Provide the basic functionality to access, search and modify
|
||||
// these objects.
|
||||
// For ease of use, there are some convenience global variables for accessing
|
||||
// objects that are very commonly accessed.
|
||||
/// Contain up to OBJECT_COUNT objects.
|
||||
/// Provide the basic functionality to access, search and modify
|
||||
/// these objects.
|
||||
/// For ease of use, there are some convenience global variables for accessing
|
||||
/// objects that are very commonly accessed.
|
||||
|
||||
#define OBJECT_COUNT 10
|
||||
#define BACKGROUND_INDEX 0
|
||||
|
|
@ -25,34 +25,34 @@
|
|||
#define spaceshipObject (objects + SPACESHIP_INDEX)
|
||||
#define character (objects + CHARACTER_INDEX)
|
||||
|
||||
// The actual container
|
||||
/// The actual container
|
||||
Object objects[OBJECT_COUNT];
|
||||
|
||||
// may return NULL
|
||||
/// may return NULL
|
||||
Object* getFirstOfType(Prototype const* type);
|
||||
// may return NULL
|
||||
/// may return NULL
|
||||
|
||||
#define getEmptyObjectSpace() getFirstOfType(NULL)
|
||||
|
||||
// Return the number of objects with a prototype being type
|
||||
/// Return the number of objects with a prototype being type
|
||||
uint8_t getCountOf(Prototype const* type);
|
||||
|
||||
// Return a reference to a random object intersecting boundingBox and having
|
||||
// a prototype of type
|
||||
/// Return a reference to a random object intersecting boundingBox and having
|
||||
/// a prototype of type
|
||||
Object* getIntersectingObjectOfType(Rectangle boundingBox, Prototype const* type);
|
||||
|
||||
// Call the tick method of every object
|
||||
// objects might respond to the elapsed time
|
||||
/// Call the tick method of every object
|
||||
/// objects might respond to the elapsed time
|
||||
void tickObjects(uint8_t previousFrameTime);
|
||||
|
||||
// Call the draw method of every object
|
||||
/// Call the draw method of every object
|
||||
void drawObjects(Rectangle window);
|
||||
|
||||
// Delete the object given by its address from objects
|
||||
// It achieves this by setting the object's prototype to NULL.
|
||||
/// Delete the object given by its address from objects
|
||||
/// It achieves this by setting the object's prototype to NULL.
|
||||
void clearObject(Object* object);
|
||||
|
||||
// Delete every object inside of objects
|
||||
/// Delete every object inside of objects
|
||||
void initializeObjectContainer();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,17 +5,17 @@
|
|||
#include "../util/rectangle/rectangle.h"
|
||||
|
||||
|
||||
// See more information in object.h
|
||||
/// See more information in object.h
|
||||
|
||||
struct _object_t;
|
||||
typedef struct _object_t Object;
|
||||
|
||||
// Update the inner state of the given object
|
||||
// The first argument is the object itself, the second is the elapsed
|
||||
// time in milliseconds.
|
||||
/// Update the inner state of the given object
|
||||
/// The first argument is the object itself, the second is the elapsed
|
||||
/// time in milliseconds.
|
||||
typedef void (*TickMethod)(Object*, uint8_t);
|
||||
|
||||
// Draw the given object if its overlapping with the given rectangle
|
||||
/// Draw the given object if its overlapping with the given rectangle
|
||||
typedef void (*DrawMethod)(Object*, Rectangle);
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
#define ASTRONAUT_SIZE ((Vec2){5, 5})
|
||||
#define MOVE_FRAME_COUNT 4
|
||||
|
||||
// Between two consecutive actions (or movements)
|
||||
// there has to be at least this many milliseconds
|
||||
/// Between two consecutive actions (or movements)
|
||||
/// there has to be at least this many milliseconds
|
||||
#define TIME_BETWEEN_ACTION_CHANGE 40
|
||||
|
||||
typedef enum {
|
||||
|
|
|
|||
|
|
@ -67,5 +67,5 @@ void initializeBackground() {
|
|||
const Prototype Background PROGMEM = {
|
||||
.tick = tick,
|
||||
.draw = draw,
|
||||
.size = (Vec2){DISPLAY_WIDTH_IN_PIXELS, DISPLAY_HEIGHT_IN_PIXELS} // == WINDOW.size
|
||||
.size = (Vec2){DISPLAY_WIDTH_IN_PIXELS, DISPLAY_HEIGHT_IN_PIXELS} /// == WINDOW.size
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include <avr/eeprom.h>
|
||||
|
||||
|
||||
// AUTO-GENERATED
|
||||
/// AUTO-GENERATED
|
||||
|
||||
const uint16_t small_character_moving[4][5][1] EEMEM = {{{0x606},{0x1f1d},{0xf0b},{0x1f1d},{0x606}},{{0x606},{0x1f1d},{0xf0b},{0xf0d},{0x1616}},{{0x606},{0x1f1d},{0xf0b},{0x1f1d},{0x606}},{{0x606},{0xf0d},{0x1f1b},{0x1f1d},{0x606}}};
|
||||
const uint16_t spaceship_idle[1][36][3] EEMEM = {{{0x404,0x1414,0x1010},{0x404,0x3e3e,0x1010},{0xceca,0xffff,0x3828},{0xee6a,0xff8a,0x3929},{0xff3b,0xff09,0x7f6f},{0xff91,0xff08,0x7f44},{0xff51,0xff08,0x7f44},{0xff31,0xff08,0x7f44},{0xff1f,0xff08,0x7f7c},{0xf111,0xff08,0x4744},{0xf010,0xff08,0x704},{0xf010,0xfff8,0x707},{0xf010,0xff28,0x705},{0xf010,0xfff8,0x707},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf414,0xff08,0x1714},{0xf414,0xff08,0x1714},{0xfc1c,0xff08,0x1f1c},{0xfc1c,0xff08,0x1f1c},{0xf818,0xff08,0xf0c},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf010,0xff0c,0x704},{0xf010,0xff0a,0x704},{0xf0b0,0xff1f,0x706},{0xe020,0xff1c,0x302},{0xe060,0xff1c,0x303},{0xc0c0,0xff9c,0x101},{0x8080,0xffdd,0x0},{0x0,0x7f7f,0x0},{0x0,0x1c1c,0x0},{0x0,0x808,0x0}}};
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include <avr/io.h>
|
||||
|
||||
|
||||
// AUTO-GENERATED
|
||||
/// AUTO-GENERATED
|
||||
|
||||
const uint16_t small_character_moving[4][5][1];
|
||||
const uint16_t spaceship_idle[1][36][3];
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@
|
|||
#include <avr/io.h>
|
||||
|
||||
|
||||
// Mustn't be zero, should be lower than 65535
|
||||
/// Mustn't be zero, should be lower than 65535
|
||||
#define SEED 42
|
||||
|
||||
// Simple LFSR with some improvements to enhance distribution
|
||||
// while maintaining short execution time
|
||||
/// Simple LFSR with some improvements to enhance distribution
|
||||
/// while maintaining short execution time
|
||||
uint8_t getRandomNumber();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@ typedef struct {
|
|||
|
||||
bool areIntersecting(Rectangle r1, Rectangle r2);
|
||||
|
||||
// Return true only if inner is fully inside of outer
|
||||
/// Return true only if inner is fully inside of outer
|
||||
bool isInside(Rectangle inner, Rectangle outer);
|
||||
|
||||
// Return the geometrical middle point of the given rectangle
|
||||
/// Return the geometrical middle point of the given rectangle
|
||||
Vec2 getCenter(Rectangle r);
|
||||
|
||||
// Return a new rectangle shifted by vector translate
|
||||
/// Return a new rectangle shifted by vector translate
|
||||
Rectangle translateRectangle(Rectangle r, Vec2 translate);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@ typedef enum {
|
|||
north, west, south, east
|
||||
} Direction;
|
||||
|
||||
// The array directions can be indexed by a Direction and
|
||||
// it contains vectors pointing into that direction.
|
||||
/// The array directions can be indexed by a Direction and
|
||||
/// it contains vectors pointing into that direction.
|
||||
const Vec2 directions[4];
|
||||
|
||||
Vec2 add(Vec2 v1, Vec2 v2);
|
||||
Vec2 substract(Vec2 v1, Vec2 v2);
|
||||
|
||||
// Return new vector with ll components between -1 and 1 (inclusive)
|
||||
/// Return new vector with ll components between -1 and 1 (inclusive)
|
||||
Vec2 clampVec2(Vec2 vector);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue