First application
12th January, 2010
Basics, Scripting
Never created a game with ShiVa ? This tutorial is for you. Follow step by step the way to create a game easily.
Summary
1 – Environment production preparation
2 – Game creation
3 – Creation, parameters setting and integration of a scene
4 – Creation of application’s main script
5 – Intelligence for the camera
Environment production preparation
First step consists in preparing production environment.
Shiva is highly configurable and is installed with a default module organization in the different virtual desktops.
First action is to configure a new workspace:
To do that, in the main interace click on: ShiVa> Parameters
Then, in the Projects tab, click Add and indicate the root directory of your project.
Game creation
We are now going to create our first application.
For ShiVa, a Game is the resource representing the application.
Therefore the Game is the basic resource of an application, the root of the arborescence of a game’s structure.
For that click GameEditor > Game > Create
Enter a name.
Once the Game is created, you need to open it in your GameEditor (double-click or drag and drop or right click > open) to edit it.
Now you have your first application ready to work.
Notice a bar full of buttons has appeared at the top right of ShiVa. This series of buttons is directly linked to your Game.
They are used for:
- play/pause the game,
- relaunch the game by rebooting the motor,
- go one frame further,
The Game can be considered as a container of resources in which have to be a minimum number of resources necessary for the realization of an application.
Indeed, even if you can already launch your application (play button), nothing happens because there is no camera to “see the scene”, no scene to see and no intelligence to pilot the set. So, the next steps are going to be creating and integrating these resources.
Creation, parameters setting and integration of a scene
For ShiVa, the scene corresponds to the world, the 3D universe in which we are going to interact.
A scene can also be considered as a container of models (static or dynamic).
You can create the scene through the Game Editor, click on Edit > Scene > Create…
Enter a name for you scene (‘MyScene’ for example) and validate. An empty scene appears in the Scene Viewer. Save the scene ( SceneViewer > Scene > Save ) and close it.
With this method, the scene is automatically referenced in the Game Editor > Scenes tab.
When saving the scene, a default camera is automatically created in the scene.
Creation of application’s main script
As in any self-respecting good intelligent application, we are going to create the start intelligence, the one that is called from the start of the Game.
For this we are going to create an AIModel (Artificial Intelligence Model) and then reference it in our game as main AIModel.
To create an AIModel, click Game Editor > Edit > UserMainAI > Create, set the name (‘MyMainAi’ for the example) and validate.
At present time, the Game Editor, for this tutorial, is complete.
At its creation, the AIModel appears in the Script Editor and we are going to edit this AIModel (by default the AIModelEditor and Script Editor modules are locates on ‘Code’ desktop at the top right corner of ShiVa).
To launch a particular operation at the loading of an AIModel, you need to implement the ‘onInit’ function of the selected AIModel.
Double click on “Add Handler…” in the AIModel Editor and select onInit.
Then in the Script Editor write this codeline: application.setCurrentUserScene ( “MyScene” ) and save (ctrl-s).
Validate your code (F7, via compilation, optional but always reassuring)
Test it! To do this go to a scene viewer, desktop ‘General’ for example, then launch your application (play button or F9)
You will then be in your scene with your camera positioned at position where the camera was when you opened the scene to edit it. We are now going to bother with the camera in order to give it a little more interest…
Intelligence for the camera
Now we are going to rotate the camera around the central point 0,0,0.
To do this open your AIModel in the AIModelEditor.
In the onInit script, you have to place the camera, insert:
local hCamera = application.getCurrentUserActiveCamera ( ) object.setTranslation ( hCamera, 3, 3, 3, object.kGlobalSpace )
Create a onEnterFrame handler and add these lines to make the camera rotating around the center of the scene and looking at this point:
local hCamera = application.getCurrentUserActiveCamera ( ) object.rotateAround ( hCamera, 0, 0, 0, 0, 1, 0, object.kGlobalSpace ) object.lookAt ( hCamera, 0, 0, 0, object.kGlobalSpace, 1 )
Here is your first version of your first application with a camera that rotates around the center of a scene.
Leave a Reply
















