Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

Creating a Basic Text/Image 2D game


ghost's Avatar
0 0

I have a question, where would be the best place to start to create a game for mobile users. This will be a multiplayer mobile game. How you would move on the map, would be from a link going north east south or west. The game will be browser based and require a reload to move the character over one space. The setup for this game would be something like this…

72x72Image

HP:XX Mana: XX

North East South West

This is where things start to puzzle me though, How would I create a map that they could move up and down on. Mobile phones are very very limited so the image would be 72x72. I have an idea of one thing. I create a whole bunch of small 8x8 images. Such as player(your character moving in game.) the ground, mountains etc. In the end it really wouldnt be that many pictures. Now how would I be able to combine them/duplicate them as needed to create a small map. When I say 72x72 pixel image, thats just the piece of the map at the time that I want to display. In reality the map would be bigger. Here is an example of what I mean.

ground

cavewall

player

turn them 3 small 8x8 images into something like this.

MMMMMMMMM MMMMMMMMM M–––– M–––– M—P–– M–––– M–––– M–––– M–––– HP: xx Mana: xx

north east south west

aka

HP: xx Mana: xx

north east south west

Things you need to consider are that this game should be playable from ANY phone. That includes old ones. This is the reason why I think I should go along the lines of something text based, then have something convert the text into image. So that way an option to have image or text would easily be able to be implemented. Any ideas? Thanks in advance.


ghost's Avatar
0 0

Why don't you pick any one of the several books on Java Game Development for the mobile platform? You can download netbeans and see their examples..


stealth-'s Avatar
Ninja Extreme
0 0

Hmmm, it may be just me, but I'm not really seeing a question here. You seem to have it figured out.


HP: xx
Mana: xx

north
east
south
west```
Assuming north, east, south, and west are button commands will appear on the users screen, just link them to actions in a php script.

Ex: <a href="move.php?direction=north">north</a> 

Then have the php script recalculate the new conditions and return the page with the map moved accordingly.

GTADarkDude's Avatar
Member
0 0

Why do you want to make the game browser based, if I may ask? Not everybody has a fancy phone bundle with unlimited internet you know. Using the internet for such a game can be quite expensive for a lot of users. I suggest learning Java (ME), which is supported by the big majority of mobile phones.


ghost's Avatar
0 0

He said multiplayer mobile game.


ghost's Avatar
0 0

stealth- wrote: Hmmm, it may be just me, but I'm not really seeing a question here. You seem to have it figured out.


HP: xx
Mana: xx

north
east
south
west```
Assuming north, east, south, and west are button commands will appear on the users screen, just link them to actions in a php script.

Ex: <a href="move.php?direction=north">north</a> 

Then have the php script recalculate the new conditions and return the page with the map moved accordingly.


I have it somewhat figured out tbh. What I have done so far is in php I have created a database. Created a table name world with 5 columns. X, Y, Z, Image, Type. They have a text image such as... X: 5, Y: 5, Z: 0, Image: t, Type: tree or whatever. Then have a table of locations. Have 4 columns (more if necessary.) with X, Y, Z, Player. This is where things start to confuse me though.

To display what I wanted of the map I could do something like this...

```markup$sql = mysql_fetch_array(mysql_query("SELECT * FROM Location WHERE Player='Example'"));

for ($y = ($sql['Y']-4);$y<=($sql['Y'] + 4);$y++)
  {
  for($x = ($sql['X'] - 4);$x<=($sql['X'] + 4);$x++)
    {
    $img = mysql_fetch_array(mysql_query("SELECT * FROM world WHERE X='" . $x . "' AND Y='" . $y . "'"));

    if (($img['X'] == $sql['X']) && ($img['Y'] == $sql['Y']))
      {
      echo str_replace($img['Image'], "P", $img['Image']);
      } else {
      echo $img['Image'];
      }
    }
    echo "<br/>";
  }```

what confuses me though How would I do this to replace the string with image instead?

stealth-'s Avatar
Ninja Extreme
0 0

If you only wanted a few different land types:

$sql = mysql_fetch_array(mysql_query("SELECT * FROM Location WHERE Player='Example'"));

for ($y = ($sql['Y']-4);$y<=($sql['Y'] + 4);$y++)
  {
  for($x = ($sql['X'] - 4);$x<=($sql['X'] + 4);$x++)
    {
    $img = mysql_fetch_array(mysql_query("SELECT * FROM world WHERE X='" . $x . "' AND Y='" . $y . "'"));

    if (($img['X'] == $sql['X']) && ($img['Y'] == $sql['Y']))
      {
      echo '<img src="images/player.jpg" />';
      } else {
      if ($img['Image'] == 't')
         echo '<img src="images/tree.jpg" />';
      elseif ($img['Image'] == 'm')
         echo '<img src="images/mountain.jpg" />';
      elseif ($img['Image'] == '.')
         echo '<img src="images/ground.jpg" />';
      else
         echo '?';
      }
    }
    echo "<br/>";
  }

If you wanted more than a few land type, you could save writting code and do this:

$sql = mysql_fetch_array(mysql_query("SELECT * FROM Location WHERE Player='Example'"));

for ($y = ($sql['Y']-4);$y<=($sql['Y'] + 4);$y++)
  {
  for($x = ($sql['X'] - 4);$x<=($sql['X'] + 4);$x++)
    {
    $img = mysql_fetch_array(mysql_query("SELECT * FROM world WHERE X='" . $x . "' AND Y='" . $y . "'"));

    if (($img['X'] == $sql['X']) && ($img['Y'] == $sql['Y']))
      {
      echo '<img src="images/p.jpg" />';
      } else {
      if ($img['Image'] != '.')
        echo '<img src="images/' . $img['Image'] . '.jpg" />';
      else
        echo '<img src="images/g.jpg" />';
      }
    }
    echo "<br/>";
  }

And then just create images inside your images/ directory that match the land types. Eg: images/p.jpg images/t.jpg images/m.jpg

Now keeping them in a grid is a different matter:

echo '<table>';
$sql = mysql_fetch_array(mysql_query("SELECT * FROM Location WHERE Player='Example'"));

for ($y = ($sql['Y']-4);$y<=($sql['Y'] + 4);$y++)
  {
  echo '<tr>';
  for($x = ($sql['X'] - 4);$x<=($sql['X'] + 4);$x++)
    {
    $img = mysql_fetch_array(mysql_query("SELECT * FROM world WHERE X='" . $x . "' AND Y='" . $y . "'"));
    echo '<td>';
    if (($img['X'] == $sql['X']) && ($img['Y'] == $sql['Y']))
      {
      echo '<img src="images/p.jpg" />';
      } else {
      if ($img['Image'] != '.')
        echo '<img src="images/' . $img['Image'] . '.jpg" />';
      else
        echo '<img src="images/g.jpg" />';
      }
    echo '</td>';
    }
  echo '</tr>';
  }
echo '</table>';

Contrary to popular thinking, tables are not actually deprecated, they're just not recommended for developing an entire website with anymore. So no worry there.

I think this should do what you want. It's a little early in the morning here, so somebody stop me if all I did was cause more trouble than help ;)

Edit: Looking over it again quickly, I realize this will probably require some restructuring somewhere, because the X/Y doesn't match the way I wrote the html table. The code is just an outline to show you a method of doing it.

And, btw, are you sure you want to make that many database calls?


ghost's Avatar
0 0

stealth- wrote: And, btw, are you sure you want to make that many database calls?

I really don't know the limits to PHP/MySQL. If there was a place I could read about it would be nice. So I have a better understanding of it.

About your example. It requires excessive img tags. I was wondering if there would be a way to combine the images with PHP. In this game, I don't expect the users to be able to move but 1 space every 2-5seconds. Unless they are on a 3G network of course.

EDIT Instead of making multiple connections to the database like I am, would it be smarter instead of breaking up the map piece, just to do it the hard way and make 100s, mabe even thousands, of images and insert them in the database with base64_encoding. Then just call upon whatever Image the location is tied to.


stealth-'s Avatar
Ninja Extreme
0 0

Although I don't see the issue with having a lot of image tags, this is what you'll want:

http://php.net/manual/en/function.imagecopy.php

There are are plethora of docs on the internet about mysql and php. I don't really know that much about mysql limitations my self, it's just 17 queries for every request seems a little excessive. It shouldn't be too much of an issue as long as the userbase is fairly low and you don't mind taking up a bit of resources.

Edit: I had originally missed your edit. As I said, I don't know a whole lot about mysql optimization, so perhaps someone a bit more familiar could help you out here. Although, that doesn't sound more effective, to me, because the database still has that (possibly) massive amount of entries to sort through.


GTADarkDude's Avatar
Member
0 0

gregorian wrote: He said multiplayer mobile game.

import javax.bluetooth.* ?


ghost's Avatar
0 0

stealth- wrote: Although I don't see the issue with having a lot of image tags, this is what you'll want:

http://php.net/manual/en/function.imagecopy.php

There are are plethora of docs on the internet about mysql and php. I don't really know that much about mysql limitations my self, it's just 17 queries for every request seems a little excessive. It shouldn't be too much of an issue as long as the userbase is fairly low and you don't mind taking up a bit of resources.

Edit: I had originally missed your edit. As I said, I don't know a whole lot about mysql optimization, so perhaps someone a bit more familiar could help you out here. Although, that doesn't sound more effective, to me, because the database still has that (possibly) massive amount of entries to sort through.

When I originally posted I wasn't thinking right. I have to break it down like I do. That is how I will have to base the whole game. Adding monsters and etc. It may seem like it's a lot, but there is a 500 users maximum allowed on at a time to prevent heavy resources being used. I don't expect to ever even have that many people online at once anyways. Only 100-300. It doesn't put to much stress on the server, at least none that I have noticed anyways. Things have been fairly quick.


stealth-'s Avatar
Ninja Extreme
0 0

Alright, hope you've got a fast server at hand ;) Good luck with your project.


ghost's Avatar
0 0

I have found my answer. I knew of the php GD functions, but I didn't know much about how to use them. With days of searching/studying, I have finally made what I want to do a reality. Thanks so much to everyone thats made suggestions and helped out.