they display a graphic and move around the screen) we can infer a common class to represent each one with potentially subclasses to define the specific behaviors of these different types. Since all of these things have common properties (i.e. The player's ship, the aliens and the shots that the players fire. In that window we want to see some things moving around. For now we can call this class Game since it represents our main game. It also needs to respond to the player's key presses to move our player's ship around. The window needs to use accelerated graphics. You don't need to read this section unless you're interested in why the source is written the way it is.įor our space invaders game we're going to have a main window. I don't guarantee that the provided source is perfect or that that it provides best practices.īefore starting any game its always a good idea to work out what's going to be in the game and how you're going to build your classes around that.
#ECLIPSE JAVA SHOOTING GAME CODE#
The tutorial isn't going to cover every line of code but should give you enough to fully understand how it works.Ĭontext highlighted source is also available here:ĭisclaimer: This tutorial is provided as is. Its intended that you read through this tutorial with the source code at your side. The complete source for the tutorial can be found here. We're going to cover the following areas at a fairly simplistic level: This tutorial hopes to give the reader a simple introduction to the world of 2D games using Java. Space Invaders 101 An Accelerated Java 2D Tutorial Space Invaders 101 - An Accelerated Java 2D Tutorial Space Invaders