aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asset/tile/building.picbin0 -> 4156 bytes
-rw-r--r--asset/tile/empty.picbin316 -> 1084 bytes
-rw-r--r--asset/tile/filled.picbin316 -> 1084 bytes
-rw-r--r--asset/tile/focus.picbin0 -> 1084 bytes
-rw-r--r--isometric.c93
5 files changed, 82 insertions, 11 deletions
diff --git a/asset/tile/building.pic b/asset/tile/building.pic
new file mode 100644
index 0000000..1a6139a
--- /dev/null
+++ b/asset/tile/building.pic
Binary files differ
diff --git a/asset/tile/empty.pic b/asset/tile/empty.pic
index 317ba1a..9955ec7 100644
--- a/asset/tile/empty.pic
+++ b/asset/tile/empty.pic
Binary files differ
diff --git a/asset/tile/filled.pic b/asset/tile/filled.pic
index dc32e49..df096c2 100644
--- a/asset/tile/filled.pic
+++ b/asset/tile/filled.pic
Binary files differ
diff --git a/asset/tile/focus.pic b/asset/tile/focus.pic
new file mode 100644
index 0000000..df5436a
--- /dev/null
+++ b/asset/tile/focus.pic
Binary files differ
diff --git a/isometric.c b/isometric.c
index 3595035..97bf20d 100644
--- a/isometric.c
+++ b/isometric.c
@@ -9,12 +9,14 @@ enum {
Cbg,
Cfg,
Ctxtbg,
+ Cgrid0,
+ Cgrid1,
NCOLOR
};
enum {
- TW = 16,
- TH = 8
+ TW = 32,
+ TH = 16
};
typedef struct Tile Tile;
@@ -28,8 +30,11 @@ struct Tile
Image *pal[NCOLOR];
Tile tiles[] = {
{ .name = "empty", .id = 'e' },
- { .name = "filled", .id = 'f' }
+ { .name = "filled", .id = 'f' },
+ { .name = "building", .id = 'b' },
+ { .name = "focus", .id = 'F' }
};
+Tile *tfocus;
RFrame worldrf;
char *map[] = {
"eeeee",
@@ -39,6 +44,8 @@ char *map[] = {
"eefee"
};
Point mpos;
+Point2 spacegrid[10][10];
+int showgrid;
Point
toscreen(Point2 p)
@@ -59,6 +66,8 @@ initpalette(void)
pal[Cbg] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DBlack);
pal[Cfg] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DDarkblue);
pal[Ctxtbg] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPaleyellow);
+ pal[Cgrid0] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DRed);
+ pal[Cgrid1] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DBlue);
}
void
@@ -72,10 +81,22 @@ inittiles(void)
fd = open(path, OREAD);
tiles[i].img = readimage(display, fd, 0);
close(fd);
+ if(tiles[i].id == 'F')
+ tfocus = &tiles[i];
}
}
void
+initgrid(void)
+{
+ int i, j;
+
+ for(i = 0; i < nelem(spacegrid); i++)
+ for(j = 0; j < nelem(spacegrid[i]); j++)
+ spacegrid[i][j] = Pt2(j*TW, i*TH, 1);
+}
+
+void
drawstats(void)
{
Point2 mp, p;
@@ -93,6 +114,17 @@ drawstats(void)
}
void
+drawgrid(void)
+{
+ int i, j;
+
+ for(i = 0; i < nelem(spacegrid); i++)
+ line(screen, toscreen(spacegrid[i][0]), toscreen(spacegrid[i][nelem(spacegrid[i])-1]), Endsquare, Endsquare, 0, pal[Cgrid0], ZP);
+ for(j = 0; j < nelem(spacegrid[0]); j++)
+ line(screen, toscreen(spacegrid[0][j]), toscreen(spacegrid[nelem(spacegrid)-1][j]), Endsquare, Endsquare, 0, pal[Cgrid1], ZP);
+}
+
+void
redraw(void)
{
Point2 dp;
@@ -102,16 +134,54 @@ 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]-i)*TW/2,(i+row-map[i])*TH/2,1);
+ dp = Pt2((row-map[i])*TW,(i)*TH,1);
for(j = 0; j < nelem(tiles); j++)
if(tiles[j].id == *row)
- draw(screen, Rpt(toscreen(dp),addpt(toscreen(dp), Pt(TW,TH))), tiles[j].img, nil, ZP);
+ draw(screen, Rpt(subpt(toscreen(dp), Pt(TW/2,0)),addpt(toscreen(dp), Pt(TW,TH))), tiles[j].img, nil, ZP);
}
+ 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);
+ if(showgrid)
+ drawgrid();
drawstats();
flushimage(display, 1);
}
void
+mmb(Mouse *m)
+{
+ enum {
+ SHOWGRID,
+ CHGBASIS
+ };
+ static char *items[] = {
+ [SHOWGRID] "toggle grid",
+ [CHGBASIS] "change basis",
+ nil
+ };
+ static Menu menu = { .item = items };
+ char buf[256], *p;
+
+ switch(emenuhit(2, m, &menu)){
+ case SHOWGRID:
+ showgrid ^= 1;
+ break;
+ case CHGBASIS:
+ snprint(buf, sizeof buf, "%g %g", worldrf.bx.x, worldrf.bx.y);
+ eenter("bx", buf, sizeof buf, m);
+ worldrf.bx.x = strtod(buf, &p);
+ worldrf.bx.y = strtod(p, nil);
+ snprint(buf, sizeof buf, "%g %g", worldrf.by.x, worldrf.by.y);
+ eenter("by", buf, sizeof buf, m);
+ worldrf.by.x = strtod(buf, &p);
+ worldrf.by.y = strtod(p, nil);
+ break;
+ }
+}
+
+void
usage(void)
{
fprint(2, "usage: %s\n", argv0);
@@ -133,10 +203,10 @@ main(int argc, char *argv[])
sysfatal("initdraw: %r");
initpalette();
inittiles();
- worldrf.p = Pt2(screen->r.min.x,screen->r.min.y,1);
- worldrf.p = addpt2(worldrf.p, Vec2(Dx(screen->r)/2,Dy(screen->r)/3));
- worldrf.bx = Vec2(1,0);
- worldrf.by = Vec2(0,1);
+ initgrid();
+ worldrf.p = Pt2(screen->r.min.x+Dx(screen->r)/2,screen->r.min.y+Dy(screen->r)/3,1);
+ worldrf.bx = Vec2(1,2);
+ worldrf.by = Vec2(-0.5,1);
einit(Emouse|Ekeyboard);
redraw();
for(;;)
@@ -145,6 +215,8 @@ main(int argc, char *argv[])
mpos = e.mouse.xy;
if((e.mouse.buttons&1) != 0)
worldrf.p = Pt2(e.mouse.xy.x,e.mouse.xy.y,1);
+ if((e.mouse.buttons&2) != 0)
+ mmb(&e.mouse);
redraw();
break;
case Ekeyboard:
@@ -162,7 +234,6 @@ eresized(int)
{
if(getwindow(display, Refnone) < 0)
sysfatal("resize failed");
- worldrf.p = Pt2(screen->r.min.x,screen->r.min.y,1);
- worldrf.p = addpt2(worldrf.p, Vec2(Dx(screen->r)/2,Dy(screen->r)/3));
+ worldrf.p = Pt2(screen->r.min.x+Dx(screen->r)/2,screen->r.min.y+Dy(screen->r)/3,1);
redraw();
}