FSharpAndGamesBreakout
FSharpAndGamesBreakout copied to clipboard
A simple F# Breakout clone using Duality
F#n and Games
Game loop
The idea of the game loop is to "Decouple the progression of game time from user input and processor speed."[1] The loop processes the input but doesn't wait for it. A game loop looks something like this
while (true)
{
processInput();
update();
render();
}
Duality has a game loop, when it runs it calls each of the components. Components you say?...
[1] from Game Programming patterns
Duality concepts
- Scenes: contain Game Objects
- Game Objects: contain component
- Components: have logic about each of the game objects and how they should behave
- Resources: stored needed to run the game, it includes seriealized scenes, game objects, sounds, textures, etc.
It's worth noting that Scenes, objects, etc are all serialized.
Duality editor
There is a really good reference about duality in the Duality Website
Let's write some game code
We are going to start off improving on the ScoreComponent, with the solution opened go to Breakout.core project and open the "components.fs" file.
The ScoreComponent type inherits from Component (a type from Duality that is implemented in C#). We also have the equivalent of a read only property in C# , with a backing mutable field, not really a very functional aproach to this.
member this.Score = score
Another thing to note on this type is that it implements ICmpUpdatable (a Duality interface).