root/tutorials/branches/0185_GEN_PHYSICS_REFACTOR_2/Tutorial4/scripts/client/GameClient.lua @ 3480

Revision 3480, 3.4 KB (checked in by trichards, 6 months ago)

Adding I_CollisionResource and improving ZODE plugin to load a HeightfieldResource? for height mapped terrains.

Line 
1
2
3-- ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
4GameClient =
5{
6        -- Put member variables for the game client here
7}
8
9-- ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
10-- new
11-- allows you to overload the Zen:GameClient implementation with
12-- additional methods and member variables
13function GameClient:new(type)
14    print("create")
15        o = Zen:createGameClient(type)
16        print("setmetatable")
17        setmetatable(getmetatable(o), self)
18        print("self.__index = self")
19        self.__index = self
20        print("return o")
21        return o
22end
23
24-- ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
25function GameClient:initialize()
26        rootGroup = self:getRootGroup()
27
28        self:createActions()
29        self:createDefaultMappings()
30        self:createScene()
31
32        self:run()
33end
34
35-- ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
36function GameClient:getRootGroup()
37    -- This is in Game now, not GameClient
38    return self:getGame():getRootGroup()
39end
40
41-- ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
42function GameClient:getActionMap(actionMapName)
43    -- This is in Game now, not GameClient
44    return self:getActionMap(actionMapName)
45end
46
47-- ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
48function GameClient:createActions()
49    print("=============\nCreate Actions...\n============")
50    self:getActionMap():createAction("Test", GameClient.testAction, self)
51    self:getActionMap():createAction("onInitDone", GameClient.onInitDone, self)
52    print("-------------\n")
53end
54
55-- ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
56function GameClient:createDefaultMappings()
57    print("=============\nCreate Default Key Mappings...\n============")
58    self:getKeyMap():mapKeyInput("t", self:getActionMap():getAction("Test"))
59    self:getKeyMap():mapKeyInput("a", self:getActionMap():getAction("Move Left"))
60    self:getKeyMap():mapKeyInput("d", self:getActionMap():getAction("Move Right"))
61    self:getKeyMap():mapKeyInput("w", self:getActionMap():getAction("Move Forward"))
62    self:getKeyMap():mapKeyInput("s", self:getActionMap():getAction("Move Backward"))
63end
64
65-- ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
66function GameClient:createScene()
67    print("=============\nCreate Scene...\n============")
68    local minSize = Math.Vector3(-2000.0, -4000.0, -2000.0);
69    local maxSize = Math.Vector3( 2000.0,  2000.0,  2000.0);
70   
71    self.zone = self:getGame():getPhysicsService():createZone();
72    self.zone:setZoneSize(minSize, maxSize);
73   
74    self:getTerrainService():setPhysicsZone(self.zone);
75   
76    local matXfm = Math.Matrix4();
77    matXfm:setXYZRotation(0, 0, 0);
78    matXfm:setPosition(0, 0, 0);
79   
80    self.terrain = self:getTerrainService():createTerrain();
81    self.terrain:loadVisualization("terrain.cfg", matXfm);
82   
83    -- Load the physics terrain
84    self:loadTerrain("terrain.cfg", matXfm);
85end
86
87-- ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
88function GameClient:testAction(action)
89    if action:getPressedState() then
90        print("Yay, the T button was pressed!!!")
91    else
92        print("Yay, the T button was released!!!")
93    end
94
95end
96
97-- ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
98function GameClient:onInitDone(gameClient)
99    self:createScene();
100end
Note: See TracBrowser for help on using the browser.