Skip to content
Browse files

Shoot player bullet

  • Loading branch information...
1 parent cfd570d commit 9d8c5af0b9c5c597204d6313ece8def4455bcdd0 @c000 committed Jun 18, 2012
Showing with 51 additions and 6 deletions.
  1. +25 −5 src/GameStage.hs
  2. +24 −0 src/GameStage/Bullet.hs
  3. +2 −1 src/GameStage/GameObject.hs
View
30 src/GameStage.hs
@@ -4,7 +4,6 @@ module GameStage
) where
import Data.Set
-import Data.Complex
import qualified Class.GameScene as GS
import Class.Sprite
@@ -13,20 +12,41 @@ import GlobalValue
import GameStage.GameObject
import qualified GameStage.Player as P
+import qualified GameStage.Bullet as B
data GameStage = GameStage
{ player :: P.Player
+ , playerBullets :: [B.Bullet]
} deriving Eq
instance GS.GameScene GameStage where
- update (GV {keyset = key}) scene@(GameStage {player = player}) = do
+ update (GV {keyset = key})
+ scene@(GameStage { player = player
+ }) = do
case member QUIT key of
True -> return GS.EndScene
- False -> return $ GS.Replace $ scene {player = P.update key player}
+ False -> return $ GS.Replace $ ( shoot
+ . update
+ ) scene
+ where
+ update :: GameStage -> GameStage
+ update (GameStage p pbs) = GameStage (P.update key p)
+ (Prelude.map B.update pbs)
+ shoot :: GameStage -> GameStage
+ shoot stage@(GameStage { player = p
+ , playerBullets = pbs
+ })
+ = let ppos = (pos.gameObject) p
+ in stage { playerBullets = if member A key
+ then B.playerBullet ppos : pbs
+ else pbs }
- render (GameStage {player = player}) = do
+ render (GameStage { player = player
+ , playerBullets = playerBullets
+ }) = do
render $ gameObject player
+ mapM_ (render.gameObject) playerBullets
return ()
gameStage :: IO GameStage
-gameStage = return $ GameStage P.player
+gameStage = return $ GameStage P.player []
View
24 src/GameStage/Bullet.hs
@@ -0,0 +1,24 @@
+module GameStage.Bullet
+ where
+
+import Data.Complex
+
+import GameStage.GameObject
+import Internal.Texture
+
+data Bullet = Bullet
+ { object :: GameObject
+ } deriving (Eq)
+
+instance HaveGameObject Bullet where
+ gameObject (Bullet {object = x}) = x
+
+update :: Bullet -> Bullet
+update bullet = bullet { object = newObject }
+ where
+ Bullet {object = currentObject} = bullet
+ newObject = objUpdate currentObject
+ objUpdate now@(GameObject { pos = pos })
+ = now {pos = pos + (1:+0)}
+
+playerBullet pos = Bullet (GameObject pos 8 (8:+8) noTexture 0)
View
3 src/GameStage/GameObject.hs
@@ -31,10 +31,11 @@ instance S.Sprite GameObject where
}) = do
let hsx = sx / 2
hsy = sy / 2
+ blendFunc $=! (One, Zero)
preservingMatrix $ do
translate $ Vector3 x y 0
renderPrimitive Quads $ do
- c3 1 1 1
+ c4 1 1 1 1
v2 (hsx) (hsy)
v2 (-hsx) (hsy)
v2 (-hsx) (-hsy)

0 comments on commit 9d8c5af

Please sign in to comment.
Something went wrong with that request. Please try again.