Block Dodge

Block Dodge is a mobile game that challenges players to dodge falling blocks while collecting apples, featuring various upgrades and unlockable character skins.

Experience fast-paced gameplay with unique power-ups and collectible skins!

Game Features

Block Dodge includes several engaging gameplay systems:


Power-Up System

Unlock and upgrade various abilities:

  • Speedster Surge - Enhanced movement speed
  • Apple Attraction - Magnetic apple collection
  • Apple Avalanche - Increased apple spawn rate
  • Iron Interceptor - Auto-block protection
  • Magnetic Mistral - Block repulsion field

Character Customization

Choose from 30 unique animal skins including Bear, Buffalo, Chick, and many more!

Dynamic Audio System

Features include:

  • Adaptive music that intensifies during gameplay
  • Sound effects for interactions and achievements
  • Death and collection audio feedback

Progress System

Comprehensive gameplay features including:

  • Save system to track progress
  • Currency system for upgrades
  • Unlockable skins and abilities

Score & Achievement System

Features an engaging scoring system with:

  • Real-time score tracking during gameplay
  • High score tracking with persistent storage
  • Audio feedback system including:
    • Special sound effects for new high scores
    • Achievement notification sounds
  • Visual feedback for score milestones

Save System Implementation

The game features a robust save system using JSON serialization:

  • JSON was chosen over binary serialization for:
    • Better cross-platform compatibility
    • Human-readable format for easier debugging
    • Standardized data structure
    • Flexible data modification and versioning
  • The system persistently stores:
    • Player progress and statistics
    • Unlocked character skins
    • Purchased upgrades and abilities
    • Currency and achievements

Technical Architecture

Block Dodge implements robust software design patterns including:

  • Game Manager Singleton - Coordinates core game systems and state
  • Audio Manager - Handles adaptive music and sound effects
  • Save Manager - Manages persistent data and player progress
  • Upgrade Manager - Controls power-up system and unlocks
  • Skin Manager - Handles character customization and unlocks

Custom UI Framework & Technical Solutions

Due to Unity's UI limitations, several custom systems were developed:

  • Dynamic UI Scaling System:
    • Custom InheritGUIScale script for runtime-modified content
    • Automatic vertical size calculation for dynamic content
    • Adaptive grid scaling for varying item counts
  • UI Content Loaders:
    • Specialized prefab instantiation systems for upgrades
    • Dynamic skin loader with runtime UI updates
    • Component-based architecture for modular UI elements
  • Performance Optimization:
    • Custom framerate management using Coroutines
    • Precise frame timing for consistent mobile performance
    • Resolution-independent scaling system
  • Mobile Adaptability:
    • Dynamic game area scaling for various device resolutions
    • Responsive UI layout system
    • Cross-device compatibility optimization

Core Technical Implementations

Key custom scripts that power Block Dodge's functionality:

Frame Rate Manager

Custom frame rate control system that ensures consistent performance across mobile devices:


// FrameRateManager.cs
// Maintains consistent frame timing using coroutines and thread sleep
using System.Collections;
using System.Threading;
using UnityEngine;
public class FrameRateManager : MonoBehaviour
{
    [Header("Frame Settings")]
    int MaxRate = 9999;
    public float TargetFrameRate = 60.0f;
    float currentFrameTime;
    void Awake()
    {
        QualitySettings.vSyncCount = 0;
        Application.targetFrameRate = MaxRate;
        currentFrameTime = Time.realtimeSinceStartup;
        StartCoroutine("WaitForNextFrame");
    }
    IEnumerator WaitForNextFrame()
    {
        while (true)
        {
            yield return new WaitForEndOfFrame();
            currentFrameTime += 1.0f / TargetFrameRate;
            var t = Time.realtimeSinceStartup;
            var sleepTime = currentFrameTime - t - 0.01f;
            if (sleepTime > 0)
                Thread.Sleep((int)(sleepTime * 1000));
            while (t < currentFrameTime)
                t = Time.realtimeSinceStartup;
        }
    }
}
                    

I acquired this code from TechGeeker's amazing video on the topic.

Dynamic UI Scaling System

Solves Unity's UI limitations with runtime content adjustment:


// InheritGUIScale.cs
// Automatically adjusts UI container height based on dynamic content
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(RectTransform))]
public class InheritGUIScale : MonoBehaviour
{
    private RectTransform rectTransform;

    void Start()
    {
        rectTransform = GetComponent();
        AdjustHeight();
    }

    void AdjustHeight()
    {
        if (transform.childCount == 0) return;

        float minY = float.MaxValue;
        float maxY = float.MinValue;

        foreach (RectTransform child in transform)
        {
            float childMinY = child.localPosition.y - (child.rect.height * child.pivot.y);
            float childMaxY = child.localPosition.y + (child.rect.height * (1 - child.pivot.y));

            if (childMinY < minY) minY = childMinY;
            if (childMaxY > maxY) maxY = childMaxY;
        }

        float totalHeight = maxY - minY;
        rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, totalHeight);
    }

        void Update()
        {
            AdjustHeight();
        }
}
                    

Disclaimer: I am aware this code is not the best, but for my usecase (the small amount of upgrades/skins) it's more that sufficient and does not cause performance degradation.

These implementations showcase:

  • Custom solutions for Unity's UI framework limitations
  • Real-time dynamic UI scaling
  • Mobile-specific optimizations

This project served as an excellent learning experience for implementing proper software architecture and design patterns in Unity game development.