jemjabella - ultimately better than you

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

 

17 comments on “PHP Game Programming”

  1. #On July 31st, 08 @ 11:37 pm, Vanesa wrote:

    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. #On July 31st, 08 @ 11:46 pm, Aaron wrote:

    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. #On August 1st, 08 @ 12:55 am, Stephanie wrote:

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

  4. #On August 1st, 08 @ 9:36 am, Martin wrote:

    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. #On August 1st, 08 @ 11:08 am, Jabed wrote:

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

  6. #On August 1st, 08 @ 12:06 pm, Mat wrote:

    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. #On August 1st, 08 @ 2:24 pm, Jem wrote:

    Forget PHP, make a game out of Flash/Actionscript

    No.

  8. #On August 3rd, 08 @ 4:28 am, Chien Yee wrote:

    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. #On August 3rd, 08 @ 4:32 am, Chien Yee wrote:

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

  10. #On August 3rd, 08 @ 1:08 pm, Rich wrote:

    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. #On August 4th, 08 @ 1:33 am, Mat wrote:

    @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. #On August 5th, 08 @ 2:21 am, Andy wrote:

    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. #On August 5th, 08 @ 6:59 am, Chien Yee wrote:

    @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. #On August 7th, 08 @ 3:16 pm, Alex wrote:

    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. #On August 7th, 08 @ 3:47 pm, WebSam wrote:

    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. #On August 13th, 08 @ 4:58 pm, Nick wrote:

    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. #On September 22nd, 08 @ 12:58 am, Justin wrote:

    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

I'm not interested in viagra or penis enhancers, first-time commenters are moderated and anonymous comments are deleted. Don't waste my time, or yours.