nuclear@4: #include nuclear@4: #include nuclear@4: #include "rend.h" nuclear@4: #include "player.h" nuclear@4: nuclear@4: static void draw_tile(struct tile *tile); nuclear@4: nuclear@4: static struct image fb; nuclear@4: nuclear@4: nuclear@4: int init_renderer(void) nuclear@4: { nuclear@4: return 0; nuclear@4: } nuclear@4: nuclear@4: void shutdown_renderer(void) nuclear@4: { nuclear@4: } nuclear@4: nuclear@4: void setup_renderer(unsigned char *pixels, int xsz, int ysz) nuclear@4: { nuclear@4: fb.xsz = xsz; nuclear@4: fb.ysz = ysz; nuclear@4: fb.pixels = pixels; nuclear@4: } nuclear@4: nuclear@4: #define MAX_Z 5 nuclear@4: #define LEFT 0 nuclear@4: #define CENTER 1 nuclear@4: #define RIGHT 2 nuclear@4: nuclear@4: #define CHR_TYPE 0 nuclear@4: #define CHR_SIDE 1 nuclear@4: #define CHR_STATE 2 nuclear@4: #define CHR_Z 3 nuclear@4: nuclear@4: void render_level(struct level *lvl, int px, int py, int pdir) nuclear@4: { nuclear@4: int i, j, dx, dy, backz, clear_start, clear_end; nuclear@4: char cells[3][MAX_Z + 1]; nuclear@4: struct tileset *ts = &lvl->tileset; nuclear@4: struct tile *tile_ceil, *tile_floor; nuclear@4: nuclear@4: dx = pdir == DIR_EAST ? 1 : (pdir == DIR_WEST ? -1 : 0); nuclear@4: dy = pdir == DIR_NORTH ? -1 : (pdir == DIR_SOUTH ? 1 : 0); nuclear@4: nuclear@4: for(i=0; i<3; i++) { /* get 3 abreast cells ... */ nuclear@4: int xoffs = (1 - i) * dy; nuclear@4: int yoffs = (i - 1) * dx; nuclear@4: nuclear@4: for(j=0; jorig_y + tile_ceil->img.ysz : 0; nuclear@4: clear_end = tile_floor ? tile_floor->orig_y : fb.ysz; nuclear@4: nuclear@4: draw_tile(tile_ceil); nuclear@4: draw_tile(tile_floor); nuclear@4: memset(fb.pixels + clear_start * fb.xsz, 0, (clear_end - clear_start) * fb.xsz); nuclear@4: nuclear@4: /* find where the back wall should go if it is within visual range nuclear@4: * and draw it ... nuclear@4: */ nuclear@4: backz = -1; nuclear@4: for(i=1; i-- */ nuclear@4: nuclear@4: for(j=0; j<3; j++) { nuclear@4: int state = 's'; nuclear@4: nuclear@4: if(j == CENTER) continue; /* no walls in the center */ nuclear@4: nuclear@4: if(cells[j][z] != '#') { nuclear@4: state = 'o'; nuclear@4: /* if it's an open cell, then skip drawing if the next z is also open */ nuclear@4: if(z >= MAX_Z || cells[j][z + 1] != '#') continue; nuclear@4: } nuclear@4: nuclear@4: name[CHR_SIDE] = j == LEFT ? 'l' : 'r'; nuclear@4: name[CHR_STATE] = state; nuclear@4: name[CHR_Z] = z + '0'; nuclear@4: draw_tile(get_tile(ts, name)); nuclear@4: } nuclear@4: } nuclear@4: } nuclear@4: nuclear@4: static void draw_tile(struct tile *tile) nuclear@4: { nuclear@4: if(!tile) return; nuclear@4: nuclear@4: blitkey(&fb, tile->orig_x, tile->orig_y, &tile->img, 31); /* TODO unhardcode key */ nuclear@4: }