module Fps:Provides first-person shooter behavior.sig..end
Yo, yo, yo:
An Fps.fps_ui_bridge receives mouse and keyboard events from
Event.event_dispatcher. It then translates these events into
calls of forward, rotate, tilt and rise of a fps_engine.
Get an instance by calling Util.make_fps_ui_bridge.
Fps.fps_engine is charged with constraining these calls to
legal movements.
An implementation might for example only move forward if there isn't a
wall in the way. fps_engine keeps track of the position
and orientation according to these calls. Users may then render
an avatar according to this position, or place the camera or whatever.
Event.event_dispatcher : keyboard events ->Fps.fps_ui_bridge : #forward, #rotate ->Fps.fps_engine : track movement, constrained by walls or whateverplayer : renders player avatar at position tracked by fps_engine.
player inherits from Fps.fps_entity, but delegates
the interface to the fps_engine.fps_engine is a virtual class, you will need to provide an implementation
that understands the boundaries of your game. There are two provided
implementations. The Fps.null_engine singleton stores no
position data. The Fps.no_clipping_engine allows unconstrained
movement.
fps_entity has the same type as fps_engine but is intended
for 'dumb' objects that delegate to an fps_engine. For example,
the player object knows nothing about walls,
and the fps_engine doesn't know whether its moving around
a player or a monster.
This code will set up a camera for the user to move around:
open FatCaml.Scene
open FatCaml.Application
open FatCaml.Fps
open FatCaml.Util
let display_renderer = new default_renderer in
let fps_ui = make_fps_ui_bridge () and
camera = new fps_camera in
fps_ui#affect (camera :> fps_entity) ;
display_renderer#set_camera (camera :> camera) ;
display_singleton#set_renderer (display_renderer :> renderer) ;
If you want the camera to avoid walls, add the following:
camera#set_engine (new my_fps_engine) ; type fps_state = {
|
position : |
|
tilt : |
|
rotation : |
class virtual fps_engine :object..end
class virtual fps_entity :fps_engine
fps_engine;
these objects should inherit from fps_entity.
val null_engine : fps_engineclass no_clipping_engine :object..end
class fps_ui_bridge :< key : < affect : Event.keyboard_listener -> 'a; .. >;
mouse : < affect : Event.mouse_listener -> 'b; .. >;
ticker : < affect : Event.frame_listener -> unit; .. >; .. > ->object..end
Fps.fps_engine.
class fps_camera :object..end
Scene.camera that implements fps_entity.