Physics in the Casanova language for game development (x-post from reddit/gamedev)

30 views
Skip to first unread message

Giuseppe Maggiore

unread,
May 21, 2013, 7:33:12 AM5/21/13
to fsharp-o...@googlegroups.com

Dear all, I would like to point out an upgrade that was recently completed for the Casanova language: physics support through the Farseer engine.

This means that now, in addition to declarative rendering, game loop, input and game scripts through coroutines, and menu support, Casanova now offers a series of primitives for handling physics. For example, the definition of the game world and entities for a simple bouncing ball is now just:

type [<CasanovaEntity>] Ball = {
  Circle              : PhysicsEntity
  Sprite              : DrawableSprite
} with
  member self.Position = self.Circle.Position
  static member SpritePosition'(self:Ball,dt:float32<s>) = 
    self.Circle.Position
  static member SpriteRotation'(self:Ball,dt:float32<s>) = 
    self.Circle.Rotation

and [<CasanovaEntity>] Wall = {
  Box                 : PhysicsEntity
  Sprite              : DrawableSprite
} with
  static member SpritePosition'(self:Wall,dt:float32<s>) = 
    self.Box.Position

and [<CasanovaWorld>] World = {
  Physics             : PhysicsWorld
  Ball                : Ball
  Ground              : Wall
}

The whole bouncing ball sources are less than 80 lines of code overall, together with saving and loading of the game. Physics requires that physical entities contain a field of type PhysicsEntity, whereas the game world must contain, before the physical entities, a field of type PhysicsWorld.

Head over to the project website if you want to see more samples, such as multiple bouncing balls, pong, etc.

Giuseppe Maggiore

unread,
May 21, 2013, 8:13:21 AM5/21/13
to fsharp-o...@googlegroups.com
Here is a video of the samples in action http://www.youtube.com/watch?v=ia6ZTYPi6S0!
Reply all
Reply to author
Forward
0 new messages