SlideShare a Scribd company logo
1 of 44
Download to read offline
VIDEOGIOCHI IN PHP
👾
dal game loop alle collisioni
Manuel Baldassarri | PHPDay GrUSP edition 2022
PHP EXTENSIONS
Mysql - Postgres - Curl - GD - Json - Intl - ...
Memcache - ImageMagick - MongoDB - Redis - ...
PHP AND MULTIMEDIA
SDL
Simple DirectMedia Layer
cross-platform: Windows, MacOS, Linux, iOS, Android
audio, keyboard, mouse, game controller
graphics hardware via OpenGL, Direct3D and Vulkan
TODO
Install deps
Window
Renderer
Game loop
Input
Collision
INSTALL DEPS
pecl install sdl-beta
1
WINDOW
SDL_Init(SDL_INIT_VIDEO);
1
2
$window = SDL_CreateWindow(
3
	 'This is not a window',
4
	 SDL_WINDOWPOS_UNDEFINED, // SDL_WINDOWPOS_CENTERED
5
	 SDL_WINDOWPOS_UNDEFINED, // SDL_WINDOWPOS_CENTERED
6
	 800,
7
	 400,
8
	 0 // SDL_WINDOW_(FULLSCREEN|HIDDEN|RESIZABLE)
9
	 // SDL_WINDOW_(OPENGL|VULKAN|METAL)
10
);
11
12
sleep(10);
13
14
SDL_DestroyWindow($window);
15
SDL_Quit();
16
$window = SDL_CreateWindow(
	 'This is not a window',
	 SDL_WINDOWPOS_UNDEFINED, // SDL_WINDOWPOS_CENTERED
	 SDL_WINDOWPOS_UNDEFINED, // SDL_WINDOWPOS_CENTERED
	 800,
	 400,
	 0 // SDL_WINDOW_(FULLSCREEN|HIDDEN|RESIZABLE)
	 // SDL_WINDOW_(OPENGL|VULKAN|METAL)
);
SDL_Init(SDL_INIT_VIDEO);
1
2
3
4
5
6
7
8
9
10
11
12
sleep(10);
13
14
SDL_DestroyWindow($window);
15
SDL_Quit();
16
sleep(10);
SDL_DestroyWindow($window);
SDL_Quit();
SDL_Init(SDL_INIT_VIDEO);
1
2
$window = SDL_CreateWindow(
3
	 'This is not a window',
4
	 SDL_WINDOWPOS_UNDEFINED, // SDL_WINDOWPOS_CENTERED
5
	 SDL_WINDOWPOS_UNDEFINED, // SDL_WINDOWPOS_CENTERED
6
	 800,
7
	 400,
8
	 0 // SDL_WINDOW_(FULLSCREEN|HIDDEN|RESIZABLE)
9
	 // SDL_WINDOW_(OPENGL|VULKAN|METAL)
10
);
11
12
13
14
15
16
$ php 00-window.php
1
RENDERER
$renderer = SDL_CreateRenderer($window, 0, 0);
SDL_Init(SDL_INIT_VIDEO);
1
$window = SDL_CreateWindow(...);
2
3
4
$orange = [0xd7, 0x6b, 0x2b, 0];
5
SDL_SetRenderDrawColor($renderer, ...$orange);
6
SDL_RenderClear($renderer);
7
SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255);
8
SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200
9
SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180)
10
SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160)
11
SDL_RenderPresent($renderer);
12
13
SDL_Delay(10000);
14
15
SDL_DestroyRenderer($renderer);
16
i d $ i d
1
$orange = [0xd7, 0x6b, 0x2b, 0];
SDL_SetRenderDrawColor($renderer, ...$orange);
SDL_Init(SDL_INIT_VIDEO);
1
$window = SDL_CreateWindow(...);
2
3
$renderer = SDL_CreateRenderer($window, 0, 0);
4
5
6
SDL_RenderClear($renderer);
7
SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255);
8
SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200
9
SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180)
10
SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160)
11
SDL_RenderPresent($renderer);
12
13
SDL_Delay(10000);
14
15
SDL_DestroyRenderer($renderer);
16
i d $ i d
1
SDL_RenderClear($renderer);
SDL_Init(SDL_INIT_VIDEO);
1
$window = SDL_CreateWindow(...);
2
3
$renderer = SDL_CreateRenderer($window, 0, 0);
4
$orange = [0xd7, 0x6b, 0x2b, 0];
5
SDL_SetRenderDrawColor($renderer, ...$orange);
6
7
SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255);
8
SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200
9
SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180)
10
SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160)
11
SDL_RenderPresent($renderer);
12
13
SDL_Delay(10000);
14
15
SDL_DestroyRenderer($renderer);
16
i d $ i d
1
SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255);
SDL_Init(SDL_INIT_VIDEO);
1
$window = SDL_CreateWindow(...);
2
3
$renderer = SDL_CreateRenderer($window, 0, 0);
4
$orange = [0xd7, 0x6b, 0x2b, 0];
5
SDL_SetRenderDrawColor($renderer, ...$orange);
6
SDL_RenderClear($renderer);
7
8
SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200
9
SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180)
10
SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160)
11
SDL_RenderPresent($renderer);
12
13
SDL_Delay(10000);
14
15
SDL_DestroyRenderer($renderer);
16
i d $ i d
1
SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200
SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180)
SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160)
SDL_Init(SDL_INIT_VIDEO);
1
$window = SDL_CreateWindow(...);
2
3
$renderer = SDL_CreateRenderer($window, 0, 0);
4
$orange = [0xd7, 0x6b, 0x2b, 0];
5
SDL_SetRenderDrawColor($renderer, ...$orange);
6
SDL_RenderClear($renderer);
7
SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255);
8
9
10
11
SDL_RenderPresent($renderer);
12
13
SDL_Delay(10000);
14
15
SDL_DestroyRenderer($renderer);
16
i d $ i d
1
SDL_RenderPresent($renderer);
SDL_Init(SDL_INIT_VIDEO);
1
$window = SDL_CreateWindow(...);
2
3
$renderer = SDL_CreateRenderer($window, 0, 0);
4
$orange = [0xd7, 0x6b, 0x2b, 0];
5
SDL_SetRenderDrawColor($renderer, ...$orange);
6
SDL_RenderClear($renderer);
7
SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255);
8
SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200
9
SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180)
10
SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160)
11
12
13
SDL_Delay(10000);
14
15
SDL_DestroyRenderer($renderer);
16
i d $ i d
1
SDL_Delay(10000);
SDL_Init(SDL_INIT_VIDEO);
1
$window = SDL_CreateWindow(...);
2
3
$renderer = SDL_CreateRenderer($window, 0, 0);
4
$orange = [0xd7, 0x6b, 0x2b, 0];
5
SDL_SetRenderDrawColor($renderer, ...$orange);
6
SDL_RenderClear($renderer);
7
SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255);
8
SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200
9
SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180)
10
SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160)
11
SDL_RenderPresent($renderer);
12
13
14
15
SDL_DestroyRenderer($renderer);
16
i d $ i d
1
DRAW FUNCTIONS
SDL_RenderDrawPoint
SDL_RenderDrawLine
SDL_RenderDrawRect
SDL_RenderFillRect
SDL_RenderCopy
SDL_RenderCopyEx
SDL_RenderDrawPointF
SDL_RenderDrawLineF
SDL_RenderDrawRectF
SDL_RenderFillRectF
SDL_RenderCopyF
SDL_RenderCopyExF
SDL_RECT
class SDL_Rect {
	 public int $x;
	 public int $y;
	 public int $w;
	 public int $h;
}
1
2
3
4
5
6
SDL_FRECT
class SDL_FRect {
	 public float $x;
	 public float $y;
	 public float $w;
	 public float $h;
}
1
2
3
4
5
6
TEXTURE
$surface = SDL_LoadBMP(__DIR__."/spaceship.bmp");
$texture = SDL_CreateTextureFromSurface($renderer, $surface);
1
2
3
SDL_IMAGE EXTENSION
pecl install sdl_image-devel
1
$texture = IMG_LoadTexture($renderer, $imageFilename);
1
PNG, JPG, BMP, TGA, TIF, ...
SDL_RENDERCOPY
SDL_RenderCopy(
	 $renderer,
	 $texture,
	 SDL_Rect $sourceRect,
	 SDL_Rect $destinationRect
)
1
2
3
4
5
6
SPRITE
$texture = IMG_LoadTexture($renderer, __DIR__."/barrel.png");
1
2
$sourceRect = new SDL_Rect(0, 0, 40, 40);
3
$destRect = new SDL_Rect(400, 200, 40, 40);
4
5
SDL_RenderCopy($renderer, $texture, $sourceRect, $destRect);
6
$sourceRect = new SDL_Rect(0, 0, 40, 40);
$destRect = new SDL_Rect(400, 200, 40, 40);
$texture = IMG_LoadTexture($renderer, __DIR__."/barrel.png");
1
2
3
4
5
SDL_RenderCopy($renderer, $texture, $sourceRect, $destRect);
6 SDL_RenderCopy($renderer, $texture, $sourceRect, $destRect);
$texture = IMG_LoadTexture($renderer, __DIR__."/barrel.png");
1
2
$sourceRect = new SDL_Rect(0, 0, 40, 40);
3
$destRect = new SDL_Rect(400, 200, 40, 40);
4
5
6
SPRITE
SDL_RenderCopyEx(
	 $renderer,
	 $texture,
	 SDL_Rect $sourceRect,
	 SDL_Rect$destRect,
	 float $rotationAngle,
	 SDL_Point $rotationCenter,
	 int $flip
	 // SDL_FLIP_NONE | SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL
)
1
2
3
4
5
6
7
8
9
10
LEVEL
+
$level = [
	 "XXXXX XXXXXXXX XXXXX",
	 " ",
	 " ",
	 " ",
	 " ",
	 " XXXXXXX XXXXXXX ",
	 " ",
	 " ",
	 " ",
	 " XXXXXXXXXXXXXXXXXXXXXX ",
	 " ",
	 " ",
	 " ",
	 "XXXXXXXXX XXXXXXXXX",
	 " ",
" "
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
GAME LOOP
/* Init window/renderer/load images */
do {
	 // a lot of stuff
} while (!$quit);
/* Clean the kitchen */
1
2
3
4
5
6
7
GAME LOOP
/* Init window/renderer/load images */
$event = new SDL_Event();
do {
	 SDL_PollEvent($event);
	 $inputStatus = checkInput();
	 $quit = updateGame($inputStatus, $event);
	 render();
} while (!$quit);
/* Clean the kitchen */
1
2
3
4
5
6
7
8
9
10
11
UPDATE
class Player {
	 private int SPEED = 1; // pixels per loop
	 private int $x;
	 public function update() {
	 	 $this->x += self::SPEED;
	 }
	 public function render($renderer) {
	 	 $renderer->drawItPlease($playerTexture, $this->x);
	 }
}
1
2
3
4
5
6
7
8
9
10
11
12
UPDATE
class Player {
	 private int SPEED = 30; // pixels per second
	 private int $x;
	 public function update(float $deltaTime) {
	 	 $this->x += self::SPEED * $deltaTime;
	 }
	 public function render($renderer) {
	 	 $renderer->drawItPlease($playerTexture, $this->x);
	 }
}
1
2
3
4
5
6
7
8
9
10
11
12
	 private int $x;
class Player {
1
	 private int SPEED = 30; // pixels per second
2
3
4
	 public function update(float $deltaTime) {
5
	 	 $this->x += self::SPEED * $deltaTime;
6
	 }
7
8
	 public function render($renderer) {
9
	 	 $renderer->drawItPlease($playerTexture, $this->x);
10
	 }
11
}
12
UPDATE
	 private float $x;
class Player {
1
	 private int SPEED = 30; // pixels per second
2
3
4
	 public function update(float $deltaTime) {
5
	 	 $this->x += self::SPEED * $deltaTime;
6
	 }
7
8
	 public function render($renderer) {
9
	 	 $renderer->drawItPlease($playerTexture, (int)$this->x);
10
	 }
11
}
12
COLLISIONS WITH AXIS-ALIGNED BOUNDING BOX
COLLISIONS WITH AABB
COLLISIONS WITH AABB
COLLISIONS WITH AABB
$rect1 = SDL_Rect($x1, $y1, $w1, $h1);
$rect2 = SDL_Rect($x2, $y2, $w2, $h3);
1
2
COLLISIONS WITH AABB
SDL_HasIntersection(SDL_Rect $rect1, SDL_Rect $rect2): bool
1
COLLISIONS WITH AABB
SDL_HasIntersection(SDL_Rect $rect1, SDL_Rect $rect2): bool
1
COLLISIONS WITH AABB
$rect1->HasIntersection($rect2);
1
COLLISIONS
COLLISIONS
5px
20px
SDL_IntersectRect(
	 SDL_Rect $rect1, SDL_Rect $rect2, SDL_Rect &$intersection
)
1
2
3
JOYSTICK
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
$joystick = SDL_JoystickOpen(0);
if ($joystick !== null) {
	 // Joystick could not be found
}
$xJoystickMotion = SDL_JoystickGetAxis($joystick, 0);
$yJoystickMotion = SDL_JoystickGetAxis($joystick, 1);
// SDL_JoystickGetAxis($j, $xOrY): int (-32768 to 32767)
1
2
3
4
5
6
7
8
9
10
11
12
KEYBOARD
$numKeys = 0;
$keys = SDL_GetKeyboardState($numKeys, false);
if (in_array(SDL_SCANCODE_LEFT, $keys)) { // left arrow presse
	 $goToLeft = true;
}
if (in_array(SDL_SCANCODE_Q, $keys)) { // q or Q pressed
	 $quit = true;
}
1
2
3
4
5
6
7
8
9
SDL_MIXER EXTENSION
~60 functions for playing music and sfx
pecl install sdl_mixer-devel
1
STATE OF THE ART (KPI*)
PHP: 20
* Kea Perception Index
Python: 500K
C/C++/C#: 100M
GRAZIE!
Manuel Baldassarri

Twitter @k3a

Github @kea









https://wireframe.raspberrypi.org/books/code-the-classics1
https://github.com/kea/code-the-classics1-php
https://www.libsdl.org/
https://github.com/easysoft/phpmicro

More Related Content

What's hot

Nullcon HackIM 2012 Solutions
Nullcon HackIM 2012 SolutionsNullcon HackIM 2012 Solutions
Nullcon HackIM 2012 SolutionsNilanjan De
 
Writing Mirror API and Native Apps for Google Glass
Writing Mirror API and Native Apps for Google GlassWriting Mirror API and Native Apps for Google Glass
Writing Mirror API and Native Apps for Google GlassJean-Luc David
 
R57shell
R57shellR57shell
R57shellady36
 
3D dualcopter
3D dualcopter 3D dualcopter
3D dualcopter prakasha g
 
The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212Mahmoud Samir Fayed
 
DAHO.AM 2015 - Abusing phones to make the internet of things
DAHO.AM 2015 - Abusing phones to make the internet of thingsDAHO.AM 2015 - Abusing phones to make the internet of things
DAHO.AM 2015 - Abusing phones to make the internet of thingsJan Jongboom
 
MANUAL DE FUNCIONAMIENTO APAFA
MANUAL DE FUNCIONAMIENTO APAFAMANUAL DE FUNCIONAMIENTO APAFA
MANUAL DE FUNCIONAMIENTO APAFAtellinos
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconftutorialsruby
 
The Ring programming language version 1.6 book - Part 61 of 189
The Ring programming language version 1.6 book - Part 61 of 189The Ring programming language version 1.6 book - Part 61 of 189
The Ring programming language version 1.6 book - Part 61 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 55 of 185
The Ring programming language version 1.5.4 book - Part 55 of 185The Ring programming language version 1.5.4 book - Part 55 of 185
The Ring programming language version 1.5.4 book - Part 55 of 185Mahmoud Samir Fayed
 
Gdg san diego android 11 meetups what's new in android - ui and dev tools
Gdg san diego android 11 meetups  what's new in android  - ui and dev toolsGdg san diego android 11 meetups  what's new in android  - ui and dev tools
Gdg san diego android 11 meetups what's new in android - ui and dev toolsSvetlin Stanchev
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
Keyboard Access APIs
Keyboard Access APIsKeyboard Access APIs
Keyboard Access APIstoddkloots
 
Informe Final Red de Area Comunal
Informe Final Red de Area ComunalInforme Final Red de Area Comunal
Informe Final Red de Area ComunalMaria Tobon
 
Node Access in Drupal 7 (and Drupal 8)
Node Access in Drupal 7 (and Drupal 8)Node Access in Drupal 7 (and Drupal 8)
Node Access in Drupal 7 (and Drupal 8)nyccamp
 
Calculadora
CalculadoraCalculadora
CalculadoraCBTa 120
 
The Ring programming language version 1.9 book - Part 129 of 210
The Ring programming language version 1.9 book - Part 129 of 210The Ring programming language version 1.9 book - Part 129 of 210
The Ring programming language version 1.9 book - Part 129 of 210Mahmoud Samir Fayed
 

What's hot (20)

Nullcon HackIM 2012 Solutions
Nullcon HackIM 2012 SolutionsNullcon HackIM 2012 Solutions
Nullcon HackIM 2012 Solutions
 
Writing Mirror API and Native Apps for Google Glass
Writing Mirror API and Native Apps for Google GlassWriting Mirror API and Native Apps for Google Glass
Writing Mirror API and Native Apps for Google Glass
 
R57shell
R57shellR57shell
R57shell
 
3D dualcopter
3D dualcopter 3D dualcopter
3D dualcopter
 
The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212
 
DAHO.AM 2015 - Abusing phones to make the internet of things
DAHO.AM 2015 - Abusing phones to make the internet of thingsDAHO.AM 2015 - Abusing phones to make the internet of things
DAHO.AM 2015 - Abusing phones to make the internet of things
 
MANUAL DE FUNCIONAMIENTO APAFA
MANUAL DE FUNCIONAMIENTO APAFAMANUAL DE FUNCIONAMIENTO APAFA
MANUAL DE FUNCIONAMIENTO APAFA
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
 
J2 me 07_5
J2 me 07_5J2 me 07_5
J2 me 07_5
 
Ojagnaha vol7
Ojagnaha vol7Ojagnaha vol7
Ojagnaha vol7
 
The Ring programming language version 1.6 book - Part 61 of 189
The Ring programming language version 1.6 book - Part 61 of 189The Ring programming language version 1.6 book - Part 61 of 189
The Ring programming language version 1.6 book - Part 61 of 189
 
The Ring programming language version 1.5.4 book - Part 55 of 185
The Ring programming language version 1.5.4 book - Part 55 of 185The Ring programming language version 1.5.4 book - Part 55 of 185
The Ring programming language version 1.5.4 book - Part 55 of 185
 
Gdg san diego android 11 meetups what's new in android - ui and dev tools
Gdg san diego android 11 meetups  what's new in android  - ui and dev toolsGdg san diego android 11 meetups  what's new in android  - ui and dev tools
Gdg san diego android 11 meetups what's new in android - ui and dev tools
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Keyboard Access APIs
Keyboard Access APIsKeyboard Access APIs
Keyboard Access APIs
 
Daily notes
Daily notesDaily notes
Daily notes
 
Informe Final Red de Area Comunal
Informe Final Red de Area ComunalInforme Final Red de Area Comunal
Informe Final Red de Area Comunal
 
Node Access in Drupal 7 (and Drupal 8)
Node Access in Drupal 7 (and Drupal 8)Node Access in Drupal 7 (and Drupal 8)
Node Access in Drupal 7 (and Drupal 8)
 
Calculadora
CalculadoraCalculadora
Calculadora
 
The Ring programming language version 1.9 book - Part 129 of 210
The Ring programming language version 1.9 book - Part 129 of 210The Ring programming language version 1.9 book - Part 129 of 210
The Ring programming language version 1.9 book - Part 129 of 210
 

Similar to Videogiochi in PHP 👾

building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconftutorialsruby
 
Samrt attendance system using fingerprint
Samrt attendance system using fingerprintSamrt attendance system using fingerprint
Samrt attendance system using fingerprintpraful borad
 
LISA QooxdooTutorial Slides
LISA QooxdooTutorial SlidesLISA QooxdooTutorial Slides
LISA QooxdooTutorial SlidesTobias Oetiker
 
The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202Mahmoud Samir Fayed
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptVisual Engineering
 
The Ring programming language version 1.10 book - Part 131 of 212
The Ring programming language version 1.10 book - Part 131 of 212The Ring programming language version 1.10 book - Part 131 of 212
The Ring programming language version 1.10 book - Part 131 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 47 of 181
The Ring programming language version 1.5.2 book - Part 47 of 181The Ring programming language version 1.5.2 book - Part 47 of 181
The Ring programming language version 1.5.2 book - Part 47 of 181Mahmoud Samir Fayed
 
Computer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportComputer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportBijoy679
 
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
Visual Component Testing  -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...Visual Component Testing  -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...Applitools
 
The Ring programming language version 1.6 book - Part 50 of 189
The Ring programming language version 1.6 book - Part 50 of 189The Ring programming language version 1.6 book - Part 50 of 189
The Ring programming language version 1.6 book - Part 50 of 189Mahmoud Samir Fayed
 
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdffootstatus
 
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)eMan s.r.o.
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges✅ William Pinaud
 
Virtual Reality in Android
Virtual Reality in AndroidVirtual Reality in Android
Virtual Reality in AndroidMario Bodemann
 
Dam gate open close lpc prog
Dam gate open close lpc progDam gate open close lpc prog
Dam gate open close lpc prognikhil dixit
 

Similar to Videogiochi in PHP 👾 (20)

building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
 
Samrt attendance system using fingerprint
Samrt attendance system using fingerprintSamrt attendance system using fingerprint
Samrt attendance system using fingerprint
 
Arduino: Arduino lcd
Arduino: Arduino lcdArduino: Arduino lcd
Arduino: Arduino lcd
 
LISA QooxdooTutorial Slides
LISA QooxdooTutorial SlidesLISA QooxdooTutorial Slides
LISA QooxdooTutorial Slides
 
The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202
 
Functions
FunctionsFunctions
Functions
 
Android Things
Android ThingsAndroid Things
Android Things
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
The Ring programming language version 1.10 book - Part 131 of 212
The Ring programming language version 1.10 book - Part 131 of 212The Ring programming language version 1.10 book - Part 131 of 212
The Ring programming language version 1.10 book - Part 131 of 212
 
The Ring programming language version 1.5.2 book - Part 47 of 181
The Ring programming language version 1.5.2 book - Part 47 of 181The Ring programming language version 1.5.2 book - Part 47 of 181
The Ring programming language version 1.5.2 book - Part 47 of 181
 
Computer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportComputer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab report
 
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
Visual Component Testing  -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...Visual Component Testing  -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
 
The Ring programming language version 1.6 book - Part 50 of 189
The Ring programming language version 1.6 book - Part 50 of 189The Ring programming language version 1.6 book - Part 50 of 189
The Ring programming language version 1.6 book - Part 50 of 189
 
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
 
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 
Virtual Reality in Android
Virtual Reality in AndroidVirtual Reality in Android
Virtual Reality in Android
 
Games 3 dl4-example
Games 3 dl4-exampleGames 3 dl4-example
Games 3 dl4-example
 
Dam gate open close lpc prog
Dam gate open close lpc progDam gate open close lpc prog
Dam gate open close lpc prog
 
dotCloud and go
dotCloud and godotCloud and go
dotCloud and go
 

More from Manuel Baldassarri

More from Manuel Baldassarri (8)

Swoole Overview
Swoole OverviewSwoole Overview
Swoole Overview
 
From * to Symfony2
From * to Symfony2From * to Symfony2
From * to Symfony2
 
Un CMS in 25min con Symfony CMF
Un CMS in 25min con Symfony CMFUn CMS in 25min con Symfony CMF
Un CMS in 25min con Symfony CMF
 
Automazione quotidiana in php
Automazione quotidiana in phpAutomazione quotidiana in php
Automazione quotidiana in php
 
Symfony2 security layer
Symfony2 security layerSymfony2 security layer
Symfony2 security layer
 
Symfony CMF: un nuovo paradigma per la gestione dei contenuti
Symfony CMF: un nuovo paradigma per la gestione dei contenutiSymfony CMF: un nuovo paradigma per la gestione dei contenuti
Symfony CMF: un nuovo paradigma per la gestione dei contenuti
 
Ant vs Phing
Ant vs PhingAnt vs Phing
Ant vs Phing
 
Form refactoring
Form refactoringForm refactoring
Form refactoring
 

Recently uploaded

BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptxBT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptxNeo4j
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!Memoori
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsLeah Henrickson
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...panagenda
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FIDO Alliance
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastUXDXConf
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxJennifer Lim
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandIES VE
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...FIDO Alliance
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimaginedpanagenda
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe中 央社
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?Mark Billinghurst
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftshyamraj55
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 

Recently uploaded (20)

BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptxBT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 

Videogiochi in PHP 👾

  • 1. VIDEOGIOCHI IN PHP 👾 dal game loop alle collisioni Manuel Baldassarri | PHPDay GrUSP edition 2022
  • 2. PHP EXTENSIONS Mysql - Postgres - Curl - GD - Json - Intl - ... Memcache - ImageMagick - MongoDB - Redis - ...
  • 4.
  • 5. SDL Simple DirectMedia Layer cross-platform: Windows, MacOS, Linux, iOS, Android audio, keyboard, mouse, game controller graphics hardware via OpenGL, Direct3D and Vulkan
  • 6.
  • 7.
  • 10. WINDOW SDL_Init(SDL_INIT_VIDEO); 1 2 $window = SDL_CreateWindow( 3 'This is not a window', 4 SDL_WINDOWPOS_UNDEFINED, // SDL_WINDOWPOS_CENTERED 5 SDL_WINDOWPOS_UNDEFINED, // SDL_WINDOWPOS_CENTERED 6 800, 7 400, 8 0 // SDL_WINDOW_(FULLSCREEN|HIDDEN|RESIZABLE) 9 // SDL_WINDOW_(OPENGL|VULKAN|METAL) 10 ); 11 12 sleep(10); 13 14 SDL_DestroyWindow($window); 15 SDL_Quit(); 16 $window = SDL_CreateWindow( 'This is not a window', SDL_WINDOWPOS_UNDEFINED, // SDL_WINDOWPOS_CENTERED SDL_WINDOWPOS_UNDEFINED, // SDL_WINDOWPOS_CENTERED 800, 400, 0 // SDL_WINDOW_(FULLSCREEN|HIDDEN|RESIZABLE) // SDL_WINDOW_(OPENGL|VULKAN|METAL) ); SDL_Init(SDL_INIT_VIDEO); 1 2 3 4 5 6 7 8 9 10 11 12 sleep(10); 13 14 SDL_DestroyWindow($window); 15 SDL_Quit(); 16 sleep(10); SDL_DestroyWindow($window); SDL_Quit(); SDL_Init(SDL_INIT_VIDEO); 1 2 $window = SDL_CreateWindow( 3 'This is not a window', 4 SDL_WINDOWPOS_UNDEFINED, // SDL_WINDOWPOS_CENTERED 5 SDL_WINDOWPOS_UNDEFINED, // SDL_WINDOWPOS_CENTERED 6 800, 7 400, 8 0 // SDL_WINDOW_(FULLSCREEN|HIDDEN|RESIZABLE) 9 // SDL_WINDOW_(OPENGL|VULKAN|METAL) 10 ); 11 12 13 14 15 16
  • 12. RENDERER $renderer = SDL_CreateRenderer($window, 0, 0); SDL_Init(SDL_INIT_VIDEO); 1 $window = SDL_CreateWindow(...); 2 3 4 $orange = [0xd7, 0x6b, 0x2b, 0]; 5 SDL_SetRenderDrawColor($renderer, ...$orange); 6 SDL_RenderClear($renderer); 7 SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255); 8 SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200 9 SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180) 10 SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160) 11 SDL_RenderPresent($renderer); 12 13 SDL_Delay(10000); 14 15 SDL_DestroyRenderer($renderer); 16 i d $ i d 1 $orange = [0xd7, 0x6b, 0x2b, 0]; SDL_SetRenderDrawColor($renderer, ...$orange); SDL_Init(SDL_INIT_VIDEO); 1 $window = SDL_CreateWindow(...); 2 3 $renderer = SDL_CreateRenderer($window, 0, 0); 4 5 6 SDL_RenderClear($renderer); 7 SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255); 8 SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200 9 SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180) 10 SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160) 11 SDL_RenderPresent($renderer); 12 13 SDL_Delay(10000); 14 15 SDL_DestroyRenderer($renderer); 16 i d $ i d 1 SDL_RenderClear($renderer); SDL_Init(SDL_INIT_VIDEO); 1 $window = SDL_CreateWindow(...); 2 3 $renderer = SDL_CreateRenderer($window, 0, 0); 4 $orange = [0xd7, 0x6b, 0x2b, 0]; 5 SDL_SetRenderDrawColor($renderer, ...$orange); 6 7 SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255); 8 SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200 9 SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180) 10 SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160) 11 SDL_RenderPresent($renderer); 12 13 SDL_Delay(10000); 14 15 SDL_DestroyRenderer($renderer); 16 i d $ i d 1 SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255); SDL_Init(SDL_INIT_VIDEO); 1 $window = SDL_CreateWindow(...); 2 3 $renderer = SDL_CreateRenderer($window, 0, 0); 4 $orange = [0xd7, 0x6b, 0x2b, 0]; 5 SDL_SetRenderDrawColor($renderer, ...$orange); 6 SDL_RenderClear($renderer); 7 8 SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200 9 SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180) 10 SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160) 11 SDL_RenderPresent($renderer); 12 13 SDL_Delay(10000); 14 15 SDL_DestroyRenderer($renderer); 16 i d $ i d 1 SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200 SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180) SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160) SDL_Init(SDL_INIT_VIDEO); 1 $window = SDL_CreateWindow(...); 2 3 $renderer = SDL_CreateRenderer($window, 0, 0); 4 $orange = [0xd7, 0x6b, 0x2b, 0]; 5 SDL_SetRenderDrawColor($renderer, ...$orange); 6 SDL_RenderClear($renderer); 7 SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255); 8 9 10 11 SDL_RenderPresent($renderer); 12 13 SDL_Delay(10000); 14 15 SDL_DestroyRenderer($renderer); 16 i d $ i d 1 SDL_RenderPresent($renderer); SDL_Init(SDL_INIT_VIDEO); 1 $window = SDL_CreateWindow(...); 2 3 $renderer = SDL_CreateRenderer($window, 0, 0); 4 $orange = [0xd7, 0x6b, 0x2b, 0]; 5 SDL_SetRenderDrawColor($renderer, ...$orange); 6 SDL_RenderClear($renderer); 7 SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255); 8 SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200 9 SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180) 10 SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160) 11 12 13 SDL_Delay(10000); 14 15 SDL_DestroyRenderer($renderer); 16 i d $ i d 1 SDL_Delay(10000); SDL_Init(SDL_INIT_VIDEO); 1 $window = SDL_CreateWindow(...); 2 3 $renderer = SDL_CreateRenderer($window, 0, 0); 4 $orange = [0xd7, 0x6b, 0x2b, 0]; 5 SDL_SetRenderDrawColor($renderer, ...$orange); 6 SDL_RenderClear($renderer); 7 SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255); 8 SDL_RenderDrawRect($renderer, new SDL_Rect(100, 100, 100, 200 9 SDL_RenderDrawRect($renderer, new SDL_Rect(110, 110, 80, 180) 10 SDL_RenderDrawRect($renderer, new SDL_Rect(120, 120, 60, 160) 11 SDL_RenderPresent($renderer); 12 13 14 15 SDL_DestroyRenderer($renderer); 16 i d $ i d 1
  • 13.
  • 15. SDL_RECT class SDL_Rect { public int $x; public int $y; public int $w; public int $h; } 1 2 3 4 5 6
  • 16. SDL_FRECT class SDL_FRect { public float $x; public float $y; public float $w; public float $h; } 1 2 3 4 5 6
  • 17. TEXTURE $surface = SDL_LoadBMP(__DIR__."/spaceship.bmp"); $texture = SDL_CreateTextureFromSurface($renderer, $surface); 1 2 3
  • 18. SDL_IMAGE EXTENSION pecl install sdl_image-devel 1 $texture = IMG_LoadTexture($renderer, $imageFilename); 1 PNG, JPG, BMP, TGA, TIF, ...
  • 19. SDL_RENDERCOPY SDL_RenderCopy( $renderer, $texture, SDL_Rect $sourceRect, SDL_Rect $destinationRect ) 1 2 3 4 5 6
  • 20. SPRITE $texture = IMG_LoadTexture($renderer, __DIR__."/barrel.png"); 1 2 $sourceRect = new SDL_Rect(0, 0, 40, 40); 3 $destRect = new SDL_Rect(400, 200, 40, 40); 4 5 SDL_RenderCopy($renderer, $texture, $sourceRect, $destRect); 6 $sourceRect = new SDL_Rect(0, 0, 40, 40); $destRect = new SDL_Rect(400, 200, 40, 40); $texture = IMG_LoadTexture($renderer, __DIR__."/barrel.png"); 1 2 3 4 5 SDL_RenderCopy($renderer, $texture, $sourceRect, $destRect); 6 SDL_RenderCopy($renderer, $texture, $sourceRect, $destRect); $texture = IMG_LoadTexture($renderer, __DIR__."/barrel.png"); 1 2 $sourceRect = new SDL_Rect(0, 0, 40, 40); 3 $destRect = new SDL_Rect(400, 200, 40, 40); 4 5 6
  • 21.
  • 22. SPRITE SDL_RenderCopyEx( $renderer, $texture, SDL_Rect $sourceRect, SDL_Rect$destRect, float $rotationAngle, SDL_Point $rotationCenter, int $flip // SDL_FLIP_NONE | SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL ) 1 2 3 4 5 6 7 8 9 10
  • 23. LEVEL + $level = [ "XXXXX XXXXXXXX XXXXX", " ", " ", " ", " ", " XXXXXXX XXXXXXX ", " ", " ", " ", " XXXXXXXXXXXXXXXXXXXXXX ", " ", " ", " ", "XXXXXXXXX XXXXXXXXX", " ", " " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
  • 24.
  • 25.
  • 26. GAME LOOP /* Init window/renderer/load images */ do { // a lot of stuff } while (!$quit); /* Clean the kitchen */ 1 2 3 4 5 6 7
  • 27. GAME LOOP /* Init window/renderer/load images */ $event = new SDL_Event(); do { SDL_PollEvent($event); $inputStatus = checkInput(); $quit = updateGame($inputStatus, $event); render(); } while (!$quit); /* Clean the kitchen */ 1 2 3 4 5 6 7 8 9 10 11
  • 28. UPDATE class Player { private int SPEED = 1; // pixels per loop private int $x; public function update() { $this->x += self::SPEED; } public function render($renderer) { $renderer->drawItPlease($playerTexture, $this->x); } } 1 2 3 4 5 6 7 8 9 10 11 12
  • 29. UPDATE class Player { private int SPEED = 30; // pixels per second private int $x; public function update(float $deltaTime) { $this->x += self::SPEED * $deltaTime; } public function render($renderer) { $renderer->drawItPlease($playerTexture, $this->x); } } 1 2 3 4 5 6 7 8 9 10 11 12 private int $x; class Player { 1 private int SPEED = 30; // pixels per second 2 3 4 public function update(float $deltaTime) { 5 $this->x += self::SPEED * $deltaTime; 6 } 7 8 public function render($renderer) { 9 $renderer->drawItPlease($playerTexture, $this->x); 10 } 11 } 12
  • 30. UPDATE private float $x; class Player { 1 private int SPEED = 30; // pixels per second 2 3 4 public function update(float $deltaTime) { 5 $this->x += self::SPEED * $deltaTime; 6 } 7 8 public function render($renderer) { 9 $renderer->drawItPlease($playerTexture, (int)$this->x); 10 } 11 } 12
  • 34. COLLISIONS WITH AABB $rect1 = SDL_Rect($x1, $y1, $w1, $h1); $rect2 = SDL_Rect($x2, $y2, $w2, $h3); 1 2
  • 35. COLLISIONS WITH AABB SDL_HasIntersection(SDL_Rect $rect1, SDL_Rect $rect2): bool 1
  • 36. COLLISIONS WITH AABB SDL_HasIntersection(SDL_Rect $rect1, SDL_Rect $rect2): bool 1
  • 39. COLLISIONS 5px 20px SDL_IntersectRect( SDL_Rect $rect1, SDL_Rect $rect2, SDL_Rect &$intersection ) 1 2 3
  • 40. JOYSTICK SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK); $joystick = SDL_JoystickOpen(0); if ($joystick !== null) { // Joystick could not be found } $xJoystickMotion = SDL_JoystickGetAxis($joystick, 0); $yJoystickMotion = SDL_JoystickGetAxis($joystick, 1); // SDL_JoystickGetAxis($j, $xOrY): int (-32768 to 32767) 1 2 3 4 5 6 7 8 9 10 11 12
  • 41. KEYBOARD $numKeys = 0; $keys = SDL_GetKeyboardState($numKeys, false); if (in_array(SDL_SCANCODE_LEFT, $keys)) { // left arrow presse $goToLeft = true; } if (in_array(SDL_SCANCODE_Q, $keys)) { // q or Q pressed $quit = true; } 1 2 3 4 5 6 7 8 9
  • 42. SDL_MIXER EXTENSION ~60 functions for playing music and sfx pecl install sdl_mixer-devel 1
  • 43. STATE OF THE ART (KPI*) PHP: 20 * Kea Perception Index Python: 500K C/C++/C#: 100M
  • 44. GRAZIE! Manuel Baldassarri Twitter @k3a Github @kea https://wireframe.raspberrypi.org/books/code-the-classics1 https://github.com/kea/code-the-classics1-php https://www.libsdl.org/ https://github.com/easysoft/phpmicro