PandA-2024.02
|
Go to the source code of this file.
Data Structures | |
struct | _obj_description |
struct | _entity |
struct | _random_state_t |
Macros | |
#define | WINDOW_WIDTH 640 |
Pong game ported to the PandA framework by Fabrizio Ferrandi. More... | |
#define | WINDOW_HEIGHT 480 |
#define | FRAMES_PER_SECOND 60 |
#define | FRAME_RATE 1000/FRAMES_PER_SECOND |
#define | YELLOW_COLOR 6 |
#define | RED_COLOR 4 |
#define | BLUE_COLOR 1 |
#define | GREEN_COLOR 2 |
#define | WHITE_COLOR 7 |
#define | BLACK_COLOR 0 |
#define | COMPUTER_Y 30 |
#define | PLAYER_Y 430 |
#define | PADDLE_WIDTH 32 |
#define | PADDLE_HEIGHT 8 |
#define | BALL_DIAMETER 8 |
#define | PLAYER_SPEED 2 |
#define | COMPUTER_SPEED 2 |
#define | BALL_SPEED_MODIFIER 4 |
#define | BALL_SPEED_Y 2 |
#define | LEFT 0 |
#define | RIGHT 1 |
#define | UP 2 |
#define | DOWN 3 |
#define | sgn(x) ((x<0)?-1:((x>0)?1:0)) |
#define | rot(x, k) (((x)<<(k))|((x)>>(32-(k)))) |
Typedefs | |
typedef struct _obj_description | obj_description |
typedef struct _entity | entity |
typedef struct _random_state_t | random_state_t |
Functions | |
unsigned int | random_number (random_state_t *x) |
void | random_number_init (random_state_t *x, unsigned int seed) |
unsigned char | convert_char_digit_2_sseg (char c) |
void | line (int x1, int y1, int x2, int y2, unsigned int color) |
void | rect (int left, int top, int right, int bottom, unsigned int color) |
void | circle (int x0, int y0, int radius, unsigned int color) |
void | rect_fill (int left, int top, int right, int bottom, unsigned int color) |
void | output_score () |
_Bool | check_wall_collisions (entity *entity, unsigned char dir) |
_Bool | check_ball_collisions (entity *paddle) |
void | move_ball () |
_Bool | manage_player_score () |
_Bool | manage_computer_score () |
void | game_initialization () |
_Bool | get_game_input () |
_Bool | manage_ball () |
void | manage_AI () |
_Bool | game_main_loop () |
void | main () |
Variables | |
entity | computer |
entity | player |
entity | ball |
unsigned char | computer_score |
unsigned char | player_score |
static int | last_speed = 0 |
static int | decision = 3 |
int | timer |
static random_state_t | random_state |
#define BALL_DIAMETER 8 |
Definition at line 36 of file main.c.
Referenced by game_initialization(), manage_computer_score(), and manage_player_score().
#define BALL_SPEED_MODIFIER 4 |
Definition at line 43 of file main.c.
Referenced by manage_ball().
#define BALL_SPEED_Y 2 |
Definition at line 44 of file main.c.
Referenced by get_game_input(), and manage_AI().
#define BLACK_COLOR 0 |
Definition at line 25 of file main.c.
Referenced by game_initialization(), and game_main_loop().
#define BLUE_COLOR 1 |
Definition at line 22 of file main.c.
Referenced by game_main_loop().
#define COMPUTER_SPEED 2 |
Definition at line 40 of file main.c.
Referenced by game_initialization(), and manage_AI().
#define COMPUTER_Y 30 |
Definition at line 28 of file main.c.
Referenced by game_initialization().
#define FRAME_RATE 1000/FRAMES_PER_SECOND |
Definition at line 17 of file main.c.
Referenced by game_main_loop().
#define GREEN_COLOR 2 |
Definition at line 23 of file main.c.
Referenced by game_main_loop().
#define LEFT 0 |
Definition at line 46 of file main.c.
Referenced by check_wall_collisions(), get_game_input(), manage_AI(), and move_ball().
#define PADDLE_HEIGHT 8 |
Definition at line 33 of file main.c.
Referenced by game_initialization().
#define PADDLE_WIDTH 32 |
Definition at line 32 of file main.c.
Referenced by game_initialization().
#define PLAYER_SPEED 2 |
Definition at line 39 of file main.c.
Referenced by game_initialization(), and get_game_input().
#define PLAYER_Y 430 |
Definition at line 29 of file main.c.
Referenced by check_ball_collisions(), and game_initialization().
#define RIGHT 1 |
Definition at line 47 of file main.c.
Referenced by check_wall_collisions(), get_game_input(), manage_AI(), and move_ball().
Definition at line 89 of file main.c.
Referenced by random_number().
#define WHITE_COLOR 7 |
Definition at line 24 of file main.c.
Referenced by game_main_loop().
#define WINDOW_HEIGHT 480 |
Definition at line 13 of file main.c.
Referenced by game_initialization(), game_main_loop(), manage_ball(), manage_computer_score(), and manage_player_score().
#define WINDOW_WIDTH 640 |
Pong game ported to the PandA framework by Fabrizio Ferrandi.
The original code has been taken from http://www.aaroncox.net/tutorials/arcade/PaddleBattle.html Pong was the first game developed by Atari Inc and was designed and built by Allan Alcorn. Further information can be found at https://en.wikipedia.org/wiki/Pong. Random functions taken from http://burtleburtle.net/bob/rand/smallprng.html
Definition at line 12 of file main.c.
Referenced by check_wall_collisions(), game_initialization(), game_main_loop(), manage_computer_score(), and manage_player_score().
#define YELLOW_COLOR 6 |
Definition at line 20 of file main.c.
Referenced by game_main_loop().
typedef struct _obj_description obj_description |
typedef struct _random_state_t random_state_t |
_Bool check_ball_collisions | ( | entity * | paddle | ) |
Definition at line 249 of file main.c.
References _obj_description::h, PLAYER_Y, _entity::screen_location, _obj_description::w, _obj_description::x, _obj_description::y, and _entity::y_speed.
_Bool check_wall_collisions | ( | entity * | entity, |
unsigned char | dir | ||
) |
Definition at line 223 of file main.c.
References LEFT, RIGHT, _entity::screen_location, _obj_description::w, WINDOW_WIDTH, _obj_description::x, and _entity::x_speed.
void circle | ( | int | x0, |
int | y0, | ||
int | radius, | ||
unsigned int | color | ||
) |
Definition at line 169 of file main.c.
References plot(), _obj_description::x, and _obj_description::y.
unsigned char convert_char_digit_2_sseg | ( | char | c | ) |
Definition at line 110 of file main.c.
References test_panda::table.
void game_initialization | ( | ) |
Definition at line 342 of file main.c.
References BALL_DIAMETER, BLACK_COLOR, computer_score, COMPUTER_SPEED, COMPUTER_Y, decision, get_ticks(), _obj_description::h, last_speed, PADDLE_HEIGHT, PADDLE_WIDTH, player_score, PLAYER_SPEED, PLAYER_Y, random_number_init(), rect_fill(), _entity::screen_location, timer, _obj_description::w, WINDOW_HEIGHT, WINDOW_WIDTH, _obj_description::x, _entity::x_speed, _obj_description::y, and _entity::y_speed.
_Bool game_main_loop | ( | ) |
Definition at line 493 of file main.c.
References ball, BLACK_COLOR, BLUE_COLOR, circle(), computer, FRAME_RATE, get_game_input(), get_ticks(), GREEN_COLOR, _obj_description::h, manage_AI(), manage_ball(), output_score(), player, rect(), _entity::screen_location, timer, _obj_description::w, WHITE_COLOR, WINDOW_HEIGHT, WINDOW_WIDTH, _obj_description::x, _obj_description::y, and YELLOW_COLOR.
_Bool get_game_input | ( | ) |
Definition at line 377 of file main.c.
References BALL_SPEED_Y, btn_ctrl(), BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT, BUTTON_UP, check_wall_collisions(), LEFT, PLAYER_SPEED, RIGHT, _entity::screen_location, _obj_description::x, and _entity::y_speed.
void line | ( | int | x1, |
int | y1, | ||
int | x2, | ||
int | y2, | ||
unsigned int | color | ||
) |
Definition at line 117 of file main.c.
References abs, plot(), sgn, _obj_description::x, and _obj_description::y.
void main | ( | void | ) |
Definition at line 526 of file main.c.
References game_initialization(), and game_main_loop().
void manage_AI | ( | ) |
Definition at line 441 of file main.c.
References abs, BALL_SPEED_Y, check_wall_collisions(), COMPUTER_SPEED, decision, last_speed, LEFT, random_number(), RIGHT, _entity::screen_location, _obj_description::w, _obj_description::x, and _entity::x_speed.
Referenced by game_main_loop().
_Bool manage_ball | ( | ) |
Definition at line 404 of file main.c.
References BALL_SPEED_MODIFIER, check_ball_collisions(), _obj_description::h, manage_computer_score(), manage_player_score(), move_ball(), _entity::screen_location, _obj_description::w, WINDOW_HEIGHT, _obj_description::x, _entity::x_speed, _obj_description::y, and _entity::y_speed.
_Bool manage_computer_score | ( | ) |
Definition at line 321 of file main.c.
References BALL_DIAMETER, computer_score, player_score, _entity::screen_location, WINDOW_HEIGHT, WINDOW_WIDTH, _obj_description::x, _entity::x_speed, _obj_description::y, and _entity::y_speed.
Referenced by manage_ball().
_Bool manage_player_score | ( | ) |
Definition at line 301 of file main.c.
References BALL_DIAMETER, computer_score, player_score, _entity::screen_location, WINDOW_HEIGHT, WINDOW_WIDTH, _obj_description::x, _entity::x_speed, _obj_description::y, and _entity::y_speed.
Referenced by manage_ball().
void move_ball | ( | ) |
Definition at line 289 of file main.c.
References check_wall_collisions(), LEFT, RIGHT, _entity::screen_location, _obj_description::x, _entity::x_speed, _obj_description::y, and _entity::y_speed.
void output_score | ( | ) |
Definition at line 203 of file main.c.
References computer_score, convert_char_digit_2_sseg(), player_score, and sevensegments_ctrl().
unsigned int random_number | ( | random_state_t * | x | ) |
Definition at line 90 of file main.c.
References _random_state_t::a, _random_state_t::b, _random_state_t::c, _random_state_t::d, and rot.
Referenced by manage_AI(), and random_number_init().
void random_number_init | ( | random_state_t * | x, |
unsigned int | seed | ||
) |
Definition at line 100 of file main.c.
References _random_state_t::a, _random_state_t::b, _random_state_t::c, _random_state_t::d, and random_number().
Referenced by game_initialization().
void rect | ( | int | left, |
int | top, | ||
int | right, | ||
int | bottom, | ||
unsigned int | color | ||
) |
void rect_fill | ( | int | left, |
int | top, | ||
int | right, | ||
int | bottom, | ||
unsigned int | color | ||
) |
entity computer |
Definition at line 70 of file main.c.
Referenced by game_main_loop().
unsigned char computer_score |
Definition at line 73 of file main.c.
Referenced by game_initialization(), manage_computer_score(), manage_player_score(), and output_score().
|
static |
Definition at line 76 of file main.c.
Referenced by game_initialization(), and manage_AI().
|
static |
Definition at line 75 of file main.c.
Referenced by game_initialization(), and manage_AI().
unsigned char player_score |
Definition at line 74 of file main.c.
Referenced by game_initialization(), manage_computer_score(), manage_player_score(), and output_score().
|
static |