From fa4e6818bd48729e6d0599627e16f8dee586772b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Mon, 3 May 2004 23:06:19 +0000 Subject: [PATCH] leveleditor related improvements. Added bkgd_speed. SVN-Revision: 960 --- src/button.cpp | 2 +- src/level.cpp | 6 ++++++ src/level.h | 1 + src/leveleditor.cpp | 44 +++++++++++++++++++++++++++++++++++++++----- src/lispreader.cpp | 5 ++++- src/menu.h | 2 ++ src/type.h | 39 +++++++++++++++++++-------------------- src/world.cpp | 2 +- 8 files changed, 73 insertions(+), 28 deletions(-) diff --git a/src/button.cpp b/src/button.cpp index 3fcfc702d..b34b24c79 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -101,7 +101,7 @@ void Button::draw() icon->draw(rect.x,rect.y); if(game_object != NULL) { - game_object->draw(); + game_object->draw_on_screen(); } if(show_info) diff --git a/src/level.cpp b/src/level.cpp index 445267126..b062f5745 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -237,6 +237,7 @@ Level::init_defaults() time_left = 100; gravity = 10.; back_scrolling = false; + bkgd_speed = 2; bkgd_top.red = 0; bkgd_top.green = 0; bkgd_top.blue = 0; @@ -315,6 +316,10 @@ Level::load(const std::string& filename) back_scrolling = false; reader.read_bool("back_scrolling", &back_scrolling); + bkgd_speed = 2; + reader.read_int("bkgd_speed", &bkgd_speed); + + bkgd_top.red = bkgd_top.green = bkgd_top.blue = 0; reader.read_int("bkgd_red_top", &bkgd_top.red); reader.read_int("bkgd_green_top", &bkgd_top.green); @@ -543,6 +548,7 @@ Level::save(const std::string& 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_speed \"%d\")\n", bkgd_speed); fprintf(fi," (bkgd_red_top %d)\n", bkgd_top.red); fprintf(fi," (bkgd_green_top %d)\n", bkgd_top.green); fprintf(fi," (bkgd_blue_top %d)\n", bkgd_top.blue); diff --git a/src/level.h b/src/level.h index 3c931c4a4..49bd17700 100644 --- a/src/level.h +++ b/src/level.h @@ -85,6 +85,7 @@ class Level Color bkgd_top; Color bkgd_bottom; int width; + int bkgd_speed; int start_pos_x; int start_pos_y; float gravity; diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index 314a5f09c..8199a536a 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -469,9 +469,11 @@ void le_init_menus() level_settings_menu->additem(MN_TEXTFIELD,"Author ",0,0,MNID_AUTHOR); level_settings_menu->additem(MN_STRINGSELECT,"Song ",0,0,MNID_SONG); level_settings_menu->additem(MN_STRINGSELECT,"Bg-Image",0,0,MNID_BGIMG); + level_settings_menu->additem(MN_STRINGSELECT,"Particle",0,0,MNID_PARTICLE); level_settings_menu->additem(MN_NUMFIELD,"Length ",0,0,MNID_LENGTH); level_settings_menu->additem(MN_NUMFIELD,"Time ",0,0,MNID_TIME); level_settings_menu->additem(MN_NUMFIELD,"Gravity",0,0,MNID_GRAVITY); + level_settings_menu->additem(MN_NUMFIELD,"Bg-Img-Speed",0,0,MNID_BGSPEED); level_settings_menu->additem(MN_NUMFIELD,"Top Red ",0,0,MNID_TopRed); level_settings_menu->additem(MN_NUMFIELD,"Top Green ",0,0,MNID_TopGreen); level_settings_menu->additem(MN_NUMFIELD,"Top Blue ",0,0,MNID_TopBlue); @@ -598,11 +600,16 @@ void update_level_settings_menu() string_list_copy(level_settings_menu->get_item_by_id(MNID_SONG).list, dfiles("music/",NULL, "-fast")); string_list_copy(level_settings_menu->get_item_by_id(MNID_BGIMG).list, dfiles("images/background",NULL, NULL)); string_list_add_item(level_settings_menu->get_item_by_id(MNID_BGIMG).list,""); + string_list_add_item(level_settings_menu->get_item_by_id(MNID_PARTICLE).list,""); + string_list_add_item(level_settings_menu->get_item_by_id(MNID_PARTICLE).list,"snow"); + string_list_add_item(level_settings_menu->get_item_by_id(MNID_PARTICLE).list,"clouds"); if((i = string_list_find(level_settings_menu->get_item_by_id(MNID_SONG).list,le_current_level->song_title.c_str())) != -1) level_settings_menu->get_item_by_id(MNID_SONG).list->active_item = i; if((i = string_list_find(level_settings_menu->get_item_by_id(MNID_BGIMG).list,le_current_level->bkgd_image.c_str())) != -1) level_settings_menu->get_item_by_id(MNID_BGIMG).list->active_item = i; + if((i = string_list_find(level_settings_menu->get_item_by_id(MNID_PARTICLE).list,le_current_level->particle_system.c_str())) != -1) + level_settings_menu->get_item_by_id(MNID_PARTICLE).list->active_item = i; sprintf(str,"%d",le_current_level->width); level_settings_menu->get_item_by_id(MNID_LENGTH).change_input(str); @@ -610,6 +617,8 @@ void update_level_settings_menu() level_settings_menu->get_item_by_id(MNID_TIME).change_input(str); sprintf(str,"%2.0f",le_current_level->gravity); level_settings_menu->get_item_by_id(MNID_GRAVITY).change_input(str); + sprintf(str,"%d",le_current_level->bkgd_speed); + level_settings_menu->get_item_by_id(MNID_BGSPEED).change_input(str); sprintf(str,"%d",le_current_level->bkgd_top.red); level_settings_menu->get_item_by_id(MNID_TopRed).change_input(str); sprintf(str,"%d",le_current_level->bkgd_top.green); @@ -643,6 +652,11 @@ void apply_level_settings_menu() le_current_level->bkgd_image = string_list_active(level_settings_menu->get_item_by_id(MNID_BGIMG).list); i = true; } + + if(le_current_level->particle_system.compare(string_list_active(level_settings_menu->get_item_by_id(MNID_PARTICLE).list)) != 0) + { + le_current_level->particle_system = string_list_active(level_settings_menu->get_item_by_id(MNID_PARTICLE).list); + } if(i) { @@ -654,6 +668,7 @@ void apply_level_settings_menu() le_current_level->change_size(atoi(level_settings_menu->get_item_by_id(MNID_LENGTH).input)); le_current_level->time_left = atoi(level_settings_menu->get_item_by_id(MNID_BGIMG).input); le_current_level->gravity = atof(level_settings_menu->get_item_by_id(MNID_GRAVITY).input); + le_current_level->bkgd_speed = atoi(level_settings_menu->get_item_by_id(MNID_BGSPEED).input); le_current_level->bkgd_top.red = atoi(level_settings_menu->get_item_by_id(MNID_TopRed).input); le_current_level->bkgd_top.green = atoi(level_settings_menu->get_item_by_id(MNID_TopGreen).input); le_current_level->bkgd_top.blue = atoi(level_settings_menu->get_item_by_id(MNID_TopBlue).input); @@ -756,7 +771,7 @@ void le_drawinterface() } if(le_selection_mode == CURSOR) - le_selection->draw( cursor_x - pos_x, cursor_y); + le_selection->draw( cursor_x - scroll_x, cursor_y); else if(le_selection_mode == SQUARE) { int w, h; @@ -780,6 +795,10 @@ void le_drawinterface() if(TileManager::instance()->get(le_current.tile)->editor_images.size() > 0) TileManager::instance()->get(le_current.tile)->editor_images[0]->draw( 19 * 32, 14 * 32); } + if(le_current.IsObject()) + { + le_current.obj->draw_on_screen(19 * 32, 14 * 32); + } //if(le_current.IsObject()) //printf(""); @@ -833,7 +852,7 @@ void le_drawlevel() /* Draw the real background */ if(le_current_level->bkgd_image[0] != '\0') { - s = pos_x / 30; + s = (int)((float)pos_x * ((float)le_current_level->bkgd_speed/60.)) % screen->w; le_current_level->img_bkgd->draw_part(s,0,0,0, le_current_level->img_bkgd->w - s - 32, le_current_level->img_bkgd->h); le_current_level->img_bkgd->draw_part(0,0,screen->w - s - 32 ,0,s, @@ -843,6 +862,17 @@ void le_drawlevel() { drawgradient(le_current_level->bkgd_top, le_current_level->bkgd_bottom); } + + if(le_current.IsTile()) + { + Tile::draw(cursor_x, cursor_y,le_current.tile,128); + if(!TileManager::instance()->get(le_current.tile)->images.empty()) + fillrect(cursor_x,cursor_y,TileManager::instance()->get(le_current.tile)->images[0]->w,TileManager::instance()->get(le_current.tile)->images[0]->h,50,50,50,50); + } + if(le_current.IsObject()) + { + le_current.obj->move_to(cursor_x, cursor_y); + } /* clearscreen(current_level.bkgd_red, current_level.bkgd_green, current_level.bkgd_blue); */ @@ -1150,6 +1180,8 @@ void le_checkevents() { if(pbutton->get_state() == BUTTON_CLICKED) { + if(le_current.IsObject()) + le_current.obj->move_to(pbutton->get_pos().x,pbutton->get_pos().y); le_current.Tile(pbutton->get_tag()); } } @@ -1160,6 +1192,8 @@ void le_checkevents() { if(pbutton->get_state() == BUTTON_CLICKED) { + if(le_current.IsObject()) + le_current.obj->move_to(pbutton->get_pos().x,pbutton->get_pos().y); le_current.Object(pbutton->get_game_object()); } } @@ -1204,7 +1238,7 @@ void le_checkevents() { BadGuy* pbadguy = dynamic_cast(le_current.obj); - le_world.bad_guys.push_back(BadGuy(cursor_x, cursor_y,pbadguy->kind,false)); + le_world.bad_guys.push_back(BadGuy(cursor_x+scroll_x, cursor_y,pbadguy->kind,false)); le_current_level->badguy_data.push_back(&le_world.bad_guys.back()); } } @@ -1220,7 +1254,7 @@ void le_checkevents() } else if(le_move_left_bt->get_state() == BUTTON_HOVER) { - pos_x -= 64; + pos_x -= 32; } if(le_move_right_bt->get_state() == BUTTON_PRESSED) @@ -1229,7 +1263,7 @@ void le_checkevents() } else if(le_move_right_bt->get_state() == BUTTON_HOVER) { - pos_x += 64; + pos_x += 32; } } diff --git a/src/lispreader.cpp b/src/lispreader.cpp index 9074633f9..8f1fe2fc6 100644 --- a/src/lispreader.cpp +++ b/src/lispreader.cpp @@ -1043,7 +1043,10 @@ LispReader::read_int (const char* name, int* i) if (obj) { if (!lisp_integer_p(lisp_car(obj))) - st_abort("LispReader expected type integer at token: ", name); + { + //st_abort("LispReader expected type integer at token: ", name); /* Instead of giving up, we return with false now. */ + return false; + } *i = lisp_integer(lisp_car(obj)); return true; } diff --git a/src/menu.h b/src/menu.h index fa276f2f2..7afe07644 100644 --- a/src/menu.h +++ b/src/menu.h @@ -79,9 +79,11 @@ enum LevelEditorSettingsMenuIDs { MNID_AUTHOR, MNID_SONG, MNID_BGIMG, + MNID_PARTICLE, MNID_LENGTH, MNID_TIME, MNID_GRAVITY, + MNID_BGSPEED, MNID_TopRed, MNID_TopGreen, MNID_TopBlue, diff --git a/src/type.h b/src/type.h index 6906ecf1a..3ae29937b 100644 --- a/src/type.h +++ b/src/type.h @@ -23,6 +23,7 @@ #include #include "SDL.h" +#include "scene.h" /* 'Base' type for game objects */ @@ -41,32 +42,30 @@ struct base_type class GameObject { -friend bool operator<(const GameObject& lhs, const GameObject& rhs) -{ - if( lhs.base.x < rhs.base.x ) - return true; - else if( lhs.base.x == rhs.base.x && lhs.base.y < rhs.base.y) - return true; - else - return false; -} - -friend bool operator>(const GameObject& lhs, const GameObject& rhs) -{ - if( lhs.base.x > rhs.base.x ) - return true; - else if( lhs.base.x == rhs.base.x && lhs.base.y > rhs.base.y) - return true; - else - return false; -} - public: GameObject() {}; virtual ~GameObject() {}; virtual void action(double frame_ratio) = 0; virtual void draw() = 0; virtual std::string type() = 0; +/* Draw ignoring the scroll_x value. FIXME: Hack? Should be discussed. @tobgle*/ +void draw_on_screen(float x = -1, float y = -1) +{ + base_type btmp = base; + if(x != -1 || y != -1) + { + btmp = base; + if(x != -1) + base.x = x; + if(y != -1) + base.y = y; + } + float tmp = scroll_x; + scroll_x = 0; draw(); + scroll_x = tmp; + base = btmp; +}; +void move_to(float x, float y) { base.x = x; base.y = y; }; base_type base; base_type old_base; diff --git a/src/world.cpp b/src/world.cpp index ad0cf6174..c0ce08ec6 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -176,7 +176,7 @@ World::draw() /* Draw the real background */ if(get_level()->bkgd_image[0] != '\0') { - int s = ((int)scroll_x / 2)%640; + int s = (int)((float)scroll_x * ((float)level->bkgd_speed/60.)) % screen->w; level->img_bkgd->draw_part(s, 0,0,0,level->img_bkgd->w - s, level->img_bkgd->h); level->img_bkgd->draw_part(0, 0,screen->w - s ,0,s,level->img_bkgd->h); } -- 2.11.0