Question: C Language #include #include #include #include #include #include #include #include #include // (Task 1) Define a function called pixel_level_collision which detects whether // two sprites
C Language
#include
// (Task 1) Define a function called pixel_level_collision which detects whether // two sprites s1 and s2 collide at pixel level. The function must be able // to work correctly even if the ZDK screen has not been set up, and should // make no attempt to use any function or variable declared in //
INSERT RETURN_TYPE FUNCTION_NAME ( PARAMETER_LIST ) { INSERT CODE HERE }
char * cross = "y y" /**/ " y y " /**/ " y " /**/ " y y " /**/ "y y" ; char * plus = " z " /**/ " z " /**/ "zzzzz" /**/ " z " /**/ " z " ;
int main( void ) { setup_screen(); sprite_id s_cross = sprite_create( 20.9, 8.3, 5, 5, cross ); sprite_id s_plus = sprite_create( 30.9, 17.9, 5, 5, plus );
while ( true ) { clear_screen(); sprite_draw( s_cross ); sprite_draw( s_plus ); if ( pixel_level_collision( s_cross, s_plus ) ) { draw_string(0, 0, "Pixel-level collision has been detected!"); } show_screen();
int key = wait_char();
if ( key == '2' ) { s_plus->y++; } else if ( key == '8' ) { s_plus->y--; } else if ( key == '4' ) { s_plus->x--; } else if ( key == '6' ) { s_plus->x++; } else if ( key == 'q' ) { break; } }
cleanup_screen();
return 0; }



Figure I: /cygdrive/a/temp 3 Use the numeric keys to move the plus sprite around, as seen in Figure 2 Figure 2 /cygdrive/a/temp yy z y yz The plus sprite can nestle in very close to the cross without triggering a collision detection, but when it does, a message is displayed (Figures 3, 4, 5)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
