Pulstar's Forum Posts

  • this sounds good but if put in

    array.indexof(emptyvalue)

    wouldn't the items just get set to going into slot 1 even if there is an item there.... seems like i need some setup to check which slots have items and which are free

    How do mark a slot as empty now? If you have not filled your empty array of size(x,y) with anything there should be a "0" in every empty slot. Look for that 0 with array.indexof(0) and you are good to go. You can also mark empty slots differently, if you want to mark some item with the number 0. But then you would need to fill the array with that value on creation and be careful that only runs once when a new game is started and not on layout start or anything (switching layouts would then delete all values from the array). 0 is a safe bet.

  • Plug whatever is the value in an empty slot in your array (I assume you use 0) into the "indexof" expression of the array object like so:

    array.indexof(emptyvalue)

    This expression will return the index at which the first X axis element matching the criteria is. Or -1 if an empty slot is not found. So in your case you will get the number of the first empty slot, in which you can put an item. Or if the result is -1 you can do some kind of "inventory is full" message.

  • The shattering into pieces part can be done by destroying the crate on collision with the bullet and creating crate bits at its former position.

    Overall you need to store the bullets angle on impact and just apply it +/- any random angle offset (to get a cone effect) to newly spawned crate pieces, which should have bullet behaviour. You can also randomly set their speed and accceleration (negative to slow down!) to give the impression some are heavier and some are lighter.

    Here's an example. The simple square cratebits sprites could be changed for actual fragments of your crate sprite, you could do multiple frames for the crate bits, disable the animation by setting the animation speed to 0, and upon creation assigning a random frame.

    https://www.dropbox.com/s/3vluoo10v8ncp ... .capx?dl=1

  • On hole creation assign each hole a unique ID value (or you could just store their IID, I prefer to use my own ID variables rather than the system ones). Store it (push back) that value as a new array element at the X axis, in an array with a default width of 0 and a height of 2. After all holes are created, assign a random number for each X array element at Y=0 (Y=1 will still store your Hole.ID). Sort that array by axis X (it will sort only by values at Y=0, so the random ones) and create objects in a loop that goes through the first three elements and picks each hole by the ID stored "array.at(loopindex,1)".

    The below example will work so long as you have just 3 colours. If you want to pick 3 random colours out of a larger set of colours, things will be a bit more complicated (personally I would do that with yet another array).

    https://www.dropbox.com/s/kv8uhun8anyjo ... .capx?dl=1

  • There is also interactive (adaptive) sprite/tilemap example for level editor:

    Yes, but it does not show the "drag to show positions before creating" mechanic used commonly in strategy/simulation games for building roads or walls (which the OP wanted to know how to do), such as that found in Rimworld, SimCity and the rest mentioned by the OP. You end up with lots of "accidental" wall/road tiles the way that example works and that is just annoying for the end user.

    It is still a very cool interactive example for bitwise auto-tiling though and the tile creation method is sufficient to show how auto-tilign works.

  • Kazan I found a fairly simple way of doing this for an isometric grid, probably far simpler than my original solution. It involves drawing a ray for overlapping tiles. It is possible to make "rigid" directional dragging by setting the ray's angle to the closest "approved" angle based on the one calculate from angle(mouse.x,mouse.y,buildcursor.x,buildcursor.y), so that walls only go along a straight line perfectly aligned with isometric grid lines.

    Might do a tutorial on this in the future. Could be useful if somebody wants to do a level editor.

    https://www.dropbox.com/s/au5wupgkvwdbx ... .capx?dl=1

  • Look at the "set position to object "hole" action. That whole event is not picking any hole in particular via the conditions. Construct 2 events work sometimes in a way where the first instance of an object is picked for an action when meeting event conditions*. This is why Tuiii wrote you need to add a "system: pick a random instance" condition to it. Add it under the "For "create x objects" condition and it should work.

    Edit: *for some actions where the engine expects to use just one object instance instead of multiple from a picked set.

  • I didn't mention it in my original post because I didn't want to bog it down with details but I am indeed trying to make something like this work with an isometric grid So yeah, this will take some research and study. This is a great help.

    Again, thanks. Appreciate you taking the time to help

    No problem. I might throw you an isometric grid solution today after I get back from work. I have a fairly good idea to do it, as outlined under the EDIT in my previous post.

  • I think it would be simpler to ditch turret behaviour altogether in your case, have each facing direction as an animation frame (or separate animation) which you switch depending on the angle calculated between the target's position and the turret's position.

  • I did something like this long ago, when I was ambitious and dreamt to clone Dwarf Fortress, in Space (this was a few years before Rimworld, back when I first toyed with the free version of Contruct 2). The good thing that came out of that foolish quest was learning how to do construction UI and how to use arrays to store jobs/orders for multiple units such as resource harvesting>go to stockpile when full>go harvest some more (with finding idle units and prioritizing them at that). Also I did some wall auto-tiling, fun times.

    The trick is to use a tiled background (unless you are using anything other than a square grid) for the build cursor*, but set its position to the grids used by your tilemap by calculating the closest grid-aligned position (gridsize*round(mouse.x/gridsize)). You stop the cursor from following the mouse when the button is held and you set the width and height as a multitude of your grid width/height depending on mouse position versus build cursor position. Once the button is released, you calculate the direction and number of walls to be generated and plug the values into a wall creating loop.

    https://www.dropbox.com/s/1njelck019iqk ... .capx?dl=1

    EDIT:

    *For other grid shapes, including isometric or hex, things get trickier. In such cases you would need to dynamically spawn wall section cursor (ghost) sprites when dragging along a given axis. Or, if you are feeling clever, you could create the maximum visible number of such sprite, index them from 1 to whatever, and set them to invisible by default. Then, whenever dragging is on, you would arrange as many sprites as needed along the line that has been dragged and make them visible after they are positioned. Once dragging is finished you make the invisible. Less messy than creating/destroying ghost wall sections all the time.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Create a variable for kills to next level.

    On Enemy destroyed> add 1 to kills.

    kills>=kills to next levels then add 1 to level, wait 0 seconds, subtract kills to next level from kills, wait 0 seconds, add 2 to kills to next level.

    I added the kills and other variables to the player object.

    Probably should add the system condition "trigger once while true" to the kills=killstonextlevel event.

    https://www.dropbox.com/s/t33wvsdkahh60 ... .capx?dl=1

  • Did you make sure the mask is on the same layer and that the layer has force own texture set to true? Please note that these blend modes do not show in the editor, the effect is only visible in preview.

    Also z-order of the mask is very important.

    Edit: set opacity to 0 the mask's. Very important!

  • The solution should work for any number of nodes. Although the execution time should be proportional to the square of the number of nodes.

    I think what is happening is the pontifex function not firing. Either because node booleans were not reset to false after new lanes were generated or because the conditions for it firing did not work. I did a few dozen runs of this and did not encouter the issue eith the version i attached to my previous post. Unless that is an old file.

    Send me the link to your capx via PM. I wil check what the issue is in 10 hours when I get home.

  • I solved the disconnected isles issues. Red lanes are lanes created by the gap-bridging logic I created:

    Basically I added another boolean to nodes, which is only set to true after the connect function is fired for nodes connected via lanes to the initiating node. So if the number of nodes that are checked and the number of nodes that are connected is the same, but it is not equal to the number of total nodes, it means that unconnected nodes exist. Then I launch a "Pontifex" function that finds connected-unconnected node-pairs that have the least distance between their nodes. It retrieves two such pairs, creates lanes between them and lanes between the second least distant unconnected node, relative to the connected node of the pair. So 4 lanes per gap with two choke-points per gap. The overlap function may delete a lane or two, but it is guaranteed to create at least one lane per every gap (two for most).

    It then goes back before the connection checking functions and runs them again. Once it finds that checked nodes=connected nodes=total nodes it stop running the generation logic.

    https://www.dropbox.com/s/d1qsk715wkmtz ... .capx?dl=1

  • A second question, how do I make this static once it's generated?

    For example, in a run of the game I would need to generate 10 of these on the start of the game and I would need access to these during the game.

    They already are static, so long as you do not run the generation events again or change layouts in game. Any loss of nodes on layout changes can be avoided by adding persistent behaviour to all randomly generated objects. You just need to remember that when you switch back to a layout all initial objects (stuff you place/see in the editor) will also be placed. So you need to check carefully if everything is where it should be and no new objects appear. Or worse, so you don't delete already existing nodes when deleting initial objects.

    Alternatively, since you just need it for a map where you just pick it once every 5-15 minutes and do nothing else, you can have the sector branching map a separate layer above the fully random node map. Hide that layer when it is unneeded (FTL does this with the star map I think). However that approach has a different problem. You need to add some conditions to all clickable objects/nodes so that nothing happens when the branching map is visible or invisible. On clicked/touched events for invisible sprites to register.

    Personally, as my current project is using lots and lots of window/screen for procedurally generated spaceships. I add a boolean to all button objects, if say ship weapons or ship cargo screens are visible (ship window button is set to true) I do not allow selecting a different ship to work as the ships are on a layer behind the window screens so you could click-through them.

    If you go with the layer approach, I also recommend naming your layers and always using the string/text name in events (not the layer number), as adding deleting any layers of your project changes the layer number order and it becomes a chore changing all the numbers to the current ones and keeping track of them.