1
0
mirror of https://github.com/krislamo/Trololo synced 2024-11-10 00:30:35 +00:00

A movable Mario on a background

This commit is contained in:
Kris Lamoureux 2013-03-04 03:31:47 -08:00
parent c1ee567335
commit 05e0ae4e60
19 changed files with 108 additions and 239 deletions

3
.gitignore vendored
View File

@ -4,8 +4,9 @@
# Linux Binary # # Linux Binary #
################ ################
Trololo mario
# Windows scripts # # Windows scripts #
################### ###################
*.bat *.bat

View File

@ -1,16 +1,17 @@
# Trololo # Mario
I'm building this while learning from [Lazy Foo' Productions' SDL Tutorials](http://lazyfoo.net/SDL_tutorials/). A fork of Trololo. Trololo was a project that wasn't really headed in any direction, well this is where it is headed now. Mario is a temporary name and will hopefully gain a unique name closer to its release.
## About ## About
Trololo is written in C++ with SDL 1.2.15 (32 bit) with the SDL extension libraries: SDL_image (1.2.12) and SDL_tff (2.0.11). Mario is written in C++ with SDL 1.2.15 (32 bit) with the SDL extension libraries: SDL_image (1.2.12) and SDL_tff (2.0.11).
## License ## License
This software is released under the GNU General Public License Version 3. Please read the LICENSE file to know your rights before continuing. This software is released under the GNU General Public License Version 3. Please read the LICENSE file to know your rights before continuing.
## System Support ## System Support
* Windows 7 Home Premium x86_64 (Service Pack 1) (g++ 4.7.0) * Windows 7 Home Premium x86_64 (Service Pack 1) (g++ 4.x)
* Linux 3.2 Debian 6.0 x86_64 (g++ 4.4.5)
## Planning to Support
* Linux 3.2 x86_64 (g++ 4.x)
## Current State ## Current State
This software doesn't do much yet. Nothing is guaranteed to compile but most of the time it should. Binary links will be added in future stable This software is in an unstable state.
updates on the [latest readme on github](https://github.com/Kris619/Trololo/).

View File

@ -1,17 +1,8 @@
Bibliography Bibliography
Green Arrow up. Digital image. Symbols & Shapes - Green Arrow up - Public Domain Nintendo. Dancing Mario GIF. Digital image. DeviantART. SuperLink9, n.d. Web. 2
Clip Art. N.p., n.d. Web. 2 Jan. 2013. <http://www.pdclipart.org Mar. 2013. <http://superlink9.deviantart.com/art/Dancing-Mario-
/displayimage.php?album=141&pos=145>. GIF-46727224>.
Kratochvil, Petr. Pool Tiles Underwater. Digital image. Free Stock Photo - Public KeR-. Mario World HD. Digital image. DeviantART. KeR-, n.d. Web. 2 Mar. 2013.
Domain Pictures. N.p., n.d. Web. 28 Oct. 2012. <http://ker-.deviantart.com/art/Mario-World-HD-19771526>.
<http://www.publicdomainpictures.net/view-image.php?image=5182&
picture=pool-tiles-underwater>.
OCAL. Illustration Of A Blue Codfish. Digital image. Free Stock Photos. N.p., n.d.
Web. 28 Oct. 2012. <http://www.freestockphotos.biz/stockphoto/10674>.
Trollface. Digital image. Wikipedia. N.p., n.d. Web. 28 Oct. 2012.
<http://upload.wikimedia.org/wikipedia/en/thumb/7/78/Trollface.svg/200px-
Trollface.svg.png>.

BIN
SDL.dll Normal file

Binary file not shown.

BIN
SDL_image.dll Normal file

Binary file not shown.

BIN
bin/IMG0.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
bin/IMG1.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
bin/IMG2.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
bin/IMG3.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
bin/IMG4.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
bin/IMG5.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

BIN
bin/Originals/stage.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

BIN
bin/stage.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

270
core.cpp
View File

@ -65,7 +65,7 @@ namespace scrns
{ {
SDL_Surface *screen = NULL; SDL_Surface *screen = NULL;
SDL_Surface *vid_init; SDL_Surface *vid_init;
int init, ttf_ret; int init;//, ttf_ret;
// Initiate SDL and check // Initiate SDL and check
init = SDL_Init(SDL_INIT_VIDEO); init = SDL_Init(SDL_INIT_VIDEO);
@ -96,7 +96,7 @@ namespace scrns
// Set window title // Set window title
SDL_WM_SetCaption(WINDOW_TITLE " " VERSION, 0); SDL_WM_SetCaption(WINDOW_TITLE " " VERSION, 0);
/*
// Initialize SDL_ttf and check // Initialize SDL_ttf and check
ttf_ret = TTF_Init(); ttf_ret = TTF_Init();
if(ttf_ret == -1) if(ttf_ret == -1)
@ -104,6 +104,7 @@ namespace scrns
fprintf(stderr, "True Type Font initialization failed: %s", SDL_GetError()); fprintf(stderr, "True Type Font initialization failed: %s", SDL_GetError());
return NULL; return NULL;
} }
*/
SDL_FreeSurface(vid_init); SDL_FreeSurface(vid_init);
@ -111,25 +112,21 @@ namespace scrns
return screen; return screen;
} }
SDL_Surface *MainMenu() /*SDL_Surface *MainMenu()
{
}*/
SDL_Surface *Stage1()
{ {
// Screen // Screen
SDL_Surface *screen = NULL; SDL_Surface *screen = NULL;
SDL_Surface *background = NULL; SDL_Surface *background = NULL;
SDL_Surface *characters = NULL;
SDL_Surface *message = NULL;
SDL_Surface *indicator = NULL;
// Image filenames // Image filenames
const char *background_image = "bin/stage1.bmp"; const char *background_image = "bin/stage.bmp";
const char *characters_image = "bin/characters.bmp";
const char *indicator_image = "bin/indicator.bmp";
// Char screen = initiateSDL(900, 646);
SDL_Rect clip[2];
screen = initiateSDL(900, 675);
if(screen == NULL) if(screen == NULL)
{ {
@ -140,230 +137,109 @@ namespace scrns
{ {
// Load images // Load images
background = scrnfunk::load_image(background_image); background = scrnfunk::load_image(background_image);
characters = scrnfunk::load_image(characters_image);
indicator = scrnfunk::load_image(indicator_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;
// Remove the background from the characters
scrnfunk::RemoveColor(characters, 0x00, 0xFF, 0x00); // Green
// Blit background image // Blit background image
scrnfunk::apply_image(0, 0, background, screen); scrnfunk::apply_image(0, 0, background, screen);
// Blit troll image
scrnfunk::apply_image(700, 40, characters, screen, &clip[0]);
// Blit codfish image
scrnfunk::apply_image(150, 300, characters, screen, &clip[1]);
// Open font at title size.
TTF_Font *font = TTF_OpenFont("bin/CaviarDreams.ttf", 80);
if(!font)
{
fprintf(stderr, "TTF_OpenFont: %s\n", TTF_GetError());
return NULL;
}
// Setup Title text
const char* title_text = "Welcome to Trololo";
SDL_Color whitecolor = { 255, 255, 255 };
// Get Title text render
if(font != 0 && title_text != 0) // 0 into the text or font causes segfaults and undefined behavior
message = TTF_RenderText_Solid(font, title_text, whitecolor);
else
fprintf(stderr, "TFF Render Text Solid Error: init error\n");
// Apply Title text render
if(message != 0)
scrnfunk::apply_image(100, 200, message, screen);
else
fprintf(stderr, "TFF Render Text Solid Error: apply error\n");
// Setup option 1 (New game)
const char* option1_text = "New game";
SDL_Color blackcolor = { 0,0,0 };
font = TTF_OpenFont("bin/CaviarDreams.ttf", 55); // reopen to resize
// Apply option 1 (New game)
if(font != 0 && option1_text != 0)
message = TTF_RenderText_Solid(font, option1_text, blackcolor);
else
fprintf(stderr, "TFF Render Text Solid Error: init error\n");
// Apply message option 1 (New game)
if(message != 0)
scrnfunk::apply_image(620, 300, message, screen);
else
fprintf(stderr, "TFF Render Text Solid Error: apply error\n");
// Setup exit option (Exit)
const char* exit_text = "Exit";
font = TTF_OpenFont("bin/CaviarDreams.ttf", 55); // reopen to resize
// Apply exit option (Exit)
if(font != 0 && option1_text != 0)
message = TTF_RenderText_Solid(font, exit_text, blackcolor);
else
fprintf(stderr, "TFF Render Text Solid Error: init error\n");
// Apply exit option (Exit)
if(message != 0)
scrnfunk::apply_image(620, 370, message, screen);
else
fprintf(stderr, "TFF Render Text Solid Error: apply error\n");
// Remove white around the indicator image
scrnfunk::RemoveColor(indicator, 0xFF, 0xFF, 0xFF); // white
// Apply starting point of indicator
scrnfunk::apply_image(550, 306, indicator, screen);
// Update screen with all applied images // Update screen with all applied images
if(screen != 0) if(screen != 0)
SDL_Flip(screen); SDL_Flip(screen);
else else
fprintf(stderr, "Couldn't update screen.\n"); fprintf(stderr, "Couldn't update screen.\n");
}
// Free old surfaces // Free old surfaces
SDL_FreeSurface(background); SDL_FreeSurface(background);
SDL_FreeSurface(characters); SDL_FreeSurface(screen);
SDL_FreeSurface(message);
SDL_FreeSurface(indicator);
}
return screen; return screen;
} }
SDL_Surface *MainMenu_survey(SDL_Surface *screen) SDL_Surface *Movement(SDL_Surface *screen)
{ {
// Return values // Movement
// 1 -- User wants option 1 (start new game) // D -- Mario move LEFT
// 2 -- User wants to quit // A -- Mario move RIGHT
SDL_Surface *background = NULL;
SDL_Surface *mario0 = NULL;
//SDL_Surface *mario1 = NULL;
//SDL_Surface *mario2 = NULL;
SDL_Surface *mario3 = NULL;
//SDL_Surface *mario4 = NULL;
//SDL_Surface *mario5 = NULL;
int x,y;
x = 125;
y = 520;
// Image filenames
const char *background_image = "bin/stage.bmp";
const char *mario_image0 = "bin/IMG0.bmp";
//const char *mario_image1 = "bin/IMG1.bmp";
//const char *mario_image2 = "bin/IMG2.bmp";
const char *mario_image3 = "bin/IMG3.bmp";
//const char *mario_image4 = "bin/IMG4.bmp";
//const char *mario_image5 = "bin/IMG5.bmp";
background = scrnfunk::load_image(background_image);
mario0 = scrnfunk::load_image(mario_image0);
//mario1 = scrnfunk::load_image(mario_image1);
//mario2 = scrnfunk::load_image(mario_image2);
mario3 = scrnfunk::load_image(mario_image3);
//mario4 = scrnfunk::load_image(mario_image4);
//mario5 = scrnfunk::load_image(mario_image5);
SDL_Rect clip;
clip.x = x;
clip.y = y;
clip.w = 100;
clip.h = 100;
scrnfunk::RemoveColor(mario0, 0x00, 0x00, 0xFF); // Blue
//scrnfunk::RemoveColor(mario1, 0x00, 0x00, 0xFF); // Blue
//scrnfunk::RemoveColor(mario2, 0x00, 0x00, 0xFF); // Blue
scrnfunk::RemoveColor(mario3, 0x00, 0x00, 0xFF); // Blue
scrnfunk::apply_image(x, y, mario0, screen);
if(screen != 0)
SDL_Flip(screen);
SDL_Event event; SDL_Event event;
int menu_option, current; while(1)
menu_option = current = 1;
bool option_wanted = false;
SDL_Surface *background = NULL;
SDL_Surface *indicator = NULL;
// Image filenames
const char *background_image = "bin/stage1.bmp";
const char *indicator_image = "bin/indicator.bmp";
background = scrnfunk::load_image(background_image);
indicator = scrnfunk::load_image(indicator_image);
// Remove white around the indicator image
scrnfunk::RemoveColor(indicator, 0xFF, 0xFF, 0xFF); // white
// Background clipping points
SDL_Rect clip[2];
// Cover points on the background for option 1
clip[0].x = 550;
clip[0].y = 306;
clip[0].w = 48;
clip[0].h = 48;
// Cover points on the background for option 2
clip[1].x = 550;
clip[1].y = 375;
clip[1].w = 48;
clip[1].h = 48;
while(!option_wanted)
{ {
while(SDL_PollEvent(&event)) while(SDL_PollEvent(&event))
{ {
if(event.type == SDL_QUIT) if(event.type == SDL_QUIT)
return NULL; return NULL;
else if(event.type == SDL_KEYDOWN) else if(event.type == SDL_KEYDOWN)
{ {
if(event.key.keysym.sym == SDLK_d) // RIGHT
if(event.key.keysym.sym == 274) // down arrow key
{ {
if(menu_option < 2) // Less than the max amount of options scrnfunk::apply_image(x, y, background, screen, &clip); // Cover current Mario
menu_option++; x=x+10;
clip.x = x;
scrnfunk::apply_image(x, y, mario3, screen); // Place new Mario
} }
else if(event.key.keysym.sym == SDLK_a) // LEFT
else if(event.key.keysym.sym == 273) // up arrow key
{ {
if(menu_option > 1) scrnfunk::apply_image(x, y, background, screen, &clip); // Cover current Mario
menu_option--; x=x-10;
clip.x = x;
scrnfunk::apply_image(x, y, mario3, screen); // Place new Mario
} }
else if(event.key.keysym.sym == 13) // enter key
option_wanted = true;
} }
if(menu_option != current)
{
current = menu_option;
switch(menu_option)
{
case 1:
scrnfunk::apply_image(550, 306, indicator, screen); // Indicator on option 1
scrnfunk::apply_image(550, 375, background, screen, &clip[1]); // Cover option 2
break;
case 2:
scrnfunk::apply_image(550, 375, indicator, screen); // Indicator on option 2
scrnfunk::apply_image(550, 306, background, screen, &clip[0]); // Cover option 1
break;
default:
cout << "Error: MainMenu_survey didn't update correctly." << endl;
break;
} }
if(screen != 0) if(screen != 0)
SDL_Flip(screen); SDL_Flip(screen);
else else
fprintf(stderr, "Couldn't update screen.\n"); fprintf(stderr, "Couldn't update screen.\n");
} }
}
}
switch(menu_option)
{
case 1:
// User wants to start a new game
cout << "Starting new game..." << endl;
break;
case 2:
// User wants to exit the game
cout << "Exiting..." << endl;
break;
default:
cout << "Fatal Error: Main Menu option given was unknown." << endl;
}
return screen; return screen;
} }
} }

View File

@ -7,10 +7,10 @@ int main(int argc, char* args[])
SDL_Surface *screen; SDL_Surface *screen;
// Display main menu // Display main menu
screen = scrns::MainMenu(); screen = scrns::Stage1();
// Main menu keyboard surveying // Main menu keyboard surveying
screen = scrns::MainMenu_survey(screen); screen = scrns::Movement(screen);
SDL_FreeSurface(screen); SDL_FreeSurface(screen);
return 0; return 0;

8
main.h
View File

@ -4,7 +4,7 @@
// SDL dependencies // SDL dependencies
#include "SDL/SDL.h" // SDL 1.2.15 (32 bit) #include "SDL/SDL.h" // SDL 1.2.15 (32 bit)
#include "SDL/SDL_image.h" // SDL_image (1.2.12) #include "SDL/SDL_image.h" // SDL_image (1.2.12)
#include "SDL/SDL_ttf.h" // SDL_tff (2.0.11) //#include "SDL/SDL_ttf.h" // SDL_tff (2.0.11)
// Standard dependencies // Standard dependencies
#include <iostream> #include <iostream>
@ -13,8 +13,8 @@
namespace scrns namespace scrns
{ {
SDL_Surface * initiateSDL(int x, int y); SDL_Surface * initiateSDL(int x, int y);
SDL_Surface * MainMenu(); SDL_Surface * Stage1();
SDL_Surface * MainMenu_survey(SDL_Surface *screen); SDL_Surface * Movement(SDL_Surface *screen);
} }
namespace scrnfunk namespace scrnfunk
@ -25,6 +25,6 @@ namespace scrnfunk
} }
#define VERSION "0.1-alpha" #define VERSION "0.1-alpha"
#define WINDOW_TITLE "Trololo" #define WINDOW_TITLE "Mario"
#endif #endif

View File

@ -7,4 +7,4 @@ else
endif endif
all: all:
g++ -Wall main.cpp core.cpp main.h -o Trololo ${INCLUDES} ${SDL_LIBS} g++ -Wall main.cpp core.cpp main.h -o mario ${INCLUDES} ${SDL_LIBS}

BIN
zlib1.dll Normal file

Binary file not shown.