From 0628e715e9ae5d5b1ff9e5d9c063781ed9b90907 Mon Sep 17 00:00:00 2001 From: rodri Date: Mon, 18 May 2020 19:33:23 +0000 Subject: isometric: per-cell tile drawing --- asset/tile/building.pic | Bin 4156 -> 8252 bytes isometric.c | 21 ++++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/asset/tile/building.pic b/asset/tile/building.pic index 1a6139a..76d8811 100644 Binary files a/asset/tile/building.pic and b/asset/tile/building.pic differ diff --git a/isometric.c b/isometric.c index 97bf20d..7a33dd9 100644 --- a/isometric.c +++ b/isometric.c @@ -124,6 +124,17 @@ drawgrid(void) line(screen, toscreen(spacegrid[0][j]), toscreen(spacegrid[nelem(spacegrid)-1][j]), Endsquare, Endsquare, 0, pal[Cgrid1], ZP); } +void +drawtile(Tile *t, Point2 cell) +{ + Point p; + cell.x *= TW; + cell.y *= TH; + p = toscreen(cell); + p.x -= TW/2; + draw(screen, Rpt(p,addpt(p, Pt(TW,TH))), t->img, nil, ZP); +} + void redraw(void) { @@ -134,15 +145,15 @@ redraw(void) draw(screen, screen->r, pal[Cbg], nil, ZP); for(i = 0; i < nelem(map); i++) for(row = map[i]; *row; row++){ - dp = Pt2((row-map[i])*TW,(i)*TH,1); + dp = Pt2(row-map[i],i,1); for(j = 0; j < nelem(tiles); j++) if(tiles[j].id == *row) - draw(screen, Rpt(subpt(toscreen(dp), Pt(TW/2,0)),addpt(toscreen(dp), Pt(TW,TH))), tiles[j].img, nil, ZP); + drawtile(&tiles[j], dp); } dp = fromscreen(mpos); - dp.x = ((int)dp.x/TW)*TW; - dp.y = ((int)dp.y/TH)*TH; - draw(screen, Rpt(subpt(toscreen(dp), Pt(TW/2,0)),addpt(toscreen(dp), Pt(TW,TH))), tfocus->img, nil, ZP); + dp.x = (int)dp.x/TW; + dp.y = (int)dp.y/TH; + drawtile(tfocus, dp); if(showgrid) drawgrid(); drawstats(); -- cgit v1.2.3