![]() |
TX Library Help – Version: 00173a, Revision: 174
|
00001 //{=========================================================================== 00012 //}=========================================================================== 00013 00014 #include "proto.h" 00015 00016 void Life (Ball_t* ball); 00017 00018 int main() 00019 { 00020 txCreateWindow (1024, 768); 00021 00022 Ball_t ball = {100, 100, 2, 3}; 00023 00024 printf ("Searching for client...\n"); 00025 00026 TX_SOCKET ball_client = txCreateSocket (TX_SERVER); 00027 00028 if (txnAssert (ball_client) == TXN_NOT_CREATED) 00029 { 00030 printf("Can't open server. Maybe, port are busy.\n"); 00031 return -1; 00032 } 00033 00034 printf ("Start draw meow.\n"); 00035 00036 while (!GetAsyncKeyState(VK_ESCAPE)) 00037 { 00038 txSendTo (ball_client, &ball, sizeof(ball)); 00039 00040 txSetFillColor (TX_GREEN); 00041 txSetColor (TX_GREEN); 00042 00043 txCircle (ball.x, ball.y, 10); 00044 Life (&ball); 00045 00046 txSleep (1); 00047 txSetFillColor (TX_BLACK); 00048 txClear(); 00049 } 00050 00051 ball.x = -100; 00052 ball.y = -100; 00053 txSendTo (ball_client, &ball, sizeof(ball)); 00054 00055 return 0; 00056 } 00057 00058 void Life (Ball_t* ball) 00059 { 00060 if (ball->x < 0) 00061 { 00062 ball->x = 0; 00063 ball->vx = -ball->vx; 00064 } 00065 00066 if (ball->y < 0) 00067 { 00068 ball->y = 0; 00069 ball->vy = -ball->vy; 00070 } 00071 00072 if (ball->x > 1024) 00073 { 00074 ball->x = 1024; 00075 ball->vx = -ball->vx; 00076 } 00077 00078 if (ball->y > 768) 00079 { 00080 ball->y = 768; 00081 ball->vy = -ball->vy; 00082 } 00083 00084 ball->y += ball->vy; 00085 ball->x += ball->vx; 00086 }