2 Replies - 954 Views - Last Post: 24 February 2011 - 02:11 PM Rate Topic: -----

#1 csanborn1989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-January 11

SDL C++ compiler error

Posted 24 February 2011 - 01:56 PM

Hi I am teaching myself C++ SDL, and on one of the tutorial videos I watch trying to make the keys work continuously when there held down but I get a compiler error Any help would be great Here's the code

#include <SDL.h>

SDL_Surface *screen = NULL;
SDL_Surface *backround = NULL;
SDL_Surface *sprite = NULL;

int width = 32;
int height = 32;
int srcX = 0;
int srcY = 0;
int dstX = 0;
int dstY = 0;

void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination)
{
	SDL_Rect rect;
	rect.x = x;
	rect.y = y;
	SDL_BlitSurface(source, NULL, destination, &rect);

}
void draw_sprite(int srcX, int srcY, int dstX, int dstY, int width, int height,SDL_Surface* source,
				 SDL_Surface* destination)
{
	SDL_Rect src;
	src.x = srcX;
	src.y = srcY;
	src.w = width;
	src.h = height;

	SDL_Rect dst;

	dst.x = dstX;
	dst.y = dstY;
	dst.w = width;
	dst.h = height;

	SDL_BlitSurface(source, &src, destination, &dst);
}


bool gameRunning = true;


SDL_Event event;

int main(int argc, char* argv[])

{
	SDL_Init(SDL_INIT_VIDEO);

	screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);

	backround = SDL_LoadBMP("backround2.bmp");
	sprite = SDL_LoadBMP("player.bmp");


	SDL_SetColorKey(sprite,SDL_SRCCOLORKEY,SDL_MapRGB(sprite->format, 200, 0, 200));

	
	bool  Keys[323] = false;
	while(gameRunning)
	{
		if(SDL_PollEvent(&event))
		{
			if(event.type == SDL_QUIT)
			{
				gameRunning = false;
			}
			if(event.type == SDL_KEYDOWN)
			{
				Keys[event.key.keysym.sym] = true;
			}
			if(event.type == SDL_KEYUP)
			{
				Keys[event.key.keysym.sym] = false;
			}
			if(event.key.keysym.sym = SDLK_RIGHT)
			{
				dstY += 1;
			}

			
			

		}
		
		


		apply_surface(0,0,backround,screen);
		draw_sprite(srcX,srcY,dstX,dstY,width,height, sprite, screen);
		
		

		SDL_Flip(screen);


	}
	SDL_Quit ();
	return 0;
} 


And this is the error message I get
error C2440: 'initializing' : cannot convert from 'bool' to 'bool [323]'
There are no conversions to array types, although there are conversions to references or pointers to arrays

any help would be great thank you

Is This A Good Question/Topic? 0
  • +

Replies To: SDL C++ compiler error

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,546
  • Joined: 23-August 08

Re: SDL C++ compiler error

Posted 24 February 2011 - 02:01 PM

On what line is this error occurring?
Sorry...I see it. When initializing arrays, you need to use {}s.

bool  Keys[323] = { false };

Was This Post Helpful? 1
  • +
  • -

#3 csanborn1989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-January 11

Re: SDL C++ compiler error

Posted 24 February 2011 - 02:11 PM

Thanks man I have been scratching my head over it for awhile thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1