From 0462b187b4ce81afa7298033b5469ac3e9e8f018 Mon Sep 17 00:00:00 2001 From: Pradana AUMARS Date: Mon, 28 Jun 2021 15:13:57 +0200 Subject: [PATCH] Added posX constants of ball and racket to pong struct --- src/pong.c | 8 +++++--- src/pong.h | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pong.c b/src/pong.c index c6b4780..9964da3 100644 --- a/src/pong.c +++ b/src/pong.c @@ -9,10 +9,12 @@ Pong_init() { // Cast away the const *(int *)&p->SCREEN_WIDTH = 640; *(int *)&p->SCREEN_HEIGHT = 480; + *(int *)&p->BALL_POSX = 100; + *(int *)&p->RACKET_POSX = 50; - p->ball = Ball_init(p->SCREEN_WIDTH, p->SCREEN_HEIGHT, 100); - p->racketL = Racket_init(p->SCREEN_WIDTH, p->SCREEN_HEIGHT, 50, p->SCREEN_HEIGHT/2, SDL_SCANCODE_E, SDL_SCANCODE_D); - p->racketR = Racket_init(p->SCREEN_WIDTH, p->SCREEN_HEIGHT, p->SCREEN_WIDTH - 50, p->SCREEN_HEIGHT/2, SDL_SCANCODE_I, SDL_SCANCODE_K); + p->ball = Ball_init(p->SCREEN_WIDTH, p->SCREEN_HEIGHT, p->BALL_POSX); + p->racketL = Racket_init(p->SCREEN_WIDTH, p->SCREEN_HEIGHT, p->RACKET_POSX, p->SCREEN_HEIGHT/2, SDL_SCANCODE_E, SDL_SCANCODE_D); + p->racketR = Racket_init(p->SCREEN_WIDTH, p->SCREEN_HEIGHT, p->SCREEN_WIDTH - p->RACKET_POSX, p->SCREEN_HEIGHT/2, SDL_SCANCODE_I, SDL_SCANCODE_K); p->window = SDL_CreateWindow( "Pong", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, p->SCREEN_WIDTH, p->SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); if( p->window == NULL ) diff --git a/src/pong.h b/src/pong.h index caf88f5..7c9cc74 100644 --- a/src/pong.h +++ b/src/pong.h @@ -14,7 +14,9 @@ typedef struct Pong { //SDL_Texture* texture; SDL_Event e; Ball *ball; + const int BALL_POSX; Racket *racketL; + const int RACKET_POSX; Racket *racketR; } Pong;