Let's Play Robo Instructus () | "Orienteering" | Gameplay Commentary | Learn to Code

Let's Play Robo Instructus () | "Orienteering" | Gameplay Commentary | Learn to Code

Views:35|Rating:5.00|View Time:28:36Minutes|Likes:3|Dislikes:0
This is one possible solution for “Orienteering” level of Robo Instructus.

Be sure to like, comment, and subscribe if you enjoyed the video, and stay tuned for more like it.

hey what's up guys john here from coast accepted and if you're coming here from part two of this video this will be part three and we're gonna be covering the orienteering level orienteering okay I think when I was actually playing I did sense of direction before orienteering but I think orienteering is actually easier than sense of direction so we're gonna do orienteering first okay so let's click on that and now you'll see here we've got these little arrow tiles and what the arrow tiles do let's see if we've got it like a little directory thing here so the arrow tiles tell you which way your character needs to go essentially okay so if we look if we exit out of this so if we were to step on this tile for instance we know that it is safe to go to the left okay and then this tile for instance it's safe to go down and you'll see that this this down arrow right here points towards like one of the void areas but since the down arrow points down right here we know that it is safe to go down and that this is the exit so I'm gonna go ahead and hit play for you guys and kind of let you see the solution in action and then we'll you know we'll start from the ground up basically and go through and build it it's a lot of a lot of stuff here so it's gonna take a hot minute so buckle up I'll drop the entire code in a comment if it will fit so that you guys can you know see it easier but yep we're gonna hit play all right so here is how my solution scored on this little chart there might be better solutions out there I'm sure people did at different ways than I did but this is how I solved it so I'm going to explain the way I did it and if you find a better way to do it or if you see something in my code that could be improved upon by all means holler at me in the caller comment sections okay so we're gonna hit reset and we're gonna build it from the ground up but before we start from the ground up I just want to kind of go ahead and explain the section so that if you guys kind of get the gist of it you can watch this part and you can go do it on your own alright so basically what I did was I set up six different variables okay and those are for the six directions that your character can face so like if we think about this little hexagon here that basically represents the six sides or you know the six directions your character can face so whenever we move a character we can actually say hey he is now facing this direction he's facing this direction he's facing this direction so I've got this function that I created called arrow check and basically anytime he steps on one of these it will you know it will do the little what does it call it the Robo use and it will say hey it's safe to go this direction it's safe to go to this direction it's safe to go to this direction and based on what direction the character is facing he'll take that new information and he'll go in that direction but since we don't know which direction the character would face normally or you know by himself we have to like program that manually okay so you'll see that I've got one two three and four based on the directions that he can face so one is up two is to the right three is four or three is down and four is to the left based on these arrows okay so we're gonna go ahead and delete everything it's gonna be kind of scary watching all the code go away but I promise we will be rebuilding it okay so we're just gonna go ahead get rid of everything all right so first thing we need to do we're gonna say hey let's create a bunch of variables for all that stuff we know that we need we're gonna we're gonna need so we're gonna create our global variable section okay and you don't have to do like this comment stuff this is just for like clarity so that when you go back and you reread your code you can easier it's easier to identify what you know you were trying to say or that when someone else looks at your code they can know what you were trying to say okay so global variable declarations okay so we're gonna make our variable scan like we always do okay we're gonna have variable arrow which is how you know the value of these arrows that we're going to assign variable up variable up and to the right variable down into the right variable down oops sorry variable down into the left and then variable up into the left so you'll see I kind of went clockwise so this would be up up right down right down down left up left okay and then I assigned numbers to them because otherwise the way this is set up it like a sines zero to these so I just went ahead and assigned numbers to them so I made this 101 I made this 102 103 104 105 and then 106 okay and then we need a variable for direction so like something that all of these variables can you know talk to so variable direction okay and by default we're gonna say that that is up okay because our character starts and like the up position all right so global variables out of the way so we'll put in a little comment bar here let us know that that section has been broken up okay so the next thing we're going to talk about is the arrow check or like the arrow functionality okay so basically whenever we step on one of these and we robo use it we need a way to know which arrow it is and you know which way is safe to go so what we're gonna do is we're gonna say if arrow is 0 which it is at the start obviously right because we haven't we haven't used direction yet then we're going to do row bow forward so we're gonna walk forward okay and at this point our direction our direction is going to be up and to the right because you know we're gonna walk forward and then our guy's gonna face this direction okay so that's the first part and then for all of these other directions so one two three four we're just going to do a bunch of else or else–if state statements right so if it's not this then is it one of these other things so else arrow is one and then we'll go ahead and duplicate this couple times so you can hit control D while you're on a line to duplicate like that okay so we're gonna break these up into various sections okay so if the arrow is one if we look up here one means that it's the up arrow so like one of these okay now if we look at the up arrow the up arrow can only be this type of triangle with like the long side on the top so we're only going to need three parts for this command so we're gonna have if the direction we're facing is up we're gonna have if the direction is down and to the left and then we're gonna have if the direction is down in to the right okay because you'll see there's like a doubt or there's a up section a down left and a down right section on this type of triangle okay now for each of these we need to say go up so simple enough if our direction is up we're going to row bow forward okay so like imagine that our guy is standing right here and he's facing this way just like this we know that this tile is safe so we're just going to walk forward and when we do our direction is going to be then up into the right okay so we've got Robo forward and then we need to say the direction is now up and to the right okay and we're gonna do basically this same little you know train of logic for these two commands okay so if we're facing to the down into the left then we need to go to the left one so that we're facing this one and then go to the left again so that we're facing up and then we just walk forward okay so we need to say Robo left Robo left Robo forward okay oh we need to put the little bracket or like the parentheses okay and since it's a triangle we know that if this one has no left and this one has two left this one's gonna have one left right it's a robo left Robo forward okay and then we need to set the direction that our character is going to face after he does both of these so the direction is going to be the same as this as these up here okay so basically regardless of how he comes into this or how or you know whatever kind of whatever when he comes into a triangle like this he's always going to leave up into the right like that okay and then we're gonna do the same thing for arrow is two arrows three arrows for so it's just it's just a lot of typing a lot of repetitive stuff here okay so if Direction is up Robo I always type robot robot left coldy Robo bored and then Direction equals down okay so arrow to is our right arrow so it's like one of these right here okay now you'll see that the right arrow can be this kind of triangle with with the flat side or you know like the up side I don't know what I'm saying the pointy side down okay or it can be like this where the pointy side is up which means that there's going to be six different sections because our character could be facing any of the six ways okay let's go ahead and it's basically a VIP the direction is up we're gonna have the if the direction is down we're gonna have if the direction is left right without yada yada yada okay so we need to sorry I'm having like a brain a brain aneurysm we need to go if the direction is down is down and to the left then do down down and left yep then do Robo left okay and then do Robo forward sorry I was like figuring figuring that out in my head there okay so if we're on an arrow too and we are facing down into the left select right here if we're facing this area we're going to do Robo left and then Robo forward okay simple enough robot left robot leftover Ford that's right okay and then our direction is going to be down okay then if direction is down right Robo forward okay and then our direction is going to be down so that you'll see that within this triangle right here there's gonna be three where the direction is down because they're all going to take the same path out okay and now we're going to move over to this type of triangle for the right where you know it's got the pointy bit up okay so if direction is up and to the left is that hell we'll start that I guess I guess we got start at the bottom since it's flat since we started with up on the top so if Direction is down let's do Robo forward and then say the direction is down left okay if direction is if the direction is up right then Robo way if the let me tell you how to enter here so this is the one triangle this is the other triangle so if our direction is down and we need to go to the right we need to go Robo left first Robo left first and for this one we just need to do Robo forward because we're going to be looking to the up right anyways alright in our direction equals down so supposed to be down right down right yeah so this should be down right and this should say equals okay so we're gonna go up go to the right so down right so one more direction to go if Direction is up it is up and to the left then we need to do Robo left control-d robo robo forward okay and our direction is still going to be down into the right okay so that's arrow two down so now we need to do arrow three it's going to be kind of like arrow one in that there's only going to be three options we could copy and paste this and like kind of go in and like you know cut out the things we need or don't need and paste in like the correct thing but we'll just go ahead and type it from from the top oh we already have it there whoops okay so if direction is down robo robo oh my gosh robo forward here we go okay and Direction equals down left okay we need like we need else if else if direction is up right do Robbo left Robbo left Robbo forward and then Direction equals down and left so last one here else if Direction is up left then we need to do Robbo left Robbo forward and then Direction equals down into the left and let's uh fix all these up here because I should have been putting else ifs okay so now we just have number four to go right we're making ground so if direction is is up I mean it's do Robo Left Robo forward Direction equals up left okay so arrow four is the left arrow select this guy right here for instance so if our direction is up if we're facing like this triangle we're gonna turn to the left and then we're gonna walk forward okay simple enough there okay so we can either face up down left or down right so if direction is down left then we need to do Robo board and then direction is then up into the left if Direction is down right down right then we need to Robo left twice and then Robo forward Direction is still up left okay so we made it through that part and that's for this type of left triangle now we need to do the left triangle with the pointy bit okay so what we're just gonna put a space there so that we understand that's a different triangle you could use comments for that type of stuff but we're just we're just going with it here so if direction what would we're supposed to be doing else s for this sorry you forgetting else let's say else if if we're facing down I'm sorry if direction is down then we need to do Robo left copy that Robo forward okay so for instance this guy right here if we're facing down we'd want to turn left or sorry okay number four if our direction is down yeah left left okay got my left and right can confuse there for a second okay else if Direction is up left then we want to do Robo forward okay and we need to say that the direction is equals because we want to assign the value to up and we can copy and paste this up here too okay and then the last one else if direction is up and to the weight oh sorry up in to the right and Robo left Robo forward and then Direction equals up so that is a lot that we just made there now the reason that I made this sorry to begin this function somehow we skipped over that to begin the function you type in font fun for function and then the name of the function I think we called this arrow check before and then everything underneath that is part of that function so the reason that I I made this into a function like this is because like I said I did the other level before this one you could if you wanted to you could just have all of this running in the loop but it just as well we do it this way okay so then we've got our comments right or like our break and then we're gonna have our loop that is running this command over and over again okay so we've got loop so we could say like cut with our comments here we could say this is the main function and then up here let's just copy this this is like our user functions so like the ones that we made ourselves like Robo Ford is like a function that's built into the game but we like we basically just made one of those right we said anytime we say arrow check we want to run all of this stuff okay so we've got our loop here we type in arrow check because we want to run this over and over and over again and then in addition to that we want to say if all right if you're standing on or I'm sorry so arrow let's go back up here so the variable arrow we want the variable arrow to be assigned to the value of Robo use so basically every time we do Robo use on one of these we're gonna get the new direction that the arrow is so I think unless we messed up our direction somewhere in here which is likely this should work so let's hit play okay there you go it looks like maybe we added in a phrase there something but for the most part it's it's what we built a second ago we started off with yeah if you have any questions about why I did something be sure to drop a comment down below and stay tuned for the next two levels okay take it easy guys peace

One Reply to “Let's Play Robo Instructus () | "Orienteering" | Gameplay Commentary | Learn to Code”

Leave a Reply

Your email address will not be published. Required fields are marked *