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.

Mr Bullet: TNT crates go off

Mason363cd5c7a11e6d6
diff --git a/games/mrbullet/src/draw.c b/games/mrbullet/src/draw.c
index 6ea99d96..86dc075e 100644
--- a/games/mrbullet/src/draw.c
+++ b/games/mrbullet/src/draw.c
@@ -161,8 +161,8 @@ static void style_of(const Obj *o, Style *st) {
} else if (f & F_BR) {
st->fill = HEX(0x4DBDAE), st->alt = HEX(0x8FDDD1), st->edge = st->edge2 = HEX(0x2A7C73);
st->pattern = PAT_GLASS;
- } else if (f & F_BO) {
- st->fill = HEX(0xE9B872), st->edge = st->edge2 = HEX(0x9A6A2E);
+ } else if (f & F_BO) { /* a TNT crate */
+ st->fill = HEX(0xE8392F), st->edge = st->edge2 = HEX(0x9C1F17);
} else if (f & F_HV) {
st->fill = HEX(0x8D99A6), st->edge = st->edge2 = HEX(0x3F4952);
} else if (f & F_F) {
@@ -223,6 +223,18 @@ static void draw_obj(int i) {
cstart[++ncont] = (uint16_t)n;
}
fill(&st, bb_y0[i], bb_y1[i]);
+ /* a TNT crate's word, while it stands (it goes off before it can tumble far) */
+ if ((o->flags & F_BO) && !o->sw && fabsf(s) < 0.34f && c > 0 && n) {
+ float mx = 0, my = 0, w0 = 1e9f, w1 = -1e9f;
+ for (int k = 0; k < cstart[1]; k++) {
+ mx += px_[k], my += py_[k];
+ if (px_[k] < w0) w0 = px_[k];
+ if (px_[k] > w1) w1 = px_[k];
+ }
+ mx /= cstart[1], my /= cstart[1];
+ if (w1 - w0 >= 18 && bb_y1[i] - bb_y0[i] >= 10 && my - 6 < gfx_y1 && my + 6 > gfx_y0)
+ gfx_text_center(&np_font_small, (int)mx, (int)my + 4, "TNT", HEX(0xFFFFFF), 256);
+ }
}
/* ------------------------------------------------------------------ characters */
diff --git a/games/mrbullet/src/game.c b/games/mrbullet/src/game.c
index ec94fd16..23fbdf86 100644
--- a/games/mrbullet/src/game.c
+++ b/games/mrbullet/src/game.c
@@ -3,7 +3,7 @@
* As in the game (gamesrc spec): level parts of density 2.1 (heavy x3), restitution 0.35, friction 0.2; characters'
* pieces 2.0, 0.35, 0.2; bullets circles of radius 2, density 0.1, restitution 1, no friction and no gravity, sent
* by an impulse of 0.008 and kept 300 steps; grenades of density 0.8, restitution 0.4, friction 0.5, that go off
- * after 150 steps. Breakables (bo, br) break at the first bullet or a blow of 7.5 m/s; explosives (be) go off. */
+ * after 150 steps. Glass (br) breaks at the first bullet or a blow of 7.5 m/s; explosives (be, and bo: TNT) go off. */
#include <math.h>
#include <string.h>
#include "game.h"
@@ -23,6 +23,10 @@ static uint8_t pending_blast[MAX_OBJ]; /* explosives set off, going off in a f
#define KIND(c) ((c) >> 8)
#define INDEX(c) ((c) & 255)
+/* what goes off when shot or hit hard: be, and bo, the TNT crates (Classic's level 7 is one crate between the two);
+ br breaks (glass) */
+#define F_EXPL (F_BE | F_BO)
+#define F_BREAK F_BR
#define BULLET_R 2.0f
#define BULLET_SPEED (0.008f / (0.1f * PI * (BULLET_R / 60) * (BULLET_R / 60)) * 60) /* units/s */
#define GRENADE_R 5.0f
@@ -616,8 +620,8 @@ static void blast(float x, float y) {
}
float d = sqrtf(dx * dx + dy * dy);
if (d >= BLAST_R) continue;
- if (o->flags & F_BE) { if (!pending_blast[i]) pending_blast[i] = 6; continue; }
- if (o->flags & (F_BO | F_BR)) { remove_obj(i); continue; }
+ if (o->flags & F_EXPL) { if (!pending_blast[i]) pending_blast[i] = 6; continue; }
+ if (o->flags & F_BREAK) { remove_obj(i); continue; }
if (!world_dynamic(o->body)) continue;
float m = world_mass(o->body), f = 3.0f * (1 - d / BLAST_R) / (d > 1 ? d : 1);
float cap = m * 12.0f / (f * (d > 1 ? d : 1) + 1e-6f);
@@ -668,9 +672,9 @@ static void switch_on(int si) {
static void hit_level(int oi, bool by_bullet, float speed) {
Obj *o = &g.obj[oi];
if (o->gone) return;
- if (o->flags & F_BE) {
+ if (o->flags & F_EXPL) {
if ((by_bullet || speed > BREAK_SPEED) && !pending_blast[oi]) pending_blast[oi] = 1;
- } else if (o->flags & (F_BO | F_BR)) {
+ } else if (o->flags & F_BREAK) {
if (by_bullet || speed > BREAK_SPEED) remove_obj(oi);
}
}