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/>.
22 sg
= require
'fail.scenegraph'
23 require
'fail.scenegraph.shapes'
24 input
= require
'fail.game.input'
25 col
= require
'fail.bullet.collision'
27 PlayerShip
= fail
.utils
.class
31 function( self
, level
)
35 self
.frame
= sg
.Frame()
37 -- Create a renderable for the player ship. For now we just conjure a procedural cone
38 -- programmaticaly, at some point it'll be a renderable loaded from disk.
39 local mat
= sg
.Material()
40 mat
.Emission
.value
= fail
.math
.Vector4f( 0, 1, 1, 1 )
41 mat
.Specular
.value
= fail
.math
.Vector4f( 0, 0, 0, 1 )
42 self
.renderable
= sg
.shapes
.Cube( mat
, self
.frame
)
45 -- Serialization test. Load the player scenegraph from a file (previously saved in urggr.lua)
46 -- self.renderable = fail.fbffile.Reader.Load( "lulz.fbf" )
47 -- self.frame = self.renderable.pFrame
49 self
.Speed
= fail
.math
.Vector3f()
51 level
:addRenderable( self
.renderable
)
53 -- Create a collision object for the player ship. A box for the time being since the other shape classes
54 -- aren't wrapped in fail yet.
55 -- TODO: also provide a way to set the collision filter mask.
56 self
.CollisionObject
= col
.Object()
57 self
.CollisionObject
.pShape
= col
.BoxShape( fail
.math
.Vector3f( 0.5, 0.5, 0.5 ) )
58 self
.CollisionObject
.pFrame
= self
.frame
59 level
:addCollisionObject( self
.CollisionObject
)
61 input
.InputManager
.GetInstance().Actions
.Left
:bindHandler( function( pressed
) self
:MoveLeft( pressed
) end )
62 input
.InputManager
.GetInstance().Actions
.Right
:bindHandler( function( pressed
) self
:MoveRight( pressed
) end )
63 input
.InputManager
.GetInstance().Actions
.Up
:bindHandler( function( pressed
) self
:MoveUp( pressed
) end )
64 input
.InputManager
.GetInstance().Actions
.Down
:bindHandler( function( pressed
) self
:MoveDown( pressed
) end )
65 input
.InputManager
.GetInstance().Actions
.Fire
:bindHandler( function( pressed
) self
:Fire( pressed
) end )
69 function PlayerShip
:MoveLeft( pressed
)
77 function PlayerShip
:MoveRight( pressed
)
85 function PlayerShip
:MoveUp( pressed
)
93 function PlayerShip
:MoveDown( pressed
)
102 function PlayerShip
:Fire( pressed
)
104 -- TODO: might be useful to provide some easier access to copy constructors to simply this.
105 -- Perhaps in the form of a global fail.copy function?
107 bulletpos
= fail
.math
.Vector3f( --self.frame.LocalToParent.position )
108 self
.frame
.LocalToParent
.position
.x
,
109 self
.frame
.LocalToParent
.position
.y
,
110 self
.frame
.LocalToParent
.position
.z
113 bulletpos
.y
= bulletpos
.y
+ 0.7
115 self
.level
:addGameObject( urggr
.PlayerBullet( self
.level
, bulletpos
) )
119 function PlayerShip
:renderingUpdate( deltatime
)
123 -- print( deltatime )
124 -- self.camframe.LocalToParent.position.x = 7
125 -- self.camframe:dirty()
128 self
.frame
.LocalToParent
.position
.x
= self
.frame
.LocalToParent
.position
.x
+ self
.Speed
.x
* ( deltatime
/ 1000 )
129 self
.frame
.LocalToParent
.position
.y
= self
.frame
.LocalToParent
.position
.y
+ self
.Speed
.y
* ( deltatime
/ 1000 )
130 self
.frame
.LocalToParent
.position
.z
= self
.frame
.LocalToParent
.position
.z
+ self
.Speed
.z
* ( deltatime
/ 1000 )