dungeon_crawler

diff prototype/src/level.cc @ 48:aa9e28670ae2

added sound playback, more to do
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 17 Sep 2012 08:40:59 +0300
parents f3030df27110
children 303743485aba
line diff
     1.1 --- a/prototype/src/level.cc	Sun Sep 16 08:16:50 2012 +0300
     1.2 +++ b/prototype/src/level.cc	Mon Sep 17 08:40:59 2012 +0300
     1.3 @@ -107,6 +107,14 @@
     1.4  	return Vector3(posx, 0, posy);
     1.5  }
     1.6  
     1.7 +void Level::get_cell_coords_at(const Vector3 &pos, int *xptr, int *yptr) const
     1.8 +{
     1.9 +	float posx = pos.x + cell_size * (float)xsz / 2.0f;
    1.10 +	float posy = pos.z + cell_size * (float)ysz / 2.0f;
    1.11 +	*xptr = (int)round(posx / cell_size);
    1.12 +	*yptr = (int)round(posy / cell_size);
    1.13 +}
    1.14 +
    1.15  unsigned int Level::get_cell_dirmask(int x, int y) const
    1.16  {
    1.17  	unsigned int dmask = TILE_ALL;
    1.18 @@ -229,6 +237,16 @@
    1.19  }
    1.20  
    1.21  
    1.22 +AudioSample *Level::get_sample(int x, int y, int which) const
    1.23 +{
    1.24 +	const GridCell *cell = get_cell(x, y);
    1.25 +	if(!cell) {
    1.26 +		return 0;
    1.27 +	}
    1.28 +	return cell->get_sample(which);
    1.29 +}
    1.30 +
    1.31 +
    1.32  GridCell::GridCell(Tile *tile)
    1.33  {
    1.34  	if(tile) {
    1.35 @@ -285,3 +303,14 @@
    1.36  		psys_draw(ps);
    1.37  	}
    1.38  }
    1.39 +
    1.40 +AudioSample *GridCell::get_sample(int which) const
    1.41 +{
    1.42 +	for(auto tile : tiles) {
    1.43 +		AudioSample *s = tile->get_sample(which);
    1.44 +		if(s) {
    1.45 +			return s;
    1.46 +		}
    1.47 +	}
    1.48 +	return 0;
    1.49 +}