How do I make a game like Flood ?

Get help using Construct 2

Post » Wed Aug 07, 2013 8:11 pm

Hello, I've done the tutorials and got a hang of this nice software. Now I want to try something "harder" .

I want to make a Flood type game but I don't know where to start.

Example 1: http://floodit.appspot.com
Example 2: https://play.google.com/store/apps/details?id=com.virtuesoft.superflood

Where or how should I start ?
B
49
S
15
G
6
Posts: 534
Reputation: 7,195

Post » Wed Aug 07, 2013 9:45 pm

take a look at arrays. You could build an array of the gameboard.
You can then check the neighbor field for there color.

You could also find some inspiration in the FAQ section. I think you could borrow some ideas from the one called Tile "digging" type game
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Thu Aug 08, 2013 8:36 pm

Ok, I've followed this tutorial:
https://www.scirra.com/tutorials/307/arrays-for-beginners/page-3

It should do the following:
- make an array of 25 elements (Width=5, Height=5)
- give the value of each cell to 1 or 2
- create a star object based of the value of the cell (1=RedStar, 2=BlueStar)

What have I done wrong ? Here is the capx:
https://mega.co.nz/#!d5ZR1I7D!AXcNcmFIAS9Ivp7Ky-oNsnRJ0o5vgvWHHCMm0OmqNekTGeorgeMihai2013-08-08 20:38:02
B
49
S
15
G
6
Posts: 534
Reputation: 7,195

Post » Fri Aug 09, 2013 7:23 pm

?
B
49
S
15
G
6
Posts: 534
Reputation: 7,195

Post » Fri Aug 09, 2013 8:00 pm

ImageImageImage
B
71
S
21
G
233
Posts: 3,697
Reputation: 130,370

Post » Fri Aug 09, 2013 9:57 pm

[QUOTE=blackhornet]http://blackhornettechnologies.com/Construct2Stuff/StarMap_BHT.capx[/QUOTE]

Thank you, I've found the solution to my problem here:
http://www.scirra.com/forum/random-number-between-2-values_topic46161.html

Basically the random() function generated non-rounded numbers like 1,23456

Thanks, this was my fix before I saw your example.


Also, nice way to load and destroy at start the sprites (I've put them outside the screen, but your solution is better)
B
49
S
15
G
6
Posts: 534
Reputation: 7,195

Post » Fri Aug 09, 2013 10:26 pm

You may want to consider just using one sprite with four frames, instead of four separate sprites. Once you start doing more things, you'll probably end up using a Family anyway, to achieve the same thing, otherwise you are going to end up doing everything four times, for each separate sprite.
ImageImageImage
B
71
S
21
G
233
Posts: 3,697
Reputation: 130,370

Post » Sat Aug 10, 2013 7:08 pm

Thanks, I will use separate sprites.

Now the "funny" part: How do I convert the following code (recursive function) in Construct 2 ?

Pseudocode
[CODE]Flood-fill (node, target-color, replacement-color):
1. If the color of node is not equal to target-color, return.
2. Set the color of node to replacement-color.
3. Perform Flood-fill (one step to the west of node, target-color, replacement-color).
    Perform Flood-fill (one step to the east of node, target-color, replacement-color).
    Perform Flood-fill (one step to the north of node, target-color, replacement-color).
    Perform Flood-fill (one step to the south of node, target-color, replacement-color).
4. Return.[/CODE]

Code
[CODE]replaceColor = 1 // select value when clicking on a color button (values 1 to 5)

private void FloodFill(Point node, Color targetColor, Color replaceColor)
    {
      //perform bounds checking X
      if ((node.X >= CANVAS_SIZE) || (node.X < 0))
        return; //outside of bounds

      //perform bounds checking Y
      if ((node.Y >= CANVAS_SIZE) || (node.Y < 0))
        return; //ouside of bounds

      //check to see if the node is the target color
      if (pixels[node.X, node.Y].CellColor != targetColor)
        return; //return and do nothing
      else
      {
        pixels[node.X, node.Y].CellColor = replaceColor;

        //recurse
        //try to fill one step to the right

        FloodFill(new Point(node.X + 1, node.Y), targetColor, replaceColor);
        //try to fill one step to the left
        FloodFill(new Point(node.X - 1, node.Y), targetColor, replaceColor);
        //try to fill one step to the north
        FloodFill(new Point(node.X, node.Y - 1), targetColor, replaceColor);
        //try to fill one step to the south
        FloodFill(new Point(node.X, node.Y + 1), targetColor, replaceColor);

        //exit method
        return;
      }
    }[/CODE]

Or is there a better implementation of the Flood fill algorithm from here:
http://www.codecodex.com/wiki/Implementing_the_flood_fill_algorithm
http://en.wikipedia.org/wiki/Flood_fill
B
49
S
15
G
6
Posts: 534
Reputation: 7,195

Post » Sat Aug 10, 2013 10:28 pm

Ok, I've found here a Flood fill example but I have trouble understanding it:

http://www.scirra.com/forum/in-something-enclosed-or-is-it-just-me_topic53841_post340661.html#340661

A little help ?
B
49
S
15
G
6
Posts: 534
Reputation: 7,195

Post » Sat Aug 10, 2013 11:38 pm

ImageImageImage
B
71
S
21
G
233
Posts: 3,697
Reputation: 130,370

Next

Return to How do I....?

Who is online

Users browsing this forum: Anonnymitet, gamecorpstudio, NECRONOMICRON, plinkie and 25 guests