shithub: etoys

Download patch

ref: d09e93e55108d208edf69e0ef0ca1b9205e3673b
parent: 0628e715e9ae5d5b1ff9e5d9c063781ed9b90907
author: rodri <rgl@antares-labs.eu>
date: Mon May 18 16:06:17 EDT 2020

isometric: draw tall tile sprites and change the map in real time

--- a/isometric.c
+++ b/isometric.c
@@ -39,7 +39,7 @@
 char *map[] = {
 	"eeeee",
 	"eefee",
-	"efefe",
+	"efbfe",
 	"eefee",
 	"eefee"
 };
@@ -132,7 +132,8 @@
 	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 @@
 }
 
 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 @@
 		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();