Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

Plants vs. Zombies: the menu's slabs, the new plant's words and How to Play's title in their place

Mason363f4daa5da51be
diff --git a/games/pvz/src/gfx.c b/games/pvz/src/gfx.c
index aff7f88b..87299bab 100644
--- a/games/pvz/src/gfx.c
+++ b/games/pvz/src/gfx.c
@@ -279,7 +279,7 @@ static void blit_frame(const Item *it, int fi, const uint16_t *pal, int bpp, int
if (r >= f.h) break;
if (r != last) {
const uint8_t *e, *p = row_at(&f, bpp, r, &e);
- if (!e) e = p + 4 * f.w + 8;
+ if (!e) e = f.end; /* (the last row: up to the next frame) */
decode_row(p, e, bpp, idx, vis, imin(f.w, 320));
last = r;
}
@@ -307,7 +307,7 @@ static void blit_frame(const Item *it, int fi, const uint16_t *pal, int bpp, int
if (bpp == 4) e = p + f.rows[r];
else {
p = f.rows + rd16(f.rows + 2 * r);
- e = r + 1 < f.h ? f.rows + rd16(f.rows + 2 * r + 2) : p + 4 * f.w + 8;
+ e = r + 1 < f.h ? f.rows + rd16(f.rows + 2 * r + 2) : f.end; /* (the last row: up to the next frame) */
}
uint16_t *out = band + (y % GFX_BAND) * SCREEN_W;
int x = 0, w = f.w;
@@ -465,8 +465,10 @@ static void draw_text(const Item *it, int y0, int y1, int dx, int dy, uint16_t c
int gfx_paragraph(int font, int x, int y, int width, const char *s, uint16_t color, int flags) {
Font f = font_info(font);
- int lh = font_line(font);
+ int lh = font_line(font) - (flags & GFX_TIGHT ? 1 : 0);
char line[160];
+ bool draw = !(flags & GFX_MEASURE);
+ flags &= ~(GFX_MEASURE | GFX_TIGHT);
while (*s) {
/* as many words as fit */
int n = 0, best = 0, w = 0;
@@ -480,7 +482,7 @@ int gfx_paragraph(int font, int x, int y, int width, const char *s, uint16_t col
if (best > (int)sizeof line - 1) best = (int)sizeof line - 1;
memcpy(line, s, (size_t)best);
line[best] = 0;
- gfx_text(font, x, y, gfx_fmt("%s", line), color, flags | GFX_CENTER);
+ if (draw) gfx_text(font, x, y, gfx_fmt("%s", line), color, flags | GFX_CENTER);
s += best;
while (*s == ' ') s++;
if (*s == '\n') s++;
diff --git a/games/pvz/src/gfx.h b/games/pvz/src/gfx.h
index 3f1717e2..8b96bb37 100644
--- a/games/pvz/src/gfx.h
+++ b/games/pvz/src/gfx.h
@@ -23,7 +23,7 @@ static inline uint16_t mix565(uint16_t f, uint16_t b, int a) {
return (uint16_t)(y | y >> 16);
}
-enum { GFX_FLIP = 1, GFX_OUTLINE = 2, GFX_CENTER = 4, GFX_RIGHT = 8, GFX_SHADOW = 16 };
+enum { GFX_FLIP = 1, GFX_OUTLINE = 2, GFX_CENTER = 4, GFX_RIGHT = 8, GFX_SHADOW = 16, GFX_MEASURE = 32, GFX_TIGHT = 64 };
/* colourings of a sprite (its palette, changed) */
enum { TINT_NONE, TINT_HIT, TINT_CHILL, TINT_FROZEN, TINT_HYPNO, TINT_SLEEP, TINT_DARK, TINT_WHITE, TINT_BLACK,
TINT_RED, TINT_GRAY, TINT_N };
@@ -67,7 +67,8 @@ void anim_box(int a, int f, int *x, int *y, int *w, int *h);
int gfx_text(int font, int x, int y, const char *s, uint16_t color, int flags);
int gfx_text_width(int font, const char *s);
int font_line(int font); /* the height of a line */
-/* text wrapped to width, centred on x (flags as gfx_text); returns the baseline after its last line */
+/* text wrapped to width, centred on x (flags as gfx_text; GFX_MEASURE: nothing drawn; GFX_TIGHT: its lines a pixel
+ * closer); returns the baseline after its last line */
int gfx_paragraph(int font, int x, int y, int width, const char *s, uint16_t color, int flags);
/* copies text into the frame's pool (text kept until gfx_end), printf-like */
const char *gfx_fmt(const char *fmt, ...);
diff --git a/games/pvz/src/res.h b/games/pvz/src/res.h
index a48a8687..b5b11592 100644
--- a/games/pvz/src/res.h
+++ b/games/pvz/src/res.h
@@ -31,11 +31,13 @@ int anim_frame_at(int a, uint32_t t);
typedef struct {
int16_t x, y; /* top-left from the anchor */
uint16_t w, h;
- const uint8_t *rows;
+ const uint8_t *rows, *end; /* end: past its last row (data.bin keeps the frames in order, then the palettes) */
} Frame;
static inline Frame frame_info(int f) {
const uint8_t *p = table(T_FRAMES) + 12 * f;
- return (Frame){rds16(p), rds16(p + 2), rd16(p + 4), rd16(p + 6), pvz_bin + rd32(p + 8)};
+ int n = (int)rd32(pvz_bin + 32); /* (the header: 6 tables, the animations, the frames) */
+ return (Frame){rds16(p), rds16(p + 2), rd16(p + 4), rd16(p + 6), pvz_bin + rd32(p + 8),
+ f + 1 < n ? pvz_bin + rd32(p + 20) : table(T_PALS)};
}
/* a palette: its colours (RGB565, aligned) */
static inline const uint16_t *pal_colors(int p, int *n) {
diff --git a/games/pvz/src/screens.c b/games/pvz/src/screens.c
index d9dffd46..5850dade 100644
--- a/games/pvz/src/screens.c
+++ b/games/pvz/src/screens.c
@@ -929,8 +929,18 @@ static void draw_award(void) {
}
gfx_text(F_HEAD, 160, 22, head, rgb565(0xF2C94C), GFX_CENTER | GFX_OUTLINE);
draw_reward(160, 82, true);
- gfx_text(F_HEAD, 160, 152, name, rgb565(0x3A2410), GFX_CENTER);
- gfx_paragraph(F_BODY, 160, 172, 200, text, rgb565(0x3A2410), 0);
+ /* the words in the card's panel, under the name: the body's letters if they fit, else the small ones, in its
+ * middle; the longest (the Potato Mine's, the trophy's) a little closer, the name a little higher */
+ int top = 154, bottom = 189, width = 114, font = F_BODY, tight = 0;
+ int h = gfx_paragraph(font, 160, 0, width, text, 0, GFX_MEASURE) - 1;
+ if (h > bottom - top) font = F_SMALL, h = gfx_paragraph(font, 160, 0, width, text, 0, GFX_MEASURE) - 1;
+ if (h > bottom - top) {
+ top = 152, width = 118, tight = GFX_TIGHT;
+ h = gfx_paragraph(font, 160, 0, width, text, 0, GFX_MEASURE | tight) - 1;
+ }
+ gfx_text(F_HEAD, 160, top - 2, name, rgb565(0x3A2410), GFX_CENTER);
+ int y = h < bottom - top ? top + (bottom - top - h) / 2 : top;
+ gfx_paragraph(font, 160, y + font_info(font).ascent, width, text, rgb565(0x3A2410), tight);
draw_button(110, 214, 100, B.level == N_LEVELS ? "Main Menu" : "Next Level", true);
}
@@ -1051,7 +1061,7 @@ static void draw_shop(void) {
static void draw_help(void) {
show_back(BG_ALMANAC);
- gfx_text(F_BIG, 160, 34, "How to Play", rgb565(0x5A3A1E), GFX_CENTER);
+ gfx_text(F_BIG, 160, 25, "How to Play", rgb565(0x5A3A1E), GFX_CENTER); /* (in the middle of the stone) */
static const char *const keys[][2] = {
{"Arrows", "Move over the lawn"},
{"1 2 3 ... 0", "Pick a seed packet"},