Thread: Getting Wierd Error

  1. #1
    Registered User CreatedByShadow's Avatar
    Join Date
    Jan 2006
    Posts
    24

    Getting Wierd Error

    Code:
    #include "SDL.h"
    #include "SDL_image.h"
    #include <string>
    
    using namespace std;
    
    //Event structure
    SDL_Event event;
    
    //Constants
    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 480;
    const short SCREEN_BPP = 32;
    
    //Surfaces
    SDL_Surface *screen = NULL;
    SDL_Surface *paddle = NULL;
    
    //Image loading function
    SDL_Surface *load_image(string filename)
    {
    	//loaded image will go here
    	SDL_Surface *loadedImage = NULL;
    	//optimized will be contained here
    	SDL_Surface *optimizedImage = NULL;
    
    	//load starting image
    	loadedImage = IMG_Load(filename.c_str());
    	//If loading was okay
    	if(loadedImage != NULL)
    	{
    		//Convert
    		optimizedImage = SDL_DisplayFormat( loadedImage );
    		//Free loaded image
    		SDL_FreeSurface( loadedImage );
    	}
    	else if( loadedImage == NULL)
    	{
    		return 0;
    	}
    
    	//return optimized image
    	return optimizedImage;
    }
    
    //Apply image
    void apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination)
    {
    	//Create temp rect to hold offsets
    	SDL_Rect offset;
    	//Offsets
    	offset.x = x;
    	offset.y = y;
    	//Blit Surface
    	SDL_BlitSurface(source, NULL, destination, &offset);
    }
    
    //Init all subsystems
    bool Init_All()
    {
    	//Initalize
    	if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
    	{
    		return false;
    	}
    	
    	//load screen
    	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
    
    	//check for screen loading errors
    	if(screen == NULL)
    	{
    		//error found
    		return false;
    	}
    
    	//set caption of window
    	SDL_WM_SetCaption("Pong Game", NULL);
    
    	//everything loaded fine
    	return true;
    }
    
    //load all pictures 
    bool load_files()
    {
    	//load paddle
    	paddle = load_image("paddle.png");
    
    	if(paddle == NULL)
    	{
    		return false;
    	}
    
    
    	//everything loaded okay
    	return true;
    }
    
    void clean_up()
    {
    	SDL_FreeSurface(paddle);
    	SDL_Quit();
    }
    
    //constants
    const int BALL_HEIGHT = 10;
    const int BALL_WIDTH = 6;
    
    class Paddle
    {
    private:
    	//offsets of paddle
    	int xCoord, yCoord;
    	//Velocity of paddle
    	int xVel, yVel;
    
    public:
    	//Init variables
    	void paddle();
    	//Deconstructor
    	~paddle();
    	//handles keypresses
    	void handle_input();
    	//moves paddle
    	void move();
    	//shows paddle on screen
    	void show();
    };
    
    void Paddle::paddle()
    {
    	//Set starting offsets
    	xCoord = 620;
    	yCoord = 240;
    
    	//set starting velocity
    	xVel = 0;
    	yVel = 0;
    }
    
    ~Paddle::paddle()
    {
    }
    
    void Paddle::handle_input()
    {
    	//if key is pressed
    	if(event.type == SDL_KEYDOWN)
    	{
    		//adjusts velocity
    		switch(event.key.keysym.sym)
    		{
    		case SDLK_LEFT:
    			xVel = xVel - BALL_HEIGHT / 2;
    			break;
    		case SDLK_RIGHT:
    			xVel = xVel + BALL_HEIGHT / 2;
    		}
    	}
    	//when key is released
    	else if(event.type == SDL_KEYUP)
    	{
    		//adjusts velocity
    		switch(event.key.keysym.sym)
    		{
    		case SDLK_LEFT:
    			xVel = xVel + BALL_HEIGHT / 2;
    			break;
    		case SDLK_RIGHT:
    			xVel = xVel - BALL_HEIGHT / 2;
    			break;
    		}
    	}
    }
    
    void Paddle::move()
    {
    	//Move paddle left or right
    	xCoord += xVel;
    
    	//if moved too far
    	if(( xCoord < 0 ) || ( xCoord + BALL_WIDTH > SCREEN_WIDTH))
    	{
    		xCoord -= xVel;
    	}
    }
    
    void Paddle::show()
    {
    	apply_surface(xCoord, yCoord, paddle, screen);
    }
    
    //this function checks for collision between the ball and the paddle
    bool check_collision(SDL_Rect &A, SDL_Rect &B)
    {
    	//sides of rectangle
    	int leftA, leftB;
    	int rightA, rightB;
    	int topA, topB;
    	int bottomA, bottomB;
    
    	//calculate sides of rectangle
    	leftA = A.x;
    	rightA = A.x + A.w;
    	topA = A.y;
    	bottomA = A.y + A.h;
    
    	leftB = B.x;
    	rightB = B.x + B.w;
    	topB = B.y;
    	bottomB = B.y + B.h;
    
    	//check for intersections
    	if(bottomA <= topB)
    	{
    		return false;
    	}
    
    	if(topA >= bottomB)
    	{
    		return false;
    	}
    
    	if(rightA <= leftB)
    	{
    		return false;
    	}
    
    	if(leftA >= rightB)
    	{
    		return false;
    	}
    
    	//if no sides are outside b
    	return true;
    }
    
    //main function
    int main(int argc, char *argv[])
    {
    
    	bool quit = false;
    
    	Paddle playerPaddle;
    
    	//Init subsystems
    	if(Init_All() == false)
    	{
    		//close if initalization failed..
    		return 0;
    	}
    
    	//load files
    	if(load_files() == false)
    	{
    		//close if failed
    		return 0;
    	}
    
    	while(quit == false)
    	{
    		while(SDL_PollEvent(&event))
    		{
    			//handles things for paddle
    			playerPaddle.handle_input();
    
    			if(event.type == SDL_QUIT)
    			{
    				//exits game
    				quit = true;
    			}
    		}
    
    		//move paddle
    		playerPaddle.move();
    		
    		//Fill screen white
    		SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF));
    
    		//Show paddle
    		playerPaddle.show();
    
    		//Update screen
    		if(SDL_Flip(screen) == -1)
    		{
    			return 1;
    		}
    	}
    
    	return 0;
    
    }
    For some reason Visual C++ keeps saying missing argument list and than points to the red line.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Can you post the exact error message(s)?

  3. #3
    Registered User CreatedByShadow's Avatar
    Join Date
    Jan 2006
    Posts
    24
    Sure.

    Error:

    1>c:\documents and settings\sinister smile\my documents\visual studio 2005\projects\pongtest1\pongtest1\main.cpp(191) : error C3867: 'Paddle:addle': function call missing argument list; use '&Paddle:addle' to create a pointer to member

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Looks like contructor and descructor are a bit off. You contructors don't have a return value, inlcuding void and the need to match the case of your class

    Code:
    class Paddle
    {
    public:
    	Paddle();
    	~Paddle();
    };
    
    Paddle::Paddle()
    {
    	//init
    }
    
    Paddle::~Paddle()
    {
    	//cleanup
    }
    Last edited by prog-bman; 07-18-2007 at 02:51 PM.

  5. #5
    Registered User CreatedByShadow's Avatar
    Join Date
    Jan 2006
    Posts
    24
    That fixed it, thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  4. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  5. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM