Code Formatting

This commit is contained in:
Armando Rivera 2013-11-09 00:26:26 -05:00
parent ac1a12ce0b
commit fd5c530ca5

View File

@ -4,209 +4,208 @@
MAIN MAIN
/* Variable declarations, SDL2 initialization */ /* Variable declarations, SDL2 initialization */
Init(SDL_INIT_VIDEO); Init(SDL_INIT_VIDEO);
DIM AS PWINDOW window; DIM AS PWINDOW window;
DIM AS PRENDERER renderer; DIM AS PRENDERER renderer;
DIM AS BOOL p1_up = false; DIM AS BOOL p1_up = false;
DIM AS BOOL p1_down = false; DIM AS BOOL p1_down = false;
DIM AS BOOL p2_up = false; DIM AS BOOL p2_up = false;
DIM AS BOOL p2_down = false; DIM AS BOOL p2_down = false;
DIM AS INT p1_y = 199; DIM AS INT p1_y = 199;
DIM AS INT p2_y = 199; DIM AS INT p2_y = 199;
DIM AS INT p1_vel = 0; DIM AS INT p1_vel = 0;
DIM AS INT p2_vel = 0; DIM AS INT p2_vel = 0;
DIM AS BOOL quit = false; DIM AS BOOL quit = false;
DIM AS INT ball_x = 639 / 2; DIM AS INT ball_x = 639 / 2;
DIM AS INT ball_y = 479 / 2; DIM AS INT ball_y = 479 / 2;
DIM AS INT ball_w = 8; DIM AS INT ball_w = 8;
DIM AS INT ball_h = 8; DIM AS INT ball_h = 8;
DIM AS INT ball_x_vel = 5; DIM AS INT ball_x_vel = 5;
DIM AS INT ball_y_vel = 0; DIM AS INT ball_y_vel = 0;
DIM AS INT delay = 30; DIM AS INT delay = 30;
DIM AS INT p1_score = 0; DIM AS INT p1_score = 0;
DIM AS INT p2_score = 0; DIM AS INT p2_score = 0;
DIM AS INT BALL_WIDTH = 10; DIM AS INT BALL_WIDTH = 10;
DIM AS INT BALL_HEIGHT = 10; DIM AS INT BALL_HEIGHT = 10;
CONSTANT INT Y_MIN = 0; CONSTANT INT Y_MIN = 0;
CONSTANT INT Y_MAX = 399; CONSTANT INT Y_MAX = 399;
CONSTANT INT P1_X = 0; CONSTANT INT P1_X = 0;
CONSTANT INT P2_X = 629; CONSTANT INT P2_X = 629;
CONSTANT INT VEL_POS = 10; CONSTANT INT VEL_POS = 10;
CONSTANT INT VEL_NEG = 0 - VEL_POS; CONSTANT INT VEL_NEG = 0 - VEL_POS;
window = CreateWindow("Pong", window = CreateWindow("Pong",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
640, 640,
480, 480,
SDL_WINDOW_SHOWN); SDL_WINDOW_SHOWN);
renderer = CreateRenderer(window, -1, 0); renderer = CreateRenderer(window, -1, 0);
PRINT("Press Q to quit."); PRINT("Press Q to quit.");
/* Main Game Loop */ /* Main Game Loop */
WHILE (NOT quit) BEGIN WHILE (NOT quit) BEGIN
EVENT event; EVENT event;
WHILE (PollEvent(ADDR event)) BEGIN WHILE (PollEvent(ADDR event)) BEGIN
SELECT (event.type) BEGIN SELECT (event.type) BEGIN
CASE KEYDOWN: CASE KEYDOWN:
SELECT (event.key.keysym.sym) BEGIN SELECT (event.key.keysym.sym) BEGIN
CASE SDLK_w:
p1_vel = VEL_NEG;
ENDCASE
CASE SDLK_w: CASE SDLK_s:
p1_vel = VEL_NEG; p1_vel = VEL_POS;
ENDCASE ENDCASE
CASE SDLK_s: CASE SDLK_UP:
p1_vel = VEL_POS; p2_vel = VEL_NEG;
ENDCASE ENDCASE
CASE SDLK_UP: CASE SDLK_DOWN:
p2_vel = VEL_NEG; p2_vel = VEL_POS;
ENDCASE ENDCASE
CASE SDLK_DOWN: CASE SDLK_q:
p2_vel = VEL_POS; quit = true;
ENDCASE ENDCASE
CASE SDLK_q: CASE SDLK_EQUALS:
quit = true; delay++;
ENDCASE ENDCASE
CASE SDLK_EQUALS: CASE SDLK_MINUS:
delay++; IF (delay > 1) delay--;
ENDCASE ENDCASE
CASE SDLK_MINUS: CASE_ELSE:
IF (delay > 1) delay--; ENDCASE
ENDCASE ENDSELECT
ENDCASE
CASE_ELSE: CASE KEYUP:
ENDCASE SELECT (event.key.keysym.sym) BEGIN
ENDSELECT
ENDCASE
CASE KEYUP: CASE SDLK_w:
SELECT (event.key.keysym.sym) BEGIN IF (p1_vel == VEL_NEG) p1_vel = 0;
ENDCASE
CASE SDLK_w: CASE SDLK_s:
IF (p1_vel == VEL_NEG) p1_vel = 0; IF (p1_vel == VEL_POS) p1_vel = 0;
ENDCASE ENDCASE
CASE SDLK_s: CASE SDLK_UP:
IF (p1_vel == VEL_POS) p1_vel = 0; IF (p2_vel == VEL_NEG) p2_vel = 0;
ENDCASE ENDCASE
CASE SDLK_UP: CASE SDLK_DOWN:
IF (p2_vel == VEL_NEG) p2_vel = 0; IF (p2_vel == VEL_POS) p2_vel = 0;
ENDCASE ENDCASE
CASE SDLK_DOWN: CASE_ELSE:
IF (p2_vel == VEL_POS) p2_vel = 0; ENDCASE
ENDCASE ENDSELECT
ENDCASE
CASE_ELSE: CASE_ELSE:
ENDCASE ENDCASE
ENDSELECT
ENDCASE
CASE_ELSE: ENDSELECT
ENDCASE WEND
ENDSELECT /* Clears the screen */
WEND SetRenderDrawColor(renderer, 0, 0, 0, 255);
RenderClear(renderer);
DIM AS RECT midline = {640/2-4, 0, 9, 479};
SetRenderDrawColor(renderer, 90, 90, 90, 255);
RenderDrawRect(renderer, &midline);
RenderFillRect(renderer, &midline);
/* Clears the screen */ /* Manipulate paddle positions */
SetRenderDrawColor(renderer, 0, 0, 0, 255); p1_y = p1_y + p1_vel;
RenderClear(renderer); p2_y = p2_y + p2_vel;
DIM AS RECT midline = {640/2-4, 0, 9, 479}; IF (p1_y < Y_MIN) p1_y = Y_MIN;
SetRenderDrawColor(renderer, 90, 90, 90, 255); IF (p1_y > Y_MAX) p1_y = Y_MAX;
RenderDrawRect(renderer, &midline); IF (p2_y < Y_MIN) p2_y = Y_MIN;
RenderFillRect(renderer, &midline); IF (p2_y > Y_MAX) p2_y = Y_MAX;
/* Manipulate paddle positions */
p1_y = p1_y + p1_vel;
p2_y = p2_y + p2_vel;
IF (p1_y < Y_MIN) p1_y = Y_MIN;
IF (p1_y > Y_MAX) p1_y = Y_MAX;
IF (p2_y < Y_MIN) p2_y = Y_MIN;
IF (p2_y > Y_MAX) p2_y = Y_MAX;
/* Draw the paddles */ /* Draw the paddles */
SetRenderDrawColor(renderer, 255, 255, 255, 255); SetRenderDrawColor(renderer, 255, 255, 255, 255);
DIM AS Rect rect1 = {P1_X, p1_y, 10, 80}; DIM AS Rect rect1 = {P1_X, p1_y, 10, 80};
DIM AS Rect rect2 = {P2_X, p2_y, 10, 80}; DIM AS Rect rect2 = {P2_X, p2_y, 10, 80};
RenderDrawRect(renderer, &rect1); RenderDrawRect(renderer, &rect1);
RenderDrawRect(renderer, &rect2); RenderDrawRect(renderer, &rect2);
RenderFillRect(renderer, &rect1); RenderFillRect(renderer, &rect1);
RenderFillRect(renderer, &rect2); RenderFillRect(renderer, &rect2);
/* Manipulate the ball position */ /* Manipulate the ball position */
ball_x = ball_x + ball_x_vel; ball_x = ball_x + ball_x_vel;
ball_y = ball_y + ball_y_vel; ball_y = ball_y + ball_y_vel;
IF (ball_x + 4 >= 630 && ball_x <= 639 && ball_y + 4 < p2_y + 80 && ball_y - 4 > p2_y) THEN IF (ball_x + 4 >= 630 && ball_x <= 639 && ball_y + 4 < p2_y + 80 && ball_y - 4 > p2_y) THEN
ball_x_vel = -ball_x_vel; ball_x_vel = -ball_x_vel;
ball_y_vel = ball_y_vel + (ball_y - (p2_y + 40)) / 10; ball_y_vel = ball_y_vel + (ball_y - (p2_y + 40)) / 10;
IF (ball_x_vel < 0) ball_x_vel--; IF (ball_x_vel < 0) ball_x_vel--;
IF (ball_x_vel > 0) ball_x_vel++; IF (ball_x_vel > 0) ball_x_vel++;
ENDIF ENDIF
IF (ball_x - 4 <= 9 && ball_x >= 0 && ball_y + 4 < p1_y + 80 && ball_y - 4 > p1_y) THEN IF (ball_x - 4 <= 9 && ball_x >= 0 && ball_y + 4 < p1_y + 80 && ball_y - 4 > p1_y) THEN
ball_x_vel = -ball_x_vel; ball_x_vel = -ball_x_vel;
ball_y_vel = ball_y_vel + (ball_y - (p1_y + 40)) / 10; ball_y_vel = ball_y_vel + (ball_y - (p1_y + 40)) / 10;
IF (ball_x_vel < 0 && ball_x_vel > -8) ball_x_vel--; IF (ball_x_vel < 0 && ball_x_vel > -8) ball_x_vel--;
IF (ball_x_vel > 0 && ball_x_vel < 8) ball_x_vel++; IF (ball_x_vel > 0 && ball_x_vel < 8) ball_x_vel++;
ENDIF ENDIF
IF (ball_y - 4 <= 0 OR ball_y + 4 >= 479) THEN IF (ball_y - 4 <= 0 OR ball_y + 4 >= 479) THEN
ball_y_vel = -ball_y_vel; ball_y_vel = -ball_y_vel;
ENDIF ENDIF
RenderDrawLine(renderer, ball_x, ball_y - 4, ball_x, ball_y + 4); RenderDrawLine(renderer, ball_x, ball_y - 4, ball_x, ball_y + 4);
RenderDrawLine(renderer, ball_x - 4, ball_y, ball_x + 4, ball_y); RenderDrawLine(renderer, ball_x - 4, ball_y, ball_x + 4, ball_y);
IF (ball_x < 0) THEN IF (ball_x < 0) THEN
p2_score++; p2_score++;
ball_x = 639 / 2; ball_x = 639 / 2;
ball_y = 439 / 2; ball_y = 439 / 2;
ball_x_vel = -6; ball_x_vel = -6;
ball_y_vel = 0; ball_y_vel = 0;
p1_y = 199; p1_y = 199;
p2_y = 199; p2_y = 199;
ENDIF ENDIF
IF (ball_x > 639) THEN IF (ball_x > 639) THEN
p1_score++; p1_score++;
ball_x = 639 / 2; ball_x = 639 / 2;
ball_y = 439 / 2; ball_y = 439 / 2;
ball_x_vel = 6; ball_x_vel = 6;
ball_y_vel = 0; ball_y_vel = 0;
p1_y = 199; p1_y = 199;
p2_y = 199; p2_y = 199;
ENDIF ENDIF
/* Draw everything to the screen */ /* Draw everything to the screen */
RenderPresent(renderer); RenderPresent(renderer);
Delay(delay); Delay(delay);
} WEND
Quit(); Quit();
RETURN 0; RETURN 0;
ENDMAIN ENDMAIN