Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • 9562850/fp-asteroids
1 result
Show changes
Commits on Source (2)
......@@ -232,11 +232,14 @@ spawnPowerup gen Nothing = (Just genPowerup, newGen)
(index, newGen) = randomR (fromEnum (minBound :: Effect), fromEnum (maxBound :: Effect)) gen''
genPowerup = Powerup (genX, genY) (toEnum index)
powerupRadius :: Float
powerupRadius = 15
checkPowerupCollision :: GameState -> GameState
checkPowerupCollision gstate@(GameState {spaceShip, powerup}) =
case powerup of
Nothing -> gstate
Just x -> if (collidesWith 15 (position x) (location spaceShip))
Just x -> if (collidesWith powerupRadius (position x) (location spaceShip))
then (claimPowerup gstate)
else gstate
......
......@@ -8,6 +8,19 @@ import System.Random
import System.IO (withFile, IOMode(ReadMode), hGetContents)
class Spawnable a where
getLastSpawn :: a -> Float
spawn :: StdGen -> (a, StdGen)
class Moving a where
getLocation :: a -> Location
getOrientation :: a -> Orientation
getVelocity :: a -> Velocity
move :: Float -> a -> a
--checkCollision :: a -> GameState -> Bool (!) not sure if we need this
data MovingObject = MovingObject Location Orientation Velocity
type Velocity = Float
type Location = (Float, Float)
type Orientation = Float
......@@ -31,7 +44,16 @@ data Specifications = Specs {
type Size = Int
data Meteor = Meteor { coordinates :: Location, directoin :: Orientation, pace :: Velocity, size :: Size}
data UFO = UFO Location Orientation Velocity Bullet
data UFO = UFO MovingObject Bullet
instance Moving UFO where
getLocation (UFO (MovingObject x _ _) _) = x
getOrientation (UFO (MovingObject _ x _) _) = x
getVelocity (UFO (MovingObject _ _ x) _) = x
move secs (UFO (MovingObject loc orient v) b) = UFO (MovingObject loc orient v) b
type Score = Int
type Name = String
type Highscore = (Name, Score)
......@@ -61,8 +83,10 @@ data GameState = GameState {
, elapsedTime :: Float
, powerupTimer :: Float
, meteorTimer :: Float
, ufoTimer :: Float
, spaceShip :: Spaceship
, meteors :: [Meteor]
, ufos :: [UFO]
, powerup :: Maybe Powerup
, seed :: StdGen -- Each game has its own 'seed' which allows for pure randomness
}
......@@ -113,9 +137,11 @@ initialState seed = GameState {
, player = Player 3 0 "Player"
, elapsedTime = 0
, powerupTimer = 0
, ufoTimer = 0
, spaceShip = Spaceship (0,0) 0 0 [] seed 0 defaultSpecs
, powerup = Nothing
, meteors = []
, ufos = []
, notification = ""
, tooltip = ""
, seed = seed
......