[ [[tutorial-en-001 | Intro]] | [[tutorial-en-002 | Begin]] | [[tutorial-en-003 | if/else]] | [[tutorial-en-004 | Loops]] | [[tutorial-en-005 | Arrays]] | [[tutorial-en-006 | Graphics]] | [[tutorial-en-007 | Animation]] | [[tutorial-en-008 | Mouse]] | [[tutorial-en-009 | Game]] | [[tutorial-en-010 | Real]] | [[tutorial-en-011 | Methods]] | [[tutorial-en-012 | Class]] | [[tutorial-en-013 | Class 2]] | [[tutorial-en-014 | Applet]] | [[tutorial-en-015 | MouseClick]] | [[tutorial-en-016 | Thread]] | [[tutorial-en-017 | Button]] ] ---- ====== Java Game Design - Basic Shoot-em-up ====== For this tutorial I will take you through the steps to design a basic Space Invaders type game. It will involve only very basic gameplay. Here will be the requirements: * A defender that moves left to right at the bottom of the screen and follows the mouse. * The defender will fire a bullet when the mouse is clicked. * 2 rows of aliens will descend from the top of the screen. They will move across the screen, then drop when they reach the edge of screen. * The aliens will drop random bombs. * If a bomb hits the defender, one life is subtracted from the lives. * If a bullet hits an alien, it will disappear, or explode if one prefers, and the defender receives 10 points. * If the defender has no lives left, the game will end. * If the aliens reach the bottom of the screen, the game will end. ===== Java Game Design - Use Cases ===== {{inv001.gif}} So the next step after the requirements are laid out, are the USE CASES. Use cases are a graphical or simplistic representation of what needs to happen in our program. So, for example, the alien will need to move, to drop bombs, and detect if it gets hit. Just have a go at it. Don't worry if you get it wrong or dont get exactly what i got. {{inv002.gif}} The bullet will need to know its starting point or x,y coordinates. It will need to be told to move or shoot and will need to know when it hits an alien and when it goes off the screen. But then again, we could let the alien take care of when it gets hit. Bullets are pretty dumb things. And also we could think also of shooting the alien bombs, and scoring points by doing so. But we will keep it in the back of our minds for later on. {{inv003.gif}} For the Defender, it will need to move right and left, following the mouse. And to fire bullets at the invading aliens. And also to keep track of its lives. We can decide here to give it an arbitrary number of 10 lives. We can change this later according to gameplay. We could have decided to use the keyboard to control this game. For example the key.RIGHT and key.LEFT keys could have made the defender move left and right and the SPACE bar used to fire bullets. {{inv004.gif}} The bomb will need to be triggered. We could do that at random times, say every 4 or 5 seconds. And we may need to know where the defender is at that point. So we may need to know the x,y coordinates of the defender/mouse at the time of triggering a bomb. Also, we will have to move the bomb and detect when it hits a defender or a bullet perhaps or when it goes off stage. But, then again we could let the defender take care of any collision detection upon itself. ===== Class Diagrams for Shoot-em-up ===== {{inv005.gif}} Class Diagrams are used to simplify all the inhabitants of a class or object. A class may have variables and it may have methods. The picture on the right is a Class Diagram for our defender. It lays out what our variables may need to be and what methods we may need to make this work. Some of the variables could be the x and y coords of the defender(defx and defy), how many lives the defender has left(lives) and the bounds(or its width and height or what space it occupies so when can determine when it has been hit). The methods that we may need are isHit(to let the system or game manager know when it has been hit), fire() - to fire a bullet, to move the defender and to draw the defender on the screen. Go ahead and try doing the rest of the class diagrams for alien, bullet and bomb. And i will continue this tutorial next week. Have a think about a class that controls the gameplay, a sort of gameManager or supervisor or controller. So see you next time and have fun with it!