Yann's Recent Forum Activity

  • xVector and yVector are indeed just mere private variables

    So is mass

    Basically a force is what make things accelerate or decelerate.

    If you don't apply any force to an object, it's speed will never change

    A force is generally modeled as a vector, because as a vector, a force has a direction and a quantifiable value (how much) which is represented by the length (norm/magnitude) of the vector.

    A vector in 2D has two composants often described as X and Y

    In construct (classic or 2) you can't store a vector in one variable, you need one variable by composant. It is the purpose of xVector and yVector.

    To calculate each composant of a vector oriented you have to find orientation and length.

    gravity = G*m1*m2/d? gives you the length

    the orientation is just the direction toward the considered object.

    so you just have to find the unit vector (vector whose length = 1) representing this direction and multiply it by the length calculated above ('cause 1 * gravity = gravity hoho)

    the unit vector is simply calculated by

    cos(angle)

    sin(angle)

    angle = angle(source.X,source.Y,target.X,target.Y) (neat function in construct)

    so just have to do a

    xVector = gravity * cos(angle)

    yVector = gravity * sin(angle)

    I also added many times this kind of calculation because adding vector is the same as adding its composant

  • selecting something would be possible by having a "selected" boolean private variable you set to true if the unit is selected.

    you just have to foreach the units and check for these variable set to true and apply your actions.

    To group, you could have a 2 dimensional array sized this way :

    DIM X = maximum number of groups

    DIM Y = maximum number of units per groups

    and then you select the units you want to group (that is to say, their "selected" variable get set to true)

    and when you use your shortcut to groupe them, you foreach them and store their UID in the arrayat(IDofTheGroup,loopindex)

    If you want to recall your selection, you just have to do a

    for 0 to DIM Y

        if unit.UID == arrayat(IDofTheGroup,loopindex) -> unit set selected to true

    I hope you have some knowledge of c2 else I might be a bit hard to understand... If you don't understand, you don't have enough knowledge yet to make a RTS I guess (:

  • For MoonShield I moved the moon with events and the asteroids with physics :

    basically for the moon I increase an angle private variable (I have the distance from the earth in another pv) and then I just position them with

    moon.X = earth.X + cos(moon.angle)*moon.distance
    moon.Y = earth.Y + sin(moon.angle)*moon.distance

    For the asteroids it's a bit more complicated. I calculate the gravity force of each asteroids toward each moons and the earth

    Moons, Earth and Asteroids have all a "mass" private variable (so I can tweak it)

    And I just have to :

    foreach asteroid
       /// Calculating the gravity vector toward the earth following the gravity formula G*m1*m2/d?  (G is multiplied when I apply force at the end)
       asteroid.xVector = (asteroid.mass* earth.mass/distance(asteroid.X,asteroid.Y,earth.X,earth.Y)^2)*cos(angle(asteroid.X,asteroid.Y,earth.X,earth.Y)
       asteroid.yVector = (asteroid.mass* earth.mass/distance(asteroid.X,asteroid.Y,earth.X,earth.Y)^2)*sin(angle(asteroid.X,asteroid.Y,earth.X,earth.Y)
    
       /// adding the other gravity vector
       foreach moon
          ADD (asteroid.mass* moon.mass/distance(asteroid.X,asteroid.Y,moon.X,moon.Y)^2)*cos(angle(asteroid.X,asteroid.Y,moon.X,moon.Y)
          ADD (asteroid.mass* moon.mass/distance(asteroid.X,asteroid.Y,moon.X,moon.Y)^2)*sin(angle(asteroid.X,asteroid.Y,moon.X,moon.Y)  
    
       /// Applying the result gravity vector
       Every Tick asteroid Apply physics force (Clamp(asteroid.xVector*gFactor*dt,minVect,maxVect),Clamp(Self.yVector*gFactor*dt,minVect,maxVect)) at image point 0

    And that's all, the physics behavior use the force I calculated to create the movement.

    Oh and I clamped the vector because the asteroids tended to go to fast and the gFactor is a global variable used to tweak the gravity a bit for better gameplay

  • find(varload, "|") = position of the first | in the string

    basically you get each token ( = part between separators) by incrementing an iterator

    the iterator can be a simple variable or a loopindex

    global iterator = 0
    every 5.0 seconds :
        set text to tokenat(varload,iterator,"|")
        add 1 to iterator[/code:32ezzhr4]
    
    or
    
    [code:32ezzhr4]for "itLoop" from 0 to tokencount(varload,"|")-1
        append to text : tokenat(varload,loopindex("itLoop"),"|")[/code:32ezzhr4]
  • Oh yeah you're completely right

    I just tested with your idea

    But! mine works too, I modified the acts.pasteObject function this way :

    ctx.save();
    ctx.scale(this.canvas.width/this.width, this.canvas.height/this.height);
    ctx.rotate(-this.angle);
    ctx.translate(-this.bquad.tlx, -this.bquad.tly);
    ctx.globalCompositeOperation = "destination-out";
    instances[x].draw(ctx);
    ctx.globalCompositeOperation = "source-out";
    ctx.restore();
    

    And it erase perfectly, even if it's a bit weird now that I think about it.

    But yeah I'll stick with your idea... it's simpler

  • r0j0, thanks for this great plugin, I was trying to come up with a line/box/circle plugin but the Canvas is more than enough. Great work.

    Just one feature, I'd like to have. But I wonder if it's feasible. Being able to erase part of the canvas, either by pasting a sprite or drawing something. I tried drawing lines or points with rgba(0,0,0,0) but it seems the drawing logic just add stuff.

    So yeah basically, is it possible to have an "erase part of the canvas" feature?

    Edit: after some research, maybe :

    acts.PasteErase = function(object)
    {
      // erase mode inside the canvas plugin object
      this.ctx.globalCompositeOperation = "destination-out";
    
      [acts.PastObject code]
    
      // back to normal mode
      this.ctx.globalCompositeOperation = "source-out";
    
    }

    Edit Bis:

    HOHOHO that works =D

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Theme is funnier

    'cause you know, game is challenge and challenge induce fun

    Fixed Theme is challenge, Therefore it's funnier

    And I'm tired...

  • s there a possibility to include gifs?

    Nope!

  • Basically you can read that as :

    BasePosition + sin(phaseOffset + time * frequency) * Amplitude

    • BasePosition : is the middle of the movement as sin will go from -1 to 1
    • All that is in the sin function is modulo 360 that is to say if you have sin(361) it's the same as sin(1)
    • phaseOffset will offset the undulation (if you have 2 platforms with different phaseOffset they won't be on top at the same time.
    • time is the time in seconds since the begining of the game. The value inside the sin() will regurally increase... But remember, sin is modulo 360 so things will always ondulate
    • frequency : high number makes rapide undulations
    • Amplitude or Range of the movement around the BasePosition
  • no waffles.txt at all o.o

  • oh noes ///////////o/

Yann's avatar

Yann

Member since 31 Dec, 2010

Twitter
Yann has 5 followers

Connect with Yann