Thesis Title
Total Page:16
File Type:pdf, Size:1020Kb
BACHELOR THESIS Andrej Ciˇzm´arikˇ Framework for Development of Tower Defense-like Games Department of Software and Computer Science Education Supervisor of the bachelor thesis: Mgr. Jakub Gemrot Study programme: Computer Science Study branch: Programming and Software Systems Prague 2017 I declare that I carried out this bachelor thesis independently, and only with the cited sources, literature and other professional sources. I understand that my work relates to the rights and obligations under the Act No. 121/2000 Sb., the Copyright Act, as amended, in particular the fact that the Charles University has the right to conclude a license agreement on the use of this work as a school work pursuant to Section 60 subsection 1 of the Copyright Act. In ........ date ............ signature of the author i N´azevpr´ace:Framework pro tvorbu her typu tower defense Autor: Andrej Ciˇzm´arikˇ Katedra: Katedra softwaru a v´yukyinformatiky Vedouc´ı bakal´aˇrsk´epr´ace: Mgr. Jakub Gemrot, Katedra softwaru a v´yuky informatiky Abstrakt: Tower Defense hry s´upopul´arnym subˇz´anromreal-time strategick´ych hier, kde hr´aˇc chr´ani str´aˇzen´y objekt obrann´ymi veˇzami pred n´ajazdmi nepriatel’ov. S´uˇcasn´e Tower Defense hry s´uvˇsak uzavret´e, ˇc´ım znemoˇzˇnuj´u ak´ukol’vek rozˇs´ıritel’nost’ a sk´umaniezdrojov´ehok´odu. Ciel’om pr´aceje preto vytvorit’ multiplatformov´yframework pre tvorbu hier typu Tower Defense spolu s ilustraˇcnouimplement´aciouhry v tomto frameworku. Framework podporuje potrebn´e hern´e objekty: veˇze, jednotky, ako aj interakcie medzi nimi – vˇsetko skriptovatel’n´ev jazyku LUA. Dalejˇ podporuje manipul´acius text´urami, anim´aciami,zvukov´ymiefektami a hern´ymimapami vytvoren´ymiv dostupnom grafickom editore. Uˇz´ıvatel’sk´erozhranie sa navrhuje v deklarat´ıvnom jazyku XAML. Ciel’ pr´acesa podarilo naplnit’ – pomocou vytvoren´ehoframeworku je moˇzn´evyv´ıjat’ Tower Defense hry na platforme Windows a Android. Kl´ıˇcov´aslova: framework, v´yvoj poˇc´ıtaˇcov´ych her, Tower Defense Title: Framework for Development of Tower Defense-like Games Author: Andrej Ciˇzm´arikˇ Department: Department of Software and Computer Science Education Supervisor: Mgr. Jakub Gemrot, Department of Software and Computer Science Education Abstract: Tower Defense is a popular subgenre or real-time strategy, where the player guards an object by building defending towers against raiding enemy units. Current Tower Defense games have, however, closed source code which completely prevents any possibility to extend these games or study their code. Due to this fact the aim of this thesis is to develop a multi-platform framework for development of Tower Defense games together with an illustrative example game created using the framework. Framework supports game objects: towers, units and interactions between them – all scriptable in scripting language LUA. Framework also supports textures, animations, sound effects and game maps created using an available graphical editor. User interface is designed using declarative language XAML. In the result we fulfilled the aim of the thesis – using the created framework users can develop Tower Defense games for platforms Windows and Android. Keywords: framework, video games development, Tower Defense ii I would like to thank my supervisor, Mgr. Jakub Gemrot, for his patient guidance and valuable advice he has provided during my work on this thesis. I am also very grateful for the support my family provided not only during the work on this thesis but throughout my whole bachelor studies. iii Contents Introduction 3 1 Problem analysis 5 1.1 Tower Defense definition . .5 1.2 Game mechanics in Tower Defense . .6 1.3 Our definition for Tower Defense-like . .8 1.3.1 Supported mechanics . .8 1.4 User interface layouts . .9 1.5 Creating and representing maps . .9 1.6 Framework requirements . 10 1.6.1 Pluggable design . 10 1.6.2 Target platforms . 10 1.6.3 Third party libraries . 11 1.6.4 Graphics library . 11 1.6.5 User interface library . 12 1.6.6 LUA interpretter library . 13 1.7 Supported features . 13 2 User documentation 15 2.1 Target audience . 15 2.2 Creating a new game . 15 2.3 Content Pipeline . 17 2.4 Adding graphics and sounds . 18 2.5 Adding unit animations . 18 2.6 Adding visual effects . 19 2.7 Adding units . 19 2.8 Adding towers . 20 2.9 Adding game actions . 21 2.10 Scripting support . 22 2.10.1 Debugging embedded scripts . 22 2.11 Scripting game entities . 23 2.12 Scripting units . 25 2.13 Scripting towers . 28 2.14 Scripting game actions . 30 2.15 Registering for scripting . 31 2.16 Adding upgrades . 32 2.17 Adding maps . 32 2.18 Adding levels . 34 2.19 Adding sounds . 36 2.20 Adding custom fonts . 36 2.21 Adding user interface screens . 37 2.21.1 Visual Studio designer tool . 39 2.22 Example game . 39 2.22.1 User interface in the example game . 41 1 3 Development documentation 43 3.1 Development tools . 43 3.2 Top-down solution design . 43 3.2.1 Solution structure . 43 3.2.2 Model-view-viewmodel pattern . 44 3.3 Overview of the solution architecture . 44 3.4 Game real-time progression . 45 3.4.1 Timestep modes in MonoGame . 45 3.4.2 Game loop in MonoGame . 46 3.5 Framework initialization phase . 47 3.6 Framework gameplay phase . 48 3.7 The main framework projects . 49 3.7.1 Game objects component . 50 3.7.2 Input/Output component . 52 3.7.3 Data and Persistent storage component . 54 3.7.4 Sound system component . 54 3.7.5 Spritesheet packing component . 55 3.7.6 Level state, Game events and World component . 55 3.7.7 User interface and other framework components . 57 3.7.8 Custom file format . 58 3.7.9 Scripting environment . 59 3.8 UserInterface.csproj . 60 3.9 GameUILibrary.csproj . 60 3.10 MapDataExtractor utility . 62 3.11 Expanding the project . 63 Conclusion 65 Bibliography 67 List of Figures 70 Attachments 71 A Framework solution and documentation . 71 B MapDataExtractor utility solution . 71 C Compiling and running framework . 71 D Licenses . 71 2 Introduction Tower Defense (TD) is a popular real-time strategy game subgenre, focusing on correct tower positioning and resource management. The main objective is to defend an object against raiding enemy units. TD games are played on maps with one or more paths leading to the guarded object. Players can then build defending towers alongside the paths to destroy and obstruct enemy units from reaching the object. TD games are usually level-based, meaning that players need to successfully finish previous levels in order to unlock harder ones. While TD games have been quite popular over the past years, there are rarely seen solutions which present tools specifically designed to simplify the development of TD games. There are some open-source real-time strategy games [1], however, these games do not serve as a tool and thus can not be directly used to create new games. Even though many successful implementations of TD games already exist, for instance, Kingdom Rush [2], Bloons TD [3] or Plants vs Zombies [4] their source code is closed. This fact completely prevents the possibility of code studying or extending these games. Majority of current game frameworks (e.g., Unity [5], MonoGame [6], Unreal Engine 4 [7] present complex solutions containing many unnecessary features for the development of TD games. Furthermore, many subsystems and game objects, which are actually needed for the development, are not implemented. As a result of mentioned reasons, the goal of this thesis is to design and implement a 2D framework for the development of TD-like games. An integral part of the thesis is implementation of an illustrative game created using the framework as a proof of concept. The framework together with the game provide a decent starting point for creating an easily extendable and multi-platform game. Project goals In this section we will list our goals that we aim to fulfill in this thesis. (G1) Easy way of defining game objects and adding content By simple to use, we mean the user is not required to be a programmer. Game objects should be defined by modifying game files, instead of writing source code. (G2) Maps The project should support an intuitive way of creating game maps. By intuitive we mean making use of a graphical editor, rather than forcing the user to define complex maps using text files. (G3) Pluggable design In order to avoid recompiling whole project every time something is changed, we intend to provide a solution relying on the pluggability. 3 (G4) Support for replays The players should be offered with an option to save the replay of the current level. This feature simplifies the process of generating gameplay videos. (G5) Multi-platform By multi-platform we mean that the project should support development for at least two different platforms. (G6) Tutorials Publishing a framework without illustrative tutorials may result in discouraging many potential users. Therefore, this thesis should provide easy-to-follow tutorials, showing users how to create their own games. (G7) Example game As a proof of concept, but also to showcase the features of the framework, a simple TD game should be implemented. Structure of this thesis In the first chapter we will analyze the TD genre, focusing on the key concepts and game mechanics found in some popular TD games. We analyze possible approaches for implementation of our framework and establish more specific goals which have to be met during the development. User documentation, consisting mainly of illustrative tutorials is contained in the second chapter. This serves as the starting point for users that want to create their own TD game mostly by modifying the example game.