SitePoint Sponsor

User Tag List

Results 1 to 23 of 23
  1. #1
    SitePoint Zealot amri's Avatar
    Join Date
    Dec 2002
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP for online game development

    Hello,
    Where I can find more information/articles about PHP that focused on online game development? I mean the game like those listed in www.mpogd.com
    Thanks

  2. #2
    SitePoint Zealot spybreak's Avatar
    Join Date
    Apr 2003
    Location
    Germany
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you can draw inspiration from existing games, like the one you listed.

    In my opinion one has to put alot of thought into such a game, it isn't really easy.

    (Ok, that didn't really answer your question)

  3. #3
    SitePoint Zealot amri's Avatar
    Join Date
    Dec 2002
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx anyway

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another question:

    Could anybody tell me, what languages I should use?

    PHP, SQL - thatīs clear and no Problem.

    But what about the realtime solution?

    I create a car / ship / whatever I need to create in my game, and it takes 30 minutes to finish it.
    I can countdown in HTML and JavaScript, but when does my DB know, that the user has got one more car / ship whatever?

    Should I create a Java Server and manage the backend like that?
    Or how could I do this?

    Thank you

    Bye, Transmitter

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isnīt there anyone, who knows a bit more of it?

  6. #6
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With all due respect, I do not think it is feasible to create games like you described above (highly interactive, multiplayer and timeline based) in PHP/js/html.

  7. #7
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    California
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had been interested in creating a text based game for quite some time.

    Just learn how to use cron jobs and you shouldn't have a problem with "events" that occur at certain times of the day, or every hour, for example.

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aska: What do you think, I should use?
    Iīve looked at some online games, and they are implemented with PHP / MySQL / HTML / JavaScript and one CroneJob per Day to update the ranking list.

    thirteenlisk: But this isnīt a job for Cron, is it?
    Lets say, a user clicks on a "build a ship / car / whatever", what happens next?
    Do you activate your CronJob, wich knows the time, user, building, and so on, and after the building time, the CronJob gets executed?
    Lets say, you have 3000 players online, everyone builds 1 building, 1 car, 1 fighter and researches a technologie .. 4 CronJobs per User, 3000 Users, so you have 12000 CronJobs to be executed the next few hours.
    Is this the way to got?
    I canīt imagine that

  9. #9
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Lithuania
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All those text based online games are driven by turns. Turn is basically executed every hour by some cronjob. This turn involves all kinds of data calculations/database updates. So when your player orders to build a ship/car/whatever you should add his request somewhere and this request will get processed by your turn script. Although, some actions such as sending messages should be real-time based.

  10. #10
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So you have a 'TempTable' where you store the users activities, like build a ship.
    Lets say the user has got 0 ships and one ship takes 10 minutes to create and he told the system to create 2 ships ( = 20 minutes ) ..
    After one hour ( worst case ) my CronJob updates everything from the temp table to the user table, and in the meantime of 40 minutes, the user hasnīt got his ships, although the were ready, 40 minutes ago?

  11. #11
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Transmitter
    Aska: What do you think, I should use?
    Iīve looked at some online games, and they are implemented with PHP / MySQL / HTML / JavaScript and one CroneJob per Day to update the ranking list.
    I really have no idea, thought if I must pick one it'd be C++.

  12. #12
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think you need cron to do what you are talking about, just a great database design. You should focus more on reducing the amount of data that needs to be pulled from the database to build a screen. You can add objects to the game world all you want. The trick is only fetching the objects near to the player, and only re-fetching as necessary. It sounds almost like a tiler.

  13. #13
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arborint
    The trick is only fetching the objects near to the player, and only re-fetching as necessary
    What do you think is the best solution for implementing something, like I said?

    Code:
    // overview.php:
    $user = getUser ( $id );
    $buildings = listBuildings ( $user );
    
    if ( $user->inTempTable ( ) )
    {
      // check actual time and finishTime
      // if ( finishTime < actualTime )
      // update UserTable FROM TempUserTable;
    }
    
    // User klicks on building, e.g. mainhouse, actual level: 3, a klick expands the 
    // mainhouse to level 4 within 2:34 hours
    
    
    // action.php
    $user = getUser ( $id ); // or from session, or what else
    $user->buildMainHouse ( );
    
    $template->showRemainingTime ( );
    
    // user.class.php:
    function buildMainHouse ( )
    {
      insert userID, actualLevel, finishTime into TempUserTable;
    }
    Do you think, thatīs the right way to go?
    With the if ( $user->inTempTable ( ) ) in overview.php I substitute a CronJob, am I right?

  14. #14
    SitePoint Zealot
    Join Date
    Nov 2002
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm working on a game like this right now. One possible solution would be when you build a ship that takes 30 minutes to build, just calculate a timestamp based on current time + 30 minutes and add that to the database record for the ship. Then you can calculate whether the ship is finished building and ready to use or whether it's not done yet.

  15. #15
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a solution, wich doesnīt cost so much DB traffic?

    With every page reload, you have to check many things against the db .. is there another possible solution, or is Java or another backend the only thing you can think of, without stressing the db such often?

  16. #16
    SitePoint Enthusiast feti's Avatar
    Join Date
    Jun 2004
    Location
    Northeastern Ohio
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I were to do an online turn-based game nowadays I would use PHP, and if I needed more backend performance I'd compile shmop into PHP to add memory-based persistence, and if that weren't an option I'd switch to a Java solution such as orionserver or resin.

    First, you should develop a prototype in a scripting language, in this case it would be PHP, but feel free to swap PHP with Ruby or Python at any time. Why a scripting language for a prototype? Ease. You can quickly whip up classes relating to the data you're handling. Who cares about speed at first. You need to get the system down first before you worry about optimizing stuff.

    If you get to a point in your programming where you feel you need some sort of memory-based persistence, make the switch to shmop or Java. But since this is turn-based, directly accessing the database for all persistence should suffice.
    feti
    Mojavi Project - Mojavi 3.0.0-dev available now!

  17. #17
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice to see you here

    But, could use Ruby / Python with your nearly perfect product?

    But Iīll consider shmop, or Java if shmop doesnīt fit to my needs.

    Thank you feti, for your excellent overview and thank you all for your help

  18. #18
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    California
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by simast
    All those text based online games are driven by turns. Turn is basically executed every hour by some cronjob. This turn involves all kinds of data calculations/database updates. So when your player orders to build a ship/car/whatever you should add his request somewhere and this request will get processed by your turn script. Although, some actions such as sending messages should be real-time based.
    That's exactly what I meant.

    PHP/MySQL/JS/HTML with a cron job at certain times of the day is what drives most online text based games today, and should be able to handle pretty much anything you throw at it.

  19. #19
    SitePoint Member
    Join Date
    Nov 2001
    Location
    Melbourne, Australia
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just wondering if anyone would know what sort of minimum specs and cost to run a web-based game server?
    < Axolotl >

  20. #20
    SitePoint Addict launchcode's Avatar
    Join Date
    Dec 2004
    Location
    Bristol, UK
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very little if no-one plays it Seriously though - at the end of the day that is exactly how you will calculate your costs. Number of active players X the resources each player uses in a typical session. All factors depend utterly on the game you've coded of course - only you can answer that question.
    Richard Davey

    Launchcode
    PHP Security Guide. Think your scripts are secure? Think again.

  21. #21
    SitePoint Member Gonavitch's Avatar
    Join Date
    Jun 2004
    Location
    Milwaukee, WI
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I couldn't help not to reply to this question. Some of you are saying use CronJobs, but no! CronJobs are not the way to go. You use JavaScript/HTML as your front-end (build stuff, etc) and PHP/MySQL as your back-end (submit stuff to your db, like who built what).
    I have been practice making PHP/MySQL/JavaScript/HTML games for awhile now.
    Hope that helps .

  22. #22
    SitePoint Zealot auth1's Avatar
    Join Date
    Nov 2004
    Location
    Melbourne, Australia
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php-gaming.org is decent.

  23. #23
    SitePoint Zealot amri's Avatar
    Join Date
    Dec 2002
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the links. This is actually what i'm looking for. I'm surprised that someone reply to my old topic


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •