Creating Maximum Movement Indicators on a Board

Get help using Construct 2

Post » Wed Aug 07, 2013 8:19 am

I'm going to tag every math wizard I know on this forum for this one xD
@Yann, @R0j0hound, @cvp, @Tobye

Firstly, this is for a board game I am developing. The idea is that once a user clicks on a unit, all available move spaces are shown on the board, just like in this game here:



In the image above, the selected unit is allowed to move 4 spaces on the game board, so every possible place the program can move is highlighted.

For my board game (you can see what I currently have in development here: CoHackTest), I want to implement the same thing, but I'm not sure where to begin.

Each program is in a family called PlayerPrograms, which has 4 instance variables. The one that's relevant to our problem is the 'Move' variable, which stores the number of spaces our program will be allowed to move. The four instance variables are displayed upon program spawn:





Does anyone know how one might calculate the maximum movable spots? There is an unused sprite in the 'ObjectDump' layout called 'MoveIndicator' that I intend to use to display the movable spots.

Any, and I literally mean any, help or ideas on how to do this are appreciated.

BoardGame.capx

My initial thoughts are that I need an array to cover the entire game board spaces (each space is 64x64 in size), and then mark which spaces are empty and which ones are walls or currently occupied by another program.Excal2013-08-07 08:32:23
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,234

Post » Wed Aug 07, 2013 8:47 am

I would done something along these lines:

I have made a small drawing to help illustrate



I would create a Function, which checks the 4 fields surrounding a specific location. and then call it recursively if the field responds positively. The function should take a parameter on how many spot the player can move.

So, from the illustration.

Call the Function on the field where the player is. It checks all the fields marked by a "1". Inside the function there is a check if the field can be used. Subtract 1 from the "move" variable which was passed to the function call. If the field can be used and there are still "moves" left then call the function on the new location (in this case field marked by "1".
This recursive call will continue until there are no more moves left.

You can save in an array if the location could be moved to or not.

Something along those lines...
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Wed Aug 07, 2013 9:10 am

@cvp Thank you very much for the picture. This is starting to make more sense to me.

I'm going to start with the creation of an array to basically document all the spaces on the board, but now I'm getting confused. I haven't really worked with a nested For loop inside another For loop:



If I use loopindex, it gets the closest loop, right? So if I loopindex under the last For loop, it will be for the rows loop?
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,234

Post » Wed Aug 07, 2013 9:18 am

You can use loopindex("name of loop") to get the index you need.
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Wed Aug 07, 2013 10:09 am

Alright, I've implemented an array. The idea is that if a NoZone exists, the array will store a 0, if a program exists, it will store 1, and if the space is empty, it will store 2.

The array has a depth of 3, with the first value being the value stored above, the second is the X value of the loop and the third is the Y value of the loop.



The game downloads the JSON file of the array after the grid has been generated. However, there is a problem - right now the array is populating everything as 2, meaning it thinks every square is empty.

This can only happen if the checks for the walls is failing.

In Yann's maze generation script, which is used to generate the random game board, he offsets every wall by 0.5, and I'm not quite sure why:


Excal2013-08-08 07:46:57
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,234

Post » Wed Aug 07, 2013 1:16 pm

I've made some tweaks so now the array is correct for PART of the game board. There's a point where it starts saying every space is not a game board space, even though that is visually not true.



I've messed around with the array setup code to accommodate for the offset in Yann's random grid generator. Now I'm confused as to why this array input code works for PART of the grid but not the whole thing.

Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,234

Post » Wed Aug 07, 2013 4:00 pm

@Yann Was there a reason why all the NoZone sprites had to be offset by 0.5?
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,234

Post » Thu Aug 08, 2013 7:51 am

Here is a bit simpler version:

Boardgame movementvee412013-08-08 07:55:35
B
24
S
9
G
7
Posts: 756
Reputation: 7,312

Post » Thu Aug 08, 2013 7:53 am

@vee41, how great of you to grace my thread with your presence!

Joking aside, Firefly Village looks great so far!

Currently, the link you posted doesn't work. I'll give it a few minutes as you might be uploading.
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,234

Post » Thu Aug 08, 2013 7:55 am

Fixed it, there is always additional space after the dropbox link for some reason :)
B
24
S
9
G
7
Posts: 756
Reputation: 7,312

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests