Feedback wanted

Hi Andrew,

Thanks for all the help!

I have working corners! But i don’t yet have a way of checking if a corner is activated twice and thus needing to “triangulate” (cant find a good translation), and to know in what direction the triangle/corner should go. Do you have any tips on how to check this?

The latest code can be found here

Many thanks and if you ever would need something be sure to let me know!

Hi Bram,

Yes, if you could explain a bit more what you mean by “triangulate”, that would be helpful.  Perhaps you could point it out in the concept video that you posted earlier?

  • Andrew

Hi Andrew,

Thanks!

What i mean is, when you touch two blocks and they intersect the corner should be stomped.

Now when i activate the cornerObject it adds an extension to the block creating a longer block.

The cornerObject holds 4 triangles, when one block is active they are all visible thus creating the extension. But when an intersection block is active only 1 of the triangles should be active creating a “stomped” corner. 

I don’t yet have a way of knowing if a block intersects en what direction the triangle should go.

By direction i mean when a horizontal block is active and a vertical block (on the right side going down). the bottomLeft triangle should be active. When the vertical block would be goin upwards the topLeft triangle should be active etc.

In the video the effect is shown on 0:22 (there is one fault in the vid though, the touched block only adds an corner to the left side. it should be on both ends, then when the intersect is created the corner would change in a triangle)

Bram

Hi Bram,

Thanks, I understand what you mean now.  To detect which triangle within the corner to show, you could compare the x,y coordinates of the corner with the x,y coordinates of the adjacent blocks?  That would be able to tell you which direction the block is in relative to the corner (e.g., if it has the same x, but the y is 1 less, than the block is above the corner).

  • Andrew

Hi Andrew, 

I have the corners working properly now, i have added the neighboring corners to the blocks by linking them in a table (simply the number they have in the corner group). And then written a massif amount of conditionals to see what kind of corner needs to be active and when. I don’t think it’s the most efficient way of doing this but it works great  ;). 

Currently i’m trying to tackle the problem of checking when all the correct blocks are active. 

Do you have any idea’s on where to start on this subject?

Many thanks!

Bram

Hi Bram,

Welcome to Corona and to the forums.

I watched the video, and everything looked OK to me.  Can you explain in more detail what’s the issue you’re facing, i.e., what you mean by “the problem I’m having with the corners is that I don’t know how to ‘show’ and hide them when a certain object is ‘active’”?  In the video, the strokes did activate when the adjacent strokes were turned on.  Is that because the video is just a concept demo, but your code doesn’t actually do that yet?

  • Andrew

Hi Andrew,

Thanks for your reply! 

The video i posted is “unfortunately” a concept demo, what i have now is a corner object witch has four triangles in it, when all active they form a square, currently that is al i’m seeing now.

What needs to happen is when a “rectangle” is active (or visible) the corner knows if it needs to be filled or show as a triangle by checking if a neighboring rectangle is active.

What i don’t know is how i can let these objects know that they are neighbors of each other.

Thanks,

Bram

Hi Bram,

Thanks for the clarification, I understand now.

I see in your level2.lua file how you’ve represented the structure of your grid, and so your question is how can you tell whether a corner is next to a block.  There are two ways to do that (1) use the way you’ve represented the structure of your grid, in which case we’ll have to figure out the math that tells us when a corner is a neighbor of a block, or (2) represent the structure of your grid in a different way that makes it easier to figure out when a corner is a neighbor of a block.

For (1), let’s say you have a corner and you want to figure out if it’s adjacent to a block that’s on.  It seems to me like you’ll have to loop through all of your blocks and, for each one, compare whether (a) the corner’s coordinate is 1 different in x or y from the block’s starting coordinate, or (b) the corner’s coordinate is 1 different in x or y from the block’s ending coordinate (which is its starting coordinate plus width-1 and height-1).

For (2), here’s an alternative way to think about representing the grid.  Instead of having “blocks” and “corners” as separate things, you would have a single 2D array of the “cells” in your grid.  Each cell could have some custom properties such as whether it’s touchable, whether it’s currently on, etc.  In addition, you’d have a table that stores, for each row and column, how many cells high the row and column is.  Thus, you can tell when two cells are neighbors simply by comparing their 2D index (if either the x or y is different by 1, they’re neighbors) and you can render the grid by using the cell heights in your row and column tables.

  • Andrew

Hi Andrew,

Thanks for the help! Do you maybe know were i can find some sort of a tutorial on this topic? i think i need to see it and reed it four times to understand how it would work  :stuck_out_tongue:

Bram

Hi Bram,

Unfortunately no, I don’t think there would be a tutorial on something quite as specific as this.  But I’d be happy to try to help clarify – what part are you finding confusing?

  • Andrew

Hi Andrew,

thanks for the support!

i’m trying to implement it in my code (pushed to github), and i have something working:

blockX = event.target.x - (event.target.width/2) + event.target.width cornerX = cX\*gridWidth blockY = event.target.y - (event.target.height/2) cornerY = cY\*gridHeight if ( math.round(blockY) == math.round(cornerY) and math.round(blockX) == math.round(cornerX) ) then fill.alpha = 1 print("susses!") end

This is taking place in a loop that goes trough all the corners when a block is clicked.

problem is that “fill.alpha = 1” fills all the corners and not the specific one corresponding with the x and y pos.

Also the math i’m doing now only triggers the corner right to the clicked block. So what i’m thinking is to add a:

blockLeftX = event.target.x - (event.target.width/2) - gridWidth

that would correspond to a block on the left side. <-- EDIT: added and works, triggers two succeses for the left and right.

what i have now is working for the horizontal blocks but not yet for the vertical blocks. <-- EDIT: i can now detect left, right, top and bottom corners

problem is the filling and only showing the correct triangle

Bram

Hi Bram,

OK great, it sounds like you’re making progress.  So if I understand correctly, you can now get the corner to highlight when adjacent blocks are selected, just not the appropriate ‘triangle’ within the corner?

  • Andrew

Hi Andrew,

Well i can trigger the locations as in printing a response, but i do not have a proper way to highlight the correct triangels or square. What happens now is that i highlight the group in which the triangels are stored (fill.alpha = 1) and thus highlighting all the squares/triangels.

Bram

Hi Bram,

It sounds to me like, rather than setting the alpha of the entire group containing the triangles, you need to do it for just one triangle.  Which triangle to highlight depends on the direction of the adjacency to the neighboring blocks.

  • Andrew

Hi Andrew,

yes indeed, but i do not yet have a way of targeting the block or triangle directly.

For the block i use the “event.target” but i don’t know how to call the block or triangle.

thanks,

Bram

Hi Bram,

I’m not sure exactly what you mean, though I think I have an idea.  Do you mean that you’re able to target (refer to) the display group that is holding the corners (triangle images), but you’re not able to target (refer to) the corners (triangle images) themselves?  In this case, you can just make the triangle images a custom property of the group so that you can refer to them.

For example:

[lua]

– Create the display group

local cornerGroup = display.newGroup

– Create the display objects

local topLeftCorner = display.newImage(…)

local topRightCorner = display.newImage(…)

local bottomLeftCorner = display.newImage(…)

local bottomRightCorner = display.newImage(…)

– Insert the display objects into the display group

cornerGroup:insert(topLeftCorner)

cornerGroup:insert(topRightCorner)

cornerGroup:insert(bottomLeftCorner)

cornerGroup:insert(bottomRightCorner)

– Create references from the display group to the display objects for easier access

cornerGroup.topLeftCorner = topLeftCorner

cornerGroup.topRightCorner = topRightCorner

cornerGroup.bottomLeftCorner = bottomLeftCorner

cornerGroup.bottomRightCorner = bottomRightCorner

[/lua]

  • Andrew

Hi Andrew,

Thanks! But if i would target the group.corner wouldn’t all the corresponding corners react. For example if i would do bottomLeftCorner.Alpha = 1 then all bottom left corners would be visible?

Bram

Hi Bram,

My understanding is that you have a display group for each square on your grid that holds corners, and that within that display group, you have four triangles.  If that’s the case, then no, targeting a particular group’s bottomLeftCorner wouldn’t affect any of the other ones.

  • Andrew

Hi Andrew,

Well now i have a loop looping trough all the x and y positions of the cornerObjects placing them and adding them to a group. But if i would create a group for every cornerObject then i would not be abel to place them with a loop right?

Bram

Hi Bram,

OK, I think I see what you mean.  You mean that, currently, all of the corner objects are part of the same display group.

I don’t see why you couldn’t continue to use a loop though.  Any time you’re doing something repetitive in code, if you’re not using a function or a loop (or both), you’re probably coding it inefficiently.  If you think you can’t use a loop, then you might be misunderstanding how display groups work.

Display groups in Corona are very flexible, and so are Lua tables (display groups are just a special kind of Lua table).  You can insert display objects into a group, or you can insert other display groups and make a display group hierarchy.  In your case, if you wanted, you could have a display group for the entire area, containing two groups – one for blocks and one for corners.  The corners group could in turn contain X display groups, one for each of the X corners you have.  Each of those groups could in turn contain four triangle display objects like in my previous post.

That’s just one way of doing it (and not necessarily the best way either).  The whole purpose of a group is to be able to manipulate all of its contents at the same time (positioning, scale, etc.).  Since it’s hard to imagine a case where you would want to change all of the corners at the same time, I don’t see why you’d need a display group to hold all the corners (or all the blocks, for that matter).  On the other hand, having a group for the entire grid probably still makes sense, in case you want to adjust certain properties quickly (make it fade in/out, scale it, etc.).

  • Andrew