July 31, 2008

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 :)

Comments

There are currently 17 approved responses to "PHP Game Programming".

  1. Vanesa   July 31st, 2008 [gravatar]

    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.

  2. Aaron   July 31st, 2008 [gravatar]

    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

  3. Stephanie   July 31st, 2008 [gravatar]

    Well just sitting here I've already worked out how I would do Hangman, so I suppose you will think of something :)

  4. Martin   August 1st, 2008 [gravatar]

    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.

  5. Jabed   August 1st, 2008 [gravatar]

    Forget PHP, make a game out of Flash/Actionscript :P

  6. Mat   August 1st, 2008 [gravatar]

    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 ;)

  7. Jem   August 1st, 2008 [gravatar]
    Forget PHP, make a game out of Flash/Actionscript

    No.

  8. Chien Yee   August 3rd, 2008 [gravatar]

    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";
    }
    }

  9. Chien Yee   August 3rd, 2008 [gravatar]

    Okay, WordPress converted part of it =_= the line breaks to be exact :(

  10. Rich   August 3rd, 2008 [gravatar]

    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)

  11. Mat   August 4th, 2008 [gravatar]

    @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.

  12. Andy   August 5th, 2008 [gravatar]

    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 ^^

  13. Chien Yee   August 5th, 2008 [gravatar]

    @Mat that's part of the code I got from the book :X I didn't check through but just sent it to Jem :)

  14. Alex   August 7th, 2008 [gravatar]

    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!

    :)

  15. WebSam   August 7th, 2008 [gravatar]

    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

  16. Nick   August 13th, 2008 [gravatar]

    There are all those text-based RPG games running on PHP backends out there. Hangman wouldn't be so difficult I don't think.

  17. Justin   September 21st, 2008 [gravatar]

    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.

Leave a Reply

No HTML please; first time comments are moderated; comments left without a legitimate first name/nickname and e-mail will be deleted (no, your momma didn't call you "cheap quality wardrobes").

[geek inside avatar]Welcome to the blog of girl geek & php ninja extraordinaire 'Jem'. Web developer, mum and supreme crazy cat lady.. »

---

Post stats

Posted on July 31, 2008 in with 17 comments

---

Related posts

Other posts you might be interested in:

---

Share this post

Talk about this post on your favourite social media website:

tweet this add to stumbleupon add to delicious add to reddit digg this post add to newsvine share on facebook share on friendfeed

---

Subscribe

Like this post? Why not subscribe to the feed?

Knowledge

Pleasure

Archives

See more...