#include <iostream>
#include "engine.h"
using namespace std;
int main(int argc, char *args[])
{
Engine::cEngine myGame(800, 600, 32);
myGame.Initialize();
while(myGame.Exit() != true)
{
myGame.HandleInput();
myGame.Render();
}
myGame.DeInitialize();
return 0;
}
#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_ttf.h>
namespace Engine {
enum
{
CONSOLE_DISABLED = 0,
CONSOLE_ENABLED
};
class cConsole {
int state;
SDL_Rect bounds;
SDL_Surface *render;
TTF_Font *font;
char *text;
public:
cConsole(int);
int State(void);
void Toggle(int);
void Render(int, int, int, int, SDL_Surface *);
void Close();
};
class cEngine {
SDL_Event events;
SDL_Surface *screen;
SDL_Surface *render;
cConsole myConsole;
int screen_width;
int screen_height;
int screen_bpp;
bool engineExit;
public:
cEngine(int, int, int);
void Initialize(void);
void DeInitialize(void);
void HandleInput(void);
void Render(void);
bool Exit(void);
};
};
#include <iostream>
#include "engine.h"
#include "video.h"
#include <SDL/SDL.h> // Simple DirectMedia Layer
#include <SDL/SDL_image.h> // Image formats(*.png, *.tga, etc...)
#include <SDL/SDL_mixer.h> // Music and sound effects
#include <SDL/SDL_ttf.h> // TrueType Fonts
using namespace std;
namespace Engine {
cConsole::cConsole(int STATE = CONSOLE_DISABLED)
{
state = STATE;
render = NULL;
font = TTF_OpenFont("console.ttf", 12);
text = "Console opened...\n";
};
int cConsole::State()
{
return state;
}
void cConsole::Toggle(int STATE)
{
state = STATE;
}
void cConsole::Render(int x, int y, int w, int h, SDL_Surface *dest)
{
if(state == CONSOLE_ENABLED)
{
SDL_color color = { 255, 255, 255 };
bounds.x = x;
bounds.y = y;
bounds.w = w;
bounds.h = h;
SDL_FillRect(render, &bounds, SDL_MapRGB(render->format, 255, 255, 255));
Video::ApplySurface(x, y, render, dest, 120);
render = TTF_RenderText_Solid(font, text, color);
Video::ApplySurface(x + 5, y + 5, render, dest)
}
}
void cConsole::Close()
{
TTF_CloseFont(font);
TTF_Quit();
};
//----------------------------------------------------------------------------//
cEngine::cEngine(int width, int height, int bpp)
{
screen_width = width;
screen_height = height;
screen_bpp = bpp;
engineExit = false;
screen = NULL;
render = NULL;
}
void cEngine::Initialize()
{
SDL_Init(SDL_INIT_EVERYTHING);
TTF_Init();
SDL_WM_SetCaption("Extreme Pong", NULL);
screen = SDL_SetVideoMode(screen_width, screen_height, screen_bpp, SDL_HWSURFACE | SDL_FULLSCREEN);
}
void cEngine::HandleInput()
{
while(SDL_PollEvent(&events))
{
switch(events.type)
{
case SDL_KEYDOWN:
{
if(events.key.keysym.sym == SDLK_ESCAPE)
{
engineExit = true;
break;
}
if(events.key.keysym.sym == SDLK_BACKQUOTE)
{
if(myConsole.State() == CONSOLE_DISABLED)
myConsole.Toggle(CONSOLE_ENABLED);
else
myConsole.Toggle(CONSOLE_DISABLED);
break;
}
}
}
}
}
void cEngine::Render()
{
myConsole.Render(10, 10, 200, 100, screen);
SDL_Flip(screen);
}
void cEngine::DeInitialize()
{
myConsole.Close();
TTF_Quit();
SDL_FreeSurface(screen);
SDL_FreeSurface(render);
SDL_Quit();
}
bool cEngine::Exit()
{
return engineExit;
}
};
#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_ttf.h>
namespace Video {
SDL_Surface *LoadImage(char *);
void ApplySurface(int, int, SDL_Surface *, SDL_Surface *, int alpha = SDL_ALPHA_OPAQUE, SDL_Rect *clip = NULL);
};
#include <iostream>
#include <SDL/SDL.h> // Simple DirectMedia Layer
#include <SDL/SDL_image.h> // Image formats(*.png, *.tga, etc...)
#include <SDL/SDL_mixer.h> // Music and sound effects
#include <SDL/SDL_ttf.h> // TrueType Fonts
using namespace std;
namespace Video {
SDL_Surface *LoadImage(char *filename)
{
SDL_Surface *loadedImage = NULL;
SDL_Surface *optimizedImage = NULL;
loadedImage = IMG_Load(filename);
optimizedImage = SDL_DisplayFormat(loadedImage);
Uint32 colorkey = SDL_MapRGB(optimizedImage->format, 255, 0, 255);
SDL_SetColorKey(optimizedImage, SDL_RLEACCEL | SDL_SRCCOLORKEY, colorkey);
SDL_FreeSurface(loadedImage);
return optimizedImage;
}
void ApplySurface(int x, int y, SDL_Surface *source, SDL_Surface *dest, int alpha = SDL_ALPHA_OPAQUE, SDL_Rect *clip = NULL)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_SetAlpha(source, SDL_RLEACCEL | SDL_SRCALPHA, alpha);
SDL_BlitSurface(source, clip, dest, &offset);
}
};