added game.h player.h and uart.h, implemented game objects
This commit is contained in:
26
src/game.h
Normal file
26
src/game.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include<stdint.h>
|
||||
#include<stdlib.h>
|
||||
#include"player.h"
|
||||
|
||||
#define PLAYER_COUNT 2
|
||||
|
||||
typedef struct game_s{
|
||||
uint16_t time; // seconds since game start
|
||||
uint8_t winner_id;
|
||||
uint8_t host_id;
|
||||
player_t player[PLAYER_COUNT];
|
||||
|
||||
enum{
|
||||
running,
|
||||
ended
|
||||
} state;
|
||||
|
||||
} game_t;
|
||||
|
||||
void game_init(game_t* game);
|
||||
void game_step(game_t* game, uint16_t time_delta);
|
||||
|
||||
#endif /* PLAYER_H */
|
||||
@@ -26,6 +26,9 @@
|
||||
#include <lcd_lld.h>
|
||||
#include <color.h>
|
||||
#include <stm32f4xx_adc.h>
|
||||
#include "player.h"
|
||||
#include "game.h"
|
||||
#include "uart.h"
|
||||
|
||||
#define SPEED 500000
|
||||
|
||||
|
||||
34
src/player.h
Normal file
34
src/player.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
|
||||
#include<stdlib.h>
|
||||
#include<stdint.h>
|
||||
|
||||
#define max_positions 320
|
||||
|
||||
typedef struct point_s{
|
||||
uint16_t x;
|
||||
uint8_t y;
|
||||
} point_t;
|
||||
|
||||
typedef struct player_s {
|
||||
|
||||
uint8_t id;
|
||||
uint16_t color;
|
||||
uint16_t num_positions;
|
||||
|
||||
enum{
|
||||
dead,
|
||||
alive,
|
||||
}state;
|
||||
|
||||
point_t past_positions[max_positions];
|
||||
point_t curr_position;
|
||||
|
||||
} player_t;
|
||||
|
||||
void player_init(player_t* player); // reset all fields
|
||||
void player_append_position(player_t* player, point_t point); // updates num_position and adds current position to the list
|
||||
|
||||
#endif /* PLAYER_H */
|
||||
24
src/uart.h
Normal file
24
src/uart.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef UART_H
|
||||
#define UART_H
|
||||
|
||||
#include<stdint.h>
|
||||
#include<stdlib.h>
|
||||
#include<stdbool.h>
|
||||
|
||||
typedef struct uart_message_s{
|
||||
uint16_t message_length;
|
||||
uint8_t *message_data;
|
||||
|
||||
// Internal, do not touch!
|
||||
bool __deleted;
|
||||
} uart_message_t;
|
||||
|
||||
void uart_init(void);
|
||||
void uart_transmit(uart_message_t *message); // transmit a message and frees it
|
||||
bool uart_has_message(void); // checks if there is at least one msg available
|
||||
void uart_message_free(uart_message_t *message); // frees a message
|
||||
|
||||
uart_message_t *uart_message_allocate(void); // allocate storage for a new message
|
||||
uart_message_t *receive_message(void); // returns a message if available else null
|
||||
|
||||
#endif /* UART_H */
|
||||
Reference in New Issue
Block a user