int main() { vga_fd = open("/dev/vga", O_RDONLY); ioctl(vga_fd, SETVGAMODE, (void*)vga_mode_320x200x256); int fd = open("/dev/mouse", O_RDONLY); mousestate_t data; int ballX = WIDTH/2 - BALL_SIZE / 2; int ballY = HEIGHT/2 - BALL_SIZE /2; int velX = 10; int velY = 10; char color = 1; while (1) { clear_buffer(buffer); // read mouse position read(fd, &data, sizeof(data)); data.y = 199 - data.y; data.x = data.x * WIDTH / 320; data.y = data.y * HEIGHT / 200; // draw ball and racket moveBall(&ballX,&ballY,&velX,&velY,data.y); drawBall(ballX,ballY,color); drawRacket(data.y,color); ioctl(vga_fd, FLUSHVGA, buffer); usleep(10000); } return 0; }
int main() { vesa_fd = open("$vesa", O_RDONLY); struct vesa_setmode_req req = { WIDTH, HEIGHT, BITS_PER_PIXEL }; color_t color; int fd = open("$mouse", O_RDONLY); struct mousedata data; int ballX = WIDTH/2 - BALL_SIZE / 2; int ballY = HEIGHT/2 - BALL_SIZE /2; int velX = 10; int velY = 10; COLOR(color, BITS_PER_PIXEL).r = 255; COLOR(color, BITS_PER_PIXEL).g = 255; COLOR(color, BITS_PER_PIXEL).b = 255; ioctl(vesa_fd, SETMODE, &req); while (1) { // read mouse position read(fd, &data, sizeof(data)); data.y = 199 - data.y; data.x = data.x * WIDTH / 320; data.y = data.y * HEIGHT / 200; // draw ball and racket moveBall(&ballX,&ballY,&velX,&velY,data.y); drawBall(ballX,ballY,color); drawRacket(data.y,color); ioctl(vesa_fd, FLUSH, 0); usleep(10000); } return 0; }
int main(){ /* Initialize scene and its objects */ Racket r1 = Racket(); Racket r2 = Racket(); Racket * List [2] = { &r1,&r2 }; boolean difficulty = false; r2.isplayer = gameMenu(&difficulty); r2.difficulty = difficulty; Dot ball = Dot(); char screen[HEIGHT][WIDTH]; initializeRacket(screen, &r1, LEFT_SIDE); initializeRacket(screen, &r2, RIGHT_SIDE); seed(); //initializes dot randomly int dotRand = rand() % 3; switch (dotRand) { case 0: initializeDot(screen, &ball, DOWNLEFT); break; case 1: initializeDot(screen, &ball, UPLEFT); break; case 2: initializeDot(screen, &ball, LEFT); break; default: initializeDot(screen, &ball, UPLEFT); break; } while (true) // Main loop { initialize(screen); drawRacket(screen, &r1); drawRacket(screen, &r2); moveDot(screen, ball.direction, &ball, List); if (screen[ball.height][ball.width] == RACKET_BRUSH) { if (ball.width < (WIDTH/2)) { dotHitRacket(screen,&ball, &r1, List); } else { dotHitRacket(screen,&ball, &r2, List); } } if (_kbhit()) { /* _kbhit is used to know if user pressed a button (keyboard) */ char pressedKey = _getch(); if (pressedKey == 'w' || pressedKey == 'W'){ moveRacket(screen, &r1,UP); } if (pressedKey == 's' || pressedKey == 'S') { moveRacket(screen, &r1, DOWN); } //Check if the user choose pvp or pvc if (r2.isplayer) { //Choose multiplayer if (pressedKey == 'i' || pressedKey == 'I') { moveRacket(screen, &r2, UP); } if (pressedKey == 'k' || pressedKey == 'K') { moveRacket(screen, &r2, DOWN); } } } if (!r2.isplayer) { moveCPU(screen, &r2,ball.direction,ball.height); } for (int i = 0; i < 2; i++) { if (List[i]->score >= 10) { system("cls"); printf("Player %d Venceu!\n", i+1); _getch(); return 0; } } draw(screen); sleep(); } return 0; }
void drawEverything() { drawBackground(BACKGROUND_COLOR); drawBall((size_t)(g_ballPosX), (size_t)(g_ballPosY), g_ballRadius, BALL_COLOR); drawRacket(g_player1PositionX, (size_t)(g_player1PosY), g_playerWidth, g_playerHeight, PLAYER1_COLOR); drawRacket(g_player2PositionX, (size_t)(g_player2PosY), g_playerWidth, g_playerHeight, PLAYER2_COLOR); }