![java shooting game tutorial java shooting game tutorial](http://www.kilobolt.com/uploads/1/2/5/7/12571940/2779734.png)
Think perhaps also about data that stores if something has occurred- or not, that is true or false. Here we don’t want to store a number but a collection of letters from the alphabet that form the player’s name. What about the name of the player, perhaps we could use a variable called But let’s consider some other potential variable types. PlayerScore variable, we are storing a number, a score. It is just a case of thinking about what information (what type) any particular variable will be used to store.
Java shooting game tutorial code#
The next thing we need to do, before we can begin to write code for our variables, Java forces us to decide what type of variable it will be. Here we are using the simple lower case word followed by upper case word because it makes the second word clear and when we introduce more types of Java code later in the course it will make our variables stand out from other types of code. In Java, you can choose your convention of choice -unless you’re being paid to follow a specific convention. Naming conventions vary from language to language, company to company and different preferences for particular conventions abound. By sticking to a naming convention especially when our code eventually becomes more extensive, will make our code more readable and easy to follow. In addition, by using the combination of lower and upper case letters we are adopting a naming convention. In Java, we can call our variables almost anything we want but by using meaningful names there is never any doubt about what the variable is for. You might have noticed that the name is simply a combination of the two words, with the first letter of the first word in lowercase and the first letter of the second word in upper case. Let’s call our variable to hold the player’s score To manage this particular piece of data we can create a variable in our code and we can make it meaningful by giving this variable an appropriate name.
![java shooting game tutorial java shooting game tutorial](https://pbs.twimg.com/ext_tw_video_thumb/996483343259717633/pu/img/karKt-uCadMUUSw7.jpg)
We mentioned a moment ago that we would need to remember the player’s score. Let’s look at some simple examples to start with. Variables enable us to easily store data in a meaningful, accessible and flexible way. What about the images for the graphics, what if each object has a different image for each of many frames of animation? What about data to describe the game environment, artificial intelligence or the layout of the different levels of a game? All this information, even in a simple retro 2d shooter, for example, will become fairly extensive once the whole game is considered.įortunately, the Java programming language solves this problem for us with variables. And it is very easy to think of lots more examples of data, a typical game might need. All of these things are part of the data of the game.