dungeon_crawler

diff prototype/src/level.cc @ 38:862461b686f4

start work on particle systems
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 29 Aug 2012 03:22:36 +0300
parents fa8f89d06f6f
children dfd3a413ef9e
line diff
     1.1 --- a/prototype/src/level.cc	Wed Aug 29 01:04:01 2012 +0300
     1.2 +++ b/prototype/src/level.cc	Wed Aug 29 03:22:36 2012 +0300
     1.3 @@ -17,6 +17,10 @@
     1.4  Level::~Level()
     1.5  {
     1.6  	delete [] cells;
     1.7 +
     1.8 +	for(auto cell : cell_list) {
     1.9 +		delete cell;
    1.10 +	}
    1.11  }
    1.12  
    1.13  bool Level::load(const char *fname)
    1.14 @@ -65,7 +69,9 @@
    1.15  			}
    1.16  
    1.17  			if(isalpha(buf[i]) || buf[i] == ' ') {
    1.18 -				*grid_row = new GridCell(deftile);
    1.19 +				GridCell *cell = new GridCell(deftile);
    1.20 +				*grid_row = cell;
    1.21 +				cell_list.push_back(*grid_row);
    1.22  			}
    1.23  			grid_row++;
    1.24  		}
    1.25 @@ -117,12 +123,17 @@
    1.26  	return dmask;
    1.27  }
    1.28  
    1.29 +void Level::update(unsigned long msec, float dt)
    1.30 +{
    1.31 +	for(auto cell : cell_list) {
    1.32 +		cell->update(msec, dt);
    1.33 +	}
    1.34 +}
    1.35 +
    1.36  void Level::draw() const
    1.37  {
    1.38  	glMatrixMode(GL_MODELVIEW);
    1.39  
    1.40 -	//draw_grid();
    1.41 -
    1.42  	for(int i=0; i<ysz; i++) {
    1.43  		for(int j=0; j<xsz; j++) {
    1.44  			const GridCell *cell = get_cell(j, i);
    1.45 @@ -194,18 +205,25 @@
    1.46  }
    1.47  
    1.48  
    1.49 -GridCell::GridCell(const Tile *tile)
    1.50 +GridCell::GridCell(Tile *tile)
    1.51  {
    1.52  	if(tile) {
    1.53  		tiles.push_back(tile);
    1.54  	}
    1.55  }
    1.56  
    1.57 -void GridCell::add_tile(const Tile *tile)
    1.58 +void GridCell::add_tile(Tile *tile)
    1.59  {
    1.60  	tiles.push_back(tile);
    1.61  }
    1.62  
    1.63 +void GridCell::update(unsigned long msec, float dt)
    1.64 +{
    1.65 +	for(auto tile : tiles) {
    1.66 +		tile->update(msec, dt);
    1.67 +	}
    1.68 +}
    1.69 +
    1.70  void GridCell::draw(unsigned int draw_mask) const
    1.71  {
    1.72  	for(auto tile : tiles) {