#include #include #include #include #include #include #include #include #include #include uint8_t colors[] = {224, 5}; /* Main Function */ void main(void) { uint8_t lifes; gfx_Begin(); gfx_SetDraw(gfx_buffer); srandom(*(volatile uint32_t*)0xF30044); for (lifes = 3; lifes; lifes--) { uint24_t x_ball = randInt(50, 270), delta_x = 1, delta_y = 1, x_paddles = 135; uint8_t y_ball = 22, index = 0, y_paddles = 100; do { kb_key_t key; char buf[10]; kb_Scan(); gfx_ZeroScreen(); gfx_SetColor(255); gfx_SetTextFGColor(255); gfx_SetTextTransparentColor(3); gfx_SetTextBGColor(0); gfx_PrintStringXY("PONG 2.6 - Made by Peter \"PT_\" Tillema", 1, 1); gfx_HorizLine_NoClip(0, 9, 320); sprintf(buf,"Lives : %d",lifes); gfx_PrintStringXY(buf, 260, 1); gfx_FillRectangle_NoClip(x_ball, y_ball, 3, 3); gfx_SetColor(colors[index]); gfx_FillRectangle_NoClip(5, y_paddles, 5, 50); gfx_FillRectangle_NoClip(310, y_paddles, 5, 50); gfx_SetColor(colors[!index]); gfx_FillRectangle_NoClip(x_paddles, 15, 50, 5); gfx_FillRectangle_NoClip(x_paddles, 230, 50, 5); key = kb_Data[kb_group_7]; if (kb_Data[kb_group_1] == kb_Mode) { index = !index; } if ((key & kb_Left) && x_paddles > 10) { x_paddles--; } if ((key & kb_Right) && x_paddles < 320-50) { x_paddles++; } if ((key & kb_Up) && y_paddles > 20) { y_paddles--; } if ((key & kb_Down) && y_paddles < 240-50-10) { y_paddles++; } if (x_ball == 9 || x_ball == 308) { delta_x = 0 - delta_x; } if (y_ball == 19 || y_ball == 228) { delta_y = 0 - delta_y; } if ( ( (x_ball == 9 || x_ball == 308) && (y_ball < y_paddles - 2 || y_ball > y_paddles + 50 || !index) ) || ( (y_ball == 19 || y_ball == 228) && (x_ball < x_paddles - 2 || x_ball > x_paddles + 50 || index) ) ) { break; } x_ball += delta_x; y_ball += delta_y; gfx_SwapDraw(); } while (kb_Data[kb_group_6] != kb_Clear); delay(1000); } gfx_SetDraw(gfx_screen); gfx_ZeroScreen(); gfx_SetColor(255); gfx_PrintStringXY("YOU DIED!!!", 140, 70); gfx_PrintStringXY("Press any key to exit...", 90, 120); while (!os_GetCSC()); gfx_End(); }