• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
haraiza

Ebooks

8 posts in this topic

Im trying to program a game with Visual C++ and SDL but without success. Do you know where find ebook about those themes?
0

Share this post


Link to post
Share on other sites
Im trying to program a game with Visual C++ and SDL but without success. Do you know where find ebook about those themes?

 

Many publishers such as O'Reilly sell books in ebook format. Could you be more specific as to what you need focus on? Are you searching for a book covering the Visual C++ IDE? SDL? Programming in general?

0

Share this post


Link to post
Share on other sites
Im trying to program a game with Visual C++ and SDL but without success. Do you know where find eBook about those themes?

 

Many publishers such as O'Reilly sell books in eBook format. Could you be more specific as to what you need focus on? Are you searching for a book covering the Visual C++ IDE? SDL? Programming in general?

I am a member of the O'Reilly Blogger Review program, so I get free books. I have to review every book I write in my Blog, however it's worth it. Considering I otherwise can't afford many books, it's a great system. You should look into that program if you're short on cash.

0

Share this post


Link to post
Share on other sites

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 ==========
0

Share this post


Link to post
Share on other sites

Try using Pre-Compiled headers. Saves you a lot of time smile.png.

 

When you declare a variable in Main.cpp, it isn't included in any other files, and it's generally bad practice to include "Main.cpp" in another .h or .cpp file. What you could do is make a new file called "Global.h" and decalre all your Global variables in that file. That way, all you have to do is include "Global.h" in all of your source files.

 

Cheers smile.png!

Edited by superman3275
0

Share this post


Link to post
Share on other sites

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. 

0

Share this post


Link to post
Share on other sites

Can you attach your source code? It's hard to understand the errors without context, however I believe your code is missing many Semicolons(;) after you are declaring Variables / Structures. You are also trying to convert (or indirectly converting) some of your variables into Integers.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0