Rapid, Scalable Game development using Functional Reactive Programming
Ray Shulang Lei
Ray Shulang Lei
int sum = 0; for (int i = 0; i < 150; i++) { if (i % 5 == 0) sum += i; } printf(sum);
show $ length [x | x <- [1..150], x `mod` 5 == 0]
GameLoop( Players(), AIs(), Trees(), Guns(), Bullets(), ... )
gameState = [playerPosition, playerSpeed, gamepadIO, playerIsColliding, ... ] t = currentTime() GameLoop( Players(gameState, t), AIs(gameState, t), Trees(gameState, t), Guns(gameState, t), Bullets(gameState, t), ... )
Signal a = Time -> aA signal function is a function from Signal to Signal:
SF a b = Signal a -> Signal bYou can't touch the signals without using sigal functions.
signal(position, speed, mouseXY) -> PlayerFunction -> signal(position, speed, mouseXY)
But what about gamepads buttons, collisions etc.?
An event is a type to represent discrete events such as a mouse click:
data Event a = NoEvent | Event a
signal(position, speed, mouseXY), event(gamepad, collision) -> PlayerFunction -> signal(position, speed, mouseXY)
But but but, what if my player dies? How do I remove and spawn?
Also, how does my object know if it is colliding with each other?
switch :: SF a (b, Event c) -> (c -> SF a b) -> SF a b
What is this non-sense? What are these strange symbols stand for?
It's haskell...I know. It says a switch will take an activated signal function with a trigger event, and another signal function as input. If the trigger event occurs, it applies the second signal function, else it applies the original signal function.
Q:What framework can I start to use FRP for game dev?
A:My presentation is based on the Yampa framework in Haskell
Q:How well is this method perform?
A:Paul Hudak made a game "PaddleBall" with 17 lines of code in FAL
Q:Is there example of complex game out there made with FRP?
A:Check out Frag, a first personal shooter game