Can you guys help me with this please?

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hello everyone, as you can see in the image, I would like it to create another cannon around it (because there is already one in its place)

    How can I make it so that when I touch it, it creates a cannon only in the green areas that are around it and not outside the area?

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The most straightforward way would be to add a condition that checks if mouse/touch is overlapping a checkmark before doing the place action.

    How are you displaying the checkmarks? You can use the exact same logic to see if it is a valid location to place a cannon.

  • I used the checks just for demonstration, I would like that when I click on the green area, it creates a cannon, but if I click on a place that already has a cannon, it creates one next to the green checks.

  • Ok, so there's two parts to this. There are a few ways to go about it, but without knowing if you have a grid or array system in place already, I'll be using the system condition Pick overlapping point.

    On clicked, if the cursor is not over a cannon, check the 8 spots around the clicked location to see if a cannon exists (9 really, just to make it easier to loop through, even though we already know there's no cannon where we clicked). We'll check each overlapping point for a cannon, and pick it if it's there. If there are any (picked count > 0), then place the cannon. We'll use a system for loop for x and y location, from -1 to 1, multiplied by the width/height of the cannon (or your grid size basically) to go through each position. If there are no cannons picked/found, that means that was not a valid place to put a cannon and nothing happens.

    + Mouse: On Left button Clicked
    + Mouse: [X] Cursor is over Cannon
    + System: For "x" from -1 to 1
    + System: For "y" from -1 to 1
    + System: Pick Cannon overlapping (Mouse.X+LoopIndex("x")×Cannon.Width, Mouse.Y+LoopIndex("y")×Cannon.Height)
    + System: Cannon.PickedCount > 0
    -> System: Create object Cannon on layer 0 at (Mouse.X, Mouse.Y), create hierarchy: False, template: ""
    

    Instead of creating at mouse x and y you should use whatever snapping system you have to align it to your grid.

    If there is already a cannon where we clicked, we will be (randomly I'm assuming?) placing a cannon in one of the 8 spots around it, that doesn't already have a cannon. We'll need local variables to keep track of which position we randomly chose, check those positions, and then only if it's valid place the cannon and stop the loop. There will also need to be a way to stop the loop if every spot around the clicked cannon is unavailable. This part is significantly more complicated, haven't quite got it working yet. Maybe using a permutation table with the advanced random plugin would be the cleanest way instead of just randomly picking spots around the target...

    dropbox.com/scl/fi/mszw7bwp4vvglgmjo9siw/neighborcheckexample.c3p

  • Thanks for the reply, I'm using touch instead of mouse, I'll test it soon

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)