======================================= ======================================= = WarioWare DIY: = = Randomizing = ======================================= ======================================= Author: Snap Version: 1.0 Last update: 22-04-2010 The original version of this FAQ can be found on: http://diy-wikihouse.wikispaces.com/In-depth+tutorial+-+Randomizing ================================================ Microgames are small and don't have a lot of content in them, meaning it doesn't take more than a few times playing to figure out what you have to do and what you can expect. These small games can have a serious disadvantage, they can quickly become repetitive and boring if the player always has to do the same thing without variation. Image if the solution to Mona's butterfly game was always up or Asley's cash register game always had the same pricetag, after a few times they wouldn't be any fun to play anymore. When you create a game you'll want to make something that players will come back to, maybe because it's addicting and fun or maybe because it's challenging and players want to beat their highscore. Which is why you need to include some variation in your game to spice things up a bit, make things slightly random. ========================================== 1 -- An object with 2 random possibilities ========================================== This method is what is used to solve the much asked about Dojo #27 lesson, based on what I've seen on the forums there are people that use it but don't know how it works. For this you'll need 1 object with 1 AI: * AI1 ----- Trigger: When Time is 1-1 & when Time is between 1-1 and 1-2 Action: Turn Switch ON The random time trigger works with an invisible switch, you set up the start and end time and somewhere between that the invisible switch will turn on and the trigger will be activated. In this case the start and end time are right next to each other, so there can only be two possibilities, the invisible switch will either turn on at 1-1 or at 1-2. So we check if the invisible random time switch turns on at Time 1-1, then we turn the Switch of the object ON, if not nothing will happen and it will stay OFF. So right from the start of the game you will get an object that will have it's switch either ON or OFF randomly. Example: we have an object with 2 Art animations, one is red, the other is blue. We want the Art of the object to be randomly chosen so that the game will randomly start with a red or blue object. * Start ------- Set Art to ArtRed, Set location * AI1 ----- Trigger: When Time is 1-1 & When Time is between 1-1 and 1-2 Action: Change Art to ArtBlue And there you go. A good method but still rather limited, sometimes you'll want more than just two options. ================================================ 2 -- An object with up to 4 random possibilities ================================================ This method will allow you to have up to four random options on a certain object. To do this you let an object start in an Area rather than a point, the object will spawn somewhere within that Area and depending on where the game places it we determine it's action. First there are a few things that you should know or that could prove helpful. - When selecting a location or an area, the border of the screen changes into a checkers board which you can use to your advantage to create nice equal size Areas. When dragging the stylus to select an Area and pressing the L button, the selection will adjust itself to the tiles of the checkers pattern. - It's usually best to set the starting Area somewhere outside the screen. - You may have a problem when using larger objects which may, if you don't select your Areas correctly, overlap multiple Areas and end up not so random in the end. - When you let an object start in an Area, the object may be larger than the Area, if that is the case, it is the center of the object that will spawn within the Area. Example: just like in the previous example we have an object with different colors, only this time we have four, red, yellow, blue and green. For this you'll need 1 object with 1 AI: --- IMAGE: http://i40.tinypic.com/24v4ls3.jpg --- * Start ------- Set Art to ArtRed, Set location to Area (red rectangle on the top of the image) * AI1 ----- Trigger: When Touches Area (choose area1 from the image) Action: change Art to ArtBlue & (something) * AI2 ----- Trigger: When Touches Area (choose area2 from the image) Action: change Art to ArtYellow & (something) * AI3 ----- Trigger: When Touches Area (choose area3 from the image) Action: change Art to ArtGreen & (something) A Switch has only two possibilities, on or off, so instead we now use the Art of an object to determine which random possibility the object has become. What we've done is divide the top part of the screen in different sections of 4 tiles wide and 2 high. We let the object start in somewhere in the big red rectangle and then we check in which section it actually spawned. If it starts in the first 4 squares we change it into blue, if it starts in the second set of 4 squares we change it to yellow and so on. If the object starts in the last 4 squares we do nothing and the object stays red. Also, if the object's Art is larger than 1 pixel, it is possible that it touches more than one section, depending on which check the game does first internally, you may get different results. You shouldn't worry too much about that, in the end you will end up with one out of four possibilities. We still have two AIs left, so if you want you can expand this to up to 6 random possibilities, however they can't all have seperate Art. This could be useful if you want an object to move around using a random pattern or have certain possibilities animate and others not. A Koopa shell for example, you could have 4 different colors of shells with their Art on hold and another which is animated and flashing to make an invincible shell. Alright, this way we can create some more variation into games but it's still only limited to one object. What if you have multiple objects and you want to use a random one? ============================================================ 3 -- Using one of four objects based on a random possibility ============================================================ 3.1 Setting it up ----------------- Example: lets say that you want to create a Mario game such as the 9-Volt games, Mario is standing on the screen and random enemies (Goombas, Koopas, Shyguys, ...) are coming from outside of the screen walking towards him. If we were to do this with the above method then we'd have to make each enemy a different animation on the object and there could only be one enemy on the screen at the same time. The problem is that each enemy may have multiple animations and perhaps we'd want more than just one enemy at the same time. So we'll have to make each enemy a seperate object and still be able to randomly send an enemy towards Mario so that in one game you get two Goombas, in another a Koopa and a Shyguy, in yet another a Koopa and a Goomba. To do this we'll use the above method but with multiple objects, a dummy object that will act as a Randomizer and the Swap function that will switch the position of two objects. Make the smallest object you can make and give it one animation with just 1 pixel somewhere in the middle. I always name this object Randomizer, this object will determine which random object to pick. --- IMAGE: http://i39.tinypic.com/17pi0j.jpg --- Look at this image, it's pretty much the same as the above situation only now there are multiple objects. The colored circles on the right side of the screen are our enemies, the pink S is the Shyguy, the cyan G is the Goomba, the orange K is the Koopa and the purple B is a Bomb-omb. For your own convenience, when you're not using an object on the screen, always move it outside of the screen, otherwise you'll have to change the Art to a blank animation and back again which will only complicate things when checking for collisions. Let's begin with our Randomizer object: * Start ------- Set Art to ..., Set location to Area (choose the red rectangle on the top of the image) * AI1 ----- Trigger: When Touches Area (choose area1 from the image) Action: Travel Swap with Shyguy * AI2 ----- Trigger: When Touches Area (choose area2 from the image) Action: Travel Swap with Goomba * AI3 ----- Trigger: When Touches Area (choose area3 from the image) Action: Travel Swap with Koopa * AI4 ----- Trigger: When Touches Area (choose area4 from the image) Action: Travel Swap with Bomb-omb Next we set the AI for the enemies, lets start with the Shyguy: * Start ------- Set Art to ..., Set location to (somewhere outside of the screen) * AI1 ----- Trigger: When Overlaps Area (choose area1 from the image) Action: (something) Now the Goomba: * Start ------- Set Art to ..., Set location to (somewhere outside of the screen) * AI1 ----- Trigger: When Overlaps Area (choose area2 from the image) Action: (something) Do this for every enemy but set the correct Area for each one. So what does this do. We tell the Randomizer object to start somewhere in the large red rectangle, then we check in which of the four sections it actually spawned. Depending on the section we want to use a different enemy and since the Randomizer object has to be in control of four enemies we can't use its Switch. So what we do is we swap the positions of the Randomizer and the enemy we need. If the Randomizer were to spawn in area1, then we swap it's position with the Shyguy object, next the Shyguy will detect that it overlaps with area1, so we tell Shyguy to do something. The result of this microgame will be that one enemy will be randomly selected at the start of the game and do something. 3.2 Finishing the example ------------------------- Before moving on, let's expand on the above example a bit. So far one out of four enemies will randomly be chosen and do something. Look at the image, to turn this into a working game we need to add some things, for starters we've added the green ground and the red rectangle with the M which is Mario. We want Mario to jump when he's tapped and so avoid hitting the enemies, we also want random enemies walking towards him, sometimes more than one. Also when Mario has avoided an enemy and he exists the screen, we want to be able to use that enemy again. The Randomizer constantly has to keep trying to send new enemies. When an enemy is already on the screen it can't be chosen by the Randomizer, which is why we'll use the Switch of the enemies, when they're on the screen their Switch will be ON, when they're outside of the screen and can be used their Switch will be OFF. --- IMAGE: http://i39.tinypic.com/euo8yw.jpg --- First of all you'll need to change the Randomizer object, it needs an animation with multiple cells which we're going to use to determine when it has to try and send an enemy. Just copy the art of the first cell to the others so that it has 3 or 4 frames with 1 pixel. Now let's set the AI: * Start ------- Set Art to ArtA play once speed slow, Set location to Area (choose the red rectangle on the top of the image) * AI1 ----- Trigger: When Touches Area (choose area1 from the image) & Shyguy Switch is OFF Action: Travel Swap with Shyguy * AI2 ----- Trigger: When Touches Area (choose area2 from the image) & Goomba Switch is OFF Action: Travel Swap with Goomba * AI3 ----- Trigger: When Touches Area (choose area3 from the image) & Koopa Switch is OFF Action: Travel Swap with Koopa * AI4 ----- Trigger: When Touches Area (choose area4 from the image) & Bomb-omb Switch is OFF Action: Travel Swap with Bomb-omb * AI5 ----- Trigger: When ArtA finishes playing Action: Set Art to ArtA play once speed slow & Travel Jump to location Area (red rectangle on the image) Everytime the animation of the Randomizer finishes playing, it will spawn somewhere in the large red rectangle on the top of the screen. If it spawns in a section and the Switch of the enemy representing that section is OFF (meaning it's outside of the screen and ready to be used), Swap positions with that enemy. This is another reason why you should place the enemies outside of the screen, otherwise the pixel of the Randomizer could appear somewhere on the screen. After the animation finishes playing the Randomizer will be moved back somewhere in the large red rectangle area. Now for the Shyguy: * Start ------- Set Art to ..., Set location to (somewhere outside of the screen) * AI1 ----- Trigger: When Overlaps Area (choose area1 from the image) Action: Travel Jump to location point (start location) & Travel Move WEST & Turn Switch ON * AI2 ----- Trigger: When Touches Area (choose an area on the left outside of the screen) Action: Turn Switch OFF & Stop Travel & Travel Jump to (original location) The first AI will be activated when the enemy is supposed to appear and turn the Switch ON indicating that the object is currently in use. The second AI will reset the enemy back to it's original position and turn the Switch OFF so that it can be used again. Do this for every enemy except with their own Area in AI1. As a result there will be a constant stream of enemies walking towards Mario. The speed at which these enemies appear depends on the speed of the Randomizer animation. ======================== 4 -- Expanding even more ======================== 4.1 Four objects with each two possibilities -------------------------------------------- So now we have four objects randomly being selected based on what a fifth dummy object is doing. Can we expand on that and make it even more random? We sure can. Lets keep working with the above example. We now have four different enemies that can each do something different, but what if we want to add a random possibility to each enemy. Let's take the Koopa for example, we could have a green Koopa that walks towards Mario or we could have a red winged Koopa who hops towards Mario. We still have free AI on our enemies so we can do that. The Koopa is represented by area3, 4 blocks wide and 2 blocks high, so how about we vertically cut that Area in half. We leave the Randomizer as it is, but we adjust and add another trigger to the Koopa AI: * Start ------- Set Art to ..., Set location to (somewhere outside of the screen) * AI1 ----- Trigger: When Overlaps Area (choose first two blocks of area3 from the image) Action: Set Art to (walking Koopa) & Travel Jump to location point (start location) & Travel Move WEST & Turn Switch ON * AI2 ----- Trigger: When Overlaps Area (choose last two blocks of area3 from the image) Action: Set Art to (winged Koopa) & Travel Jump to location point (start location) & Travel Move NORTH-WEST & Travel Bounce & Turn Switch ON * AI3 ----- Trigger: When Touches Area (choose an area on the left outside of the screen) Action: Turn Switch OFF & Stop Travel & Travel Jump to (original location) So now we have two possible Koopa enemies, if you want you can do the same for all the enemies and then you'll have four objects with each two possibilities for a total of eight random possibilities. As you can see we still have 2 AI remaining so if you want you can add 2 more possibilities so that each object has four possibilities. In that case you have to cut the Area in four parts and check which one your object overlaps. However, you may need those AI for collision detection or changing art so before you go nuts and add all these random options, be sure that you have AI left to make the object do what you want it to do. 4.2 Up to eight objects with each two possibilities --------------------------------------------------- And what if even four different objects with two possibilities is not enough? This will be a very rare situation because at this point you're probably going to get in trouble with the amount of points or objects you have left. I don't think I need to go into much detail here because it's exactly the same as we did before, only this time we add a second Randomizer object and give it its own Area to check, in the image below the blue rectangle. If if doesn't matter that enemies from both Randomizers appear at the same time, for example an Asteroids type game you can use a copy of the first Randomizer and change its areas. In our Mario example we don't want enemies appearing at the same time and right on top of each other so for this one we'll need an extra AI so the second Randomizer will only be able to use three objects. Lets add 3 more enemies, Enemy5, Enemy6 and Enemy7. Set the animation speed of the second Randomizer to the same speed as the first and give it this AI: * Start ------- Set Art to ArtA on hold, Set location to (somewhere on the bottom of the screen, unused space) * AI1 ----- Trigger: When Time is 1-3 Action: Set Art to ArtA play once speed slow & Travel Jump to location Area (choose the blue rectangle on the image) * AI2 ----- Trigger: When Touches Area (choose area5 from the image) & Enemy5 Switch is OFF Action: Travel Swap with Enemy5 * AI3-4 ----- The same as Randomizer1 but with the new objects * AI5 ----- Trigger: When ArtA finishes playing Action: Set Art to ArtA play once speed slow & Travel Jump to location Area (choose the blue rectangle on the image) --- IMAGE: http://i41.tinypic.com/5ju0hu.jpg --- This way, the second Randomizer will start playing after the first one, since they have the same animation speed, they will never Jump to their Area at the same time so the objects that depend on Randomizer1 and those depending on Randomizer2 will never start at the same time. So let's say that we add some more enemies, Enemy5, Enemy6 and Enemy7 and then play the game, this is a possible outcome: 1. Randomizer1 will spawn inside the red rectangle, in area1 2. Randomizer2 will spawn somewhere outside of the blue rectangle 3. Shyguy is moved to area1, Shyguy is moved to the starting point, its Switch turns ON and travels to the left 4. Randomizer2 will be moved to somewhere inside the blue rectangle, in area6 5. Enemy6 is moved to area6, Enemy6 is moved to the starting point, its Switch turns ON and travels to the left 6. Shyguy touches the left side of the screen, Shyguy is moved back to it's original position, Switch is turned OFF 7. Randomizer1 will be moved to somewhere inside the red rectangle, in the right half of area3 8. Koopa is moved to area3, Koopa checks the area, winged Koopa has to be used, Koopa is moved to the starting point, its Switch turns ON and starts bouncing to the left 9. Randomizer2 will be moved to somewhere inside the blue rectangle, in area6 10. Enemy6 Switch is ON, meaning it is already on the screen, nothing happens 11. ... 4.3 Up to 33 completely random possibilities! --------------------------------------------- This is where it gets really fun. One last problem we have in the previous example is that it constantly switches between objects from Randomizer1 and Randomizer2. As the icing on the cake we want even that to be randomized, for that we'll need an extra object because we're going to make a Randomizer for ... our Randomizers. Make another dummy object, give it an animation with 1 pixel like you did for the previous Randomizer, lets name the object RandomPar (Randomizer Parent, I'll explain later). First take a look at this image: --- IMAGE: http://i42.tinypic.com/2emig5k.jpg --- We'll be using this structure to set up a scenario where we can have up to 17 random possibilities. If you've chosen to give each object four options, then 1-1 and 1-2 are actually divided into 1-1, 1-2, 1-3 and 1-4, and the same for the rest. In that case you can have 33 possibilities. Lets start with the AI of RandomPar: * Start ------- Set Art to ArtA play once speed slow, Set location to Area (somewhere inside the green rectangle) * AI1 ----- Trigger: When Overlaps Area (choose the top part of the green rectangle, R1) Action: Turn Switch ON * AI2 ----- Trigger: When Overlaps Area (choose the bottom part of the green rectangle, R2) Action: Turn Switch OFF * AI3 ----- Trigger: When Art finishes playing Action: Set Art to ArtA play once speed slow & Travel Jump to location Area (somewhere inside the green rectangle) R1 represents the red rectangle (Switch ON) and R2 represents the blue rectangle (Switch OFF). Next let's make some changes to Randomizer1 and Randomizer2, here's the example for 1: * AI1 ----- Trigger: When Touches Area (choose area1 from the screenshot) & RandomPar Switch is ON & Shyguy Switch is OFF Action: Travel Swap with Shyguy * AI2-4 ------- Repeat for the other enemies * AI5 ----- Trigger: When ArtA finishes playing Action: Set Art to ArtA play once speed slow & Travel Jump to location Area (choose the red rectangle on the image) We've added a trigger that checks if the RandomPar Switch is ON. Do this for AI2, 3 and 4 as well. Randomizer1 will still continue to Jump to a different position within the red rectangle every time its animation finished playing, but if the RandomPar Switch is OFF, nothing will happen. Also you probably noticed that the red rectangle is now larger than before, it has a third row, if Randomizer1 end up in the third row then nothing will happen either, which is the 17th possibility. Now do the same thing for Randomizer2 but make the trigger check for RandomPar Switch is OFF. All our other objects remain the same. This is pretty much the maximum amount of randomness you can achieve in this game, ofcourse you could keep expanding on this but you just don't have enough points or objects to do so. So let's take a look at the amount of randomness we've created. * First up is RandomPar in the green rectangle, based on it's outcome there's a 50/50 chance of getting either Randomizer1 (red) or Randomizer2 (blue) * Next the Randomizer in it's own rectangle, here we have a 1/3 chance that the result will do nothing and a 2/3 chance that it will activate an object * There's a 1/6 chance that it will pick a certain object * When a certain object has been picked, it may be available or it may already be in use, again a 50/50 chance * When the object is not in use, an object may still have different modes (walking Koopa and winged Koopa for example), again a 50/50 chance. If you've given your object three or four possibilities then you should have a 1-3 and 1-4 and so on as well, in that case there's a 33,33% or 25% chance of getting a certain possibility As you can see, 17 or even up to 33 possibilities is quite a lot of randomness for a game that doesn't last more than a few seconds. It will take a player several games before he has seen everything your game has to offer and many many more before he has seen every possible combination. The way the areas are set up in the above examples were chosen for the convenience of explaining things. You can set up these areas any way you like, if you want one object to be rare and another common, you can make certain areas bigger and others smaller to change the odds, it's entirely up to you. ============================= 5 -- Some further explanation ============================= DIY may be a simple game creating tool which tries to keep things as simple as possible for the user but what we have created here is actually something that is used in pretty much every game or often programming in general. What we've made here is a fairly simple Parent-Child structure, also known as a Tree structure. A Tree structure is called that because just like an actual tree, it has a core and it constantly splits up into smaller parts after that. A tree has a trunk which splits up into several branches, which split up in several twigs which split up in several leaves which each have veins that keep splitting up as well. Everything you do to the trunk will happen to the rest of the tree as well, if you move the trunk the rest will move with it, if you break off a twig the leaves attached to it will come off along with the twig. Everything is connected and everything depends on the part before it. In our structure RandomPar is the trunk of the tree, it has two branches Randomizer1 and Randomizer2 which each have 4 twigs, objects 1-4 and objects 5-8, which each have up to 4 leaves, up to 4 possibilities per object. A Tree structure is incredibly useful in programming and as you can see, even in DIY where there are so many limits, the Tree structure has allowed us to create a large amount of possibilities while still keeping everything connected.