This game is similar to the original Mario Bros. games. The player uses the arrow keys to control a ninja which must jump over boxes and avoid scissors and bugs. The ninja can jump on bugs to kill them. He can jump to hit special boxes to release random objects: scissors, bugs, or potions. Potions count as extra lives. The screen constantly moves to the right. The ninja cannot go off of the screen.
There is an event for when the ninjas head hits the cube This calls world.releaseObject. This method first chooses a random item from world.boxItems (which contains beetle, scissors, and bottle). The random item then moves out of the box and moves foward on the ground. This world used only one cube and one of each of the three objects even though there appears to be 2 (and you can add more. In my first method, it periodically has the box move forward 20 meters, then calls moveObjectsToBox. This happens after the cube is out of sight.Picking up potions
There is an event for when the ninja gets close enough to the bottle which calls pick up potion. There is a variable called world.potions which keeps track of the number of potions picked up. There are also always two invisible bottles at the top of the screen (vehicles set to camera). pickUpPotion first sets the potion that was picked up to invisible. Then it moves it down out of the way so can't be touched again by the ninja. Then it increments the potions variable by one and calls showPotions. Show potions is the called both when a potion is picked up or used. It had nest if statements for each possible number of potions (up to 2). It must set the current potion visible, and set the next invisble (in case one was just lost).Not moving through boxes when jumping
This is controlled in the jump method. The ninja first moves up 1.5 meters then moves part way pack down, then checks the distance to the crate. While it is within 1.2 meters of the crate (touching it), nothing happens (he stays up). Once the player moves the ninja off of the box, it comes out of the while loop and the ninja moves back downRestricting movement (off of screen and through boxes)
I have a tryToMove method, I have if statements to check if the ninja distance to the box is great enough. To keep the ninja from going off of the screen, I put two invisible boxes, one at each side of the screen. In try to move, I check for collision the same way. I have an event for the box at the back of the screen. If the ninja's distance to the box is too small, the ninja moves right as seen by the camera