Skip to content

Commit

Permalink
add doxygen comments
Browse files Browse the repository at this point in the history
  • Loading branch information
petrkucerak committed May 4, 2021
1 parent 9887b2d commit 38a8e5d
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 61 deletions.
21 changes: 10 additions & 11 deletions final_score.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/*******************************************************************
Program to draw text to frame buffer on MicroZed
based MZ_APO board designed by Petr Porazil at PiKRON
final_score.h - functions for draw final score
(C) Copyright 2021 by Petr Kucera
e-mail: kucerp28@fel.cvut.cz
license: any combination of GPL, LGPL, MPL or BSD licenses
*******************************************************************/
/**
* @file final_score.c
* @author Petr Kucera (kucerp28@fel.cvut.cz)
* @brief Module with function draw final score that draws the final score to the screen and waits for user input. Returns true if the user pressed the s key and therefor wants to continue playing or the q key indicating he wants to end the program
* @version 0.1
* @date 2021-05-04
*
* @copyright Copyright (c) 2021
*
*/

#include <stdio.h>
#include "final_score.h"
Expand Down
31 changes: 18 additions & 13 deletions final_score.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/*******************************************************************
Program to draw text to frame buffer on MicroZed
based MZ_APO board designed by Petr Porazil at PiKRON
final_score.h - functions for draw final score
(C) Copyright 2021 by Petr Kucera
e-mail: kucerp28@fel.cvut.cz
license: any combination of GPL, LGPL, MPL or BSD licenses
*******************************************************************/
/**
* @file final_score.h
* @author Petr Kucera (kucerp28@fel.cvut.cz)
* @brief Module with function draw final score that draws the final score to the screen and waits for user input. Returns true if the user pressed the s key and therefor wants to continue playing or the q key indicating he wants to end the program
* @version 0.1
* @date 2021-05-04
*
* @copyright Copyright (c) 2021
*
*/
#include <stdbool.h>
#include "data_structures.h"
#include "font_types.h"
Expand All @@ -17,8 +16,14 @@
#define FINAL_SCORE_H

/**
* function draw final score
* @return false - quit game; true - play game again
* @brief Draws the final score to the screen and waits for user input
*
* @param score
* @param frame_buff
* @param lcd_mem_base
* @param font
* @return true if the user pressed the s key and therefor wants to continue playing
* @return false if the user pressed the q key indicating he wants to end the program
*/
bool draw_final_score(int score, fb_data *frame_buff, unsigned char *lcd_mem_base, font_descriptor_t *font);

Expand Down
41 changes: 16 additions & 25 deletions game.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/*******************************************************************
Program to draw text to frame buffer on MicroZed
based MZ_APO board designed by Petr Porazil at PiKRON
game.c - file with game logic
(C) Copyright 2021 by Petr Kucera, Lukas Nejezchleb
e-mail: kucerp28@fel.cvut.cz, nejezluk@fel.cvut.cz
license: any combination of GPL, LGPL, MPL or BSD licenses
*******************************************************************/
/**
* @file game.c
* @author Lukas Nejezchleb (nejezluk@fel.cvut.cz), Petr Kucera (kucerp28@fel.cvut.cz)
* @brief Module where the game is taking place
* @version 0.1
* @date 2021-05-04
*
* @copyright Copyright (c) 2021
*
*/

#include "game.h"
#include "update_peripherals.h"
Expand All @@ -21,14 +20,6 @@
#include "text_fb.h"
#include "font_types.h"

//internal function
void led_blink(unsigned char *led_mem_base, int scare_countdown, int pacman_score);
void pause(fb_data *fb, peripherals_data_t *peripherals);

//returns true if the game should be rendered imedeatly
bool game_tick(map_data *map, pacman_type *pacman, ghost_type *ghost_arr, int num_ghosts, int *scare);
//end of internal functions

int run_game(game_init_data_t *game_data, peripherals_data_t *peripherals)
{
map_data *map = create_map_data(peripherals->lcd_w, peripherals->lcd_h, game_data->map);
Expand Down Expand Up @@ -66,7 +57,7 @@ int run_game(game_init_data_t *game_data, peripherals_data_t *peripherals)
break;
}
}
//do the rendering
// do the rendering
led_blink(peripherals->led_mem_base, scare_countdown, pacman.score);
coins_to_eat = render_map(map, &fb);
draw_pacman(&pacman, &fb, map);
Expand All @@ -76,7 +67,7 @@ int run_game(game_init_data_t *game_data, peripherals_data_t *peripherals)
}
led_strip_number(peripherals->led_mem_base, game_data->pacman_lives, pacman.lives);
lcd_from_fb(&fb, peripherals->lcd_mem_base);
//get new key
// get new key
pthread_mutex_lock(&mtx);
read = read_thread_data.last_read;
pthread_mutex_unlock(&mtx);
Expand All @@ -102,7 +93,7 @@ void led_blink(unsigned char *led_mem_base, int scare_countdown, int pacman_scor
static int time = 0;
static uint32_t color = LED_NORMAL_COLOR;
if ((scare_countdown > 0) && (period == 0))
{ //scared regime began
{ // scared regime began
period = scare_countdown / 30 + 1;
time = 0;
color = LED_SCARE_COLOR2;
Expand All @@ -114,13 +105,13 @@ void led_blink(unsigned char *led_mem_base, int scare_countdown, int pacman_scor
{
period = scare_countdown / 30 + 1;
time = 0;
//change color
// change color
color = (color == LED_SCARE_COLOR1) ? LED_SCARE_COLOR2 : LED_SCARE_COLOR1;
}
}
else
{
//no scare regime
// no scare regime
color = (((uint8_t)(255*(pacman_score/(float)MAX_SCORE)))<<8);
}
sel_leds_color(led_mem_base, color);
Expand Down Expand Up @@ -153,7 +144,7 @@ bool game_tick(map_data *map, pacman_type *pacman, ghost_type *ghost_arr, int nu
}
ret = true;
}
bool scare_regime = false; //find out if by chance all ghost have not been eaten
bool scare_regime = false; // find out if by chance all ghost have not been eaten
for (int i = 0; i < num_ghosts; ++i)
{
// move every ghost and check if pacman has not been eaten
Expand Down
57 changes: 45 additions & 12 deletions game.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/*******************************************************************
Program to draw text to frame buffer on MicroZed
based MZ_APO board designed by Petr Porazil at PiKRON
game.c - file with game logic
(C) Copyright 2021 by Petr Kucera, Lukas Nejezchleb
e-mail: kucerp28@fel.cvut.cz, nejezluk@fel.cvut.cz
license: any combination of GPL, LGPL, MPL or BSD licenses
*******************************************************************/
/**
* @file game.h
* @author Lukas Nejezchleb (nejezluk@fel.cvut.cz), Petr Kucera (kucerp28@fel.cvut.cz)
* @brief Module where the game is taking place
* @version 0.1
* @date 2021-05-04
*
* @copyright Copyright (c) 2021
*
*/

#ifndef GAME_H
#define GAME_H
Expand All @@ -17,8 +16,42 @@
#include "ghost.h"

/**
* @return packman score
* @brief Initialises all necessary data structures and loops the game tick and refreshing screen while the player has not won, lost or pressed the q key
*
* @param game_data
* @param peripherals
* @return int pac-man game score
*/
int run_game(game_init_data_t* game_data, peripherals_data_t* peripherals);

/**
* @brief Internal functions for setting the color of RGB leds according to the game state
*
* @param led_mem_base
* @param scare_countdown
* @param pacman_score
*/
void led_blink(unsigned char *led_mem_base, int scare_countdown, int pacman_score);

/**
* @brief displays the pause message and waits for user to press the pause of quit key
*
* @param fb
* @param peripherals
*/
void pause(fb_data *fb, peripherals_data_t *peripherals);

/**
* @brief moves pacman and each ghost one step, checking for collisions and user input
*
* @param map
* @param pacman
* @param ghost_arr
* @param num_ghosts
* @param scare
* @return true
* @return false
*/
bool game_tick(map_data *map, pacman_type *pacman, ghost_type *ghost_arr, int num_ghosts, int *scare);

#endif

0 comments on commit 38a8e5d

Please sign in to comment.