aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2020-05-18 20:06:17 +0000
committerrodri <rgl@antares-labs.eu>2020-05-18 20:06:17 +0000
commitd09e93e55108d208edf69e0ef0ca1b9205e3673b (patch)
treee151fbd7c63cab74ac8c1b6ecaeb50c10e54fb15
parent0628e715e9ae5d5b1ff9e5d9c063781ed9b90907 (diff)
downloadetoys-d09e93e55108d208edf69e0ef0ca1b9205e3673b.tar.gz
etoys-d09e93e55108d208edf69e0ef0ca1b9205e3673b.tar.bz2
etoys-d09e93e55108d208edf69e0ef0ca1b9205e3673b.zip
isometric: draw tall tile sprites and change the map in real time
-rw-r--r--isometric.c26
1 files 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
@@ -161,6 +162,25 @@ redraw(void)
}
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)
{
enum {
@@ -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();