Question
I've been asked to utilize a source code (in C) with multiple files in .h and .c. This assignment is to create a simulation of
I've been asked to utilize a source code (in C) with multiple files in .h and .c. This assignment is to create a simulation of a 2-person air hockey game using the C programming language. I'm having trouble understanding the connection with all the files and the lines of code given in the source code. I'd appreciate "//" comments on the given source code describing what each line could mean, including the # at the top of the program. This will give me a good foundational start to the project. Thank you!
#include
// Main Game function void air_hockey(){ int zone_height, zone_width; struct timespec tim = {0,200000000}; struct timespec tim_ret; int arrow, c; int slider_x_speed = 5, slider_y_speed = 5; initscr(); getmaxyx(stdscr,zone_height, zone_width); zone_height-=1; zone_width-=1; zone_t *z = init_zone(0, 0, zone_width, zone_height); ball_t *b = init_ball(zone_width/2, zone_height/2, 1, 1); slider_t *top = init_slider(zone_width/2, 5, 'T'); slider_t *bottom = init_slider(zone_width/2, zone_height-5, 'U'); draw_zone(z); draw_slider(top); draw_slider(bottom); draw_ball(b); refresh(); nodelay(stdscr,TRUE); // Do not wait for characters using getch. noecho(); while(1) { // Move the current piece if ((arrow = read_escape(&c)) != NOCHAR) { switch (arrow) {
// Functionality for Left Arrow Key that controls the bottom slider case LEFT: mvprintw(1, 5,"L"); break; // Functionality for Rigth Arrow Key that controls the bottom slider case RIGHT: mvprintw(1, 5,"R"); break; // Functionality for A Key that controls the top slider case A: mvprintw(1, 5,"A"); break; case D: // Functionality for D Key that controls the top slider mvprintw(1, 5,"D"); break; default: mvprintw(1, 5,"%c", c); break;
} } refresh(); undraw_zone(z); draw_zone(z); undraw_ball(b); moveBall(b); checkCollisionSlider(bottom, b); checkCollisionSlider(top, b); checkCollisionWithZone(b, z); draw_ball(b); refresh(); // usleep(200000); nanosleep(&tim, &tim_ret); }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started