zatyka's Recent Forum Activity

  • sivricmarijan

    I might. Ludum Dare's October Challenge is coming up, so I may use that as an excuse to turn it into a full game, and perhaps release it on mobile platforms. If so, I'd probably need to come up with some additional game mechanics. Maybe an extended story mode, and an arcade mode.

  • Results are in. Congratulations to everyone who participated. The next Ludum Dare is scheduled for 12/11 - 12/14.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the kind words everyone.

    mattb

    Timer with +/- random is exactly how it's set up now, but the timer and random values are modified per level. I agree that if I were to continue working on the game, some levels would need to be tweaked.

    EXPFall

    I'm not sure exactly what you're asking, but the bouncing basically works like this:

    • Each enemy/projectile has horizontal and vertical knockback variables called Hpower and Vpower .
    • When the player collides with an enemy/projectile:
      • Calculate the angle between the enemy and the player: angle(enemy.x, enemy.y, player.x, player.y)
      • Set the player's Vector Y to -enemy.Vpower. This ensures that collisions always result in upward motion.
      • Set the player's Vector X to (Player.Platform.VectorX + cos(angle)*enemy.Hpower). This pushes the player away from the enemy horizontally.
  • Play Earth Was a Bad Choice

    You're an alien that was hoping Earth was a nice vacation destination, but quickly found out the inhabitants are hostile. Race to your ship through a flurry of explosions. There's a definitive ending. I hope you get to see it.

    Directions:

    • Press any key to progress the dialog
    • Move left and right with either Arrow keys or A&D. (Touch controls are enabled work if you're on a mobile device)
    • M toggles audio
    • Try and remain airborne
    • Chain explosions for sweet combos

    Here's the game's Ludum Dare page. I hope you enjoy it! Feedback is always welcome. I'm eying this up for Ludum Dare's October challenge.

    Also, check out this thread for other LD games made in Construct 2.

  • C2 game list added to original post. If you put "Construct 2" or "Scirra" or "capx" somewhere in your entry, it should already be on the list.

    If my crawler missed your game, just let me know and I'll add it.

  • Here's my entry:

    Earth Was a Bad Choice

    I'm looking forward to playing through everyone's games.

  • There is no magic bullet. Some people add borders to their layout, some people set object's positions relative to screen size. The correct answer is "it depends on how you've set up your game".

  • SashikLV

    Well, I can think of a few ways to use variables to accomplish this. Let's pretend there are 4 layouts:

    • LayoutD
    • LayoutB
    • LayoutC
    • LayoutA

    Let's make a variable called "AllLevels", and set it to "DBCA":

    var AllLevels = "DBCA"[/code:23l96eti]
    
    We're going to use a method to do the following
    
    [ul]1.  Pick a random character (i.e. one of the letters) from AllLevels, and save it to a variable
    2.  Remove the character from AllLevels
    3.  Go to that picked layout[/ul]
    
    We're going to leverage the Len(), Random(), Floor(), TokenAt(), and Replace() expressions.  Here's their definition from the manual:
    
    [ul]
    [b]len(text)[/b]
    Return the number of characters in text.
    
    [b]random(x)[/b]
    Generate a random float from 0 to x, not including x. E.g. random(4) can generate 0, 2.5, 3.29293, but not 4. Use floor(random(4)) to generate just the whole numbers 0, 1, 2, 3.
    
    [b]floor(x) [/b]
    Round down x e.g. floor(5.9) = 5
    
    [b]tokenat(src, index, separator[/b])
    Return the Nth token from src, splitting the string by separator. For example, tokenat("apples|oranges|bananas", 1, "|") returns oranges.
    
    [b]replace(src, find, rep)[/b]
    Find all occurrences of find in src and replace them with rep.[/ul]
    
    Alright, just to reiterate, the first step is to pick one of the random characters (i.e. letters) from the AllLevels variable.  To do that, we first need to know how many total characters there are in the string.  That's where the Len() expression comes in handy.  Let's get the length of AllLevels, and stick it in a variable called "StringLength":
    
    [code:23l96eti]
    var AllLevels = "DBCA"
    var StringLength = Len(AllLevels)
    [/code:23l96eti]
    
    Right now, the string is 4 characters long.  Since Construct 2 uses 0 based indexes, those 4 characters correspond to index 0 (D), 1 (B), 2 (C), and 3 (A). We need to randomly choose one of those indexes.  To do that, we'll use the random() and floor() function, and stick the random index into a variable called "RandIndex".
    
    [code:23l96eti]
    var AllLevels = "DBCA"
    var StringLength = Len(AllLevels)
    var RandIndex = floor(random(StringLength))
    [/code:23l96eti]
    
    Now that we have our random index, we need to get the character at that index from AllLevels.  To do that, we'll use the tokenat() function, and assign the results to a variable called "SelectedLevel"
    
    [code:23l96eti]
    var Allevels = "DBCA"
    var StringLength = Len(AllLevels)
    var RandIndex = floor(random(StringLength))
    var SelectedLevel = tokenat(AllLevels,RandIndex,"")
    [/code:23l96eti]
    
    Ok, we have our letter, and we'll go to the appropriate layout in a moment, but let's first remove the SelectedLevel from AllLevels, so the process doesn't pick it again later.  There are a couple ways to do it, but let's use the Replace() expression.  
    
    [code:23l96eti]
    var AllLevels = "DBCA"
    var StringLength = Len(AllLevels)
    var RandIndex = floor(random(StringLength))
    var SelectedLevel = tokenat(AllLevels,RandIndex,"")
    var AllLevels = replace(AllLevels,SelectedLevel,"")
    [/code:23l96eti]
    
    Finally, let's go to the selected Layout.
    
    [code:23l96eti]
    var AllLevels = "DBCA"
    var StringLength = Len(AllLevels)
    var RandIndex = floor(random(StringLength))
    var SelectedLevel = tokenat(AllLevels,RandIndex,"")
    var AllLevels = replace(AllLevels,SelectedLevel,"")
    Go to Layout by name "Layout"&SelectedLevel
    [/code:23l96eti]
    
    There you go.  Repeat the process whenever you need to go to another Layout.   You should now know how to use variables to go to a random, non-repeating stage.  We're done here, right?
    
    [h2][b]NO![/b][/h2]
    
    This is convoluted and problematic.  For example, it won't work for more complex Layout names?  The bottom line is that variables are a poor way of selecting random non-repeating values.  Variables are meant to hold 1 value, not a series of values.  Sure, you could make it work, but they're not the right tool for the job.  Arrays, on the other hand, are far more appropriate.  Arrays are, by definition, a series of values.  They're also far more flexible, and easier to manipulate.
    
    I'm assuming you're asking how to use variables in this scenario because you're not sure how to use arrays.  Well, if you were able to follow along with the above steps, you can use arrays because it's pretty much the same process. Here's how to use the exact same method with Arrays:
    
    Set the size of the array to 0,1,1.  This empties the array, but makes it ready to receive a list of values.
    [code:23l96eti]
    Array Size = 0,1,1
    [/code:23l96eti]
    
    Insert the different layout values to the array.  I'll use just the letters to remain consistent with the previous method, but you could just as easily use the full Layout names.
    [code:23l96eti]
    Array Size = 0,1,1
    Insert "D" into Array
    Insert "B" into Array
    Insert "C" into Array
    Insert "A" into Array
    [/code:23l96eti]
    
    Determine a random index based on the width of the array.  No need to use len().
    [code:23l96eti]
    Array Size = 0,1,1
    Insert "D" into Array
    Insert "B" into Array
    Insert "C" into Array
    Insert "A" into Array
    var RandIndex = floor(random(Array.Width))
    [/code:23l96eti]
    
    Get the value stored in the array at the random index.  No need to use Tokenat().
    [code:23l96eti]
    Array Size = 0,1,1
    Insert "D" into Array
    Insert "B" into Array
    Insert "C" into Array
    Insert "A" into Array
    var RandIndex = floor(random(Array.Width))
    var SelectedLevel = Array.at(RandIndex)
    [/code:23l96eti]
    
    Delete the index from the array.  No need to use replace():
    [code:23l96eti]
    Array Size = 0,1,1
    Insert "D" into Array
    Insert "B" into Array
    Insert "C" into Array
    Insert "A" into Array
    var RandIndex = floor(random(Array.Width))
    var SelectedLevel = Array.at(RandIndex)
    Delete index RandIndex from Array
    [/code:23l96eti]
    
    Finally, go to the selected layout:
    [code:23l96eti]
    Array Size = 0,1,1
    Insert "D" into Array
    Insert "B" into Array
    Insert "C" into Array
    Insert "A" into Array
    var RandIndex = floor(random(Array.Width))
    var SelectedLevel = Array.at(RandIndex)
    Delete index RandIndex from Array
    Go to Layout by name "Layout"&SelectedLevel
    [/code:23l96eti]
    
    Check out the capx I posted above.  If you made it to the end of this unexpectedly/unnecessarily long post, I bet you can understand the capx now.  Like I said earlier, Arrays are extremely useful, worth learning, and in this case, the best solution.
  • That makes sense. Thank you.

  • Look for function atan2 which takes dy and dx as parameters.

    Just to add onto this, the atan2 function will return radians. To get to degrees, multiply by (180/pi):

     var degrees = Math.atan2(y2-y1,x2-x1) * (180/Math.PI);[/code:jyyxq4ol]
    
    You could have undoubtedly found this solution by googling "Calculate angle between 2 points in javascript".
  • My "I'm In" video.

    In case you couldn't tell, I get pretty hyped about Ludum Dare.

  • phimaka

    That may be a workaround for the capx I posted, but that doesn't resolve the issue. The issue persists even if the object's global flag is set to "No". Using a create action should create an instance regardless of whether the object is global. In the workaround you provided, the correct result should be 2 global objects.

    Also, since this doesn't occur on r208, I'm guessing this was unintended behavior introduced in one of the last few betas.

zatyka's avatar

zatyka

Member since 11 Aug, 2012

Twitter
zatyka has 1 followers

Trophy Case

  • 12-Year Club
  • Jupiter Mission Supports Gordon's mission to Jupiter
  • x11
    Coach One of your tutorials has over 1,000 readers
  • RTFM Read the fabulous manual

Progress

15/44
How to earn trophies