Jump to content

Game


Porl123

Recommended Posts

I'm trying to make a little game, which I guess I'll be using PHP/MySQL to make. I know you guys are busy so I'll try and make this as brief and as detailed at the same time as I possibly can :X

I'm trying to make a game based around coordinates. Ideally I'm trying to make it so there's a grid playing field, that would be -99 to 99 both horizontally and vertically, although it only displays the grid 9 by 9 with your character center and middle of the table. I'd need a for() loop to make the 9 by 9 grid and I can position the character, although I'm not sure how you would manage the links. (<a href="?x=$x&y=$y"><img src="square.gif" /></a>) If you have any hints or clues you can give me, or if possible any tutorials based around this area I'd be very appreciative :) thanks people. I wouldn't normally ask for something this broad on here but I've been trying to make this for a while and just need a bump to show I've been going at it the right way

Link to comment
Share on other sites

Hmm.. do you have any code yet?  Having something to work with makes it much easier.

 

And the question of how to show the links depends on your data structure.

 

So let's say you're using a 2 level array like this:

 

ini_set('memory_limit', '64M');

function blank_map() {
  $map = array();
  for ($y = -10; $y <= 10; $y++) {
    $row = array();
    for ($x = -10; $x <= 10; $x++) {
      $row[$x] = array(
        'terrain' => rand(0,1) ? 'grass' : 'sand',
        'objects' => array(),
      );
    }
    $map[$y] = $row;
  }
  return $map;
}

function display_map($map) {
  foreach ($map as $y) {
    foreach ($y as $x) {
      if ($x['terrain'] == 'grass') {
        print "\"";
      } elseif ($x['terrain'] == 'sand') {
        print "-";
      }
    }
    print "\n";
  }
}

$map = blank_map();
display_map($map);

 

I'm limiting it to -10 to 10 for debugging.  For -99 to 99 you will probably need to increase the memory limit.  Is that the kind of thing you're looking for?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.