[Super-tux-commit] supertux/src leveleditor.h,1.19,1.20 leveleditor.cpp,1.151,1.152
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-10-08 11:08:18
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30608/src Modified Files: leveleditor.h leveleditor.cpp Log Message: Fixed following bug from level editor: - impossibility to add bad guys from a certain range. - while mouse was pressed, tiles change was happening all the time. - it's possible to make enemies out of tiles squares now. Zoom is still broken on change() and on selection. It should also be supported on tilemap. Index: leveleditor.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.h,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- leveleditor.h 24 Sep 2004 15:10:10 -0000 1.19 +++ leveleditor.h 8 Oct 2004 11:07:38 -0000 1.20 @@ -121,7 +121,7 @@ Menu* create_subset_menu; Menu* settings_menu; - bool left_button, middle_button; + bool left_button, middle_button, mouse_moved; bool done; bool show_grid; Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.151 retrieving revision 1.152 diff -u -d -r1.151 -r1.152 --- leveleditor.cpp 24 Sep 2004 15:10:10 -0000 1.151 +++ leveleditor.cpp 8 Oct 2004 11:07:38 -0000 1.152 @@ -37,6 +37,7 @@ #include "badguy.h" #include "gameobjs.h" #include "door.h" +#include "camera.h" LevelEditor::LevelEditor() { @@ -47,8 +48,7 @@ frame_timer.init(true); level_name_timer.init(true); selection_end = selection_ini = Vector(0,0); -left_button = false; -middle_button = false; +left_button = middle_button = mouse_moved = false; cur_layer = LAYER_TILES; level_changed = false; @@ -236,6 +236,8 @@ void LevelEditor::events() { +mouse_moved = false; + while(SDL_PollEvent(&event)) { Menu* menu = Menu::current(); @@ -373,6 +375,7 @@ switch(event.type) { case SDL_MOUSEMOTION: + mouse_moved = true; if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(SDL_BUTTON_RIGHT)) { // movement like in strategy games scroll.x += -1 * event.motion.xrel; @@ -381,6 +384,7 @@ break; case SDL_MOUSEBUTTONDOWN: + mouse_moved = true; if(event.button.button == SDL_BUTTON_LEFT) left_button = true; else if(event.button.button == SDL_BUTTON_MIDDLE) @@ -391,6 +395,7 @@ break; case SDL_MOUSEBUTTONUP: + mouse_moved = true; if(event.button.button == SDL_BUTTON_LEFT) left_button = false; else if(event.button.button == SDL_BUTTON_MIDDLE) @@ -525,11 +530,14 @@ if(scroll.y > height - screen->h/2) scroll.y = height - screen->h/2; - if(left_button) + // set camera translation, since BadGuys like it + sector->camera->set_scrolling((int)scroll.x, (int)scroll.y); + + if(left_button && mouse_moved) for(unsigned int x = 0; x < selection.size(); x++) for(unsigned int y = 0; y < selection[x].size(); y++) - change((int)((scroll.x + event.button.x)/(32*zoom)) + x, - (int)((scroll.y + event.button.y)/(32*zoom)) + y, selection[x][y], + change((int)(scroll.x + event.button.x) + (x*32), + (int)(scroll.y + event.button.y) + (y*32), selection[x][y], cur_layer); } } @@ -804,57 +812,66 @@ void LevelEditor::change(int x, int y, int newtile, int layer) { // find the tilemap of the current layer, and then change the tile -if(x < 0 || (unsigned int)x > sector->solids->get_width() || - y < 0 || (unsigned int)y > sector->solids->get_height()) +if(x < 0 || (unsigned int)x > sector->solids->get_width()*32 || + y < 0 || (unsigned int)y > sector->solids->get_height()*32) return; level_changed = true; +if(zoom != 1) + { // no need to do this for normal view (no zoom) + x = (int)(x * (zoom*32) / 32); + y = (int)(y * (zoom*32) / 32); + } + if(newtile < 0) // add object { // remove an active tile or object that might be there change(x, y, 0, LAYER_TILES); if(newtile == OBJ_TRAMPOLINE) - sector->add_object(new Trampoline(x*32, y*32)); + sector->add_object(new Trampoline(x, y)); else if(newtile == OBJ_FLYING_PLATFORM) - sector->add_object(new FlyingPlatform(x*32, y*32)); + sector->add_object(new FlyingPlatform(x, y)); else if(newtile == OBJ_DOOR) - sector->add_object(new Door(x*32, y*32)); + sector->add_object(new Door(x, y)); else - sector->add_object(new BadGuy(BadGuyKind((-newtile)-1), x*32, y*32)); + sector->add_object(new BadGuy(BadGuyKind((-newtile)-1), x, y)); sector->update_game_objects(); } else if(cur_layer == LAYER_FOREGROUNDTILES) - foregrounds->change(x, y, newtile); + foregrounds->change(x/32, y/32, newtile); else if(cur_layer == LAYER_TILES) { // remove a bad guy if it's there + // we /32 in order to round numbers for(Sector::GameObjects::iterator i = sector->gameobjects.begin(); i < sector->gameobjects.end(); i++) { BadGuy* badguy = dynamic_cast<BadGuy*> (*i); if(badguy) - if(badguy->base.x == x*32 && badguy->base.y == y*32) + if((int)badguy->base.x/32 == x/32 && (int)badguy->base.y/32 == y/32) sector->gameobjects.erase(i); Trampoline* trampoline = dynamic_cast<Trampoline*> (*i); if(trampoline) - if(trampoline->base.x == x*32 && trampoline->base.y == y*32) + { + if((int)trampoline->base.x/32 == x/32 && (int)trampoline->base.y/32 == y/32) sector->gameobjects.erase(i); + } FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i); if(flying_platform) - if(flying_platform->base.x == x*32 && flying_platform->base.y == y*32) + if((int)flying_platform->base.x/32 == x/32 && (int)flying_platform->base.y/32 == y/32) sector->gameobjects.erase(i); Door* door = dynamic_cast<Door*> (*i); if(door) - if(door->get_area().x == x*32 && door->get_area().y == y*32) + if((int)door->get_area().x/32 == x/32 && (int)door->get_area().y/32 == y/32) sector->gameobjects.erase(i); } sector->update_game_objects(); - solids->change(x, y, newtile); + solids->change(x/32, y/32, newtile); } else if(cur_layer == LAYER_BACKGROUNDTILES) - backgrounds->change(x, y, newtile); + backgrounds->change(x/32, y/32, newtile); } void LevelEditor::show_help() |