Skip to content

About

Knife-throwing hyper-casual mobile game (Unity 6 URP 2D) with direction-reversing boss logs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

Timber Strike

A tiny hypercasual mobile game built in Unity 6 (URP 2D) as a portfolio piece: throw knives into a spinning log without hitting one already stuck there, one input - tap.

Inspired by Ketchapp's Knife Hit. My twist: boss logs that brake and reverse mid-spin, so timing the throw becomes a read of the log's rhythm, not just of its position.

Timber Strike gameplay

Play it in the browser: davidbarredo.netlify.app

How it was made: I designed the game and owned the feel and the iterations; the code was written with AI (Claude).


What this project demonstrates

Timber Strike is deliberately small in scope so the code stays readable end to end, but it's built to show a specific set of engineering habits recruiters look for in a Unity codebase:

  • Object pooling, written from scratch (Utils/ObjectPool.cs) instead of relying on Instantiate/Destroy in a loop - knives are recycled every throw and every level.
  • ScriptableObject-driven configuration (Data/GameplayConfig.cs): every level-progression, log and knife number lives in one designer-facing asset, not hardcoded constants - a designer could rebalance the whole game without touching a script.
  • A small, explicit state machine (Core/GameManager.cs) driving Menu / Countdown / Playing / Paused / GameOver, instead of scattered booleans.
  • Decoupled communication via C# events (Core/GameEvents.cs): gameplay systems (the log, the knife thrower, score, audio, camera shake, particles, haptics) never hold references to each other or to the UI - they all react to the same small set of static events. Adding a new reaction to "a knife hit another knife" never requires touching the class that raises it.
  • Angle math instead of physics for the actual game rule: whether a throw is safe is a pure function of two angles and a tolerance (Gameplay/LogController.cs), not a collider - see Design notes below for why.
  • The new Input System, used both as a raw polled action (Core/TapInputReader.cs, works with touch/mouse/pen through the generic Pointer device) and through InputSystemUIInputModule for UI navigation.
  • A UI layer built entirely from code (UI/, see UI architecture below) - no hand-tweaked Canvas prefab to keep in sync with the scripts.

Gameplay

  • A single tap throws a knife straight into the log. Land it cleanly and it sticks; land it on top of a knife that's already there and the run ends.
  • Clear a log (stick the required number of knives) and it "breaks" - the log resets, spins faster, and needs one more knife next time.
  • A bonus apple sometimes appears on the log; landing a knife on it adds points and pops a "+N" next to the live score, so the payoff is obvious the moment it happens.
  • Boss logs (every 5th level, tunable in GameplayConfig): the log turns red, the HUD announces "BOSS LOG", and instead of a constant spin its speed follows a sine wave - it brakes, stops and reverses (the square root of the wave keeps it near full speed and makes reversals snappy). Clearing one grants a +10 bonus. It breaks the rhythm players settle into on normal logs.
  • Knife shop (meta loop): every apple hit is also banked across runs (SaveSystem), and apples buy knife skins from the menu's KNIVES screen - the kunai is free, then pencil, paper plane, axe, hammer (3 to 15 apples). Owned knives show in color and can be equipped; locked ones are silhouettes with their price. The catalog (names, prices, sprites) lives in GameplayConfig.knifeSkins, so adding a skin is data, not code. Play -> earn apples -> unlock -> play again.
  • The live score (knives stuck + apple bonuses) is HUD-only feedback during a run. The one stat that actually persists is logs cleared, saved locally as a single best-ever number (PlayerPrefs, SaveSystem.GetBestLogsCleared/SubmitLogsCleared) - no Top-5 leaderboard, deliberately: for a level-based game "how many logs did you clear" is the whole story. Menu -> Play -> Pause anytime -> Game Over -> Replay/Menu, all with a short fade transition.

Project structure

Assets/_Project/
  Scripts/
    Core/        GameManager (state machine), GameEvents, GameState, TapInputReader, AudioPreferences
    Gameplay/     LogController, KnifeThrower, ScoreManager, CameraShake, ImpactParticles, HapticsFeedback
    UI/           UIManager, MenuScreen, PauseScreen, GameOverScreen, HudView, CountdownView, SafeAreaFitter
    Data/         GameplayConfig (ScriptableObject)
    Audio/        AudioManager
    Save/         SaveSystem
    Utils/        ObjectPool<T>, UIFactory, RuntimeSpriteFactory, PlaceholderVisual
    Editor/       BuildScript (command-line WebGL/Android build entry points), SpriteImportPostprocessor
  Data/Configs/   GameplayConfig.asset (the actual tunable instance - tune this in the Inspector)
  Prefabs/        Knife.prefab (pooled)
  Scenes/         Game.unity (single scene; UI/state fully code-driven, no scene reload needed)

How a throw is resolved

The log only ever rotates (transform.eulerAngles.z); a knife always arrives at the same fixed world point, directly below the log's center. LogController converts that fixed world angle into the log's local angle at the moment of impact (worldAngle - transform.eulerAngles.z) and checks it against every previously-stuck knife's local angle, within a tolerance (GameplayConfig.collisionToleranceDegrees). This is the one piece of the codebase worth reading first if you're evaluating the math: it's a handful of lines, no physics engine involved, and it's why a stuck knife visually keeps spinning with the log for free - it's just a child transform of the log, parented at the exact moment its world position matched the impact point.

UI architecture note

The Canvas, EventSystem and every screen (Menu/Pause/GameOver/HUD) are built at runtime in code (UIFactory + UIManager), not authored as a Canvas prefab in the Editor. This was a deliberate trade-off: it kept the whole UI reliably reproducible and scriptable end to end. The cost is that it's less drag-and-drop than a typical Unity UI workflow - real art (see below) is wired in by Resources.Load path convention rather than dragging assets onto Inspector fields. Worth knowing if you extend this project.

Art & audio

A rustic "lumberjack workshop" direction - warm wood-brown/parchment palette, a bold condensed display font, cream-and-oak UI chrome - deliberately distinct from this project's sibling portfolio piece (OrbitDash's cool navy/cyan sci-fi look), including at the code level: UITheme now carries the whole palette as named constants (PanelBackground, TextPrimary, ButtonPrimaryLabel, ...) instead of every screen repeating its own Color(...) literals.

Use File Source License
Primary/secondary buttons Art/Resources/Sprites/UI/Buttons/button_primary.png, button_secondary.png UI Pack: Adventure (button_brown, button_grey) CC0
Round icon-button badge Art/Resources/Sprites/UI/Buttons/button_icon.png UI Pack: Adventure (round_brown) CC0
Pause / sound / home icons Art/Resources/Sprites/UI/Icons/icon_*.png Game Icons Expansion, Black variant (dark glyphs, readable on the new light buttons - the old set was white-on-transparent, meant for a dark button) CC0
Bonus apple Art/Resources/Sprites/Gameplay/apple.png Food Kit (apple.png preview render) CC0
Knife skins Art/Resources/Sprites/Gameplay/Knives/*.png (downscaled into 130x256) Stylized 2D Weapons Pack by PanksCreations (free version) CC0
UI font Art/Fonts/Anton-Regular.ttf -> generated SDF asset Anton (Google Fonts) - bold and condensed, reads at HUD sizes, common in hypercasual UI OFL

License files for the CC0 packs are kept alongside the art at Art/Licenses/ (no attribution is actually required, but it's there for provenance). CC0 needs no credit; OFL needs none either but Anton's Anton-OFL.txt sits next to the font file regardless.

Forest art pass (flat vector, one style everywhere):

Slot Source
Backdrop Background Elements Remastered (backgroundColorFall, CC0), tiled sideways and scaled to the view by Gameplay/SceneDressing.cs, which also adds a soft log shadow and falling leaves
Log, apple Drawn by Tools/GenerateArt.ps1 (seeded, reproducible): bark with a wobbly edge, irregular growth rings, drying cracks, highlight; apple with shade, highlight, stem and leaf. Output to Art/Resources/Sprites/Gameplay/ and picked up by the existing Resources.Load path, no code change
Knives Stylized 2D Weapons Pack (see table above); the kunai is the default knife
UI Menu/shop panels are see-through over the forest; light text gets a dark outline (OUTLINE_ON is enabled on the font material so the keyword survives build stripping)

SFX are wired up - real clips now sit at each AudioManager slot's expected Resources path:

Slot File Source License
Throw Audio/Resources/SFX/throw.ogg RPG Audio (drawKnife1.ogg) CC0
Stuck Audio/Resources/SFX/stuck.ogg Impact Sounds (impactWood_light_000.ogg) CC0
Bonus Audio/Resources/SFX/bonus.ogg RPG Audio (handleCoins.ogg) CC0
Collision (run-ending) Audio/Resources/SFX/collision.ogg Impact Sounds (impactMetal_heavy_000.ogg) CC0
Level clear Audio/Resources/SFX/level_clear.ogg Impact Sounds (impactWood_heavy_000.ogg) - the log "breaking" CC0

License files are at Audio/Licenses/, mirroring the Art/Licenses/ convention.

Still no background music - the Music/theme slot is left empty on purpose rather than filled with a bad fit: Kenney's music packs (music-jingles, rpg-audio) are short one-shot stingers, not seamless loops, and a jarring loop point would hurt a portfolio piece more than silence does. AudioManager already no-ops safely on a null music clip, so this is still a drop-in-and-go once a real CC0/CC-BY loop (e.g. incompetech.com, CC-BY, credit required) is placed at Audio/Resources/Music/theme.mp3.

Slot Note
Particle burst texture Gameplay/ImpactParticles.cs's ParticleSystemRenderers currently use a plain circle sprite. Swap in a nicer texture/material later via Unity's free Particle Pack (re-assign to a URP Particles/Unlit shader after import).

Setup

  1. Unity 6000.5.10f1 (Unity 6 LTS) or newer, with the 2D URP template.
  2. Open the project, let Unity import; if prompted, run Window > TextMeshPro > Import TMP Essential Resources once.
  3. Open Assets/_Project/Scenes/Game.unity and press Play - mouse click doubles as tap in the Editor.

Building

WebGL Build Support is installed; Android Build Support (SDK/NDK/OpenJDK) needs to be added via Unity Hub before an Android build can run. Assets/_Project/Scripts/Editor/BuildScript.cs exposes two command-line entry points:

Unity.exe -batchmode -quit -projectPath . -executeMethod TimberStrike.EditorTools.BuildScript.BuildWebGL
Unity.exe -batchmode -quit -projectPath . -executeMethod TimberStrike.EditorTools.BuildScript.BuildAndroid

(Close the Editor first - Unity refuses a second instance on a project that's already open.) Output goes to Builds/WebGL/ and Builds/Android/TimberStrike.apk, both git-ignored.

For the portfolio: host the WebGL build on itch.io (set it as an embedded HTML5 game) so it's playable directly from the portfolio page without installing anything, and keep the APK as a downloadable link for a mobile demo.

Design notes / known simplifications

  • Only one knife in flight at a time, but a tap during that window isn't lost: KnifeThrower buffers a single extra tap (_hasQueuedThrow) and fires it the instant the thrower frees up (EndBusy), instead of requiring the player to land a fresh tap after the busy window closes - rapid clicking felt like it was "eating" inputs before this. It's a depth-1 buffer, not a real queue: spamming five taps during one throw results in exactly one more throw right after, not five queued up. The buffer is explicitly cleared on pause/menu/game-over (OnDisable) so resuming never throws a knife the player didn't just tap for - and, separately, on crossing into a new level (HandleLevelStarted), so a tap buffered while the previous log was wrapping up can't auto-throw into the new one; that read as the game acting on its own rather than responsiveness. Buffering still applies to every other busy window (mid-throw, normal cooldown) - just not across a level change.
  • The busy window isn't a fixed duration - it's usually GameplayConfig.throwCooldownSeconds after a knife lands, but a knife that clears the level keeps the thrower busy until GameEvents.LevelStarted fires instead (KnifeThrower._isWaitingForNextLevel). LogController stays in a stale, about-to-reset state for the ~0.4s between meeting a log's requirement and the next log actually being configured; a fixed short cooldown let a fast extra tap land a knife inside that window, which re-evaluated as "still met the old requirement" and fired the clear sequence again per extra knife - level count would jump by more than one under rapid tapping. Worth reading if you're evaluating how the codebase handles a timing-window bug like this.
  • Difficulty ramps per level, not per second: GameplayConfig.GetRequiredKnives/ GetRotationSpeedDegreesPerSecond are simple linear lookups by level index, capped at a max. Trivial to swap for an AnimationCurve if you want a hand-tunable ramp instead of a linear one.
  • Bonus apple placement is independent of knife placement: the apple's angle is chosen uniformly at random at the start of a level and never re-rolled to avoid existing knife angles, since the log starts each level empty (no knives yet) - simple by construction, not a special case.
  • Log knots (LogController.SpawnKnot, unlocked from GameplayConfig.knotUnlockLevel, level 4 by default): a second difficulty axis beyond rotation speed - an obstacle angle a level starts with already occupied. It's added straight into the same _stuckLocalAngles list a real stuck knife would occupy, so RegisterKnifeAttempt's existing collision check treats a hit on it as a run-ending collision for free, with zero extra branching.
  • Every clean stick gets its own (small) feedback, not just the loss: GameEvents.KnifeStuckAt carries the impact point purely for VFX, separate from KnifeStuck (which carries HUD pip-progress counts instead) - ImpactParticles reacts to both with two differently-sized bursts, so a normal successful throw feels like it landed even though only a collision triggers camera shake/haptics.
  • UI raycast vs. gameplay taps: TapInputReader checks EventSystem.IsPointerOverGameObject() before firing, so tapping the in-game Pause button doesn't also throw a knife underneath it.
  • Single-scene architecture: Menu/Playing/Paused/GameOver are UI overlays + enabled/disabled gameplay systems, not separate Unity scenes - avoids scene-load hitches for a game this small.

About

Knife-throwing hyper-casual mobile game (Unity 6 URP 2D) with direction-reversing boss logs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages