blubber-server-0.0.1: The blubber server, serves blubber clients.

Copyright(c) plaimi 2015
LicenseAGPL-3
Maintainerblubber@plaimi.net
Safe HaskellNone
LanguageHaskell2010

Blubber.Server.World

Description

 

Synopsis

Documentation

data World Source

The World in which the Entitys reside.

Constructors

MkWorld 

Fields

width :: Double

The width of the World.

height :: Double

The height of the World.

players :: Map String Entity

The PlayerBlobs in the World indexed on their names.

neutrals :: Set Entity

The NeutralBlobs in the World.

entropy :: StdGen

The entropy of the World, for randomising things.

Instances

addNeutral :: World -> World Source

Try to add a NeutralBlub to the World, if there is room for it. But don't try *very* hard.

addPlayer :: World -> String -> World Source

Add a PlayerBlub belonging to the name in the passed in String, lest it already has a PlayerBlub, in which case it's just ignored.

delPlayer :: World -> String -> World Source

Delete a PlayerBlub belonging to the name in the passed in String, lest it doesn't exist, in which case it's just ignored.

available :: World -> Entity -> Bool Source

For use with Entitys that are not yet placed in the World, in order to check that the spot you are attempting to place them in is actually available -- i.e. that it doesn't intersect with already placed out Entitys

clamp :: Ord a => a -> a -> a -> a Source

clamp stuff between a min and a max.

createWorld :: StdGen -> World Source

The initial World.

updateVel :: Double -> Entity -> Entity Source

Update the velocity of an Entity based on its targetPos, and limited by its mass.

updatePos :: Double -> World -> Entity -> Entity Source

Update the 'position of an Entity based on its velocity. Makes sure to clamp the Entity to the World edges.

decay :: Double -> Entity -> Entity Source

Natural decaying of Entity mass, so as to not have too huge Entitys.

playerBlubbers :: World -> World Source

Check if any one Entity collides with any one other. If they do, delete them out of the recursion, and keep checking the others until every Entity is checked with every other.

neutralBlubbers :: World -> World Source

Check if any one Entity collides with any one other. If they do, delete them out of the recursion, and keep checking the others until every Entity is checked with every other.

playerBlubs :: (String, Entity) -> [(String, Entity)] -> Maybe ((String, Maybe Entity), (String, Maybe Entity)) Source

Given an Entity of a PlayerBlub and its id (as a String), and a list of other such things, let the Entity fite all the ones in the passed in the list.

It keeps checking until there's a collision. At that point, it figures out which one blubbers which. The blubberer grows, and the blubberee is deleted. Ruthless.

If there is no collision it returns Nothing. If there is one, it returns a Just with two tuples -- one for each Blub. The survivor will be a Just, the other one Nothing.

neutralBlubs :: (String, Entity) -> [Entity] -> Maybe ((String, Entity), Entity) Source

Given an Entity of a PlayerBlub and its id (as a String), and a list of NeturalBlubs Entitys, let the PlayerBlub Entity fite all the NeutralbBlubs in the passed in list.

It keeps checking until there's a collision. At that point, it returns the now rather quiute big PlayerBlub and the poor NeutralBlub it has blubbered. If there is no collision it just returns Nothing.

setTargetPos :: String -> Double -> Double -> World -> Map String Entity Source

Check if the client in the passed in String is the owner of an Entity; if so, set its targetPos to the passed in Doubles.

updateWorld :: Double -> World -> World Source

Update the World. updateVel, updatePos, decay, and check for blubbers.

handleInput :: Ord c => [(c, (Double, Double))] -> Map c String -> World -> World Source

Checks if a client has a player. If it does, then update the targetPos of the player's Entity.