Created a test obstacle to test collisions with.
[urggr.git] / src / urggr_package / level.lua
blobf1ff762a7803515d59c81f236627f949639ddfa7
1 --[[
2 Urggr - An horizontal scrolling shoot'em up.
3 Copyright 2008 Antoine Chavasse <a.chavasse@gmail.com>
5 This file is part of Urggr.
7 Urggr is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 3
9 as published by the Free Software Foundation.
11 Urggr is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 --]]
20 require 'fail.utils'
21 require 'fail.math'
22 sg = require 'fail.scenegraph'
23 col = require 'fail.bullet.collision'
25 Level = fail.utils.class
27 function( self )
28 self.gameobjects = {}
30 -- The top level container of the rendering scene graph.
31 -- Just a group because there's nothing else currently,
32 -- and this project won't be needing anything more sophisticated
33 -- for a while.
34 self.renderablegroup = sg.Group()
36 -- Create the bullet collision world
37 local broadphase = col.AxisSweep3(
38 fail.math.Vector3f( -1000, -1000, -1000 ),
39 fail.math.Vector3f( 1000, 1000, 1000 ) )
40 self.btcollisionworld = col.World( broadphase )
42 self:addGameObject( urggr.Camera() )
43 self:addGameObject( urggr.PlayerShip( self ) )
44 self:addGameObject( urggr.TestObstacle( self ) )
45 end
48 function Level:addGameObject( gobj )
49 table.insert( self.gameobjects, gobj )
50 end
52 function Level:addRenderable( renderable )
53 self.renderablegroup:add( renderable )
54 end
56 function Level:addCollisionObject( colobj )
57 self.btcollisionworld:addObject( colobj )
58 end
60 function Level:update( deltatime )
61 self.btcollisionworld:performDiscreteCollisionDetection()
63 for i,v in ipairs( self.gameobjects ) do
64 v:update( deltatime )
65 end
66 end
68 function Level:evaluateRender( renderpass )
69 self.renderablegroup:evaluate( renderpass )
70 end