From b58b123aea0adfa0596907d649cd3de376ef6801 Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Sun, 11 Apr 2004 20:46:31 +0000 Subject: [PATCH] Added support for gradients :) Changed bkgd_* to bkgd_top_* and bkgd_bottom_* (being * either r, b or g) This change includes both code and level files. SVN-Revision: 492 --- data/levels/default/level4.stl | 9 ++++++--- src/gameobjs.cpp | 3 ++- src/level.cpp | 27 ++++++++++++++++++--------- src/level.h | 9 ++++++--- src/leveleditor.cpp | 39 ++++++++++++++++++++++++++------------- src/screen.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/screen.h | 1 + src/world.cpp | 3 ++- 8 files changed, 100 insertions(+), 30 deletions(-) diff --git a/data/levels/default/level4.stl b/data/levels/default/level4.stl index 714a1727b..beb4396cb 100644 --- a/data/levels/default/level4.stl +++ b/data/levels/default/level4.stl @@ -6,9 +6,12 @@ (height 15) (background "") (music "Mortimers_chipdisko.mod") - (bkgd_red 100) - (bkgd_green 230) - (bkgd_blue 140) + (bkgd_top_red 120) + (bkgd_top_green 120) + (bkgd_top_blue 160) + (bkgd_bottom_red 215) + (bkgd_bottom_green 215) + (bkgd_bottom_blue 250) (time 190) (gravity 10.0) (particle_system "clouds") diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp index db4b38639..8c6bf6606 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -139,7 +139,8 @@ BouncyBrick::draw() { fillrect(base.x - scroll_x, base.y, 32,32, - plevel->bkgd_red, plevel->bkgd_green, plevel->bkgd_blue, 0); + plevel->bkgd_top_red, plevel->bkgd_top_green, plevel->bkgd_top_blue, 0); +// FIXME: doesn't respect the gradient, futhermore is this necessary at all?? } else { diff --git a/src/level.cpp b/src/level.cpp index 6de01f8cb..1e8e6444e 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -200,9 +200,12 @@ Level::init_defaults() width = 21; time_left = 100; gravity = 10.; - bkgd_red = 0; - bkgd_green = 0; - bkgd_blue = 0; + bkgd_top_red = 0; + bkgd_top_green = 0; + bkgd_top_blue = 0; + bkgd_bottom_red = 0; + bkgd_bottom_green = 0; + bkgd_bottom_blue = 0; endpos = 0; for(int i = 0; i < 15; ++i) @@ -273,9 +276,12 @@ Level::load(const std::string& filename) reader.read_int("version", &version); reader.read_int("width", &width); reader.read_int("time", &time_left); - reader.read_int("bkgd_red", &bkgd_red); - reader.read_int("bkgd_green", &bkgd_green); - reader.read_int("bkgd_blue", &bkgd_blue); + reader.read_int("bkgd_top_red", &bkgd_top_red); + reader.read_int("bkgd_top_green", &bkgd_top_green); + reader.read_int("bkgd_top_blue", &bkgd_top_blue); + reader.read_int("bkgd_bottom_red", &bkgd_bottom_red); + reader.read_int("bkgd_bottom_green", &bkgd_bottom_green); + reader.read_int("bkgd_bottom_blue", &bkgd_bottom_blue); reader.read_float("gravity", &gravity); reader.read_string("name", &name); reader.read_string("theme", &theme); @@ -467,9 +473,12 @@ Level::save(const char * subset, int level) fprintf(fi," (music \"%s\")\n", song_title.c_str()); fprintf(fi," (background \"%s\")\n", bkgd_image.c_str()); fprintf(fi," (particle_system \"%s\")\n", particle_system.c_str()); - fprintf(fi," (bkgd_red %d)\n", bkgd_red); - fprintf(fi," (bkgd_green %d)\n", bkgd_green); - fprintf(fi," (bkgd_blue %d)\n", bkgd_blue); + fprintf(fi," (bkgd_top_red %d)\n", bkgd_top_red); + fprintf(fi," (bkgd_top_green %d)\n", bkgd_top_green); + fprintf(fi," (bkgd_top_blue %d)\n", bkgd_top_blue); + fprintf(fi," (bkgd_bottom_red %d)\n", bkgd_bottom_red); + fprintf(fi," (bkgd_bottom_green %d)\n", bkgd_bottom_green); + fprintf(fi," (bkgd_bottom_blue %d)\n", bkgd_bottom_blue); fprintf(fi," (time %d)\n", time_left); fprintf(fi," (width %d)\n", width); fprintf(fi," (gravity %2.1f)\n", gravity); diff --git a/src/level.h b/src/level.h index 96fcb1f0a..bdd5b92f7 100644 --- a/src/level.h +++ b/src/level.h @@ -64,9 +64,12 @@ class Level unsigned int* ia_tiles[15]; /* Tiles which can interact in the game (solids for example)*/ unsigned int* fg_tiles[15]; /* Tiles in the foreground */ int time_left; - int bkgd_red; - int bkgd_green; - int bkgd_blue; + int bkgd_top_red; + int bkgd_top_green; + int bkgd_top_blue; + int bkgd_bottom_red; + int bkgd_bottom_green; + int bkgd_bottom_blue; int width; int endpos; float gravity; diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index d7dbdb817..c16a27d73 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -205,7 +205,7 @@ int leveleditor(int levelnb) { switch (level_settings_menu->check()) { - case 13: + case 16: apply_level_settings_menu(); Menu::set_current(leveleditor_menu); break; @@ -432,9 +432,12 @@ int le_init() level_settings_menu->additem(MN_NUMFIELD,"Length ",0,0); level_settings_menu->additem(MN_NUMFIELD,"Time ",0,0); level_settings_menu->additem(MN_NUMFIELD,"Gravity",0,0); - level_settings_menu->additem(MN_NUMFIELD,"Red ",0,0); - level_settings_menu->additem(MN_NUMFIELD,"Green ",0,0); - level_settings_menu->additem(MN_NUMFIELD,"Blue ",0,0); + level_settings_menu->additem(MN_NUMFIELD,"Top Red ",0,0); + level_settings_menu->additem(MN_NUMFIELD,"Top Green ",0,0); + level_settings_menu->additem(MN_NUMFIELD,"Top Blue ",0,0); + level_settings_menu->additem(MN_NUMFIELD,"Bottom Red ",0,0); + level_settings_menu->additem(MN_NUMFIELD,"Bottom Green",0,0); + level_settings_menu->additem(MN_NUMFIELD,"Bottom Blue",0,0); level_settings_menu->additem(MN_HL,"",0,0); level_settings_menu->additem(MN_ACTION,"Apply Changes",0,0); @@ -482,12 +485,18 @@ void update_level_settings_menu() level_settings_menu->item[7].change_input(str); sprintf(str,"%2.0f",le_current_level->gravity); level_settings_menu->item[8].change_input(str); - sprintf(str,"%d",le_current_level->bkgd_red); + sprintf(str,"%d",le_current_level->bkgd_top_red); level_settings_menu->item[9].change_input(str); - sprintf(str,"%d",le_current_level->bkgd_green); - level_settings_menu->item[10].change_input(str); - sprintf(str,"%d",le_current_level->bkgd_blue); - level_settings_menu->item[11].change_input(str); + sprintf(str,"%d",le_current_level->bkgd_top_green); + level_settings_menu->item[10].change_input(str); + sprintf(str,"%d",le_current_level->bkgd_top_blue); + level_settings_menu->item[11].change_input(str); + sprintf(str,"%d",le_current_level->bkgd_bottom_red); + level_settings_menu->item[12].change_input(str); + sprintf(str,"%d",le_current_level->bkgd_bottom_green); + level_settings_menu->item[13].change_input(str); + sprintf(str,"%d",le_current_level->bkgd_bottom_blue); + level_settings_menu->item[14].change_input(str); } void update_subset_settings_menu() @@ -526,9 +535,12 @@ void apply_level_settings_menu() le_current_level->change_size(atoi(level_settings_menu->item[6].input)); le_current_level->time_left = atoi(level_settings_menu->item[7].input); le_current_level->gravity = atof(level_settings_menu->item[8].input); - le_current_level->bkgd_red = atoi(level_settings_menu->item[9].input); - le_current_level->bkgd_green = atoi(level_settings_menu->item[10].input); - le_current_level->bkgd_blue = atoi(level_settings_menu->item[11].input); + le_current_level->bkgd_top_red = atoi(level_settings_menu->item[9].input); + le_current_level->bkgd_top_green = atoi(level_settings_menu->item[10].input); + le_current_level->bkgd_top_blue = atoi(level_settings_menu->item[11].input); + le_current_level->bkgd_bottom_red = atoi(level_settings_menu->item[12].input); + le_current_level->bkgd_bottom_green = atoi(level_settings_menu->item[13].input); + le_current_level->bkgd_bottom_blue = atoi(level_settings_menu->item[14].input); } void save_subset_settings_menu() @@ -686,7 +698,8 @@ void le_drawlevel() } else { - clearscreen(le_current_level->bkgd_red, le_current_level->bkgd_green, le_current_level->bkgd_blue); + drawgradient(le_current_level->bkgd_top_red, le_current_level->bkgd_top_green, le_current_level->bkgd_top_blue, + le_current_level->bkgd_bottom_red, le_current_level->bkgd_bottom_green, le_current_level->bkgd_bottom_blue); } /* clearscreen(current_level.bkgd_red, current_level.bkgd_green, current_level.bkgd_blue); */ diff --git a/src/screen.cpp b/src/screen.cpp index 2ac21d088..d757eac54 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -54,6 +54,45 @@ void clearscreen(int r, int g, int b) #endif } +/* --- DRAWS A VERTICAL GRADIENT --- */ + +void drawgradient(int top_r, int top_g, int top_b, int bot_r, int bot_g, int bot_b) +{ +#ifndef NOOPENGL + if(use_gl) + { + glBegin(GL_QUADS); + glColor3ub(top_r, top_g, top_b); + glVertex2f(0, 0); + glVertex2f(640, 0); + glColor3ub(bot_r, bot_g, bot_b); + glVertex2f(640, 480); + glVertex2f(0, 480); + glEnd(); + } + else + { +#endif + + SDL_Rect r; + r.x = 0; + r.w = 640; + r.h = 2; + + for(float y = 0; y < 480; y += 2) + { + r.y = (int)y; + + SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, (int)(((float)(top_r-bot_r)/640) * y + top_r), (int)(((float)(top_g-bot_g)/640) * y + top_g), (int)(((float)(top_b-bot_b)/640) * y + top_b))); + } +/* calculates the color for each line, based in the generic equation for functions: y = mx + b */ + +#ifndef NOOPENGL + + } +#endif +} + /* 'Stolen' from the SDL documentation. * Set the pixel at (x, y) to the given value * NOTE: The surface must be locked before calling this! diff --git a/src/screen.h b/src/screen.h index 7ff7a22ba..f779dc5fd 100644 --- a/src/screen.h +++ b/src/screen.h @@ -26,6 +26,7 @@ void drawline(int x1, int y1, int x2, int y2, int r, int g, int b, int a); void clearscreen(int r, int g, int b); +void drawgradient(int top_r, int top_g, int top_b, int bot_r, int bot_g, int bot_b); void fillrect(float x, float y, float w, float h, int r, int g, int b, int a); void updatescreen(void); void flipscreen(void); diff --git a/src/world.cpp b/src/world.cpp index cd187e5df..f2a64b509 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -134,7 +134,8 @@ World::draw() } else { - clearscreen(level->bkgd_red, level->bkgd_green, level->bkgd_blue); + drawgradient(level->bkgd_top_red, level->bkgd_top_green, level->bkgd_top_blue, + level->bkgd_bottom_red, level->bkgd_bottom_green, level->bkgd_bottom_blue); } /* Draw particle systems (background) */ -- 2.11.0