R0J0hound's Forum Posts

  • Updated links in my original post. It’s more of a way to do keyframe animations. The tweening from one thing to another is only a small part of it.

  • It's "scroll to player.x, player.y" if unbounded scrolling if off. If it's on, it would be:

    scroll to clamp(player.x, OriginalWindowWidth/2, LayoutWidth-OriginalWindowWidth/2), clamp(player.y, OriginalWindowHeight/2, LayoutHeight-OriginalWindowHeight/2)

    But eh, it's fundamentally the same, except the layout sizes are different, and the result of some of the calculations are saved to variables. Coding doesn't have to be so verbose.

  • You could do something like this to generate it in one go. It's also if you don't care about the upper bound.

    array: set size to (0,1,1)
    
    set v0 to -1
    set v1 to -1
    set v2 to -1
    
    repeat 10 times
    --- set v2 to v1
    --- set v1 to v0
    --- if v2 +1 = v1 
    ------ add int(random(2,10)) to v0
    --- else
    ------ add  int(random(1,10)) to v0
    --- array: push v0 to back[/code:3q6v6xg8]
    
    But if you want all the values to be within a range you can do the following.  Note: this will hang if you can't possibly have 'num' values without 3 consecutive values below 'maxVal'
    Anyways, barring any typos.
    [code:3q6v6xg8]array: set size to (0,1,1)
    var num =10
    var maxVal = 30
    
    repeat num times
    --- array: push int(random(maxVal)) to back
    
    array: sort
    
    //// get rid of duplicates by making consecutive
    var shift=0
    for "" from 1 to num-1
    --- add shift to array.at(loopindex)
    --- if array.at(loopindex) = array.at(loopindex-1)
    ------ add 1 to shift
    ------ add 1 to array.at(loopindex)
    
    /// get rid of three consecutive numbers sequences
    set shift to 0
    for "" from 2 to num-1
    --- add shift to array.at(loopindex)
    --- if array.at(loopindex) = array.at(loopindex-1)+1
    --- and if array.at(loopindex-1) = array.at(loopindex-2)+1
    ------ add 1 to shift
    ------ add 1 to array.at(loopindex)
    
    //// shift stuff back down so the last number in within the maxVal
    var i=0
    while
    array.at(num-1) >= maxVal
    --- set i to int(random(1, num))
    --- if array.at(i) > array.at(i-1)+1
    --- and if array.at(i-1) =/= array.at(i-2)+1
    --- and for "" from n to num-1
    ------ subtract 1 from array.at(loopindex)[/code:3q6v6xg8]
    
    edit:
    bruno's example would fail if z ended up being 0.  Also it could still give three consecutive numbers.
  • It’s getting a color off anywhere on the game canvas that’s not reliably possible with webgl without some changes to the runtime. Getting a color off the pasture texture with webgl however is possible, and actually the webgl snippit in that link is close to how it would be done.

    It’s not something I’m willing to do though. There are too many more fun ways to spend my time.

    Anyways, cheers to black hornet for porting it to a c3 addon.

  • If you give the object two instance variables: radius and ang

    Then you can do this

    Moon: on created

    —- moon: set radius to distance(planet.x, planet.y, moon.x, moon.y)

    —- moon: set ang to angle(planet.x, planet.y, moon.x, moon.y)

    Every tick:

    —- moon: add 100*dt to ang

    —- moon: set position to planet

    —- moon: move self.radius pixels at self.ang degrees

  • I fiddled with it a bit more, didn't find any worthwhile changes.

    On a performance note I get 6-7 fps on my machine. I made the entire thing in javascript completely independent from Construct and got 22 fps, but that's also with a 360x360 grid instead of 50x50 and I'm not doing anything fast with the rendering.

    I found that fun. I'm probably going to do that sort of thing more and more. No engine, no editor, completely diy, and no limits. Completely carefree, and it actually isn't harder and doesn't take much longer than doing it in a game maker. Sorry for the off-topic tangent, it doesn't help with the op in relation to this software.

  • I don’t think that will work. You’d have to make sure to only update it if it won’t be touched again in the loop. Then you’d also have to update the remaining ones after the loop finishes. I think it’s overly complicated for what you’re doing.

    Even at 60fps the water will spread slowly. This was so water wouldn’t go negative. Never letting it go below zero is a fix to that but the total amount of water would change.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • bbjGames

    I actually didn’t measure if it’s that much slower, so I’m probably mistaken. It does move slower but that’s just to prevent water from going negative. There is likely other ways to do this that are faster.

    The other game wasn’t made in Construct so there’s lots of things he could have done to make it faster.

    Events are basically interpreted, so there’s that. If you made a plugin with JavaScript to do the water calculations there it would be a lot faster since JavaScript is jit’d into machine code.

    dop2000

    I guess I’m not seeing what you mean from the pictures. The water will try to flow downhill when it can. If too much water is added to one spot the water spills over in every direction. Given a bit of time it should settle down to the valleys. So if anything it solves it too slow. I haven’t based this on any existing algorithms so I’m probably not doing many parts of it the right way. Even after posting it there are things I want to try to do differently.

    The idea behind it is simple enough. I take two adjacent cells and calculate how much water to move from the higher one so the two are level. If there is enough water that is.

    The tricky part is doing that with the four adjacent cells at once and keep things unbiased. I’m also trying to keep the total amount of water the same as it moves around. The only problem so far is it flows too slow in large quantities, but given enough time it will level out.

  • Here's an unbiased version. It required looping over the array twice, which was bad for performance.

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

  • It compares each two consecutive values so with repeat 50 the last value would be compared with nothing. You wouldn’t notice it unless there was water at the edge. I think it would just cause it to drain.

    On another note, I need to rework the algorithm. I’m modifying the array as I loop over it and that causes a bias. In the 1d version, water flows more to the left than right at first, but it’s visually tolerable when adding a low amount of water at a time. The 2d one is distractingly worse, water flows to the top left more than other directions. A fix is to not change anything till the end of the loop but there’s a bit more to it.

  • resdesign

    This is a plugin for Construct Classic, not Construct 2.

  • I had to give this a go too, even though dop's example is pretty cool. I found it helped to solve the problem first with 1d water:

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

    Then do 2d water later.

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

    Anyways, it's something you can play with and see if any of the ideas help.

  • mekonbekon

    I got a wild hair and tried an attempt. Only works if the object is onscreen because C2 doesn't draw off screen stuff. So the next step would to try something complicated to trick C2 to always draw in the cases we want. But that's ugly and hacky, plus that leads to an ever increasing number of side effects that would have to be handled. Baw I say, I like the event version better.

    roracle

    Those things are scrolling related, that's different than visually wrapping the layout from one side to the other.

    Ajbael

    The physics behavior doesn't work well when you set positions like that. I think the solution is what you're doing, except you need to wait till the next tick to restore the velocities. Anyways it's not something I want to re-figure out, instead you could use another physics behavior such as chipmunk, which works fine if you move objects like that.

  • An array is just a large amount of values. For a rewind just save the position of everything every tick. It doesn't make things slow.

    For example look here. It's basically just one action to record, and one action to rewind. Performance will be the same if you just started recording or have been playing for an hour.

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

    Probably an array per object you want to rewind will do.

    It's based on this older example I made that makes a recording of every attempt.

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

    Now, if you can use lerp if you want to rewind slower than a frame at a time or want to account for variances in frame time. It's a bit more involved and probably isn't necessary.

  • A plugin probably could be made. The objective is to draw objects twice. So it could be done by replacing the draw function with two calls to the old draw function with two set positions in between. It’s not something I’m interested in doing.