problems with making the game pong in C++

Hi guys I'm really new to the forum and fairly new to c++, but have been really struggling with making a game pong. At my university we use a thing called Gwin, to program, (its equivalent for cin>> would be Gwin.write) etc. I have used two images for the game, firstly an image of the paddle and secondly an image of a ball, and I am having problems with getting the ball to collide with the paddle. If anyone could give me any tips or hints I would be really grateful.my coding is posted below

#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <vector>
#include <cmath>
#include "gwin.h"


const int NUMBEROFBALLS = 1;

struct objects
{
GImage Paddle;

};

int main()
{
GWindow Gwin;
objects info [1];
GImage blueball(GPath("pictures/BLUEBALL.png").transform());

GImage Paddle (GPath("pictures/Paddle.png").transform());
//GImage Paddles (GPath("pictures/Paddle1.png").transform());
std::vector<GSprite *> ball_list;
typedef std::vector<GSprite *>::iterator ball_list_iter;

// Create a new sprite for every ball
for (int i = 0 ; i < NUMBEROFBALLS ; i++)
{
GSprite *ball = new GSprite();
ball_list.push_back(ball);


int x = rand() % 1;

if (!x)
ball->attachImage(&blueball);


ball->x = rand() % 100 + 250;
ball->y = rand() % 100 + 250;

ball->vx = 0;
while (fabs(ball->vx) < 0.3)
ball->vx = ((rand() % 400) - 200.0) / 100.0;

ball->vy = 0;
while (fabs(ball->vy) < 0.3)
ball->vy = ((rand() % 400) - 200.0) / 100.0;


}

int ball_width = blueball.getWidth();
int ball_height = blueball.getHeight();
int Paddle_width = Paddle.getWidth();
int Paddle_height = Paddle.getHeight();


// Seed the random-number generator with current time so that
// the numbers will be different every time we run.
srand( (unsigned)time( NULL ) );

bool isRequired = true;
int x = 90;

// Loop until user presses Esc
while (isRequired)
{
Gwin.clear();


Gwin.drawImage(2,0, &Paddle);
Gwin.drawImage(620,0, &Paddle);
//Gwin.drawImage(400,0, &Paddles);

//Gwin.clear();






//int mx = Mouse.x;
//int my = Mouse.y;
int z = 0;



for (ball_list_iter i = ball_list.begin() ; i != ball_list.end() ; ++i)
{
(*i)->render();
(*i)->x += (*i)->vx;
(*i)->y += (*i)->vy;

//Check collisions with wall
//if //((((*i)->x + ball_width) > Gwin.getWidth()) || ((*i)->x <= 0))
//(*i)->vx *= -1;



if ((((*i)->y + ball_height )> Gwin.getHeight ()) || ((*i)->y <= 0))
(*i)->vy *= -1;

//if((((*i)->y + Paddle_height )>Gwin.getHeight () ) || ((*i)->y <= 0))
//(*i)->vy *= -1;

if (Keyboard.isPressed(GwinKeyNames::CURSOR_DOWN))
{
Gwin.drawImage(2,x++, &Paddle);

}
if (Keyboard.isPressed(GwinKeyNames::CURSOR_UP))
{
Gwin.drawImage(2,x--, &Paddle);
}

++z;
}
Gwin.refresh();

if (Keyboard.isKeyReady())
{// check if they want to exit
if (Keyboard.waitKey() == GwinKeyNames::ESCAPE)
{// let them exit
isRequired = false;
}
}
}
return 0;
}
Topic archived. No new replies allowed.