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
https://forums.phpfreaks.com/topic/126222-game/
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
https://forums.phpfreaks.com/topic/126222-game/#findComment-653526
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.