Created a test obstacle to test collisions with.
[urggr.git] / src / urggr_package / game.lua
blobed0ad90008bc1b4731dcfcf0e09fcad4645b5d74
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 'qtgui'
21 require 'fail.utils'
22 require 'fail.math'
23 sg = require 'fail.scenegraph'
25 Game = fail.utils.class
27 function( self, view )
28 -- Create camera
30 -- TODO: that's just testing, this should be moved into the camera class.
31 self.camframe = sg.Frame()
32 self.camera = sg.Camera( self.camframe )
33 --self.camera.FOV = 60
34 local mtx = fail.math.Matrix44f()
35 mtx:rotation( 90, fail.math.Vector3f( 0, 0, 1 ) )
37 -- TODO: investigate why setting the position in mtx before assigning it
38 -- to the localtoparent matrix doesn't work.
39 --mtx.position.x = -7
40 self.camframe.LocalToParent = mtx
41 self.camframe.LocalToParent.position.x = 15
42 self.camframe:dirty()
44 -- Create viewport
45 self.viewport = sg.ViewPort( sg.PerspectiveProjection(), self.camera )
46 self.viewport.Rect = fail.math.Rectu32( 0, 0, 1024, 768 )
48 self.mainpass = sg.RenderPass( self.viewport )
49 self.mainpass.bClearDepthBuffer = true
50 self.mainpass.bClearColorBuffer = true
52 self.qtscene = QGraphicsScene()
53 self.qtscene.drawBackground = function() self:render() end
55 fail.game.input.Action( "Left", "Move left" )
56 fail.game.input.Action( "Right", "Move right" )
57 fail.game.input.Action( "Up", "Move up" )
58 fail.game.input.Action( "Down", "Move down" )
60 fail.game.input.InputManager.GetInstance():bindAction( "Left", "keyboard", "Left" )
61 fail.game.input.InputManager.GetInstance():bindAction( "Right", "keyboard", "Right" )
62 fail.game.input.InputManager.GetInstance():bindAction( "Up", "keyboard", "Up" )
63 fail.game.input.InputManager.GetInstance():bindAction( "Down", "keyboard", "Down" )
66 self.level = urggr.Level()
68 self.lasttime = 0
69 self.time = QTime()
70 self.time:start()
72 view:setScene( self.qtscene )
74 fail.game.keyboard.Provider( self.qtscene )
75 end
78 function Game:render()
80 --collectgarbage()
82 local deltatime = self.time:elapsed() - self.lasttime
83 self.lasttime = self.lasttime + deltatime
85 sg.RenderPass.ClearAll()
86 self.mainpass:prependToRenderList()
88 self.level:update( deltatime )
89 self.level:evaluateRender( self.mainpass )
90 sg.RenderPass.RenderAll( true )
92 QTimer.singleShot( 10, self.qtscene, "1update()" )
94 end