All pastes #908450 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-02-18 14:08 UTC
rendered paste body
//g++ test.cpp -o test -lSDL -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
#include <stdlib.h>
#include "SDL/SDL.h"
#include <iostream>

class ball
{
	public:
	ball()
	{
		x = 0;
		y = 0;
		speedX = 10;
		speedY = 10;
	}
	
	private:
	int x, y;
	int speedX, speedY;
};

class pong
{
	public:
	pong()
	{
		init();
		game();
	}
	
	private:
	void init()
	{
		initGame();
		initScreen();
	}
	
	void initGame()
	{
		pallo = new ball();
	}
	
	void initScreen()
	{
		if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
		{
			fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
			exit(1);
		}
		atexit(SDL_Quit);
		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
		SDL_Surface *screen;

		screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
	}
	
	void game()
	{
		int color = SDL_MapRGB( screen->format, 0,0,0);
		while( true )
		{
			SDL_Event event;
			SDL_PumpEvents();
			while ( SDL_PollEvent(&event) )
			{
				if ( event.type == SDL_QUIT )
				{ 
						exit(0);
				}
			}
			SDL_FillRect(screen, NULL, color );
			SDL_Flip(screen);
			SDL_Delay(50);
		}
	}
	
	ball* pallo;
	SDL_Surface *screen;
};

int main()
{
	pong* game = new pong();
	delete game;
	return 0;
}