Showing posts with label Game services. Show all posts
Showing posts with label Game services. Show all posts

Friday, 21 June 2013

Completed Tower Defense Game Source code (GDX Engine ver 1.2.6)

Our new games on Play Store:
https://play.google.com/store/apps/developer?id=Best+free+games

please support us for download and give our games rating.

GDX document using ver 1.2.2 Engine à  1.2.5

Update: 1.2.6

Some of the features added in this version are:
• Integrate the A * algorithm
• Add InputEvent for game components
• Completed Tower Defense Game

View Game: 
Download:
Game made from ​​libgdx so i can play on PC! Jar file you can download here: https://docs.google.com/file/d/0B9TsWVI1UbkKMGlmRTBOcXdyT3c/edit?usp=sharing 
Then install the JRE and always play jar files (double-click)

This document overview of the main features of GDX Engine
Update: 1.2.4 
Create the ability to automatically load resource by class
AssetLoader.setAssetClass(Texture.class);
           Texture Texture1 = AssetLoader.load("data/1.png");
           Texture Texture2 = AssetLoader.load("data/2.png");
           Texture Texture3 = AssetLoader.load("data/3.png");
           // ...
For above example, you set the class of asset will load (Texture). Then you call the load method and pass the path to the asset. That's it, that engine will load up and asset returns true class for loading your textures. method setAssetClass should be called to determine the type of asset that you want to load first. After all textures loaded, you might want to load BitmapFont, you must set the BitmapFont class in setAssetClass method.

AssetLoader.setAssetClass(BitmapFont.class);
           BitmapFont font1 = AssetLoader.load("data/font1.fnt"); // ...
And the load is similar to the texture.

Additional features of the scene created using UIManager ui

Illustrations by Video i posted in gdengine.blogspot.com. UIManager will have a Main Menu for Scene and other ui components (Button, checkbox...) . If Main Menu ‘s visible, it will block another update of the scene and Gameplay go normal if you turn off the main menu.
Recommendation you should start creating UIManager by override the method setupUIManager (String) of Scene the class you are taking:
@ Override
          public void setupUIManager (String skinPath)
              {// create newuiManager and
              superskin.setupUIManager(skinPath);
             
/ / Next, create the UI component and add it to uiManager
              / / ...

The following example creates a button (Image and toggle button):

ImageButton iconButton = new ImageButton (style);

              Button buttonMulti = new TextButton("Hello!" skin, "toggle");

The ui component as Button, CheckBox ... is from the libgdx framework. You go to libgdx documentation to know how to create them. After ui already have, you can add it directly to uiManager:

uiManager.AddActor (iconButton);
/ / you're done, iconButton will
uiManager update and drawdone automatically

if you create the main menu of scene. For example, when you play Starcraft II, you press F10, it will drop the main menu and pause the game so that players can use the menu, adjust settings or restart the game ... you need a method getWindows () to get the main menu. After that, you can call add () of window to add the UI on the main menu of the scene
uiManager.getWindows().defaults().spaceBottom(10);
              uiManager.getWindows().row().fill().expandX();
              uiManager.getWindows().add(iconButton);
              uiManager.getWindows().add(buttonMulti);
              uiManager.getWindows().add(btnCloseMenu);
              uiManager.getWindows().add(imgToggleButton);
              uiManager.getWindows().row();

Menu of Libgdx using TableLayout, you read the libgdx documentation to learn more about TableLayout. I explain some method in above code:

defaults () indicates the default setting for a menu cell in theTableLayout
row() Creates a new line on the TableLayout
add () Add a ui the current cell in the current row of TableLayout. Then if you call add () again, the next ui will add to the next cell in the row.
At above example, I call the add () four times, so   
             
             
                  

TableLayout is currently with four column and then row () method is called, it cause a new table row is created. This row will of course also have four columns as the row above (Table layout)
Row second you can still call the add () to add ui normally. You do not need to worry about the size of the table, as long as you remember to call the method pack () it will automatically resize to fit your design.

                   UiManager.GetWindows (). Pack ();

You can use ChangeListener to control the behavior of the UI, for example:

btnShowMenu.
addListener(new ChangeListener ()

                     {@Override
                     public void changed (ChangeEvent event, Actor actor) {
                           uiManager.setMenuVisible(true);}
                     });
             
Button above, when clicked on will be referred to the changed method () of ChangeListener. It will be called the method setMenuVisible. of uiManager. Read the method name to make you guess how it works, right? It will show the Main Menu of the scene I mentioned above.


Create Tab Panel

If you used to create java swing app, you will see a menu tab. However GDX Engine is to make the game, not the app, so the original will not be any UI Tab Menu as such, i have coded the tab pane for the engine: 3
To use the tabbed panel, you need to declare it:

TabPane pane = new TabPane (2)

Parameter 2 is the number of tabs will be, here are 2 tab panels.
, then add ui to uiManager:

uiManager.addActor (pane);

Then you add tabs for TabPanel , and set the default active tab:

pane.addTab("Tab1",tab1, skin);
              pane.addTab("Tab2",tab2, skin);
              pane.setActiveTab (0)
In setActiveTab (int), index is 0 is the first tab, 1 is the second tab ...
And tab1, tab2 is TabContent, which is a interface ITabContent that you can use to create anonymous class instance:
ITabContent tab1 = new ITabContent()

                     {@Override
                     public void setContent (Table content)
                           {content.clear();
                           content.row (.) expand ();
                           content.add (label1);
                           content.pack
                     ();}

                     @ Override
                     public float getHeight ()
                           {return label1.getHeight
                     ();}

                     @ Override
                     public float getWidth ()
                           {return label1.getWidth
                     ();}};
             

Above code has two methods of taking the tab content size. Method setContent () to set the tabContent content. On his first try add label to TabContent. Of course how much you want to add UI to be as well. tabContent also use TableLayout.

Additional Action ActionManager management.

Action is an action of a game object after a certain time. Illustrations used in demo Action and ActionManager CatchDrop, automatically create new drop after 5 seconds.

Firstly, you need to have ActionManager, create it in your Scene classes:
ActionManager am = new ActionManager();
              services.AddService (am),

you add it to GameService, then update it in the update method of the scene:
                   am.Updates (gametime)

If you use the action, you get ActionManager from GameService, then add your Action:
@ Override
       public void initialize ()

              {ActionManager am = getGameServices (). getService(ActionManager.classes);
              / / create a sẽ Perform action after each 5 seconds
              BaseSimpleAction action = new BaseSimpleAction(false, 5f)
                    
                     {@Override
                     public void onActionPerformance()
                           {addItem(new Drop
                     ());}};
             
              am.addActionToDefault
       (action);}
It is recommended from the getService method initialize  method ()to avoid bug GameComponent. Action on using BaseSimpleAction It is extremely easy to use, as you can see, false passed to pause, pause that is false, action will be executed as soon as add on after 5s (2nd parameter in the constructor). If Pause is true, then there is no action after 100s happen ;)

After 5s,event onActionPerformance will be known when it will drop to add new one for DropCollection (above code is in class DropCollection):
                             @ Override
                     public void onActionPerformance(){
                           addItem(new Drop
                     ());}

Update: 1.2.3

 Supports automatic camera zoom and locate the tiled scene, watch video below illustrates this feature in the demo "Angry bird" Fix not display properly in game screen resolution different. Additional constants for some TiledScene, to set the parameters of the scene as the targeted size, world size, scale values ​​...
Using not be easier! You call the method setupCamera (); Scene Of class you are taking and that's it, the engine will do everything for you.
Sometimes the frame rate of the device (Width / Height) will be different than if you design the game, This common ratio is now 4:3 and 16:9. Default Engine will stretch to fit the screen. If you do not want that, you can use the method  keepGameAspectRatio () of the scene to keep the frame rate as you have designed. (When the engine will crop away some parts to fit on the screen)

Update: 1.2.2

 Additional PhysicsManager initialize and update all physical objects in your game, so you do not have to use that PhysicsScene can use any one scene, then create PhysicsManager and add PhysicsManager as a game component for that scene. A new interface is IPhysicsObject to identify a physical object in the game, so you are not forced to use PhysicsObject class that means it can use any class game component to implement IPhysicsObject interface, then it is possible to add to PhysicsManager or PhysicsScene.
demo source code "Angry Birds" has been revised to illustrate the use and PhysicsManager IPhysicsObject.
PhysicsManager Usage of similar PhysicsScene. You only need to change the method of PhysicsScene by method PhysicsManager object is
ok, For example, you add an object to physicsScene as follows:
Body body = addDynamicBoxObject (brick, object.width, object.height)
Similarly, now you add in PhysicsManager as follows:
Body body = physicManager.addDynamicBoxObject (brick, object.width, object.height);

(a brick
is physicsSprite or IPhysicsObject interface)
physic manager automatically update and render all your physicsObject, you just add the manager to the Scene of the physic engine, and the engine will take care of all of physicsObject update and draw for you!

For more details, the source code Demo "Angry Birds "I did and I got some comments there.

Thursday, 4 April 2013

Introduction of Game Service


when you develop game with GDX Engine, you will be familiar with a concept very popular in GDX engine, it's the game-services. Game-services are a special object is created in the Game classes. The service contain all services provided by Game, as retrieved sprite batch, take out the camera, scene management, add an object to make custom services ... You can understand the Game-services is a variable that contains a lot of references to objects will be used frequently when development in game. Game shared services to all Game Component and extend the class of Game Component. Game-services will be retrieved by method getGameServices() of Game Component.
Game-services are separated as GameService class for Game 2D (Class Game) and Game3DService for Game 3D (Class Game3D). Game3DService inherited from GameService and added some services such as CameraManager, LightManager and ShaderManager that manage all cameras, lights and shaders in any 3D game using GDX Engine. To construct the Game-service, you must call the initializeGameServices() method of Game Class.
Game-services allow you to render a texture directly on the screen by using method drawTexture(),or render a texture region using the method drawTextureRegion() upon the screen. It also allows you to draw any text on the screen using a bitmap font by using the DrawText () method .
Method changeScene () of the Game-services is very convenient when you want to move the screen, refer to the introduction engine architecture, [ Game-scene ].
You must call initializeGameServices() method in your Game class, but it is not required to create  every instance for every object services to pass into the method as parameters, you ‘re allowed to pass ‘null’ value. If you pass the ‘null’ value into any parameter in the method, the engine will automatically create an instance instead of null value using proper existing default class.
The service contained two basic types of service, These are built-in services, and custom services.

Built-in services

This is the services available, including sprite batch, game asset, game setting, scene changing, camera for Game2D and some 3D service managers in game3D. asset and setting are the objects require to create an instance and then use that instance to initialize the Game-services. 3D service managers, of course, is only necessary when you create a 3D game. With 2D game there is no need to.
When you initialize Game-services, you need to pass in an instance of GameAsset and GameSetting. You can extend from the base class BaseGameAsset andBaseGameSetting in the engine to generate asset or a special setting for your game, or you can use the default class that engine has built.
To initialize the Game-services, You need to call method initializeGameService ( ) of the Game class, there are two parameters using the default built-in class of Gdx engine.
Example:
//Call in Extended Game class
initializeGameService (new DefaultGameAsset (), new DefaultGameSetting ());
In game3D, with 3D services manager, you can create an instance of the 3D Managers, and initialize the Game-services. In game3D, there are five parameters
For example: / / Create managers
CameraManager cameraManager = new CameraManager ();
LightManager lightManager = new LightManager ();
ShaderManager shaderManager = new ShaderManager ();          
/ / Initialize settings and assets
BaseGameSetting setting = new DefaultGameSetting ( );
DefaultGameAsset asset = new Asset ();
/ / Initialize Game-service for all scene can use later
initialzeGameService (assetsettingcameraManagershaderManagerlightManager);
When you call method initializeGameService, engine automatically call the load...() method of GameAsset and GameSetting in Game-services to load the asset and setting when the game is starting.

Custom services

is discretionary services that contain references to other objects in the game. For example, you make the asteroid game, in which the player is a ship floating in space. Ship will be destroyed if a collision with Meteor or hit the Enemy's bullet. So you can think the player is a Game-services. the the Meteor and EnemyBullet class can use the player game-service to check for collision with the player. This actually is the ship which gamer controls in the game. For Player can become a services, it needs implement IService interface. Rest assured this is just empty interface to notify Gdx engine that instances of this class can be used as a service in the game.

/ / Player class declaration
class Player extend GameComponent implements the IService {/ / your code}
/ / Create a real player that gamer controls:
Player player = new Player ();
// Make player into a service.
getGameServices (). addService (player);
You just using method addService () of Game-service so this can turn the player into a services!
To use the Player service , you simply call to getService() method of Game-service object:
/ / In the Meteor class, in initialize () method. Get the Player service.
Player player = getGameServices().GetService(Player.class);
/ / Check collision, in the update method of the meteor class:
If (player.collides(this) { / / do some funny stuffs... }
getService () method is a generic method, which means you do not need to cast the return object to Player.
The method wisely return the Player type, but it will return the data type Player. Similarly if you call getGameServices (). getService(ABCXYZ.class); getService ( ) method will return type ABCXYZ  for you :-D
You need to get a service, then add service before! If you do not correct the order, the service which will be null and Engine will throw an GdxRuntimeException “Service is not existing...”. To be safe, it is best to add services in the constructor of the Scene, and get services in method initialze () of the Game component object.
Default permission for number of using custom services up to ten. If you want to change,  before calling method  initialzeGameService(), you need to specify the number of services that you would like in static variable MAX_SERVICES:
Example:
GameService.
MAX_SERVICES = 20;
              / / Initialize Game-service for all scene can use later
              initializeGameService (asset, baseGameSetting );
code above will make your game supports up to 20 Custom services.