static SDL_Window *window = NULL;
static SDL_Renderer *renderer = NULL;
-static Vec2di windowSize;// = { 1920, 1080 };
static bool quit = false;
-static const float speed = 20.f;
+static float speed = 20.f;
static const Colour bgClr = { 0x1c, 0x1c, 0x1c, 0xff };
+// base window size to set pixel-values against, actual window size to scale to
+static const Vec2di baseWindowSize = { 1920, 1080 };
+static Vec2di windowSize;
+static Vec2df windowScale;
+
Vbox pad, ball;
Box *vec_bricks = NULL;
Vec2df vline[2];
static void paddle_init()
{
- pad.r.w = 192;
- pad.r.h = 32;
+ pad.r.w = 192 * windowScale.x;
+ pad.r.h = 32 * windowScale.y;
pad.r.x = (windowSize.x / 2) - (pad.r.w / 2);
pad.r.y = windowSize.y - ((windowSize.y / 8) - (pad.r.h / 2));
static void ball_init()
{
ball.r.h = ball.r.w = 32;
+ ball.r.w *= windowScale.x;
+ ball.r.h *= windowScale.y;
ball.r.x = (windowSize.x / 2) - (ball.r.w / 2);
ball.r.y = (windowSize.y / 2) - (ball.r.h / 2);
vline[1].y = vline[0].y + ball.v.y + ( ball.v.y > 0 ? ball.r.h / 2 : 0);
- // paddle bounds checks & responses
- /*
- if( (
- (ball.r.x > pad.r.x && ball.r.x < pad.r.x + pad.r.w ) ||
- (ball.r.x + ball.r.w > pad.r.x && ball.r.x + ball.r.w < pad.r.x + pad.r.w )
- ) && (
- (ball.r.y > pad.r.y && ball.r.y < pad.r.y + pad.r.h ) ||
- (ball.r.y + ball.r.h > pad.r.y && ball.r.y + ball.r.h < pad.r.y + pad.r.h )
- )
- )
- {
- ball.v.y *= -1;
- }
- */
-
-
// screen bounds checks & responses
if(ball.r.x + ball.r.w > windowSize.x && !collisionResponded){
ball.r.x = windowSize.x - ball.r.w;
windowSize.x = dm.w;
windowSize.y = dm.h;
+ windowScale.x = windowSize.x / baseWindowSize.x;
+ windowScale.y = windowSize.y / baseWindowSize.y;
+
window = SDL_CreateWindow("pong",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
windowSize.x, windowSize.y,