ref: c15bd84425763ff4d2886de229c0b393e5127214
parent: 54083e59aaa1cc66f8d12cbb2ffa40c4c1e489fb
author: qwx <qwx@sciops.net>
date: Sun Mar 16 19:03:35 EDT 2025
draw background grid, use sprites for blocks
--- /dev/null
+++ b/dat.c
@@ -1,0 +1,167 @@
+#include <u.h>
+#include "dat.h"
+
+u32int palette[256] = {
+0x000000,0x1f170b,0x170f07,0x4b4b4b,0xffffff,0x1b1b1b,0x131313,0x0b0b0b,
+0x070707,0x2f371f,0x232b0f,0x171f07,0x0f1700,0x4f3b2b,0x473323,0x3f2b1b,
+0xffb7b7,0xf7abab,0xf3a3a3,0xeb9797,0xe78f8f,0xdf8787,0xdb7b7b,0xd37373,
+0xcb6b6b,0xc76363,0xbf5b5b,0xbb5757,0xb34f4f,0xaf4747,0xa73f3f,0xa33b3b,
+0x9b3333,0x972f2f,0x8f2b2b,0x8b2323,0x831f1f,0x7f1b1b,0x771717,0x731313,
+0x6b0f0f,0x670b0b,0x5f0707,0x5b0707,0x530707,0x4f0000,0x470000,0x430000,
+0xffebdf,0xffe3d3,0xffdbc7,0xffd3bb,0xffcfb3,0xffc7a7,0xffbf9b,0xffbb93,
+0xffb383,0xf7ab7b,0xefa373,0xe79b6b,0xdf9363,0xd78b5b,0xcf8353,0xcb7f4f,
+0xbf7b4b,0xb37347,0xab6f43,0xa36b3f,0x9b633b,0x8f5f37,0x875733,0x7f532f,
+0x774f2b,0x6b4727,0x5f4323,0x533f1f,0x4b371b,0x3f2f17,0x332b13,0x2b230f,
+0xefefef,0xe7e7e7,0xdfdfdf,0xdbdbdb,0xd3d3d3,0xcbcbcb,0xc7c7c7,0xbfbfbf,
+0xb7b7b7,0xb3b3b3,0xababab,0xa7a7a7,0x9f9f9f,0x979797,0x939393,0x8b8b8b,
+0x838383,0x7f7f7f,0x777777,0x6f6f6f,0x6b6b6b,0x636363,0x5b5b5b,0x575757,
+0x4f4f4f,0x474747,0x434343,0x3b3b3b,0x373737,0x2f2f2f,0x272727,0x232323,
+0x77ff6f,0x6fef67,0x67df5f,0x5fcf57,0x5bbf4f,0x53af47,0x4b9f3f,0x439337,
+0x3f832f,0x37732b,0x2f6323,0x27531b,0x1f4317,0x17330f,0x13230b,0x0b1707,
+0xbfa78f,0xb79f87,0xaf977f,0xa78f77,0x9f876f,0x9b7f6b,0x937b63,0x8b735b,
+0x836b57,0x7b634f,0x775f4b,0x6f5743,0x67533f,0x5f4b37,0x574333,0x533f2f,
+0x9f8363,0x8f7753,0x836b4b,0x775f3f,0x675333,0x5b472b,0x4f3b23,0x43331b,
+0x7b7f63,0x6f7357,0x676b4f,0x5b6347,0x53573b,0x474f33,0x3f472b,0x373f27,
+0xffff73,0xebdb57,0xd7bb43,0xc39b2f,0xaf7b1f,0x9b5b13,0x874307,0x732b00,
+0xffffff,0xffdbdb,0xffbbbb,0xff9b9b,0xff7b7b,0xff5f5f,0xff3f3f,0xff1f1f,
+0xff0000,0xef0000,0xe30000,0xd70000,0xcb0000,0xbf0000,0xb30000,0xa70000,
+0x9b0000,0x8b0000,0x7f0000,0x730000,0x670000,0x5b0000,0x4f0000,0x430000,
+0x00bbbb,0xc7c7ff,0xababff,0x8f8fff,0x7373ff,0x5353ff,0x3737ff,0x1b1bff,
+0x0000ff,0x0000e3,0x0000cb,0x0000b3,0x00009b,0x000083,0x00006b,0x000053,
+0xffffff,0xffebdb,0xffd7bb,0xffc79b,0xffb37b,0xffa35b,0xff8f3b,0xff7f1b,
+0xf37317,0xeb6f0f,0xdf670f,0xd75f0b,0xcb5707,0xc34f00,0xb74700,0xaf4300,
+0x00c7c7,0xffffd7,0xffffb3,0xffff8f,0xffff6b,0xffff47,0xffff23,0xffff00,
+0xfef000,0xf9ea00,0xefe100,0xe8d000,0x4f3b27,0x432f1b,0x372313,0x2f1b0b,
+0x00dede,0x009292,0x005a5a,0x003535,0x000023,0x000017,0x00000b,0x000000,
+0xff9f43,0xffe74b,0xff7bff,0xff00ff,0xcf00cf,0x9f009b,0x6f006b,0xa76b6b
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e7,0xe7,0xe7,0xe7,0xe7,0xe9,0xe9,
+0xe9,0xea,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xea,0xe9,
+0xea,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,
+},
+[FS] {
+0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x70,0x70,
+0x76,0x70,0x70,0x71,0x71,0x71,0x71,0x71,0x71,0x71,0x71,0x70,0x70,0x70,0x70,0x75,
+0x76,0x75,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x75,0x75,
+0x76,0x75,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x74,0x75,0x75,
+0x76,0x75,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x74,0x74,0x75,0x75,
+0x76,0x75,0x73,0x73,0x73,0x73,0x73,0x74,0x73,0x73,0x73,0x73,0x73,0x73,0x75,0x75,
+0x76,0x75,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x74,0x75,0x75,
+0x76,0x75,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x74,0x75,0x75,
+0x76,0x75,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x75,0x75,
+0x76,0x76,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x74,0x75,0x75,
+0x77,0x76,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x74,0x73,0x73,0x73,0x74,0x75,0x75,
+0x77,0x75,0x73,0x73,0x73,0x74,0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x74,0x75,0x75,
+0x76,0x75,0x73,0x73,0x73,0x73,0x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xb7,0xb6,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb2,0xb6,0xb6,
+0xb7,0xb6,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb6,0xb6,
+0xb7,0xb6,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb6,0xb6,
+0xb7,0xb6,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb6,0xb6,
+0xb7,0xb6,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb6,0xb7,
+0xb7,0xb6,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb6,0xb7,
+0xb7,0xb6,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb6,0xb7,
+0xb6,0xb7,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb2,0xb2,0xb1,0xb1,0xb1,0xb2,0xb6,0xb7,
+0xb6,0xb9,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xb9,0xb7,
+0xb8,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xba,0xb9,
+},
+};
--- a/dat.h
+++ b/dat.h
@@ -44,7 +44,11 @@
Wside = 3,
Vwidth = Block * (Wwidth + 2 * Wside),
Vheight = Block * Wheight,
+};
+extern u32int palette[256];
+extern uchar sprites[NF][Block*Block];
+enum{
K← = 1<<0,
K→ = 1<<1,
K↑ = 1<<2,
--- a/fns.h
+++ b/fns.h
@@ -6,6 +6,5 @@
void step(void);
void initgame(void);
void redraw(void);
-void initimg(void);
void quit(void);
u64int nanosec(void);
--- a/gm4s.c
+++ b/gm4s.c
@@ -141,7 +141,6 @@
|| (keychan = chancreate(sizeof(ulong), 8)) == nil)
sysfatal("chancreate: %r");
initemu(Vwidth, Vheight, 4, XRGB32, 1, nil);
- initimg();
fmtinstall('H', encodefmt);
regkey("up", Kup, K↑);
regkey("down", Kdown, K↓);
--- a/mkfile
+++ b/mkfile
@@ -3,6 +3,7 @@
TARG=gm4s
HFILES= dat.h fns.h /sys/src/games/eui.h
OFILES=\
+ dat.$O\
game.$O\
gm4s.$O\
nanosec.$O\
--- a/piece.c
+++ b/piece.c
@@ -1,12 +1,12 @@
#include <u.h>
#include <libc.h>
#include <thread.h>
-#include <pool.h>
#include <draw.h>
#include "dat.h"
#include "fns.h"
#include "/sys/src/games/eui.h"
+/* FIXME: z and s pieces definitely should not wobble when rotating */
/* FIXME: stabler rotations? */
int fours[NF][Nrot] = {
[FI] {
@@ -53,77 +53,112 @@
},
};
-static u32int cols[NF] = {
- [FI] DCyan,
- [FJ] DBlue,
- [FL] DOrange,
- [FO] DYellow,
- [FS] DGreen,
- [FT] DPurple,
- [FZ] DRed,
+enum{
+ Cline = 0xf5,
};
-static Image *piece[NF];
/* FIXME: draw level, line clears, score */
/* FIXME: freeze screen on game over + print message instead of immediate exit */
static void
-drawplayfield(void)
+drawbackground(void)
{
- u32int c, *s, *p, *pe;
- char fc, *f, *fe;
+ int n, m, y;
+ u32int c, *p, *pe;
- memset(pic, 0, Vwidth * Vheight * sizeof *p); /* FIXME: sides */
- p = (u32int *)pic + Wside * Block;
- f = playfield + Wwidth * (Nrow - Wheight);
- for(s=p, fe=playfield+nelem(playfield); f<fe; f++){
- if((fc = *f) == 0)
- //c = cols[nrand(nelem(cols))];
- c = 0xff000000;
- else
- c = cols[fc - 1];
- for(pe=p+Block; p<pe; p++)
+ memset(pic, 0, Vheight * Vwidth * sizeof *p);
+ c = palette[Cline];
+ p = (u32int *)pic;
+ for(y=Nrow-Wheight; y<Nrow; y++){
+ p += Wside * Block;
+ for(pe=p+Ncol*Block; p<pe; p++)
*p = c;
- if(p - s == Wwidth * Block){
- p += Vwidth * (Block - 1) + 2 * Wside * Block;
- s = p;
+ p += Wside * Block;
+ m = y == Nrow - 1 ? Block - 2 : Block - 1;
+ for(n=0; n<m; n++){
+ p += Wside * Block;
+ for(pe=p+Ncol*Block; p<pe; p+=Block)
+ *p = c;
+ p[-1] = c;
+ p += Wside * Block;
}
}
+ p += Wside * Block;
+ for(pe=p+Ncol*Block; p<pe; p++)
+ *p = c;
}
static void
+drawplayfield(void)
+{
+ int n, y;
+ u32int *p, *pe;
+ char fc, *f, *fs, *fe;
+ uchar *sp;
+
+ p = (u32int *)pic;
+ fs = playfield + Wwidth * (Nrow - Wheight);
+ for(y=Nrow-Wheight; y<Nrow; y++){
+ fe = fs + Ncol;
+ for(n=0; n<Block; n++){
+ p += Wside * Block;
+ for(f=fs; f<fe; f++){
+ if((fc = *f) == 0){
+ p += Block;
+ continue;
+ }
+ sp = sprites[fc - 1] + n * Block;
+ for(pe=p+Block; p<pe; p++)
+ *p = palette[*sp++];
+ }
+ p += Wside * Block;
+ }
+ fs += Ncol;
+ }
+}
+
+static void
drawfour(int x, int y, int rot, int type)
{
- int f, m, n;
- u32int c, *l, *s, *p, *pe;
+ int f, n, m, k;
+ uchar *sp;
+ u32int *l, *s, *p, *pe;
- s = (u32int *)pic;
- s += (y - Nstartrow + Nextrarows) * Vwidth * Block + x * Block;
- l = s;
- c = cols[type];
+ p = (u32int *)pic + (y - Nstartrow + Nextrarows) * Vwidth * Block;
+ p += (Wside + x) * Block;
+ l = p;
f = fours[type][rot];
- for(n=0, m=1<<(Nside*Nside-1); m>0; m>>=1){
- if(s >= (u32int *)pic && f & m)
- for(p=s, pe=p+Block; p<pe; p++)
- *p = c;
- if(++n == Nside){
+ for(k=0, m=1<<(Nside*Nside-1); m>0; m>>=1){
+ s = p;
+ if(f & m){
+ sp = sprites[type];
+ for(n=0; n<Block; n++){
+ if(p >= (u32int *)pic)
+ for(pe=p+Block; p<pe; p++)
+ *p = palette[*sp++];
+ else
+ p += Block;
+ p += Vwidth - Block;
+ }
+ }
+ p = s + Block;
+ if(++k == Nside){
+ k = 0;
l += Vwidth * Block;
- s = l;
- n = 0;
- }else
- s += Block;
+ p = l;
+ }
}
}
static void
-drawui(void)
+drawsides(void)
{
int y, *p;
if(held != -1)
- drawfour(-1, Nrow / 2, 1, held);
+ drawfour(-4, Nrow / 2, 1, held);
for(y=1, p=next; p<next+nelem(next); p++, y+=5)
- drawfour(Wside + Wwidth, Nstartrow - Nextrarows + y, 1, *p);
+ drawfour(Wwidth, Nstartrow - Nextrarows + y, 1, *p);
}
static void
@@ -131,44 +166,22 @@
{
if(cur == nil)
return;
- drawfour(Wside + cur->x, cur->y, cur->rot, cur->type);
+ drawfour(cur->x, cur->y, cur->rot, cur->type);
}
static void
-vscalepic(void)
+drawui(void)
{
- int n;
- u32int *p, *s, *e;
-
- n = Vwidth;
- for(s=(u32int*)pic, e=s+n*Vheight; s<e; s=p)
- for(p=s+n; p<s+n*Block; p+=n)
- memcpy(p, s, n * sizeof *p);
}
void
redraw(void)
{
+ drawbackground();
drawplayfield();
drawpiece();
+ drawsides();
drawui();
- vscalepic();
flushmouse(1);
flushscreen();
-}
-
-void
-initimg(void)
-{
- u32int col, *c;
- Rectangle r;
- Image **i, **ie;
-
- r = Rect(0, 0, Block, Block);
- for(c=cols, i=piece, ie=i+nelem(piece); i<ie; i++, c++){
- col = *c;
- if((*i = allocimage(display, r, XRGB32, 0, col)) == nil)
- sysfatal("allocimage: %r");
- *c = col & 0xff << 24 | col >> 8 & 0xffffff;
- }
}
--
⑨