How to Build a Turn Based Strategy Game

5

Index

Attached Files

The following files have been attached to this tutorial:

Stats

3,553 visits, 6,362 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 11 Feb, 2023. Last updated 28 Feb, 2023

3. Turn System

3.1 End Turn

The button EndTurn on clicked simply needs to disable player control during AI’s turn. In event 26 we deselect player’s units to avoid AI controlling player’s unit and hand over control to AI by starting the Timer “AI Timer” which belongs to the text object called Turn.

3.2 Resetting

We will use one function “ResetMoves” event 29 where for each unit we call the function “Instantiate” and reset the units of various specific type to their default values. Specifically how many moves those units have left. Ignore event 31 as it is not needed.

4. Player Control

4.1 Travelling

In this part, we use a function called “Highlight_Nodes” event 33 that is not a crucial game element but is a nice to have to see what nodes your unit travelled too. The “Highlight_Nodes” function is dependent on another function called “Find_Nodes” which will be discussed later in Part 7. Find Path.

The way “Highlight_Nodes” works is we pick the last node to which the player unit travelled to and extract the prev variable from that node. Then for each node that has a prev not equal to -1 pick it and highlight it repeating until reaching the start node.

4.2 Selecting

In order to avoid repeatedly using the on left button clicked condition we will only use it once as seen in event 37 conditioned with the Turn text object to be equal to “Your” to ensure player can control their units when it is their turn.

On left check if mouse is overlapping player unit event 38 wait 0.1 seconds to ensure that events 42 to 47 do not get triggered and mark that unit as selected. In addition, event 39 is needed to correctly trigger the function “Find_Nodes”. Event 40 deselects other selected units that are not equal to the current selection and event 41 simply enables that node at which the selected unit was at too its original state.

4.3 Deselecting

There are two cases when deselecting the already selected unit occurs and that is when clicking the already selected unit, events 43 to 45, or anywhere that is not permissible for the unit to move event 46. Even on an already occupied node by your own or enemy units your selected unit will be deselected.

4.4 Moving

To move from one node to another, events 42, that is within the travel range of the selected unit check if the unit is selected and that it can move to a given node. On clicking a node that satisfies the set conditions set the selected unit to that position and highlight the path travelled. This event 42 is dependent of the “Find_Nodes” function.

4.4 Attacking

Similar to moving the unit and dependent on “Find_Nodes” function event 47 simply spawns an Attacked sprite to deal damage to enemy unit.

  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Hallo. Idont see AJAX plugin in add.

    • AJAX plugin already exists by default in Construct 2 and 3.

      When you double-click in one of your layouts a new window will appear for creating new objects.

      Inside that new window scroll all the way down to the Web category until you see the AJAX plugin. Or simply use the search tool and search for AJAX. Double-click the AJAX icon or click on the insert button to add AJAX into your project.

      If you do not see the AJAX plugin in your attempt to add it into your project, then it simply means that you have already added AJAX into your project already.