/* * IceBreaker * Copyright (c) 2000 Matthew Miller http://www.mattdm.org/ * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., 59 * Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "SDL/SDL.h" #ifndef _TINSPIRE #include #endif #include "icebreaker.h" #include "laundry.h" #include "grid.h" #include "penguin.h" #include "globals.h" static char maskgrid[WIDTH][HEIGHT]; // kludge-o-rama static long rcount; #define MAXRCOUNT 80000 void markgrid(int x, int y, int w, int h, char fillchar) { int i; for (i=x;iformat, 0x00, 0x40, 0x80)); soil(tmprect); } //printwholegrid(); } /* for (j=0;jMAXRCOUNT) // bail { fprintf(stderr,"Damn. Ran out of recursions.\n"); return(2); } // shouldn't need to check bounds because we're only painting in the // middle. and we call this function so much that the time saved // is worth it //if (i<0 || j<0 || i>=WIDTH || j>=HEIGHT) //{ // fprintf(stderr,"That shouldn't have happened (penguinsearch)! (%d,%d)\n",i,j); // exit(1); //} if (maskgrid[i][j]==' ' || maskgrid[i][j]=='1' || maskgrid[i][j]=='2' || maskgrid[i][j]=='w') // Ah ha! The nefarious "instant melting ice" bug solved! NOTE: if more lines are added to the game, add them here too! { maskgrid[i][j]=','; searchval=penguinsearch(i+BLOCKWIDTH, j); if (!searchval) searchval=penguinsearch(i-BLOCKWIDTH, j); if (!searchval) searchval=penguinsearch(i, j-BLOCKHEIGHT); if (!searchval) searchval=penguinsearch(i, j+BLOCKHEIGHT); } else if (maskgrid[i][j]=='*') // found a penguin! { searchval=1; } return(searchval); } void floodfill(int x, int y) { // shouldn't need to check bounds because we're only painting in the // middle. //if (x<0 || y<0 || x>WIDTH || y>HEIGHT) //{ // fprintf(stderr,"That shouldn't have happened! (%d,%d)\n",x,y); // exit(1); //} if (grid[x][y]==' ' || grid[x][y]=='1' || grid[x][y]=='2' || grid[x][y]=='w') { grid[x][y]='.'; floodfill(x+1, y); floodfill(x-1, y); floodfill(x, y+1); floodfill(x, y-1); } } void squarefill(int x, int y) { // x and y must be the top left corner of a square, or else this // will look silly. and there's no bounds checking! if (grid[x][y]==' ' || grid[x][y]=='1' || grid[x][y]=='2' || grid[x][y]=='w') { markgrid(x,y,BLOCKWIDTH,BLOCKHEIGHT,'.'); squarefill(x+BLOCKWIDTH, y); squarefill(x-BLOCKWIDTH, y); squarefill(x, y+BLOCKHEIGHT); squarefill(x, y-BLOCKHEIGHT); } }