SlideShare a Scribd company logo
1 of 33
Download to read offline
Sponsored by
Using FireMonkey as a game engine
Patrick Prémartin
DELPHICON 2021
The Official Online Conference All About Embarcadero Delphi
delphicon.embarcadero.com
Sponsored by
Agenda
● What is a game engine ?
● What is FireMonkey ?
● Why using FireMonkey to code games ?
● Really ? Games in Delphi FMX ?
● Managing music and sound effects
● Managing backgrounds and scenes
● Managing user interface
● Managing sprites, animations and collisions
● What about 3D ?
● You want more ?
Sponsored by
Speaker
● Patrick Prémartin - MVP Embarcadero
● Freelance Delphi and web developer since 2000
(just after the bug)
● Delphi user since the beginning and before
with Borland / Turbo Pascal.
● Game coder since a little more (TO7-70 J)
Sponsored by
Speaker
● Patrick Prémartin - MVP Embarcadero
● Follow me on :
● GitHub : https://github.com/DeveloppeurPascal
● Itch.io : https://gamolf.itch.io
● Twitch : https://www.twitch.tv/patrickpremartin
● My blog : https://developpeur-pascal.fr
● LinkedIn : https://www.linkedin.com/in/patrickpremartin/
Sponsored by
What is a game engine ?
● A game engine is a library or set of components available to
create games.
● You have code, SDK and sometimes editor tools or you can use
external tools like Tiled to create your scenes and maps.
● A game engine is not a complete game making software like
you have with GameMaker Studio, AppGameKit Studio, Game
Guru, Clickteam Fusion, Unreal Engine or Unity but the code to
work with when creating games.
Sponsored by
What is a game engine ?
● There are a lot of game making software and game engines
coded in Pascal.
● One of the most known is Castle Game Engine available at
https://castle-engine.io/
It now has Delphi compatibility. Look at Michalis Kamburelis
DelphiCon 2021 session to know more about it.
https://delphicon.embarcadero.com/talks/castle-game-engine-
coming-to-delphi/
Sponsored by
What is a game engine ?
● You perhaps eared about some of this other game engines for
Delphi or Pascal developers :
○ Gorilla 3D Framework : https://www.gorilla3d.de
○ Apus Game Engine : https://github.com/Cooler2/ApusGameEngine
○ SDL2 for Pascal : https://github.com/PascalGameDevelopment/SDL2-for-
Pascal
○ Andorra 2D, Turbu, Asphyre, DelphiX, Rage3D, and a lot more listed at
https://wiki.freepascal.org/Game_Engine
Sponsored by
What is FireMonkey ?
● FireMonkey is the multiplatform set of components and
libraries available in Delphi.
● You have VCL for Windows projects since Delphi 1.
● And since Delphi XE2 we have FireMonkey for all major
platforms.
● With Delphi 11 Alexandria you can target Windows, Mac, Linux,
iOS and Android platforms depending on your license level.
Sponsored by
What is FireMonkey ?
● The idea behind FireMonkey is to have one project and one
source code to target all major platforms.
● You don’t need to know “platforms languages” like Objective-C,
Swift, Java, Kotlin, C, C++, C#, .Net, …
Sponsored by
What is FireMonkey ?
● FireMonkey includes classic visual components but also
shapes, animations, visual effects, 3D, access to system API
and other libraries.
● It’s included in all Delphi license level even the Community
Edition (free for personal use) and Academic Edition.
Sponsored by
Why using FireMonkey to code games ?
● The simple answer could be “why not ?” and in fact it’s the first
reason I had to play with it.
● Second answer is more technical :
● FireMonkey draws everything on screen by default.
● Visual components are sets of shapes and effects. They are styled and can
be changed without coding.
● We have 2D and 3D components and layers in standard.
Sponsored by
Why using FireMonkey to code games ?
● The simple answer could be “why not ?” and in fact it’s the first
reason I had to play with it.
● Second answer is more technical :
● Touch, mouse and keyboard are managed by Delphi. It works for classic
programs, so it works for games too.
● We can use properties and events, timers and threads, multi resolution
images and bitmaps, classes and all thinks needed to code games.
Sponsored by
Really ? Games in Delphi FMX ?
● In 2021 I streamed weekly game coding sessions on Twitch,
with Delphi and FireMonkey.
● Published games are available at https://gamolf.itch.io
● Some projects have been open sourced on my GitHub account:
https://github.com/DeveloppeurPascal/DevPas-Games-Pack
● A lots of other projects are available with “delphi-game”
hashtag: https://github.com/topics/delphi-game
Sponsored by
Really ? Games in Delphi FMX ?
● You can also check the showcase part of Embarcadero blogs at
https://blogs.embarcadero.com/category/showcase/
● And more on iOS and Android stores !
● Simply look at the list of games which developers forgot to
change default package name in their project options :
https://www.google.com/search?q=%22com.embarcadero.%22
+game+site%3Aplay.google.com
Please don’t forget to personalize your project version info option page.
Sponsored by
How to ?
● Know, let’s look a little more at developer side of game making
with FireMonkey projects in Delphi.
● You’ll find code samples and usable Delphi units on GitHub at
https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe
ts
Sponsored by
Managing music and sound effects
● Managing sounds in a Delphi project is simple. We have a
component for that : TMediaPlayer.
● In my games I use it to play MP3 music in background. A timer
check if the music is over and restart it for a loop.
● For sound effects, I play WAV files with another TMediaPlayer
(or more than one in a TObjectList<TMediaPlayer> depending
on the game).
● To do the same, use the TMusicLoop class in uMusicLoop.pas
Sponsored by
Managing backgrounds and scenes
● For backgrounds and scenes, I use TImage component, the Fill
property of shapes like TRectangle or TCircle and the TPath to
draw SVG path depending on my needs.
● All FireMonkey visual components are containers. They can be
parents for all other visual components.
● All visual components have opacity, rotation and scale
properties.
Sponsored by
Managing backgrounds and scenes
● We can use nonvisual components to change property values in
a specific duration (TFloatAnimation is very useful).
● We have visual effect as nonvisual components like
TShadowEffect and TGlowEffect, useful for games and classic
programs to show errors or needed edit fields.
● It give us unlimited possibilities without coding anything… and
of course we can code !
Sponsored by
Managing backgrounds and scenes
● For Egg Hunter project, available at https://gamolf.itch.io/egg-
hunter, I needed to manage sprites positions and actions in
different threads.
● I wanted 60 FPS (because we need goals in life).
● I didn’t check if I succeeded but the result is good enough in
term of user experience.
Sponsored by
Managing backgrounds and scenes
● My scene is a TImage. I never draw on it.
● I use a TBitmap in background as a buffer. It’s only refreshed
depending on the viewport position and sprite actions.
● A timer checks every 16ms if I changed the buffer bitmap. If so,
I copy it to the scene image.
● It’s simple. Just need some Booleans and TMutex to avoid
access violations, conflicts and sprites flipping.
Sponsored by
Managing backgrounds and scenes
● In other games, I simply use TLayout on a TForm to simulate a
Z-Index if needed.
● You have a sample at
https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe
ts/tree/main/AnimationVaguesEtCanards
● I used it for Ok Ducky ! game available at
https://gamolf.itch.io/ok-ducky
Sponsored by
Managing user interface
● User interface is simple : I can use styled visual components,
shapes, images, …
● For texts I user TLabel if I want the look and feel of the OS or
TText when I prefer to change color, size and font in my
program.
● For buttons I use TButton, a personalized button style or I
“draw” them in a TFrame with TRectangle, images, effects and
texts.
Sponsored by
Managing user interface
● Have a look at this 2018 CodeRage replay to see how I proceed :
https://serialstreameur.fr/coderage2018-christmasgame-
codereview.php
● This project source code is available on GitHub :
https://github.com/DeveloppeurPascal/CodeRage2018-
ChristmasGame
Sponsored by
Managing sprites, animations and collisions
● For sprites I use the bitmap kind of Fill property from
TRectangle or TCircle components.
● For other visual elements I use TImage with a TImageList or the
background (Fill.Bitmap) of other shapes.
Sponsored by
Managing sprites, animations and collisions
● Animating is easy : FireMonkey give us a TBitmapListAnimation
component which accepts a sprite sheet.
● Look this samples :
https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe
ts/tree/main/AnimSpriteExplosion
and
https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe
ts/tree/main/AnimSpritePersonnage
Sponsored by
Managing sprites, animations and collisions
● To check collisions, I use what Delphi use for the visual
components and testing mouse clicks.
● IntersectRect() is a very useful (too unknown) method to check
if two rectangles collide.
● It’s standard. It works since more than 26 years in the VCL and
now in FMX. Why not using it ?
Sponsored by
Managing sprites, animations and collisions
● For circles I calculate the distance between center of each circle
and compare it to the sum of their radius.
● You have a sample with Soap Bubbles game available at
https://gamolf.itch.io/soap-bubbles
● The base code for this game is available on GitHub :
https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe
ts/tree/main/JeuDesCercles
Sponsored by
Managing sprites, animations and collisions
● For circle versus a rectangle, I calculate the distance between
the circle center and each angle of the rectangle.
● The classic sample for this is a Pong or Breakout game, when
the ball hits a wall or a brick.
● You have the source code of a sample breakout done for Learn
To Code Summer Camp 2021 event at
https://github.com/DeveloppeurPascal/Casse-Briques
Sponsored by
What about 3D ?
● 3D is little more complicated, but FireMonkey includes 3D
viewport and 3D shapes.
● You can use them to create games like did Grégory Bersegeay,
another French Embarcadero MVP, for
○ 3D Pong : a pong game in 3D.
https://github.com/gbegreg/FMXPong
○ FMX Corridor : a The Light Corridor remake.
https://github.com/gbegreg/FMXCorridor
○ FMX Island : an island in 3D, base for FPS games.
https://github.com/gbegreg/FMXISland
Sponsored by
You want more ?
● Did I say it’s simple to use Delphi and FireMonkey for game
coding and deploying them for Windows, Mac, Linux, iOS and
Android devices ?
● With those samples and links, I hope you have all what you need
to understand how to use FireMonkey as a game engine in your
games.
● If not, contact me and tell me what is missing or submit new
feature requests directly in Embarcadero’s Quality Portal.
Sponsored by 31
Q&A
Sponsored by
Q&A
● Sorry, I’m not live for Q&A during DelphiCon 2021 but if you
want to talk, leave me a message on LinkedIn or at
https://developpeur-pascal.fr/contact/
● You also can talk with me on Twitch during a live (game or
other) coding stream at
https://www.twitch.tv/patrickpremartin
● Please write in French or English.
Use https://www.deepl.com/translator tool to translate if
needed.
Sponsored by
THANK YOU!

More Related Content

What's hot

Game Story and Character Development
Game Story and Character DevelopmentGame Story and Character Development
Game Story and Character Development
Tracie King
 
Approaching zero driver overhead
Approaching zero driver overheadApproaching zero driver overhead
Approaching zero driver overhead
Cass Everitt
 
Unity 3D game engine seminar
Unity 3D game engine  seminarUnity 3D game engine  seminar
Unity 3D game engine seminar
NikhilThorat15
 
【Drop wave】cedec2012『オンラインゲーム時代における、 ゲーム内コミュニケーション設計の基礎知識』
【Drop wave】cedec2012『オンラインゲーム時代における、 ゲーム内コミュニケーション設計の基礎知識』【Drop wave】cedec2012『オンラインゲーム時代における、 ゲーム内コミュニケーション設計の基礎知識』
【Drop wave】cedec2012『オンラインゲーム時代における、 ゲーム内コミュニケーション設計の基礎知識』
モノビット エンジン
 
[UNREAL FEST EAST 2017] VRゲームairtone制作事例 - VRを活かす3つのゲームデザイン的挑戦
[UNREAL FEST EAST 2017] VRゲームairtone制作事例 - VRを活かす3つのゲームデザイン的挑戦[UNREAL FEST EAST 2017] VRゲームairtone制作事例 - VRを活かす3つのゲームデザイン的挑戦
[UNREAL FEST EAST 2017] VRゲームairtone制作事例 - VRを活かす3つのゲームデザイン的挑戦
historia_Inc
 

What's hot (20)

Shader Programming With Unity
Shader Programming With UnityShader Programming With Unity
Shader Programming With Unity
 
Player Traversal Mechanics in the Vast World of Horizon Zero Dawn
Player Traversal Mechanics in the Vast World of Horizon Zero DawnPlayer Traversal Mechanics in the Vast World of Horizon Zero Dawn
Player Traversal Mechanics in the Vast World of Horizon Zero Dawn
 
Unityで本格戦国シュミレーションRPG 開発
Unityで本格戦国シュミレーションRPG 開発Unityで本格戦国シュミレーションRPG 開発
Unityで本格戦国シュミレーションRPG 開発
 
Game Story and Character Development
Game Story and Character DevelopmentGame Story and Character Development
Game Story and Character Development
 
How the Universal Render Pipeline unlocks games for you - Unite Copenhagen 2019
How the Universal Render Pipeline unlocks games for you - Unite Copenhagen 2019How the Universal Render Pipeline unlocks games for you - Unite Copenhagen 2019
How the Universal Render Pipeline unlocks games for you - Unite Copenhagen 2019
 
CEDEC2016 「コントラスト」で考えるゲームデザイン・レベルデザイン
CEDEC2016 「コントラスト」で考えるゲームデザイン・レベルデザインCEDEC2016 「コントラスト」で考えるゲームデザイン・レベルデザイン
CEDEC2016 「コントラスト」で考えるゲームデザイン・レベルデザイン
 
The Tipping Point: How Virtual Experiences Are Transforming Global Industries
The Tipping Point: How Virtual Experiences Are Transforming Global IndustriesThe Tipping Point: How Virtual Experiences Are Transforming Global Industries
The Tipping Point: How Virtual Experiences Are Transforming Global Industries
 
Approaching zero driver overhead
Approaching zero driver overheadApproaching zero driver overhead
Approaching zero driver overhead
 
Ninja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for BeginnersNinja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for Beginners
 
MMORPG economics
MMORPG economicsMMORPG economics
MMORPG economics
 
LAFS SVI Level 3 - Game Design and Analysis
LAFS SVI Level 3 - Game Design and AnalysisLAFS SVI Level 3 - Game Design and Analysis
LAFS SVI Level 3 - Game Design and Analysis
 
Unity 3D game engine seminar
Unity 3D game engine  seminarUnity 3D game engine  seminar
Unity 3D game engine seminar
 
Unity 3d Basics
Unity 3d BasicsUnity 3d Basics
Unity 3d Basics
 
良くわかるMeta
良くわかるMeta良くわかるMeta
良くわかるMeta
 
Game Development with Unity
Game Development with UnityGame Development with Unity
Game Development with Unity
 
Lecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinks
 
ゲームシナリオ作成について
ゲームシナリオ作成についてゲームシナリオ作成について
ゲームシナリオ作成について
 
【Drop wave】cedec2012『オンラインゲーム時代における、 ゲーム内コミュニケーション設計の基礎知識』
【Drop wave】cedec2012『オンラインゲーム時代における、 ゲーム内コミュニケーション設計の基礎知識』【Drop wave】cedec2012『オンラインゲーム時代における、 ゲーム内コミュニケーション設計の基礎知識』
【Drop wave】cedec2012『オンラインゲーム時代における、 ゲーム内コミュニケーション設計の基礎知識』
 
[UNREAL FEST EAST 2017] VRゲームairtone制作事例 - VRを活かす3つのゲームデザイン的挑戦
[UNREAL FEST EAST 2017] VRゲームairtone制作事例 - VRを活かす3つのゲームデザイン的挑戦[UNREAL FEST EAST 2017] VRゲームairtone制作事例 - VRを活かす3つのゲームデザイン的挑戦
[UNREAL FEST EAST 2017] VRゲームairtone制作事例 - VRを活かす3つのゲームデザイン的挑戦
 
Best Practices for Shader Graph
Best Practices for Shader GraphBest Practices for Shader Graph
Best Practices for Shader Graph
 

Similar to Using FireMonkey as a game engine

Simplifying training deep and serving learning models with big data in python...
Simplifying training deep and serving learning models with big data in python...Simplifying training deep and serving learning models with big data in python...
Simplifying training deep and serving learning models with big data in python...
Holden Karau
 
Encode x ICH: Intro to Building on the IC in Motoko
Encode x ICH: Intro to Building on the IC in MotokoEncode x ICH: Intro to Building on the IC in Motoko
Encode x ICH: Intro to Building on the IC in Motoko
KlaraOrban
 

Similar to Using FireMonkey as a game engine (20)

Introduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsIntroduction to html5 game programming with impact js
Introduction to html5 game programming with impact js
 
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...
 
How to build Kick Ass Games in the Cloud
How to build Kick Ass Games in the CloudHow to build Kick Ass Games in the Cloud
How to build Kick Ass Games in the Cloud
 
Advanced Video Production with FOSS
Advanced Video Production with FOSSAdvanced Video Production with FOSS
Advanced Video Production with FOSS
 
GDCE 2015: Blueprint Components to C++
GDCE 2015: Blueprint Components to C++GDCE 2015: Blueprint Components to C++
GDCE 2015: Blueprint Components to C++
 
Simplifying training deep and serving learning models with big data in python...
Simplifying training deep and serving learning models with big data in python...Simplifying training deep and serving learning models with big data in python...
Simplifying training deep and serving learning models with big data in python...
 
Castle Game Engine and the joy of making and using a custom game engine
Castle Game Engine and the joy  of making and using a custom game engineCastle Game Engine and the joy  of making and using a custom game engine
Castle Game Engine and the joy of making and using a custom game engine
 
Intro - End to end ML with Kubeflow @ SignalConf 2018
Intro - End to end ML with Kubeflow @ SignalConf 2018Intro - End to end ML with Kubeflow @ SignalConf 2018
Intro - End to end ML with Kubeflow @ SignalConf 2018
 
AGDK tutorial step by step
AGDK tutorial step by stepAGDK tutorial step by step
AGDK tutorial step by step
 
DEF CON 24 - Allan Cecil and DwangoAC - tasbot the perfectionist
DEF CON 24 - Allan Cecil and DwangoAC -  tasbot the perfectionistDEF CON 24 - Allan Cecil and DwangoAC -  tasbot the perfectionist
DEF CON 24 - Allan Cecil and DwangoAC - tasbot the perfectionist
 
How We Won Gamedev By Rolling Our Own Tech (no notes)
How We Won Gamedev By Rolling Our Own Tech (no notes)How We Won Gamedev By Rolling Our Own Tech (no notes)
How We Won Gamedev By Rolling Our Own Tech (no notes)
 
Python on Android with Delphi FMX - The Cross Platform GUI Framework
Python on Android with Delphi FMX - The Cross Platform GUI Framework Python on Android with Delphi FMX - The Cross Platform GUI Framework
Python on Android with Delphi FMX - The Cross Platform GUI Framework
 
Developing games and graphic visualizations in Pascal
Developing games and graphic visualizations in PascalDeveloping games and graphic visualizations in Pascal
Developing games and graphic visualizations in Pascal
 
An introduction to_golang.avi
An introduction to_golang.aviAn introduction to_golang.avi
An introduction to_golang.avi
 
HTML5 Game Development frameworks overview
HTML5 Game Development frameworks overviewHTML5 Game Development frameworks overview
HTML5 Game Development frameworks overview
 
Flutter not yet another mobile cross-platform framework - i ox-kl19
Flutter   not yet another mobile cross-platform framework - i ox-kl19Flutter   not yet another mobile cross-platform framework - i ox-kl19
Flutter not yet another mobile cross-platform framework - i ox-kl19
 
Puppet@Citygrid - Julien Rottenberg - PuppetCamp LA '12
Puppet@Citygrid - Julien Rottenberg - PuppetCamp LA '12Puppet@Citygrid - Julien Rottenberg - PuppetCamp LA '12
Puppet@Citygrid - Julien Rottenberg - PuppetCamp LA '12
 
Овчаренко Євген “Відеоігри це ефективність”
Овчаренко Євген “Відеоігри це ефективність”Овчаренко Євген “Відеоігри це ефективність”
Овчаренко Євген “Відеоігри це ефективність”
 
Encode x ICH: Intro to Building on the IC in Motoko
Encode x ICH: Intro to Building on the IC in MotokoEncode x ICH: Intro to Building on the IC in Motoko
Encode x ICH: Intro to Building on the IC in Motoko
 
Using Delphi as a no code development environment
Using Delphi as a no code development environmentUsing Delphi as a no code development environment
Using Delphi as a no code development environment
 

More from pprem

Utiliser FireMonkey comme moteur de jeux vidéo
Utiliser FireMonkey comme moteur de jeux vidéoUtiliser FireMonkey comme moteur de jeux vidéo
Utiliser FireMonkey comme moteur de jeux vidéo
pprem
 
Internationaliser les projets VCL / FMX
Internationaliser les projets VCL / FMXInternationaliser les projets VCL / FMX
Internationaliser les projets VCL / FMX
pprem
 
Utiliser des dessins vectoriels à la place d'images
Utiliser des dessins vectoriels à la place d'imagesUtiliser des dessins vectoriels à la place d'images
Utiliser des dessins vectoriels à la place d'images
pprem
 

More from pprem (20)

Easy coding a multi device game with FireMonkey
Easy coding a multi device game with FireMonkeyEasy coding a multi device game with FireMonkey
Easy coding a multi device game with FireMonkey
 
Utiliser FireMonkey comme moteur de jeux vidéo
Utiliser FireMonkey comme moteur de jeux vidéoUtiliser FireMonkey comme moteur de jeux vidéo
Utiliser FireMonkey comme moteur de jeux vidéo
 
Coder sans coder : Delphi en mode no code !
Coder sans coder : Delphi en mode no code !Coder sans coder : Delphi en mode no code !
Coder sans coder : Delphi en mode no code !
 
Quoi de neuf dans la version 11 Alexandria ?
Quoi de neuf dans la version 11 Alexandria ?Quoi de neuf dans la version 11 Alexandria ?
Quoi de neuf dans la version 11 Alexandria ?
 
Faire des applications web avec Delphi
Faire des applications web avec DelphiFaire des applications web avec Delphi
Faire des applications web avec Delphi
 
Utilisation de git avec Delphi
Utilisation de git avec DelphiUtilisation de git avec Delphi
Utilisation de git avec Delphi
 
Diffuser nos logiciels et leurs mises à jour
Diffuser nos logiciels et leurs mises à jourDiffuser nos logiciels et leurs mises à jour
Diffuser nos logiciels et leurs mises à jour
 
Delphi et les tests unitaires
Delphi et les tests unitairesDelphi et les tests unitaires
Delphi et les tests unitaires
 
Développer une application pour Android TV avec Delphi
Développer une application pour Android TV avec DelphiDévelopper une application pour Android TV avec Delphi
Développer une application pour Android TV avec Delphi
 
Sauvegarder et restaurer l'état des applications mobiles
Sauvegarder et restaurer l'état des applications mobilesSauvegarder et restaurer l'état des applications mobiles
Sauvegarder et restaurer l'état des applications mobiles
 
Gérer le clavier virtuel sous iOS et Android
Gérer le clavier virtuel sous iOS et AndroidGérer le clavier virtuel sous iOS et Android
Gérer le clavier virtuel sous iOS et Android
 
Internationaliser les projets VCL / FMX
Internationaliser les projets VCL / FMXInternationaliser les projets VCL / FMX
Internationaliser les projets VCL / FMX
 
Comment développer pour Linux avec Delphi
Comment développer pour Linux avec DelphiComment développer pour Linux avec Delphi
Comment développer pour Linux avec Delphi
 
Utiliser des dessins vectoriels à la place d'images
Utiliser des dessins vectoriels à la place d'imagesUtiliser des dessins vectoriels à la place d'images
Utiliser des dessins vectoriels à la place d'images
 
Embarquer une base de données locale dans vos logiciels et applications mobiles
Embarquer une base de données locale dans vos logiciels et applications mobilesEmbarquer une base de données locale dans vos logiciels et applications mobiles
Embarquer une base de données locale dans vos logiciels et applications mobiles
 
Déploiement et débogage à distance
Déploiement et débogage à distanceDéploiement et débogage à distance
Déploiement et débogage à distance
 
Utiliser l'EDI pour développer en multiplateforme
Utiliser l'EDI pour développer en multiplateformeUtiliser l'EDI pour développer en multiplateforme
Utiliser l'EDI pour développer en multiplateforme
 
Faire une interface adaptive avec la VCL
Faire une interface adaptive avec la VCLFaire une interface adaptive avec la VCL
Faire une interface adaptive avec la VCL
 
Faire une interface adaptive avec FireMonkey
Faire une interface adaptive avec FireMonkeyFaire une interface adaptive avec FireMonkey
Faire une interface adaptive avec FireMonkey
 
QR codes et codes à barres sous Delphi
QR codes et codes à barres sous DelphiQR codes et codes à barres sous Delphi
QR codes et codes à barres sous Delphi
 

Recently uploaded

Recently uploaded (20)

Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdf
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea Goulet
 
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
 
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST API
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with Links
 
GraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with Graph
GraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with GraphGraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with Graph
GraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with Graph
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto
^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto
^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
What is a Recruitment Management Software?
What is a Recruitment Management Software?What is a Recruitment Management Software?
What is a Recruitment Management Software?
 

Using FireMonkey as a game engine

  • 1. Sponsored by Using FireMonkey as a game engine Patrick Prémartin DELPHICON 2021 The Official Online Conference All About Embarcadero Delphi delphicon.embarcadero.com
  • 2. Sponsored by Agenda ● What is a game engine ? ● What is FireMonkey ? ● Why using FireMonkey to code games ? ● Really ? Games in Delphi FMX ? ● Managing music and sound effects ● Managing backgrounds and scenes ● Managing user interface ● Managing sprites, animations and collisions ● What about 3D ? ● You want more ?
  • 3. Sponsored by Speaker ● Patrick Prémartin - MVP Embarcadero ● Freelance Delphi and web developer since 2000 (just after the bug) ● Delphi user since the beginning and before with Borland / Turbo Pascal. ● Game coder since a little more (TO7-70 J)
  • 4. Sponsored by Speaker ● Patrick Prémartin - MVP Embarcadero ● Follow me on : ● GitHub : https://github.com/DeveloppeurPascal ● Itch.io : https://gamolf.itch.io ● Twitch : https://www.twitch.tv/patrickpremartin ● My blog : https://developpeur-pascal.fr ● LinkedIn : https://www.linkedin.com/in/patrickpremartin/
  • 5. Sponsored by What is a game engine ? ● A game engine is a library or set of components available to create games. ● You have code, SDK and sometimes editor tools or you can use external tools like Tiled to create your scenes and maps. ● A game engine is not a complete game making software like you have with GameMaker Studio, AppGameKit Studio, Game Guru, Clickteam Fusion, Unreal Engine or Unity but the code to work with when creating games.
  • 6. Sponsored by What is a game engine ? ● There are a lot of game making software and game engines coded in Pascal. ● One of the most known is Castle Game Engine available at https://castle-engine.io/ It now has Delphi compatibility. Look at Michalis Kamburelis DelphiCon 2021 session to know more about it. https://delphicon.embarcadero.com/talks/castle-game-engine- coming-to-delphi/
  • 7. Sponsored by What is a game engine ? ● You perhaps eared about some of this other game engines for Delphi or Pascal developers : ○ Gorilla 3D Framework : https://www.gorilla3d.de ○ Apus Game Engine : https://github.com/Cooler2/ApusGameEngine ○ SDL2 for Pascal : https://github.com/PascalGameDevelopment/SDL2-for- Pascal ○ Andorra 2D, Turbu, Asphyre, DelphiX, Rage3D, and a lot more listed at https://wiki.freepascal.org/Game_Engine
  • 8. Sponsored by What is FireMonkey ? ● FireMonkey is the multiplatform set of components and libraries available in Delphi. ● You have VCL for Windows projects since Delphi 1. ● And since Delphi XE2 we have FireMonkey for all major platforms. ● With Delphi 11 Alexandria you can target Windows, Mac, Linux, iOS and Android platforms depending on your license level.
  • 9. Sponsored by What is FireMonkey ? ● The idea behind FireMonkey is to have one project and one source code to target all major platforms. ● You don’t need to know “platforms languages” like Objective-C, Swift, Java, Kotlin, C, C++, C#, .Net, …
  • 10. Sponsored by What is FireMonkey ? ● FireMonkey includes classic visual components but also shapes, animations, visual effects, 3D, access to system API and other libraries. ● It’s included in all Delphi license level even the Community Edition (free for personal use) and Academic Edition.
  • 11. Sponsored by Why using FireMonkey to code games ? ● The simple answer could be “why not ?” and in fact it’s the first reason I had to play with it. ● Second answer is more technical : ● FireMonkey draws everything on screen by default. ● Visual components are sets of shapes and effects. They are styled and can be changed without coding. ● We have 2D and 3D components and layers in standard.
  • 12. Sponsored by Why using FireMonkey to code games ? ● The simple answer could be “why not ?” and in fact it’s the first reason I had to play with it. ● Second answer is more technical : ● Touch, mouse and keyboard are managed by Delphi. It works for classic programs, so it works for games too. ● We can use properties and events, timers and threads, multi resolution images and bitmaps, classes and all thinks needed to code games.
  • 13. Sponsored by Really ? Games in Delphi FMX ? ● In 2021 I streamed weekly game coding sessions on Twitch, with Delphi and FireMonkey. ● Published games are available at https://gamolf.itch.io ● Some projects have been open sourced on my GitHub account: https://github.com/DeveloppeurPascal/DevPas-Games-Pack ● A lots of other projects are available with “delphi-game” hashtag: https://github.com/topics/delphi-game
  • 14. Sponsored by Really ? Games in Delphi FMX ? ● You can also check the showcase part of Embarcadero blogs at https://blogs.embarcadero.com/category/showcase/ ● And more on iOS and Android stores ! ● Simply look at the list of games which developers forgot to change default package name in their project options : https://www.google.com/search?q=%22com.embarcadero.%22 +game+site%3Aplay.google.com Please don’t forget to personalize your project version info option page.
  • 15. Sponsored by How to ? ● Know, let’s look a little more at developer side of game making with FireMonkey projects in Delphi. ● You’ll find code samples and usable Delphi units on GitHub at https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe ts
  • 16. Sponsored by Managing music and sound effects ● Managing sounds in a Delphi project is simple. We have a component for that : TMediaPlayer. ● In my games I use it to play MP3 music in background. A timer check if the music is over and restart it for a loop. ● For sound effects, I play WAV files with another TMediaPlayer (or more than one in a TObjectList<TMediaPlayer> depending on the game). ● To do the same, use the TMusicLoop class in uMusicLoop.pas
  • 17. Sponsored by Managing backgrounds and scenes ● For backgrounds and scenes, I use TImage component, the Fill property of shapes like TRectangle or TCircle and the TPath to draw SVG path depending on my needs. ● All FireMonkey visual components are containers. They can be parents for all other visual components. ● All visual components have opacity, rotation and scale properties.
  • 18. Sponsored by Managing backgrounds and scenes ● We can use nonvisual components to change property values in a specific duration (TFloatAnimation is very useful). ● We have visual effect as nonvisual components like TShadowEffect and TGlowEffect, useful for games and classic programs to show errors or needed edit fields. ● It give us unlimited possibilities without coding anything… and of course we can code !
  • 19. Sponsored by Managing backgrounds and scenes ● For Egg Hunter project, available at https://gamolf.itch.io/egg- hunter, I needed to manage sprites positions and actions in different threads. ● I wanted 60 FPS (because we need goals in life). ● I didn’t check if I succeeded but the result is good enough in term of user experience.
  • 20. Sponsored by Managing backgrounds and scenes ● My scene is a TImage. I never draw on it. ● I use a TBitmap in background as a buffer. It’s only refreshed depending on the viewport position and sprite actions. ● A timer checks every 16ms if I changed the buffer bitmap. If so, I copy it to the scene image. ● It’s simple. Just need some Booleans and TMutex to avoid access violations, conflicts and sprites flipping.
  • 21. Sponsored by Managing backgrounds and scenes ● In other games, I simply use TLayout on a TForm to simulate a Z-Index if needed. ● You have a sample at https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe ts/tree/main/AnimationVaguesEtCanards ● I used it for Ok Ducky ! game available at https://gamolf.itch.io/ok-ducky
  • 22. Sponsored by Managing user interface ● User interface is simple : I can use styled visual components, shapes, images, … ● For texts I user TLabel if I want the look and feel of the OS or TText when I prefer to change color, size and font in my program. ● For buttons I use TButton, a personalized button style or I “draw” them in a TFrame with TRectangle, images, effects and texts.
  • 23. Sponsored by Managing user interface ● Have a look at this 2018 CodeRage replay to see how I proceed : https://serialstreameur.fr/coderage2018-christmasgame- codereview.php ● This project source code is available on GitHub : https://github.com/DeveloppeurPascal/CodeRage2018- ChristmasGame
  • 24. Sponsored by Managing sprites, animations and collisions ● For sprites I use the bitmap kind of Fill property from TRectangle or TCircle components. ● For other visual elements I use TImage with a TImageList or the background (Fill.Bitmap) of other shapes.
  • 25. Sponsored by Managing sprites, animations and collisions ● Animating is easy : FireMonkey give us a TBitmapListAnimation component which accepts a sprite sheet. ● Look this samples : https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe ts/tree/main/AnimSpriteExplosion and https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe ts/tree/main/AnimSpritePersonnage
  • 26. Sponsored by Managing sprites, animations and collisions ● To check collisions, I use what Delphi use for the visual components and testing mouse clicks. ● IntersectRect() is a very useful (too unknown) method to check if two rectangles collide. ● It’s standard. It works since more than 26 years in the VCL and now in FMX. Why not using it ?
  • 27. Sponsored by Managing sprites, animations and collisions ● For circles I calculate the distance between center of each circle and compare it to the sum of their radius. ● You have a sample with Soap Bubbles game available at https://gamolf.itch.io/soap-bubbles ● The base code for this game is available on GitHub : https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe ts/tree/main/JeuDesCercles
  • 28. Sponsored by Managing sprites, animations and collisions ● For circle versus a rectangle, I calculate the distance between the circle center and each angle of the rectangle. ● The classic sample for this is a Pong or Breakout game, when the ball hits a wall or a brick. ● You have the source code of a sample breakout done for Learn To Code Summer Camp 2021 event at https://github.com/DeveloppeurPascal/Casse-Briques
  • 29. Sponsored by What about 3D ? ● 3D is little more complicated, but FireMonkey includes 3D viewport and 3D shapes. ● You can use them to create games like did Grégory Bersegeay, another French Embarcadero MVP, for ○ 3D Pong : a pong game in 3D. https://github.com/gbegreg/FMXPong ○ FMX Corridor : a The Light Corridor remake. https://github.com/gbegreg/FMXCorridor ○ FMX Island : an island in 3D, base for FPS games. https://github.com/gbegreg/FMXISland
  • 30. Sponsored by You want more ? ● Did I say it’s simple to use Delphi and FireMonkey for game coding and deploying them for Windows, Mac, Linux, iOS and Android devices ? ● With those samples and links, I hope you have all what you need to understand how to use FireMonkey as a game engine in your games. ● If not, contact me and tell me what is missing or submit new feature requests directly in Embarcadero’s Quality Portal.
  • 32. Sponsored by Q&A ● Sorry, I’m not live for Q&A during DelphiCon 2021 but if you want to talk, leave me a message on LinkedIn or at https://developpeur-pascal.fr/contact/ ● You also can talk with me on Twitch during a live (game or other) coding stream at https://www.twitch.tv/patrickpremartin ● Please write in French or English. Use https://www.deepl.com/translator tool to translate if needed.