R0J0hound's Forum Posts

  • So the qarp(a,b,c,t) expression is the basis for that. With one for x and y you will get a quadratic Bézier curve. A and c are the endpoints and b is a control point in the middle. Typically the curve will not touch the middle control point but newt is utilizing a little additional math to have the control point be on the curve.

    Anyways, the t is a value from 0 to 1 to get any point along the curve.

    Basically this is how you’d create points along the curve.

    Repeat 10 times

    — create at qarp(ax,bx,cx,loopindex/10), qarp(ay,by,cy,loopindex/10)

    Newts example draws lines between them with canvas and adds them as waypoints for the move to behavior to move along the curve. Conceptually you can think of the curve getting approximated by multiple lines that are moved along in series. That was done so the speed would be constant. If you alternately just changed t over time and used the qarp expression you could have a more precise curve but the speed would vary.

    The shape of the curve is limited by those three control points. You could use cubic() instead to get one more control point to give finer control. There are other ways to do curves between points too, but you’d have to write the whole equation out.

    All that in the example was just expressions. No js used there.

  • You can use the distort mesh to make it. This example is slightly out of date.

    construct.net/en/forum/construct-3/your-construct-creations-9/example-mesh-distort-sphere-161470

  • So basically you’d just need to set the z when you create it much like the velocities. For example here it starts with a z of -150. Then you can make it stop on the ground by comparing the z with 0.

    every 1 second
    — create shadow at random(640), random(480)
    — create ball at shadow.x, shadow.y-150
    — set z to -150
    
    Every tick
    — set y to self.y-self.z
    — set position to self.x+self.vx*dt, self.y+self.vy*dt
    — add 200*dt to vz
    — add vz*dt to z
    
    Z>0
    — set z to 0
    — set vz to -0.5*abs(self.vz)
    
    Every tick 
    — set y to self.y+self.z
  • You’ll have to refer to the documentation for how to do it.

    Basically you’d access the runtime object, find the list of object types from that, then a list of each instance for each type. Then you can either compare the x y or calculate the distance with:

    var dx=x1-x0, dy=y1-y0

    Math.sqrt(dx*dx+dy*dy)

    Or maybe the sdk has a distance function you can use. Anyways that’s the gist of it.

  • Here’s the rough idea. You’d need to get the actual time from the system. One way to get that is with the JavaScript Date.now() which gives the number of milliseconds from some fixed date.

    Here I specified that clicking a button will make the timer last 5 seconds.

    Then you can do a comparison to see if the timer has passed the endtime.

    All that’s left is to save and load the endtime to local storage when the game starts and closes. You’ll have to consult some docs how that’s done as I haven’t messed with it in a while.

    var endtime = 0
    
    On start of layout
    — set endtime to webstorage.at(“endtime”)
    
    On button clicked
    — set endtime to browser.execjs(“Date.now()”)/1000+5
    
    endtime >= browser.execjs(“Date.now()”)/1000
    Trigger once
    — do something
    
    On end of layout
    — web storage save endtime to key “endtime”
  • Something like this should work. Being mirrored means the width is negative. Using cos on the moving angle gets the horizontal movement. The ?: expression sees if the horizontal motion is negative.

    Every tick:

    — set width to abs(self.width)*(cos(self.moveTo.movingAngle)<0?-1:1)

  • Arrays are basically just a way to store a lot of values.

    If if just want a list of values you can use it as a 1 dimensional array with size (count, 1, 1).

    Another common use, like in that tutorial, is to do a 2d array to have a value for every tile on a grid, or one value for every pixel of an image. So size (width,height,1).

    Also in that tutorial it uses an array to store a list of the x,y,width and height of multiple rooms. So the size is (roomCount,4,1). 4 because there are four values: x,y,width,height.

    You just need to keep in mind what those values mean. So for example you wanted to get the width of the 10th box in that list it would be:

    Array.at(10-1, 2).

    It’s 10-1 instead of 10 because things count from 0 instead of one. And the 2 is for width. 0:x, 1:y, 2:width, 3:heights.

    However, don’t tell me that’s easy to read. It’s rather obscure what it means at a glance.

    All that tutorial is doing is:

    1: place multiple different sized rectangles on the layout.

    2: make paths that go horizontal then vertical between them.

    3: draw it to the tilemap. Basically amounts to looping over the tiles under the rooms and paths.

    4: once on the tilemap you can check the surrounding tiles to mark the ones on the edge as walls.

    4b: in a similar fashion it colors the floor differently depending on what surrounds it.

    Using an array instead of a tilemap directly is merely a preference.

  • Cool. Glad it was useful.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That formula doesn’t look familiar but possibly. Most of the formulas I post are either found online or just multiple formulas combined together and simplified.

  • I will say I downloaded one of those so called english word lists and most of them don't look like words to me, but anyways.

    Here is a test to load such a wordlist into a dictionary without hanging the browser. Once loaded it's as simple as the "has key" dictionary condition.

    dropbox.com/s/in4dx5x2z03yvqc/dictionary_load.capx

    As far as speed goes, its way faster to have the words in a dictionary instead of an array if you need to find if a word is in it.

    With an array it would have the worst case of having to look at every single word before finding it.

    You can do a binary search since the words are sorted to improve that. Maybe a worst case of checking 40% of the words.

    With a dictionary it finds the word more or less directly.

  • Here's the equations. t is how long you want it to take to get there in seconds. And mouse is the destination spot. Probable can put it into a function for easy use.

    var t=1
    On click
    -- set speed to distance(0,0,(mouse.X-Self.X)/t, (mouse.Y-Self.Y)/t-0.5*Self.Bullet.Gravity*t)
    -- set angle of motion to angle(0,0,(mouse.X-Self.X)/t, (mouse.Y-Self.Y)/t-0.5*Self.Bullet.Gravity*t)
  • Hi,

    Here is a capx that finds the floating chunks. It's probably not the same as your project but maybe some of it would be a useful reference.

    dropbox.com/s/ubx5knq6ulww365/voxel_destroy.capx

    The way it finds the floating chunks is similar to your way. It starts by marking the bottom layer, then visiting each marked and marks their four neighbors. It knows it's done when all the marked have been visited. You then know all the floating blocks are the ones that aren't marked. I utilized an else for that.

    An idea I utilized to make it faster is to use a lookup array with the uids of the objects in a grid. So you can find what immovable block is in a location with lookup.at(int(x/32), int(y/32)). This is much faster than relying on the overlap checks that construct provides with that many objects. A side effect of this is we can make the floating island faster too.

    Another idea to make it render faster is to use a tilemap for all the non moving tiles and just create the movable sprites as needed. The drawback is you'd have to do the floading blocks check in a different way.

    Anyways, maybe you can use some ideas from that capx.

  • Looks good. I like how you can drag them around. I'm not sure why you can't drag number 1 though. Glad it was helpful.

  • I mean you can find the bounding box that surrounds all the sprites, and change the canvas size to that.

    var x0= 10000
    var x1=-10000
    var y0= 10000
    var y1=-10000
    
    for each sprite
    -- set x0 to min(x0, sprite.bboxLeft)
    -- set x1 to max(x1, sprite.bboxRight)
    -- set x0 to min(y0, sprite.bboxTop)
    -- set x0 to max(y1, sprite.bboxBottom)
    
    set canvas size to max(640, abs(x1-x0)), max(480, abs(y1-y0))
    scroll to (x0+x1)/2, (y0+y1)/2

    To pack all the sprites to fill the layout like that you may get good results if you use physics with prevent rotation to try to keep things inside.

  • It basically involves pushing overlapping boxes out of each other repeatedly until they don't overlap. This differs from newts a bit. It more closely matches the gif and runs till they are only slightly overlapping. as a final step you could make the sprites slightly smaller so they won't be in contact at all.

    dropbox.com/s/bcyzlitqf5i6kp0/box_push_out.capx