1
0
mirror of https://github.com/krislamo/Trololo synced 2024-09-19 20:20:36 +00:00
Trololo/main.cpp

115 lines
2.3 KiB
C++
Raw Normal View History

2012-10-24 11:46:45 +00:00
// SDL + Extensions
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
2012-10-28 22:01:33 +00:00
#include "SDL/SDL_ttf.h"
2012-10-24 11:46:45 +00:00
// Common SDL functions for general processing.
#include "commonSDL.h"
#define WINDOW_TITLE "Trololo"
// Screen
SDL_Surface *screen = NULL;
SDL_Surface *background = NULL;
SDL_Surface *characters = NULL;
2012-10-24 11:46:45 +00:00
2012-10-28 22:01:33 +00:00
SDL_Surface *message = NULL;
2012-10-24 11:46:45 +00:00
// Image filenames
const char *background_image = "stage1.bmp";
const char *characters_image = "characters.bmp";
// Char
SDL_Rect clip[2];
2012-10-24 11:46:45 +00:00
int main(int argc, char* args[])
{
screen = StartUp(WINDOW_TITLE, 900, 675);
2012-10-24 11:46:45 +00:00
if(screen == NULL)
{
fprintf(stderr, "Start up failure.\n");
return 1;
}
else
{
// Load images
background = load_image(background_image);
characters = load_image(characters_image);
// The troll's coordinates
clip[0].x = 0;
clip[0].y = 0;
clip[0].w = 200;
clip[0].h = 160;
// The codfish's coordinates
clip[1].x = 0;
clip[1].y = 160;
clip[1].w = 200;
clip[1].h = 100;
2012-10-24 11:46:45 +00:00
// Remove the background from the characters
RemoveColor(characters, 0x00, 0xFF, 0x00); // Green
2012-10-24 11:46:45 +00:00
// Blit background image
2012-10-24 11:46:45 +00:00
apply_image(0, 0, background, screen);
// Blit troll image
2012-10-28 22:01:33 +00:00
apply_image(700, 40, characters, screen, &clip[0]);
// Blit codfish image
2012-10-28 22:01:33 +00:00
apply_image(150, 300, characters, screen, &clip[1]);
// Setup welcome text
SDL_Color whitecolor = { 255, 255, 255 };
TTF_Font *font = TTF_OpenFont("CaviarDreams.ttf", 80);
const char* text = "Welcome to Trololo";
if(!font)
{
fprintf(stderr, "TTF_OpenFont: %s\n", TTF_GetError());
}
/*
Checks if font or text is NULL due to the documentation:
NULL font into this function will cause a segfault.
NULL text into this function will result in undefined behavior.
*/
if(font != NULL && text != NULL)
message = TTF_RenderText_Solid(font, text, whitecolor);
else
fprintf(stderr, "TFF Render Text Solid Error: init error\n");
// Apply message
if(message != NULL)
apply_image(100, 200, message, screen);
else
fprintf(stderr, "TFF Render Text Solid Error: apply error\n");
2012-10-24 11:46:45 +00:00
if(screen != NULL)
SDL_Flip(screen);
else
fprintf(stderr, "Couldn't update screen.\n");
SDL_Event event;
int quit = 1;
// Check if user quit
while(quit == 1)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
quit = 0;
}
}
return 0;
}
}