Crashing and Stopping
Today at my internship I worked on making my little person stop when he crashed into the bird. I implemented the bird in my code last week. This was pretty difficult when I started to do it, but I soon got the hang of it.
First I needed to find the dimensions of my little character. Since my little guy isn't a perfect square, I had to make one. Instead of finding some complicated dimensions of this abstract guy, I just put the dimensions of a square that was very close to the height and width of the little guy. After I did this, I did the same thing with the bird. Since the bird is also an abstract shape, I found the dimensions of a square that was very close to the height and width of the bird.
Now came the hard part for me. I then had to find a way to say that "if this first square (the little guy) crashes into this other square (the bird) then console.log("Crashed") + stop(). The last part of the if statement might seem confusing, but it is quite simple. The console.log("Crashed") means that the console will print "Crashed" if the little guy comes into contact with the bird. As you know the stop() function just stops the character. The plus sign is their to show that you want to do both of these commands at the same time. In the case that this doesn't happen, one can put the command else. The else command means that if this doesn't happen, then do this. Finally, I was able to get the little guy to stop when he would hit the bird.
First I needed to find the dimensions of my little character. Since my little guy isn't a perfect square, I had to make one. Instead of finding some complicated dimensions of this abstract guy, I just put the dimensions of a square that was very close to the height and width of the little guy. After I did this, I did the same thing with the bird. Since the bird is also an abstract shape, I found the dimensions of a square that was very close to the height and width of the bird.
Now came the hard part for me. I then had to find a way to say that "if this first square (the little guy) crashes into this other square (the bird) then console.log("Crashed") + stop(). The last part of the if statement might seem confusing, but it is quite simple. The console.log("Crashed") means that the console will print "Crashed" if the little guy comes into contact with the bird. As you know the stop() function just stops the character. The plus sign is their to show that you want to do both of these commands at the same time. In the case that this doesn't happen, one can put the command else. The else command means that if this doesn't happen, then do this. Finally, I was able to get the little guy to stop when he would hit the bird.

Comments
Post a Comment