PHP Game Programming
I am very interested in creating some PHP-based simple text/image games, like hangman, guessing games, “higher or lower”, that sort of thing. Unfortunately, resources seem few and far between to get me started on the right track. I’m sure I could sit down and eventually drill something out but it’d save me a lot of time if I could get a head start.
If any of my more knowledgeable visitors have any suggestions for books, links to websites, etc… I’d very much appreciate them. Either in the comments or via e-mail — thanks :)
Vanesa said:
On 31 Jul at 10:37 pm
I once tried making a “mad libs” with PHP… it worked, in a weird and I-have-no-idea-what-I’m-doing kind of way. It’s still up and everything. Unfortunately, it doesn’t have any security techniques or spam protection, so I’m not putting it up for public any time soon.
Aaron said:
On 31 Jul at 10:46 pm
PHP … games? Hmm, well, that’s a first. I have hardly any basic PHP skills beyond includes and copying template tags for WordPress, so I’m probably not gooing to be able to help you.
Maybe you could create an adventure game where if the player completed all the levels with 100% score, they end up with their own CMS? :P
Stephanie said:
On 31 Jul at 11:55 pm
Well just sitting here I’ve already worked out how I would do Hangman, so I suppose you will think of something :)
Martin said:
On 01 Aug at 8:36 am
I don’t think you need any specific books on PHP game programming, game works bretty much like a regular info system. I have made 2 games with PHP (one role playing and one real estate simulator).
At first you have to define, what is the aim of the game you are creating. Personal development? Profit? Just interest? That defines where you should start your research. When I created my real estate simulator I had only one specific goal – making as much money as possible. When I started with my RPG game I just wanted to create a full Ajax user interface and funny environment. I didn’t make a single cent with the game, but I learned a lot about Ajax, had fun and entertained my friends, some of them spent 5-6 hours straight playing my game.
I would personally recommend using as much Ajax scripting in your game as possible, giving user a real time overview of the game client.
Jabed said:
On 01 Aug at 10:08 am
Forget PHP, make a game out of Flash/Actionscript :P
Mat said:
On 01 Aug at 11:06 am
You’re going to need a buttload of javascript to keep the game responsive and clear.
PHP isn’t really something id recommend to do things like this unless it was purely command line driven but as a web app.. you really should just use javascript thats what its suited toward client thick super response web applications.
If you need help with anything though while you’re developing, you know my email don’t be a stranger ;)
Jem said:
On 01 Aug at 1:24 pm
No.
Chien Yee said:
On 03 Aug at 3:28 am
I know one guess game code which I learned through one of the PHP books I’ve got. It’s something like this *prays WordPress doesn’t eat up my comment*
if (isset($_POST['posted'])) {
$number = rand(1,10);
if ($_POST['guess'] > $number) {
echo "Your guess is
too high";
echo "The number is
$number, you don't win, please play again";
} else if ($_POST['guess'] < $number) {
echo "Your guess is too low";
echo "The number is
$number, you don't win, please play again";
} else {
echo "The number is
$number, you win, please play again";
}
}
Chien Yee said:
On 03 Aug at 3:32 am
Okay, WordPress converted part of it =_= the line breaks to be exact :(
Rich said:
On 03 Aug at 12:08 pm
I’m with Jabed on this one, Actionscript3 is a truly beautiful language to work in (do not get it confused with the abomination that was Flash8/AS2, they are worlds apart). Having spent 10 years coding in PHP I picked-up AS3 very quickly, and am happy making actual proper real games with it, having released 6 so far this year. Of course all of those games still use PHP for the server side work (and always will) :)
If you really want to make a game out of true PHP then there is a really good book on the subject by Matt Rutledge which is available for free on Google Books (http://books.google.co.uk/books?id=F0xfkqTpS2AC&dq=php+game+development+book&pg=PP1&ots=K647fXq-Ka&sig=budRnYWtYLB5wOMj51w-AkFWGwE&hl=en&sa=X&oi=book_result&resnum=1&ct=result)
Mat said:
On 04 Aug at 12:33 am
@Chien Yee – I see a bunch of assumptions in that code.
what if $_POST[‘guess’] isn’t numeric?
Also it’s not really the ideal scenario as you only get one guess.. the whole idea is ‘warming’ upto the number.
Andy said:
On 05 Aug at 1:21 am
For a ‘guess the number’ game:
Use two session variables to keep track of the correct number and the number of guesses so far.
Use something like Chien Yee’s code to check their guess and compare it with the correct number.
Display the message (too low, too high, correct), and if they didn’t win, display the same form again.
I guess that’s some *really* pseudo pseudo-code :P But that’s pretty much it. If you can code that, you should be able to get a simple, working PHP game.
I’m quite experienced in coding PHP games, if you need any help, you can always ask me ^^
Chien Yee said:
On 05 Aug at 5:59 am
@Mat that’s part of the code I got from the book :X I didn’t check through but just sent it to Jem :)
Alex said:
On 07 Aug at 2:16 pm
This is an interesting one!
Myself and a friend have been longing to write a text/image style web based game (probabily in PHP with AJAX) he has the story idea and I am going to program it hopefully!!
A work college I used to work with, plays travian – http://www.travian.com/.
I think writing anything in any language just takes preparation.
I think you should go grab yourself one of the many AJAX libraries (mootools, scriptilicious, jquery to name a few!) and get to work with PHP and MySQL (whatever db), that way you can create user profiles, or have money – whatever really the sky is your limit!
:)
WebSam said:
On 07 Aug at 2:47 pm
I agree that php is’t best for web games. Look some links:
http://www.santosj.name/php/php-game-programming-chapter-1-introduction/
PHP Game Programming
http://books.google.ru/url?id=F0xfkqTpS2AC&q=http://www.worldcat.org/wcpa/oclc/55530710&clientid=librarylink&usg=AFQjCNHVL1AT4djiutQ3VA5zGbg8xjSf_g&source=gbs_buy_r&cad=2
Nick said:
On 13 Aug at 3:58 pm
There are all those text-based RPG games running on PHP backends out there. Hangman wouldn’t be so difficult I don’t think.
Justin said:
On 21 Sep at 11:58 pm
I own and coded a textbased multiplayer rpg game and in it i have a random number game using mt_rand that lets u guess 9 numbers and the prize is randomized. and if u can get more than one number right u get a amazing weapon and that was simple to code! Any question about it or making a php game mail me at solis972@talesofdormire.net.