From d09e93e55108d208edf69e0ef0ca1b9205e3673b Mon Sep 17 00:00:00 2001 From: rodri Date: Mon, 18 May 2020 20:06:17 +0000 Subject: isometric: draw tall tile sprites and change the map in real time --- isometric.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/isometric.c b/isometric.c index 7a33dd9..afbe868 100644 --- a/isometric.c +++ b/isometric.c @@ -39,7 +39,7 @@ RFrame worldrf; char *map[] = { "eeeee", "eefee", - "efefe", + "efbfe", "eefee", "eefee" }; @@ -132,7 +132,8 @@ drawtile(Tile *t, Point2 cell) cell.y *= TH; p = toscreen(cell); p.x -= TW/2; - draw(screen, Rpt(p,addpt(p, Pt(TW,TH))), t->img, nil, ZP); + p.y -= Dy(t->img->r)-TH; + draw(screen, Rpt(p,addpt(p, Pt(TW,Dy(t->img->r)))), t->img, nil, ZP); } void @@ -160,6 +161,25 @@ redraw(void) flushimage(display, 1); } +void +lmb(Mouse *m) +{ + Point2 mp; + Point cell; + char buf[2]; + + mp = fromscreen(mpos); + if(mp.x < 0 || mp.y < 0) + return; + cell.x = mp.x/TW; + cell.y = mp.y/TH; + if(cell.y >= nelem(map) || cell.x >= strlen(map[cell.y])) + return; + snprint(buf, sizeof buf, "%c", map[cell.y][cell.x]); + if(eenter("tile id", buf, sizeof buf, m) > 0) + map[cell.y][cell.x] = buf[0]; +} + void mmb(Mouse *m) { @@ -225,7 +245,7 @@ main(int argc, char *argv[]) case Emouse: mpos = e.mouse.xy; if((e.mouse.buttons&1) != 0) - worldrf.p = Pt2(e.mouse.xy.x,e.mouse.xy.y,1); + lmb(&e.mouse); if((e.mouse.buttons&2) != 0) mmb(&e.mouse); redraw(); -- cgit v1.2.3