Through the course of this recipe you will learn the steps that are necessary to set up a very basic application structure to get your application going.
To follow the steps of this recipe you should have finished the first recipe in this chapter to have a properly configured development environment.
Follow these steps to create an empty project skeleton:
Start NetBeans and click File | New Project… in the main menu.
Select Python Project and click Next on the first screen of the New Project Wizard.
On the New Python Project screen, set the Project Name and choose a Project Location. Also select Set as Main Project and Create Main File. Set the textbox to main.py, and check that the right Python Platform is active. Click Finish to proceed.
Right-click the Project Name | Sources | Top Level item in the tree view in the Projects tab and select New | Empty Module.
In the window that opens, set the File Name to Application and click Finish.
Paste the following code into
Application.py
:from direct.showbase.ShowBase import ShowBase class Application(ShowBase): def __init__(self): ShowBase.__init__(self)
The code that follows goes into
main.py
:from Application import Application if __name__ == "__main__": gameApp = Application() gameApp.run()
Open your project directory in Windows Explorer and create folders called
models
andsounds
next to thesrc
folder. The folder structure should resemble the following screenshot:Open the
Config.prc
file as described in the prior recipe and add the following lines:model-path $MAIN_DIR/../models model-path $MAIN_DIR/../sounds
Hit F6 to run the application.
First, we start by creating a new project in NetBeans. It generally is a very good idea to name the main file that will be launched by the Python runtime main.py
, so we are already set when we want to package our code and assets for redistribution later on.
The Application
class, derived from ShowBase
, is added as an abstraction of our game application. We must not forget to call the constructor of ShowBase
in the constructor of Application
or else there won't be a window opening when launching the program.
Because we do not want code files and assets to be scattered in a mess inside one single folder, we add folders dedicated to certain asset types. Depending on the type of project we intend to create, this setup may vary and we may wish to add additional folders. What's important about that is not to forget to add these extra folders to Panda3D's search paths too in Config.prc
, just like the models
and sounds
folders!