Yann's Recent Forum Activity

  • breackzin

    Indeed you're right, you can do the same thing using pick nearest.

    But still a circular sprite won't really be usefull here

    Here is how it looks with pick nearest:

    nearestInstance.capx

    And if you know a bit how it works internally, this version is a bit less efficient than the one I provided.

    And also, since the question was "how to compare distance between 2 instances", my code was merely an example of a specific use case.

    You can do other interesting things like range checking or other fancy stuff (:Yann2013-05-23 19:13:29

  • breackzin

    How would that give you the closest instance ?

    Also if you want something to be invisible you better set it to invisible instead of setting the opacity to 0 so it's not processed by the drawing function.

  • Joannesalfa

    This code is an example of how to check distance between each instance to find the closest one for each of them.

    So printing any distance in a text object doesn't make any sense.

    closestInstance.capx

    That's what you can use it for.

    You can also use the dist variable which is just the distance between the current and the closest. And it is used during the loop to get to the closest one.

    Answering the question "How can I check distance between 2 instances?" is closely tied to what you want to use this comparison for. So I had to provide such case as an illustration.

    (also you made a mistake, when I write "!=" it means "not equal to")

  • Joannesalfa

    Hmm after carefull reading this code shouldn't work

    Here is a corrected/commented version

    // two nested loop to compare each instances to each other
    + System: for "first" from 0 to sprite.Count-1
         Local number firstPass = 1 // tell if it's the first pass (to set default "second" as closest)
         
         + System: for "second" from 0 to sprite.Count-1
         + System: loopindex("first") != loopindex("second") // avoid comparing with itself
            Local number tmpDist = 0 // will hold the distance between the current "first" and "second" instance
            -> System: set tmpDist to distance(sprite(loopindex("first").X,sprite.(loopindex("first").Y,sprite(loopindex("second").X,sprite.(loopindex("second").Y)
    
            + System: Pick Sprite instance loopindex("first") 
                // first time we check this "first" instance
                // the "second" is set as the closest by default
                //  OR      
                // the current distance kept in sprite.dist is greater than the current one
                // it means the current "second" one is closer, so we overwrite the values with this one
                + System: firstPass = 1  
                   OR
                + System: Sprite(loopindex("first").dist > tmpDist  
                     -> System: set firstPass to 0
                     -> Sprite: set closest to Sprite(loopindex("second)).UID
                     -> Sprite: set dist to tmpDist[/code:1w6j1y72]It probably looks better without all those comments actually [code:1w6j1y72]+ System: for "first" from 0 to sprite.Count-1
         Local number firstPass = 1 
         
         + System: for "second" from 0 to sprite.Count-1
         + System: loopindex("first") != loopindex("second")
            Local number tmpDist = 0
            -> System: set tmpDist to distance(sprite(loopindex("first").X,sprite.(loopindex("first").Y,sprite(loopindex("second").X,sprite.(loopindex("second").Y)
    
            + System: Pick Sprite instance loopindex("first") 
                + System: firstPass = 1  
                   OR
                + System: Sprite(loopindex("first").dist > tmpDist  
                     -> System: set firstPass to 0
                     -> Sprite: set closest to Sprite(loopindex("second)).UID
                     -> Sprite: set dist to tmpDist[/code:1w6j1y72]
  • Try Construct 3

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

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

    you can download release 130 through steam by going

    Library > All Software

    Right click on Construct 2 > Properties > Betas > Select Beta- Construct 2 beta updates and close

    Steam should automagically download the last beta (:

  • <img src="http://images.devs-on.net/Image/xRvwh5FTTdcVl6Z6-SROPSGoogleChro.png" border="0" />

    As you can see it's on chrome, and the zoom factor is 100% though it doesn't really change anything.

    "Movement: Arrow keys or..."

    I don't have the end screen 'cause well... I would have to replay the game (:

    You probably just need to extend the text object's size to be on the safe side.

  • thatjoshguy

    Heh nice you're welcome (:

    You probably already thought about this but as a nice mecanism, having to walk slowly/silently (maybe holding shift) when you are just behind an enemy to avoid being "heard" could be a nice addition (:

    Also you should probably resize your text object, it seems some words get clipped

    Like

    "Move: Arrow Keys or ..." in the menu

    and

    "End of..." at the end

    And I didn't understand at first that if the enemies where to close to me in alerted mode I would automagically lose. I think they should just shot you dead (: So something like

    ->move to player
    if between such and such range
       -> stop and shot

    and

    if lose line of sight 
       -> go to last known position

    But nice start overall and the light effect is neat indeed (:

  • The game loop is implicit in C2

    If you have programming background, consider that things work this way:

    While (true) {
        Event Sheet   
        Rendering
    }

    Which means that what you try to do is

    while (true) {
       Text.position(200,200)
       Text.move(200,90)
       Render()
    }

    Every game loop iteration, or simply said "every tick", you are repositionning your text back to (200,200) and then moving it.

    The result of this is that, Text will be at (200,400) then will be rendered

    If you inverse the order of event, you'll always see the text at (200,200) for the same reason.

    You probably need to go through a couple of tutorial.

  • New video \o/

    I cover some interesting aspect of random sampling without replacement to get 1 good and 3 bad possible answer to choose from.

    Matching Game (learning hiragana): youtube (autoSplit playlist) - twitch

    Enjoy \o/

  • imothep85

    need to learn server side programming (:

  • Petres

    No problem (:

Yann's avatar

Yann

Member since 31 Dec, 2010

Twitter
Yann has 5 followers

Connect with Yann