/*----------------------------------------------------------------------------- Njammap.cpp Handling all that concerns game maps (worlds): Loading, saving, searching for tiles, etc... Copyright 2003 Milan Babuskov This file is part of Njam (http://njam.sourceforge.net). Njam 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. Njam 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 Njam in file COPYING; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -----------------------------------------------------------------------------*/ #include #include "SDL.h" #include "njamutils.h" #include "njammap.h" //--------------------------------------------------------------------------- NjamMap::NjamMap() { Clear(); } //--------------------------------------------------------------------------- // returns number of maps loaded int NjamMap::Load(const char *file) { if (file == NULL) { printf("Warning! NjamMap::Load(), file == NULL\n"); return -1; } FILE *fp = fopen(file, "rb"); if (fp == NULL) { printf("ERROR: Map file: \"%s\" could not be opened.\n", file); return -1; } Clear(); // reads maps in order int i, loaded; bool ok = true; for (i=0; i= MAPS || map2 < 0 || map2 >= MAPS || map1 == map2) return; Uint8 temp; for (int i=0; i= 0 && NewCurrentMap < MAPS) { for (int i=0; i=MAPW || y<0 || y>=MAPH) return ttWall; return (TileType)(m_Tiles[MAPS][x][y]); } //--------------------------------------------------------------------------- void NjamMap::SetTile(int x, int y, TileType Value) { if (x < 0 || x>=MAPW || y<0 || y>=MAPH) return; m_Tiles[MAPS][x][y] = (char)Value; } //--------------------------------------------------------------------------- void NjamMap::SetMapImages(SDL_Surface *Surface, int TileW, int TileH) { m_Images = Surface; m_TileW = TileW; m_TileH = TileH; } //--------------------------------------------------------------------------- // insert random powerups void NjamMap::AddPowerups(int HowMuch) { TileType allowed[] = { ttJuice, ttFreezer, ttTrap, ttInvisible, ttCookie }; for (int i=0; i