Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Joe Watkins:
Expanding Horizons
Nov 03, 2016 @ 14:40:49

In his most recent post Joe Watkins talks about a PHP extension he's been working on that wraps the libui library making it easier to use PHP to create cross-platform user interfaces.

Recently I have been working on a new extension. It is a wrapper around libui, which is a cross platform user interface development library, that allows the creation of native look and feel interfaces in the environments it supports.

That's a few hundred lines of PHP 7 code, moulded into an imitation of the snake game we all used to have on our phones. We've seen other user interface extensions before in PHP, there's even a modified PHP runtime that will allow you to write GTK+ applications.

I don't know anyone that ever deployed any of those extensions, and for very good reasons; PHP5 can barely do anything without allocating a bunch of memory, and doing a bunch of other extremely inefficient things, almost everything it does is inefficient. Beyond a basic forms like application, PHP5 is close to useless.

You can see an example of the snake game in action in this YouTube video. He goes on to talk about the low amounts of CPU and RAM the game (and extension) use and that, with the right amount of work, it can achieve around 60 frames per second. He points out that it is still early on in the development cycle for the extension and libui but there's already documentation for those wanting to investigate.

tagged: libui extension example video snake game efficiency

Link: http://blog.krakjoe.ninja/2016/11/expanding-horizons.html

SitePoint PHP Blog:
How’d They Do It? PHPSnake: Detecting Keypresses
Oct 31, 2016 @ 20:14:23

The SitePoint PHP blog has a new tutorial posted from editor Bruno Skvorc looking at building a "snake" game purely with PHP and handling/catching keypresses.

At a recent conference in Bulgaria, there was a hackathon for which Andrew Carter created a PHP console version of the popular “snake” game. I thought it was a really interesting concept, and since Andrew has a history of using PHP for weird things, I figured I’d demystify and explain how it was done.

The original repository is here, but we’ll build a version of it from scratch in this series so no need to clone it.

They start by defining some of the requirements for the game, including that it is to be CLI based with no browser functionality allowed. With those defined, they get into the code, starting with some of the "boilerplate" code to work with the command line environment, handle output and reading in characters as keys are pressed. The tutorial then gets into mapping the snakes to "directions" do that the keypresses would make the snake go up, down, left or right.

tagged: phpsnake snake detect keypress tutorial commandline

Link: https://www.sitepoint.com/howd-they-do-it-phpsnake-detecting-keypresses/

Trending Topics: