/    Sign up×
Community /Pin to ProfileBookmark

Heya

Best way to learn a programming language is to do a project and complete it.

A recent one of mine was to make a multiplayer PHP online strategy game.

[B]Overview:[/B]

-MySQL is at the core

-Admin page, this goes to the mysql database and writes to a table that the game is running. This Admin page now starts looking for ‘commands’. (if admin page is closed MYSQL is written to reflect that)

-Player logs in and joins a game. Checks if game is running and if it is stores game data in SESSIONS and then displays the HTML GUI. A player can now say move a unit around the map. This writes to a mysql and makes a ‘command’. The client itself doesnt do any moving but the page is constantly checking mysql for the position of the unit.

In the mean time the Admin page reads the ‘command’ from mysql and acts it out and constantly updates the unit position by writing the new location(s) to the database. (time based, i.e unit_move_distance = (current_time – time_since_last_move) * unit_speed. ) Once the unit reaches its destination (or encounters another unit say) the command is removed from the database.

So at the clients end the unit is seen to move across the screen and will do so for any other client that logs into the game. So if they log off the SESSION is killed but logging back in will recreate those exact same sessions from MYSQL. (all object orientated)

So this technique can be used (and i have) for any other number of game functions like mines and factories and battles etc.

So using AJAX / Javascript nifty stuff like mouse scrollable elements (map) and even ‘bitmapping’ (where is the player looking, display images only in that area, hes moved map, grab more images and stop displaying out of view ones) it actually appears as a playable game like any other. (albeit from the 80’s lol graphics were not part of the deal)

Works a treat when i test it on a few machines.

[B]My question is, what are the limitations of this techinique? How many users can log in at once and how many simultanious queries can MYSQL handle etc? Was a great PHP/Javascript learning tool but how practical is PHP in the real world?[/B]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @Belrick spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...