Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/src/main/cpp/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ enum FillStyle {
// a shape. The renderer repacks these into per-instance vertex attributes
// (InstanceData in vk_renderer.cpp) consumed by shape.vert/.frag.
struct DrawCmd {
float mtx[4]; // m00, m01, m10, m11
float tx, ty; // NDC translation
float color[4]; // r, g, b, a
float style; // FillStyle (as float — goes straight into the instance attributes)
float seed; // reserved per-draw parameter (unused by current styles)
int shape;
float mtx[4] = {}; // m00, m01, m10, m11
float tx = 0.0f, ty = 0.0f; // NDC translation
float color[4] = {}; // r, g, b, a
float style = 0.0f; // FillStyle (as float — goes straight into the instance attributes)
float seed = 0.0f; // reserved per-draw parameter (unused by current styles)
int shape = 0;
};
111 changes: 55 additions & 56 deletions app/src/main/cpp/game.cpp

Large diffs are not rendered by default.

72 changes: 39 additions & 33 deletions app/src/main/cpp/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,36 +65,42 @@ class Game {
// One invader. Its world position derives from the formation origin plus
// its (row, col) slot, so the whole wave marches as a unit.
struct Alien {
int row, col;
AlienType type;
bool alive;
int row = 0, col = 0;
AlienType type = ALIEN_SQUID;
bool alive = false;
};
struct Bullet { float x, y, vx, vy; bool alive; }; // player laser, flies up
struct Bomb { float x, y, vx, vy, wobble; bool alive; }; // alien laser, falls down
struct Saucer { float x, y, vx; bool alive = false; };
// player laser, flies up
struct Bullet { float x = 0.0f, y = 0.0f, vx = 0.0f, vy = 0.0f; bool alive = false; };
// alien laser, falls down
struct Bomb { float x = 0.0f, y = 0.0f, vx = 0.0f, vy = 0.0f, wobble = 0.0f; bool alive = false; };
struct Saucer { float x = 0.0f, y = 0.0f, vx = 0.0f; bool alive = false; };
// Level-10 boss: a giant mothership drifting sinusoidally across the top,
// lobbing bombs aimed at the player. Killing it wins the game.
struct Boss {
float t = 0.0f, x = 0.0f;
int hp = 0, maxHp = 0;
bool alive = false;
};
struct PowerUp { float x, y, vy, rot, spin; PowerUpType type; bool alive; };
struct PowerUp {
float x = 0.0f, y = 0.0f, vy = 0.0f, rot = 0.0f, spin = 0.0f;
PowerUpType type = PU_SHIELD;
bool alive = false;
};
struct Particle {
float x, y, vx, vy;
float rot, spin;
float t, maxLife, size;
float r, g, b;
bool alive;
float x = 0.0f, y = 0.0f, vx = 0.0f, vy = 0.0f;
float rot = 0.0f, spin = 0.0f;
float t = 0.0f, maxLife = 0.0f, size = 0.0f;
float r = 0.0f, g = 0.0f, b = 0.0f;
bool alive = false;
};
struct Explosion {
float x, y, radius;
float t, maxLife;
float cr, cg, cb;
bool alive;
float x = 0.0f, y = 0.0f, radius = 0.0f;
float t = 0.0f, maxLife = 0.0f;
float cr = 0.0f, cg = 0.0f, cb = 0.0f;
bool alive = false;
};
struct Star { float x, y, size, phase; };
struct Pointer { bool active; float x, y; };
struct Star { float x = 0.0f, y = 0.0f, size = 0.0f, phase = 0.0f; };
struct Pointer { bool active = false; float x = 0.0f, y = 0.0f; };
struct HighScore { long score = 0; int level = 0; };

static const int kMaxScores = 5;
Expand Down Expand Up @@ -142,33 +148,33 @@ class Game {
// style selects the fragment-shader fill (STYLE_FLAT default, STYLE_GLOW).
void emit(std::vector<DrawCmd>& out, int shape, float wx, float wy,
float sx, float sy, float rot, float r, float g, float b, float a,
float style = (float)STYLE_FLAT);
float style = (float)STYLE_FLAT) const;
void drawDigit(std::vector<DrawCmd>& out, int d, float cx, float cy,
float h, float r, float g, float b, float a);
float h, float r, float g, float b, float a) const;
void drawNumber(std::vector<DrawCmd>& out, int value, float leftX, float cy,
float h, float r, float g, float b, float a);
float h, float r, float g, float b, float a) const;
void drawLetter(std::vector<DrawCmd>& out, char ch, float cx, float cy,
float h, float r, float g, float b, float a);
float h, float r, float g, float b, float a) const;
void drawText(std::vector<DrawCmd>& out, const char* text, float cx, float cy,
float h, float r, float g, float b, float a);
float h, float r, float g, float b, float a) const;
void drawShip(std::vector<DrawCmd>& out, float cx, float cy, float scale,
float tilt, float alpha);
float tilt, float alpha) const;
void drawAlien(std::vector<DrawCmd>& out, const Alien& a, float cx, float cy,
float alpha);
void drawPowerUpHUD(std::vector<DrawCmd>& out);
void drawBossHealthBar(std::vector<DrawCmd>& out);
void drawControlStrip(std::vector<DrawCmd>& out);
float alpha) const;
void drawPowerUpHUD(std::vector<DrawCmd>& out) const;
void drawBossHealthBar(std::vector<DrawCmd>& out) const;
void drawControlStrip(std::vector<DrawCmd>& out) const;
void drawGearIcon(std::vector<DrawCmd>& out, float cx, float cy, float size,
float r, float g, float b, float a);
float r, float g, float b, float a) const;
void drawGlassesIcon(std::vector<DrawCmd>& out, float cx, float cy, float size,
float r, float g, float b, float a);
void drawOnGlassesOverlay(std::vector<DrawCmd>& out);
void drawSettingsScreen(std::vector<DrawCmd>& out);
float r, float g, float b, float a) const;
void drawOnGlassesOverlay(std::vector<DrawCmd>& out) const;
void drawSettingsScreen(std::vector<DrawCmd>& out) const;
void loadSettings();
void saveSettings();
void updateAutoPlay(float dt);
bool isGearTap(float px, float py) const;
int numDigits(int v) const;
static int numDigits(int v);

// --- audio ---
AudioEngine* audio_ = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct Engine {
};

static double now_s() {
struct timespec t;
struct timespec t{};
clock_gettime(CLOCK_MONOTONIC, &t);
return (double)t.tv_sec + (double)t.tv_nsec * 1e-9;
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/cpp/test/audio_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include "audio.h"
AudioEngine::AudioEngine() = default;
AudioEngine::~AudioEngine() {} // impl_ is always nullptr in stubs
bool AudioEngine::init() { return false; }
// NOLINT below: the stub ignores `this`, but the real audio.cpp impl doesn't,
// so the shared declaration in audio.h cannot be static.
bool AudioEngine::init() { return false; } // NOLINT(readability-convert-member-functions-to-static)
void AudioEngine::shutdown() {}
void AudioEngine::triggerLaser() {}
void AudioEngine::triggerExplosion() {}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/test/game_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ TEST(March, StaysWithinSideMargins) {
// Centers reverse at asp - margin - halfWidth = asp - 0.053;
// 0.05 leaves slack for a single frame of overshoot.
ASSERT_LT(fabsf(g.alienXForTest(a)), aspect() - 0.05f)
<< "alien " << a << " out of margin after " << (i + 1) * 0.1f << " s";
<< "alien " << a << " out of margin after " << (float)(i + 1) * 0.1f << " s";
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/cpp/vk_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ bool VkRenderer::createVertexBuffer() {
for (int r = 0; r < h; r++) {
for (int c = 0; c < w; c++) {
if (rows[r][c] != 'X') continue;
float x0 = -1.0f + 2.0f * c / w;
float x1 = -1.0f + 2.0f * (c + 1) / w;
float y0 = -1.0f + 2.0f * r / h;
float y1 = -1.0f + 2.0f * (r + 1) / h;
float x0 = -1.0f + 2.0f * (float)c / (float)w;
float x1 = -1.0f + 2.0f * (float)(c + 1) / (float)w;
float y0 = -1.0f + 2.0f * (float)r / (float)h;
float y1 = -1.0f + 2.0f * (float)(r + 1) / (float)h;
push(x0, y0); push(x1, y0); push(x1, y1);
push(x0, y0); push(x1, y1); push(x0, y1);
}
Expand Down Expand Up @@ -773,10 +773,10 @@ void VkRenderer::recordCommandBuffer(VkCommandBuffer cb, uint32_t imageIndex,
// Centered viewport, scaled by renderScale_ (1.0 = full surface). The
// render pass has already cleared the whole framebuffer, so the surround
// is clear-colour (black = transparent on AR lenses).
float vw = extent_.width * renderScale_;
float vh = extent_.height * renderScale_;
float vx = (extent_.width - vw) * 0.5f;
float vy = (extent_.height - vh) * 0.5f;
float vw = (float)extent_.width * renderScale_;
float vh = (float)extent_.height * renderScale_;
float vx = ((float)extent_.width - vw) * 0.5f;
float vy = ((float)extent_.height - vh) * 0.5f;
VkViewport vpt{vx, vy, vw, vh, 0.0f, 1.0f};
VkRect2D sc{{(int32_t)vx, (int32_t)vy}, {(uint32_t)vw, (uint32_t)vh}};
vkCmdSetViewport(cb, 0, 1, &vpt);
Expand Down