Jump to content

  • Log In with Google      Sign In   
  • Create Account

haraiza

Member Since 20 Dec 2012
Offline Last Active Jan 31 2013 12:46 AM

Posts I've Made

In Topic: Ebooks

30 December 2012 - 02:22 PM


ISDCaptain01: Thanks. A friend will lead me te book but until the next month... right now he´s on vacations in Cuba.
 
superman3275: Here´s the whole file. My IDE doesnt show any sisntax error but maybe you will see more than I do.  Any help will be very appreciate smile.png

 

https://dl.dropbox.com/u/3679069/Pruebas%20con%20SDL.rar


In Topic: Ebooks

29 December 2012 - 05:23 PM

I followed your advice. Now the error its different and as always I'm clueless. Who else but Superman can help me :)  

 

 

1>------ Build started: Project: Pruebas con SDL, Configuration: Debug Win32 ------
1>  timer.cpp
1>c:\sdl-1.2.15\include\sdl_config_win32.h(33): error C2628: 'Timer' followed by 'signed' is illegal (did you forget a ';'?)
1>c:\sdl-1.2.15\include\sdl_config_win32.h(33): error C2628: 'Timer' followed by '__int8' is illegal (did you forget a ';'?)
1>c:\sdl-1.2.15\include\sdl_stdinc.h(126): error C2118: negative subscript
1>  functions_SDL.cpp
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\globals.h(7): error C2146: syntax error : missing ';' before identifier 'event'
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\globals.h(7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\constants.h(5): error C2628: 'Timer' followed by 'int' is illegal (did you forget a ';'?)
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\constants.h(5): error C2440: 'initializing' : cannot convert from 'int' to 'Timer'
1>          No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\functions_sdl.cpp(45): error C2572: 'apply_surface' : redefinition of default parameter : parameter 5
1>          c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\functions_sdl.h(12) : see declaration of 'apply_surface'
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\functions_sdl.cpp(66): error C2664: 'SDL_SetVideoMode' : cannot convert parameter 1 from 'const Timer' to 'int'
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>  dot.cpp
1>c:\sdl-1.2.15\include\sdl_config_win32.h(33): error C2628: 'Dot' followed by 'signed' is illegal (did you forget a ';'?)
1>c:\sdl-1.2.15\include\sdl_config_win32.h(33): error C2628: 'Dot' followed by '__int8' is illegal (did you forget a ';'?)
1>c:\sdl-1.2.15\include\sdl_stdinc.h(126): error C2118: negative subscript
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(10): error C2533: 'Dot::{ctor}' : constructors not allowed a return type
1>  General.cpp
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\globals.h(7): error C2146: syntax error : missing ';' before identifier 'event'
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\globals.h(7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\constants.h(5): error C2628: 'Dot' followed by 'int' is illegal (did you forget a ';'?)
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\constants.h(5): error C2440: 'initializing' : cannot convert from 'int' to 'Dot'
1>          No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\general.cpp(54): error C2664: 'SDL_PollEvent' : cannot convert parameter 1 from 'int *' to 'SDL_Event *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\general.cpp(61): error C2228: left of '.type' must have class/struct/union
1>          type is 'int'
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

 

 

 

 

 

 

Here´s my source code. 


In Topic: Ebooks

29 December 2012 - 01:31 PM

dmreichard: You´re right, I didn´t specify about my problem. I am following the tutorials in lazyfoo.net/SDL_tutorials/index.php

 

I was writtting the lesson 16, downloaded the source code (at the bottom of the page) to rewrite it and separate the interface from the implementation. After rewrite all the source code the class Dot didnt have access to the  global variables declarated in the file with the main.cpp. 

 

Im pretty shure this its a really dumb problem but since Im noob with de SDL library it´s very hard to me. 

 

superman3275: Didnt know about that.. its a sweet deal. I will try to do that, thanks smile.png

//main.cpp
#include "SDL_image.h"
#include "timer.h"
#include "dot.h"
#include <string>

//Screen attributes
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

//The frame rate
const int FRAMES_PER_SECOND = 20;

//The dimensions of the dot
const int DOT_WIDTH = 20;
const int DOT_HEIGHT = 20;

//The surfaces
SDL_Surface *dot = NULL;
SDL_Surface *screen = NULL;

//The event structure
SDL_Event event;

SDL_Surface *load_image( std::string filename )
{
    //The image that's loaded
    SDL_Surface* loadedImage = NULL;

    //The optimized surface that will be used
    SDL_Surface* optimizedImage = NULL;

    //Load the image
    loadedImage = IMG_Load( filename.c_str() );

    //If the image loaded
    if( loadedImage != NULL )
    {
        //Create an optimized surface
        optimizedImage = SDL_DisplayFormat( loadedImage );

        //Free the old surface
        SDL_FreeSurface( loadedImage );

        //If the surface was optimized
        if( optimizedImage != NULL )
        {
            //Color key surface
            SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0xFF, 0, 0xFF ) );
        }
    }

    //Return the optimized surface
    return optimizedImage;
}

void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL)
{
//Holds offsets
SDL_Rect offset;

//Get offsets
offset.x = x;
offset.y = y;

//Blit
SDL_BlitSurface (source, clip, destination, &offset);
}

bool init()
{
    //Initialize all SDL subsystems
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    {
        return false;
    }

    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

    //If there was an error in setting up the screen
    if( screen == NULL )
    {
        return false;
    }

    //If everything initialized fine
    return true;
}

bool load_files()
{
//Load the image
dot = load_image("dot.bmp");

//If there was a problem in loading the dot
if(dot == NULL)
return false;

//If everything loaded fine
return true;
}

void clean_up()
{
SDL_FreeSurface( dot );

//Quit SDL
SDL_Quit();
}

int main( int argc, char* args[] )
{
//Quit flag 
bool quit = false;

//The dot that will be used
Dot myDot;

//The frame rate regulator
Timer fps;

//Initializate
if( init() == false )
return 1;

//Load the files
if( load_files() == false )
return 1;

//While the user hasn´t quit
while( quit == false )
{
//If there´s events to handle
if( SDL_PollEvent ( &event ) )
{

//Handle events for the dot
myDot.handle_input();

//If Xed was press
if(event.type == SDL_QUIT)
{
//Close the window
quit = true;
}

}//PollEvent

//Move the dot
myDot.move();

SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF) );

//Show the dot on the screen
myDot.show();

//Update the screen
if( SDL_Flip( screen ) == -1)
return 1;

//Cap the frame rate
if(fps.get_ticks() < 1000/FRAMES_PER_SECOND)
{
SDL_Delay( (1000/FRAMES_PER_SECOND)-fps.get_ticks()  );
}

}//while

//Clean up
clean_up();

return 0;
}

 

//dot.h
#ifndef DOT_H
#define DOT_H

class Dot
{
public:
	Dot();
	void handle_input();
	void move();
	void show();

private:
	int x;
	int y;
	int xVel;
	int yVel;
}
#endif

 

 

//dot.cpp
#include "dot.h"
#include "SDL.h"
#include "SDL_image.h"

Dot::Dot()
{
	x = 0;
	y = 0;
	xVel = 0;
	yVel = 0;
}

void Dot::handle_input()
{
	if(event.type == SDL_KEYDOWN)
	{
		//Adjust the velocity
		switch(event.key.keysym.sym)
		{
			case SDLK_UP:		yVel -= DOT_HEIGHT /2; break;
			case SDLK_DOWN:		yVel += DOT_HEIGHT /2; break;
			case SDLK_LEFT:		xVel -= DOT_HEIGHT /2; break;
			case SDLK_RIGHT:	xVel += DOT_HEIGHT /2; break;
		}
	}
	//If a key was released
	else if(event.type == SDL_KEYUP)
	{
		switch(event.key.keysym.sym)
		{
			case SDLK_UP:		yVel += DOT_HEIGHT /2; break;
			case SDLK_DOWN:		yVel -= DOT_HEIGHT /2; break;
			case SDLK_LEFT:		xVel += DOT_HEIGHT /2; break;
			case SDLK_RIGHT:	xVel -= DOT_HEIGHT /2; break;
		}
	}
}

void Dot::move()
{
	//Move the dot right or left
	x += xVel;

	//If the dot went too far to the left or right
	if( (x < 0) || (x + DOT_WIDTH > SCREEN_WIDTH) )
	{
		//move back
		x -= xVel;
	}

	//Move the dot up or down
	y += yVel;

	//If the dot went too far to the left or right
	if( (y < 0) || (x + DOT_HEIGHT > SCREEN_HEIGHT) )
	{
		//move back
		y -= yVel;
	}
}

void Dot::show()
{
	apply_surface(x, y, dot, screen);
}
//timer.h
#ifndef TIMER_H
#define TIMER_H

class Timer
{
public:
	
	Timer();		//Initialize the class
	void start();	
	void stop();
	void pause();
	void unpause();
	int get_ticks();
	bool is_started();
	bool is_paused();

private:

	int startTicks;	//The clock time when the time start
	int pausedTicks;	//The clock stored when the timer was paused
	bool paused;	// The timer status
	bool started;	// The timer status
}
#endif
//timer.cpp
#include "timer.h"
#include "SDL_image.h"

Timer::Timer()
{
	startTicks = 0;
	pausedTicks = 0;
	paused = false;
	started = false;
}

void Timer::start()
{
	started = true;
	paused = false;
	startTicks = SDL_GetTicks();
}

void Timer::stop()
{
	started = false;
	paused = false;
}

void Timer::pause()
{
	if(	(started == true) && (paused == false) )
	{
		paused = true;
		pausedTicks = SDL_GetTicks() - startTicks;
	}
}

void Timer::unpause()
{
	if(paused == true)
	{
		paused = false;
		startTicks = SDL_GetTicks() - pausedTicks;
		pausedTicks = 0;
	}
}

int Timer::get_ticks()
{
	if(started == true)
	{
		if(paused == true)
			return pausedTicks;
		else
			return SDL_GetTicks() - startTicks;
	}

	return 0;
}

bool Timer::is_started()
{
	return started;
}

bool Timer::is_paused()
{
	return paused;
}

 

At the end, the Output says:

 

1>------ Build started: Project: Pruebas con SDL, Configuration: Debug Win32 ------
1>  timer.cpp
1>c:\sdl-1.2.15\include\sdl_config_win32.h(33): error C2628: 'Timer' followed by 'signed' is illegal (did you forget a ';'?)
1>c:\sdl-1.2.15\include\sdl_config_win32.h(33): error C2628: 'Timer' followed by '__int8' is illegal (did you forget a ';'?)
1>c:\sdl-1.2.15\include\sdl_stdinc.h(126): error C2118: negative subscript
1>  dot.cpp
1>c:\sdl-1.2.15\include\sdl_config_win32.h(33): error C2628: 'Dot' followed by 'signed' is illegal (did you forget a ';'?)
1>c:\sdl-1.2.15\include\sdl_config_win32.h(33): error C2628: 'Dot' followed by '__int8' is illegal (did you forget a ';'?)
1>c:\sdl-1.2.15\include\sdl_stdinc.h(126): error C2118: negative subscript
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(15): error C2065: 'event' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(15): error C2228: left of '.type' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(18): error C2065: 'event' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(18): error C2228: left of '.key' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(18): error C2228: left of '.keysym' must have class/struct/union
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(18): error C2228: left of '.sym' must have class/struct/union
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(20): error C2065: 'DOT_HEIGHT' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(21): error C2065: 'DOT_HEIGHT' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(22): error C2065: 'DOT_HEIGHT' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(23): error C2065: 'DOT_HEIGHT' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(27): error C2065: 'event' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(27): error C2228: left of '.type' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(29): error C2065: 'event' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(29): error C2228: left of '.key' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(29): error C2228: left of '.keysym' must have class/struct/union
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(29): error C2228: left of '.sym' must have class/struct/union
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(31): error C2065: 'DOT_HEIGHT' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(32): error C2065: 'DOT_HEIGHT' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(33): error C2065: 'DOT_HEIGHT' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(34): error C2065: 'DOT_HEIGHT' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(45): error C2065: 'DOT_WIDTH' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(45): error C2065: 'SCREEN_WIDTH' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(55): error C2065: 'DOT_HEIGHT' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(55): error C2065: 'SCREEN_HEIGHT' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(64): error C2065: 'dot' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(64): error C2065: 'screen' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.cpp(64): error C3861: 'apply_surface': identifier not found
1>  General.cpp
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.h(5): error C2236: unexpected 'class' 'Dot'. Did you forget a ';'?
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.h(5): error C2143: syntax error : missing ';' before '{'
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\dot.h(5): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\general.cpp(139): error C2065: 'Dot' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\general.cpp(139): error C2146: syntax error : missing ';' before identifier 'myDot'
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\general.cpp(139): error C2065: 'myDot' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\general.cpp(160): error C2065: 'myDot' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\general.cpp(160): error C2228: left of '.handle_input' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\general.cpp(172): error C2065: 'myDot' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\general.cpp(172): error C2228: left of '.move' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\general.cpp(177): error C2065: 'myDot' : undeclared identifier
1>c:\users\humberto\dropbox\programas en c++\pruebas con sdl\pruebas con sdl\general.cpp(177): error C2228: left of '.show' must have class/struct/union
1>          type is ''unknown-type''
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

PARTNERS