/[enigma]/enigma/src/game.cc
ViewVC logotype

Diff of /enigma/src/game.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.35 by reallysoft, Sun Jul 6 15:37:23 2003 UTC revision 1.36 by reallysoft, Mon Jul 7 21:16:07 2003 UTC
# Line 132  GameMenu::~GameMenu() { Line 132  GameMenu::~GameMenu() {
132  void  void
133  GameMenu::draw_background(px::GC &gc) {  GameMenu::draw_background(px::GC &gc) {
134      if (!zoomed) {      if (!zoomed) {
135          const int PART             = 3;          const Rect& game_area   = display::GetGameArea();
136          const int WIDTH            = 640;          int         part_width  = game_area.w/3;
137          const int SCREEN_HEIGHT    = 480;          int         part_height = (part_width*480)/640;
         const int INVENTORY_HEIGHT = 64;  
         const int GAME_HEIGHT      = SCREEN_HEIGHT-INVENTORY_HEIGHT;  
         const int PART_WIDTH       = WIDTH/PART;  
         const int PART_HEIGHT      = SCREEN_HEIGHT/PART;  
138    
139          // randomly choose upper-left corner (zoomxypos is always visible)          if (part_height > game_area.h) {
140          int x, y;              part_height = game_area.h/3;
141          for (int trials = 0; trials<5; ++trials) {              part_width  = (part_height*640)/480;
142              x = zoomxpos - IntegerRand(16, PART_WIDTH-16-1);              assert(part_width <= game_area.w);
143              y = zoomypos - IntegerRand(16, PART_HEIGHT-16-1);          }
   
             x = min(max(8, x), WIDTH-(PART_WIDTH+24));  
             if (zoomypos<48 || zoomypos >= (GAME_HEIGHT-48))  
                 y = min(max(16, y), GAME_HEIGHT-(PART_HEIGHT+16));  
             else  
                 y = min(max(48, y), GAME_HEIGHT-(PART_HEIGHT+48)); // skip first and last row  
   
             x = (x/32)*32+24;  
             y = (y/32)*32+16;  
   
             int xoff = zoomxpos-x;  
             int yoff = zoomypos-y;  
144    
145              // fprintf(stderr, "xoff=%i, yoff=%i\n", xoff, yoff);          // randomly choose ball offset
146            int x, y;
147            for (int trials = 5; trials; --trials) {
148                x = IntegerRand(0, 5);
149                y = IntegerRand(0, 3);
150    
151                // try to avoid menu-ball overlap:
152                if (x<2 || x>3 || y<1 || y>2 || (trials == 1)) {
153                    int ax = zoomxpos-game_area.x;
154                    int ay = zoomypos-game_area.y;
155    
156                    // upper left corner of part
157                    x = ax/32-1-x;
158                    y = ay/32-1-y;
159    
160                    // ensure part is inside game_area
161                    x = max(0, min(x, (game_area.w-part_width)/32-1));
162                    y = max(0, min(y, (game_area.h-part_height)/32-1));
163    
164                    // adjust to game fields
165                    x = x*32+24;
166                    y = y*32+16;
167    
168              if (xoff<72 || xoff>136 || yoff<37 || yoff>96)                  break;
169                  break; // no overlap with menu -> take it              }
170          }          }
171    
172            // get the selected part from screen
173          Surface  back(video::GetScreen()->get_surface());          Surface  back(video::GetScreen()->get_surface());
174          Rect     src_area(x, y, PART_WIDTH, PART_HEIGHT);          Rect     src_area(game_area.x+x, game_area.y+y, part_width, part_height);
175          Surface *src = Grab(&back, src_area);          Surface *src = Grab(&back, src_area);
176    
177          const double stepsize = 0.3; // zoom multiple times for softer image          // zoom multiple times for softer image
178            const double stepsize = 0.3;
179          for (double zoom = stepsize; zoom <= (1.0-stepsize/2); zoom += stepsize) {          for (double zoom = stepsize; zoom <= (1.0-stepsize/2); zoom += stepsize) {
180              int      sx  = int(zoom*WIDTH+0.5);              int      sx  = int(zoom*640+0.5);
181              int      sy  = int(zoom*SCREEN_HEIGHT+0.5);              int      sy  = int(zoom*480+0.5);
182              Surface *tmp = src->zoom(sx, sy);              Surface *tmp = src->zoom(sx, sy);
183    
184              delete src;              delete src;
185              src = tmp;              src = tmp;
186          }          }
187            zoomed = src->zoom(640, 480);
         zoomed = src->zoom(WIDTH, SCREEN_HEIGHT);  
188          delete src;          delete src;
189      }      }
190    
# Line 461  Game::load_level(int ilevel) Line 467  Game::load_level(int ilevel)
467  px::Surface *  px::Surface *
468  Game::create_preview(LevelPack *lp, int ilevel)  Game::create_preview(LevelPack *lp, int ilevel)
469  {  {
470      player::NewGame(2, lp->needs_twoplayers());         // two virtual players      px::Surface *img = 0;
471    
472        sound::TempDisableSound();
473        player::NewGame(2, lp->needs_twoplayers()); // two virtual players
474      if (lp->load_level (ilevel))      if (lp->load_level (ilevel))
475      {      {
476          GC gc(video::BackBuffer());          GC gc(video::BackBuffer());
477          display::DrawAll(gc);          display::DrawAll(gc);
478          return( video::BackBuffer());          img = video::BackBuffer();
479      }      }
480      return 0;      sound::TempReEnableSound();
481        return img;
482  }  }
483    
484  void  void
# Line 569  Game::handle_events() Line 579  Game::handle_events()
579              on_mousebutton(e);              on_mousebutton(e);
580              break;              break;
581          case SDL_ACTIVEEVENT:          case SDL_ACTIVEEVENT:
582              if( e.active.gain == 0)              // if( e.active.gain == 0) show_menu();
                 show_menu();  
583              break;              break;
584          case SDL_QUIT:          case SDL_QUIT:
585              change_state(ABORT);              change_state(ABORT);

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.36

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26