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