summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dat.h8
-rw-r--r--main.c39
2 files changed, 38 insertions, 9 deletions
diff --git a/dat.h b/dat.h
index 0ccea6f..21e2891 100644
--- a/dat.h
+++ b/dat.h
@@ -6,3 +6,11 @@ enum
K→,
Ke
};
+
+typedef struct Sprite Sprite;
+
+struct Sprite
+{
+ Point p;
+ Memimage *spr;
+};
diff --git a/main.c b/main.c
index 244097c..065d8cf 100644
--- a/main.c
+++ b/main.c
@@ -14,6 +14,7 @@ double Δt;
Image *screenb;
Memimage *fb;
Memimage *bg, *fg;
+Sprite bob;
Rune keys[Ke] = {
[K↑] Kup,
@@ -46,6 +47,22 @@ rgb(ulong c)
return i;
}
+Memimage*
+loadtexture(char *path)
+{
+ Memimage *i;
+ int fd;
+
+ fd = open(path, OREAD);
+ if(fd < 0)
+ sysfatal("open: %r");
+ i = readmemimage(fd);
+ if(i == nil)
+ sysfatal("readmemimage: %r");
+ close(fd);
+ return i;
+}
+
void
kbdproc(void*)
{
@@ -114,16 +131,9 @@ void
redraw(void)
{
Rectangle r;
- Point p;
- static Point incp = {1,1};
memimagedraw(fb, fb->r, bg, ZP, nil, ZP, SoverD);
- for(p.y = 0; p.y < Dy(fb->r); p.y++)
- for(p.x = 0; p.x < Dx(fb->r); p.x++)
- if(p.x%15 == 0 || p.y%15 == 0)
- memimagedraw(fb, Rpt(p, addpt(p, incp)), fg, ZP, nil, ZP, SoverD);
- /*for(p = ZP; ptinrect(p, fb->r); p.x++, p.y++)
- memimagedraw(fb, Rpt(p, addpt(p, Pt(1,1))), fg, ZP, nil, ZP, SoverD);*/
+ memimagedraw(fb, Rpt(subpt(bob.p, Pt(Dx(bob.spr->r),Dy(bob.spr->r))), addpt(bob.p, Pt(32,32))), bob.spr, ZP, nil, ZP, SoverD);
for(r = fb->r; r.min.y < fb->r.max.y; r.min.y++){
r.max.y = r.min.y+1;
loadimage(screenb, r, byteaddr(fb, r.min), bytesperline(r, fb->depth));
@@ -176,6 +186,8 @@ threadmain(int argc, char *argv[])
resetfb();
bg = rgb(DWhite);
fg = rgb(DBlack);
+ bob.spr = loadtexture("assets/bob.pic");
+ bob.p = divpt(fb->r.max, 2);
drawc = chancreate(1, 0);
display->locking = 1;
unlockdisplay(display);
@@ -188,7 +200,7 @@ threadmain(int argc, char *argv[])
{mctl->c, &mctl->Mouse, CHANRCV},
{mctl->resizec, nil, CHANRCV},
{drawc, nil, CHANRCV},
- {nil, nil, CHANEND}
+ {nil, nil, CHANNOBLK}
};
switch(alt(a)){
case MOUSE: mouse(); break;
@@ -198,5 +210,14 @@ threadmain(int argc, char *argv[])
t = nsec();
Δt = (t-t0)/1e9;
t0 = t;
+ if(kdown & 1<<K↑)
+ bob.p.y--;
+ if(kdown & 1<<K↓)
+ bob.p.y++;
+ if(kdown & 1<<K←)
+ bob.p.x--;
+ if(kdown & 1<<K→)
+ bob.p.x++;
+ sleep(16);
}
}