This study focuses on the development of an intelligent enemy behavior system in the 2D maze game Dungeon Escape by combining the A* algorithm for pathfinding and a Behavior Tree (BT) structure for decision-making. The main objective is to enhance Non-Playable Character (NPC) intelligence, enabling more adaptive and realistic interactions with players. The A* algorithm is implemented to allow NPCs to pursue players through the shortest and most efficient paths while avoiding obstacles on a grid-based map. Meanwhile, the Behavior Tree framework is designed to manage NPC actions based on dynamic conditions, such as attacking when in close proximity, chasing players within a certain detection radius, and retreating to the original guard position when the player leaves the active zone. The research methodology involves a comprehensive literature review, system design, and implementation using the Unity game engine. Testing procedures consist of both white-box and black-box approaches to evaluate the correctness, functionality, and efficiency of the system. The results indicate that all major game features—including player navigation, combat mechanics, key collection, enemy pathfinding, and user interface interactions—operate smoothly as expected. Furthermore, NPCs exhibit adaptive behavior by dynamically switching between patrolling, chasing, and attacking modes depending on the player’s location and proximity. Performance testing shows that the integrated A* and BT system runs efficiently without significant delays or instability, even in higher-level stages with more complex layouts. The final game prototype includes seven progressively challenging levels, offering players an engaging and dynamic gameplay experience. This study demonstrates that the combination of pathfinding and decision-making algorithms provides an effective solution for designing intelligent NPCs, improving both realism and entertainment value in 2D games. The findings are expected to serve as a useful reference for future research and development in AI-based game design, particularly in the context of Unity game projects.
Copyrights © 2025