Yann's Recent Forum Activity

  • top-down?... why physics?

  • stemkoski

    nifty indeed (:

  • Line of Sight...

    LoS.capx

  • Alright thanks (: I think you can safely close this one

  • ranma

    hmmm yeah probably but it makes the expression far less cute ;_;

    lvl.At(loopindex("x")+round(cos(a)),loopindex("y")+round(sin(a)))

    instead of

    lvl.At(loopindex("x")+cos(a),loopindex("y")+sin(a))

    yeah ok... you're right :D

  • Try Construct 3

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

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

    Yeah you're probably right on one thing, I probably doesn't get exaclty 0 in the expression.

    In theory cos(270) should return 0 (because it's the downward 90 degree angle so it projects on 0 in the abscisses)

    But I know for instance that in C++ you don't get perfect number. I guess in js it must be the same, but as the display in the text object is ok, I think there's already some kind of rounding somewhere along the line.

    Except in Array.At() expression (and maybe in others)

    That's why I think it's a bug or at least an unexpected behavior. (doesn't happen for cos(90) for instance)

  • ranma

    google works with radian angles, construct 2 with degrees

    270? = 3*pi/2 radians

    and google says cos(3*pi/2) = 0

  • Here I gave it a try and optimized code and perfs

    terrainGenerator.capx

    Didn't know this midpoint algo

  • When I use a cos(270) or cos(-270) in an Array.At expression

    I don't get the expected result unless I round them.

    Anyway, a capx is better than a thousand words

    cos&Array.capx

    I discovered this weird bug by playing with a terrain generator (from Intrepid) to get the 4 surrounding cell of the terrain array through a loop instead of 4 events (was too lazy)

    Yann2012-05-24 01:59:57

  • 1\ System condition doesn't pick (unless it's a foreach, a pick nth instance, or a pick random instance)

    2\ You use a global variable to carry the direction, thus applying the same value for everyone

    Things could be waaaaaay simplier:

    +Enemy: Is on-screen
      -> Enemy: set a to ceil(((angle(self.x,self.y,player.x,player.y)+360)/45)-0.5)%8
      -> Enemy: set animation to "direction_"&a
      +System: Every 3 seconds
      +System: For each Enemy
        -> Enemy: Spawn Ts on layer 4 at image point "shoot1"
        -> Ts: set bullet angle to Enemy.a*45 degrees
        -> Audio: Play Explosion1 no looping (tag:"")

    These few line should replace your "AI_AimAtAngles" and "AI_ShootWhileonScreen" groups

    Note that you'll have to create an instance variable named 'a' type number for your enemies

    And also rename your animations:

    • right -> direction_0
    • rightdown45 -> direction_1
    • down -> direction_2
    • .. etc (respect the clockwise rotation)
  • A good way to learn how to use array might be to start with one dimensional array.

    A one 1D-array is just like a simple indexed list.

    Array are usefull because they provide a unique name (the name of the array) for more than one value.

    Classical variables (instance, global, local, etc) don't, it's always one name <-> one value.

    Using one name for many values helps to lessen the number of variable.

    Imagine a list of enemy. With variable you'd have to do stuff like:

    global variable enemy1 = "wolf"
    global variable enemy2 = "bear"
    global variable enemy3 = "cactus" // why not?
    etc

    There's no advantage and many drawback to this method

    I'd use Array like this

    +On Start of layout
      -> enemy set size to (3,1,1)
      -> enemy.At(0) = "wolf"
      -> enemy.At(1) = "bear"
      -> enemy.At(2) = "cactus"

    (note that array are 0-based)

    This way you can do stuff like

    +On Start of layout
      -> Text: set Text to "There are "&enemy.width&" types of enemy in this area:"&newline
      +for each X element 
        -> Text append "  -"&enemy.CurValue&newline

    Note that:

    • using foreach X element is the same as doing:+for "" from 0 to enemy.width-1

    -> Text append " -"&enemy.At(loopindex)&newline

    - using enemy.CurValue is the same as using enemy.At(enemy.CurX)

    Once you're used to work with 1D array, you can begin to use 2D arrays. For instance you could store the area index in X index and use the Y indexing for the list of enemies.

    Like

    +On Start of layout
      -> enemy set size to (2,3,1)
      -> enemy.At(0,0) = "wolf"
      -> enemy.At(0,1) = "bear"
      -> enemy.At(0,2) = "cactus"
      -> enemy.At(1,0) = "pony"
      -> enemy.At(1,1) = "jar jar binks"
      -> enemy.At(1,2) = "your stepmother"

    And you could go really far with this idea if you want to even store the name of the area and some characteristics.

    There you can do it by organising your array such as the 2 first Y indexes are for these data and the rest is for the list of enemies

    +On Start of layout
      -> enemy set size to (2,5,1)
      -> enemy.At(0,0) = "The Shire" //name of the area
      -> enemy.At(0,1) = "mostly cloudy" // type of weather
      -> enemy.At(0,2) = "wolf"
      -> enemy.At(0,3) = "bear"
      -> enemy.At(0,4) = "cactus"
      -> enemy.At(1,0) = "DreamLand" //name of the area
      -> enemy.At(1,1) = "sunny"  // type of weather
      -> enemy.At(1,2) = "pony"
      -> enemy.At(1,3) = "jar jar binks"
      -> enemy.At(1,4) = "your stepmother"

    Or you could build a 3D array to split things up a bit more

    +On Start of layout
      -> enemy set size to (2,2,3)
      -> enemy.At(0,0,0) = "The Shire" //name of the area
      -> enemy.At(0,0,1) = "mostly cloudy" // type of weather
      -> enemy.At(0,1,0) = "wolf"
      -> enemy.At(0,1,1) = "bear"
      -> enemy.At(0,1,2) = "cactus"
      -> enemy.At(1,0,0) = "DreamLand" //name of the area
      -> enemy.At(1,0,1) = "sunny"  // type of weather
      -> enemy.At(1,1,0) = "pony"
      -> enemy.At(1,1,1) = "jar jar binks"
      -> enemy.At(1,1,2) = "your stepmother"

    (overkill isn't it?)

    Anyway in the end the most important thing to consider when using array is how you'll organize it.

    And also, I never set so much data by end. I always end up putting all that in a string and parsing it (via tokenat and tokencount)

    But that's another story (:

  • jbadams

    There's one, if the object isn't global, the variables are reset on start of layout. There is a "reset all global variables" but that's an all or nothing function. I like to keep some data (like score or current level) but reset some other (like enemy counter or some) and even have some different initial values for the same variable in different layouts (like base strength of ennemies or stuff like that)

    Also the object is accessible from other event sheets yes, and that's fine, but it's not accessible in a layout where you didn't put the object. Which make the variable holder object truely 'by layout'. So you will just have to be carefull with included event sheet that uses these variables not to include them in event sheets of layout that doesn't have the object.

Yann's avatar

Yann

Member since 31 Dec, 2010

Twitter
Yann has 5 followers

Connect with Yann