Skip to main content

2D ADVANCED JAVA GAME PROGRAMMING

This article is a continuation of the two articles on making Java game before. In this article, the author will discuss more about the concept of game programming using java.

Lots of interesting articles that are published on the website forum develover games like www.gamedev.net or www.javagaming.org. start from the basic game programming concepts to complex programming sebenarnyamalah porses simplify manufacture. Indeed, in programming, not only in games programming, design becomes the main foundation for making process does not come out of the main objectives. You can choose whichever method of suitable design for you. However, in this article the author would not discuss the issue. We return to the basic concepts of programming in java gaming.



After learning how to use java to make a simple 2D game, this time the author will present advanced concepts for a game. To further simplify, the author uses source code that has been made in the previous article, which can also be downloaded on the blog writer, http "/ / www.fauzihaqqi.net.

Sprite

Part that almost always there in a game is a sprite. The word sprite has multiple meanings in game programming. which means that there is a set of sprite images or animations that united in a larger gambaryang. Others say that the sprite is a term used to encapsulate a character in the game. a more general, and the sprite is defined as any object that has the location, pictures, and usually can be moved.

But in this article, sprite more emphasis on the encapsulation of an object in the game, whether the object moves or tidak.Bahkan itudapat a button "New Game" in the game menu could also be considered as a sprite, jikamemangmemiliki location and other attributes.

Try to think back a bit, what are the objects that must be defined in your game. A simple example of this snake game, there must be at least gamepanel for game area, snake to the representation of a snake, and apple to apple representation.

Gamepanel and snake we've created in the previous article. The rest, you just create a sprite apple that will form the food of the snake.

Simple, right? which pperlu you do just think in a structured starting from scratch. sprite design whatever is needed for your game. attributes and capabilities needed any sprite. Like for example, the snake must have the ability to migrate. different from the apple that exist only in one place for every apple-nya.Yang need to really think about is all the things that concerns only the sprites, the sprite must be done by itself. One example is the rendering. Each sprite should be able to draw himself, although nantinaymemakai Graphics2D object from its container. This is in accordance with OOP programming concept that is suitable for making games.

Collision Detection

The next basic thing in programming games is a collision detection (collision). The definition of collision here is not what happens if there is an accident. But the collision detection here is how to determine if an object is being cut (intercept) of other objects in the game.

There are many techniques and algorithms to detect whether the collision occurred or not. This collision is most easily detect if your game bettipe tile-based. Thus, all you have to do is check every tile of your game. The most serious incident, you should check that in fact the whole tile is smaller in number than the pixel size of these games. Thus, the computer will not take too long to detect it.

Unlike pixel-based collision detection him, indeed our eyes can easily detect whether an object is star-shaped star collided with another at the end. But it's not easy enough for a computer. If the algorithm you use is not efficient then the computer will be forced to check the entire pixel, until finally discovered that the collision occurred. this can reduce the performance of your artificial game.

In the example in the previous article, there is no collision detection between the snake with the edge of the area gamepanel. So if the snake up on the edge, he'll keep walking and disappear into the area outside the range. This should not be terjadi.Karena this snake game is a tile-based games. You only need to check whether the head of the snake out of the arena. Collision detection should be carried out section that holds the second largest object to be detected. In this case, means you have to detect it on gamepanel.

Sample source code simple. You can add the method below to the class Gamepanel:
... ...
not only the collision between a snake with the edge of the arena, but need also captured whether a snake's head was hit the apple, which means that the snake has eaten. You simply add a simple line below:
... ....
CreateNewApple method () will create a new apple somewhere random. While the method addBody () on the snake will add a body length of the snake. It will not be described in detail in this article, but you can learn more at an existing full souce code diblog author.
For the class first person shooter games like Counter Strike has been using collision detection based on pixel. It is not easy to do, especially for three-dimensional game. Slah one simple way is to define the boundary (boundaries) of the object to be in check. So, they only need to check each object edge pixel. Then, how to detect the edge of the object with the program? That is your challenge as a programmer.

Background

Background (background), including things that are important in game development. A good background will be able to define trembling well too. There is background only serves as a complement to, but there is also a character as an object of the game. There is a static background, there also may be engaged.

An interesting trick that gives the impression that kerakter move is by moving the background. You may see the classic Mario Bros. game. When Mario runs, Mario is not really moving on the screen, but the background is moving against the direction, so it would seem that directly mariolah're moving forward.

In rendering the concept, background is the first object to be rendered on the screen. It was clear that the goal is to not cover the background characters that will direndersesudahnya.
In tile-based games like Final Fantasy Tactic, Romance of the Three Kingdom, as well as the usual game two dimension of this snake, the background is not included in the large size, but dipecahmenjadi small sizes. Then the loop will be done to render background images.

Typically, image files and the file mapping information terletakterpisah background. It is intended to avoid redundancy between the image file that stu tile with another tile if you use the same file. Enough background mapping information stored in the form of text to index every file of the drawing.

However, there is also a background that is stored in large sizes, usually only once or indeed digunakn unnecessary surgery on the background. Typically, this type of background articles used to make the game start menu.

Background in the example source code consists of a writer only fil; e image size 10 x 10 pixels which will render the loop so that all plots have the same background.

State Game

Situation (state) of the game must be kept properly. The most simple things of this state is whether the game is running, pause it or are already game over. This is very influential on the game you made. Render the information in the game will also vary depending on the state's happening. For example, when you play Warcraft, if the tone of pressing the F10, by default the game will stop (pause), and the menu will be displayed.

Another example of state that is your destination information that are superior players at that time. For example in fighthing game, win-lose position each player is also stored.
Game state can be global or local according to each object. One example of a global state is a condition in Game Counter-Strike game, how many times terrorists win and how often do Counter Terrorist win. While the example is whether a local state of each player is still alive or already dead shot.

In the example source code provided by the author, can be seen that the state is still simple. State of the game was whether the game is running, pause it or game over. This is so that you can further explore to make the state-state ynag more detail again.

For any game over, the only way the game was when the snake struck his own body. In the game you made, you can add sprites form of a wall that will make the snake die if hit.
To put the interception that state, you can change the thread a little structure on the source code for the previous article, to be like this:
... ....
As is known, to declare a global variable in java, you can use the keyword "static". The aim is that these variables can be accessed by any object, without the need to contruct an object that has the variable. While the konstansta to declare, you can use the keyword "static final" variable so that it can not be modified, but can be accessed by any objeck.

To display information on whether the game is in the running position, pause it or game over, you simply add a few lines on the method paintComponent () senjadi as below:
... ... ..
Thus, updating a snake and collision detection is only done when the game is running. Depictions of information "Paused" or "Game Over" hanay happen, if the state is in progress in accordance with the conditions.

Do not forget to set the keyboard keys used to intercept the event pause. In contoj writer, the game will be paused or running if the player hit the Enter key. You simply turn it on in Game KeyAdapter Panel:
... ...
You can add a simple form of value-state players, that is what apple has been eaten by siular ynag, then displayed on the screen. You simply create a new variabelstatic and add value to it when there is a collision between the head of the snake with an apple.
Note: The author uses Windows 7 and JDK6u17untuk run source code. In the skin of Windows 7 have a nonconformity that causes packing java components leave little blank area and right edge of the section under the window, as shown.

Easier to Game Engine

The main skill a programmer is to copy-paste. When the programmer wants to create a game with a new idea, but with the same structure. Will generally be open long program code, then copy-paste the line that can be used again. If using this method, at least all the lines that became the basic functions of the game to be moved. Imagine, if you haruh carefully sorting lines which can be used again and which ones have to be rewritten, what more if you create a program with a structure that is less tidy. If it is so, like sodium absorption ratio would force spearheading ynag matalah. All the concepts and basic game programming that has been submitted, the author usually has been there in a game engine.

Game Engine is a software that is designed and articles used for the manufacture and development of a good engine game.Game should at least be able to menghendle citation needed-these basic operations. In fact, the existing game engine that provides basic AI (Artificial intelligence), a basic artificial intelligence such as the shortest route search and so forth.
The background of this game engine is very heavy because they to make a game from scratch. Because you have to make all the basic things, like how to display an animation, how to make sound effects and how to detect collisions. Though the process is usually almost the same in all games.

Thus, they invented a library that includes all the basic game development so that these libraries can be reused by programmers all want to make a new game, without starting from scratch. Or in other words is a copy-paste and unloading pairs.

Any type of game engine range. Some only provide the basic components, there are already providing a special class game with a certain genre, and even have a GUI that exists at making games look pretty doing drag and drop only.

Here is a list of Java game engine that you could try, and its official Web site address:
• A Menkey Engine (www.jmonkey-engine.com)
• Golden T Game Engine (www.goldenstudios.od.id) - game engine made in Indonesia
• JGame (www.13thmonkey.org/ ~ Boris / igame /)
• Slick (http://slick.cokeandcode.com/).
• LWJGL (http://www.lwjgl.org/).

Every game engine has its own cirikhas and methods. Game engines are also different levels, there are only providing basic methods, there ynag two-dimensional and there is even a three-dimensional. All of the above game engine is open source. You just try it, and choose which is appropriate for you. Deepen your skills with a selected game engine.

If you want to and intend to dive in the world of game programming, you'll want to make the game engine itself. This game engine that you use as needed, nothing less and nothing more. Learn how the concept of the structure of an existing game engine, how the active process of rendering it, how the main methods. For convenience, look for open source game engine with the same language, then copy-paste the code you need. However, do not forget to continue to respect the source code license.

Welcome to make games.

Comments

Popular posts from this blog

Redmi Officially Launches Redmi Watch

  Redmi officially released its initial smartwatch Redmi Watchin China. In terms of style, Redmi Watch looks similar to the Apple Watch. Redmi Watch has a square-shaped design with rounded corners. Redmi Watchcarries a 1.4 inch 2.5 D display with a resolution of 320 x 320 pixels. Its weight is quite light, just 35 grams.Redmi Watch brings water resistance technology with a depth of up to 50 meters. Redmi Watch brings a variety of sports activity discovery features, from running, cycling, swimming, and also much more. Redmi Watchhas numerous innovative features including a heart price detector and also a rest period tracker. All tracking tasks can be kept track of and also accessed through the Mi Fit application. Via this application additionally, users can establish the screen face on Redmi Watch. There are greater than 120 types of front views to select from for free. Redmi Watchcan get in touch with mobile using Bluetooth connection. This wise watch includes NFC assistance

Graphical User Interface in Java (Part 1 From 3)

Frankly, graphics-based applications are always more interesting than the application of command-line based. And the good news, building graphical applications in Java, it is not as difficult as imagined Java is a programming language first released by Sun Microsystems in 1995. Java philosophy of "Write Once, Run Everywhere" make Java become one of the popular programming languages today. According to the official website of Java, Java technology currently used in 4.5 billion devices (more than 800 million PCs, 1.5 billion gadgets, 2.2 billion smart cards) and still did not include use in printers, web-cam, games, car navigation systems, medical devices, etc Know Java If you've heard of Java, but not so deeply in the program, chances are you will be confused with terms such as Java 2 SDK, JDK, Java Applets, Java Script, Java Runtime Engine (JRE), Java SE 6, etc. All of the Java technology, but if you want to learn to develop Java applications on a PC, the Java SE (Standar

New Autoit: Debug Mode!

The virus is always ranks 10 most popular of the virus, even in the big 3 a few months back. How new variants in action? Follow this following discription Virus-like folder icon with the standard Windows default this is the older players in the world of viruses. Variannya very much, and comes with a variety of sizes. Of the first characteristics that never change is the use of a folder icon with the aim to deceive users. Antivirus others have to recognize that Autoit virus with a lmaut, Sohaned, or YahLover, known as our own Autoit.EE What Is Autoit ? Alleged that the author himself called Nhatquanglan the most likely came from Thailand. But we are not sure whether the new variants also come from the same manufacturer. For those of you who have never know what it is to Autoit. Autoit or full Autoit Script, is also the name of the applications that use automation to create a script, exactly automation, hotkeys, and scripting, as written in the site. In short, the script will be in autoi