Follow us on Twitter!
Capitalism is an Island of wealth in a sea of poverty
Thursday, April 24, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 23
Guests Online: 22
Members Online: 1

Registered Members: 82903
Newest Member: Piriformis
Latest Articles
View Thread

HellBound Hackers | General | Games

Author

Creating a Basic Text/Image 2D game


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 13-07-10 05:44
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
cosmicshade.x10hosting.com/images/caveground.gif
cavewall
cosmicshade.x10hosting.com/images/cavewall.gif
player
cosmicshade.x10hosting.com/images/Player.gif

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

cosmicshade.x10hosting.com/images/imagemade.gif
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.
Author

RE: Creating a Basic Text/Image 2D game


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 13-07-10 06:20
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..
Author

RE: Creating a Basic Text/Image 2D game

stealth-
Member



Posts: 1003
Location: Eh?
Joined: 10.04.09
Rank:
Mad User
Posted on 13-07-10 09:34
Hmmm, it may be just me, but I'm not really seeing a question here. You seem to have it figured out.
Code
Map

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.



The irony of man's condition is that the deepest need is to be free of the anxiety of death and annihilation; but it is life itself which awakens it, and so we must shrink from being fully alive.
http://www.stealt. . .

Edited by stealth- on 13-07-10 09:35
http://www.stealth-x.com
Author

RE: Creating a Basic Text/Image 2D game

GTADarkDude
Member



Posts: 142
Location: The Netherlands
Joined: 23.02.08
Rank:
Newbie
Posted on 13-07-10 10:55
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.


...
- - -
Author

RE: Creating a Basic Text/Image 2D game


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 13-07-10 11:09
He said multiplayer mobile game.
Author

RE: Creating a Basic Text/Image 2D game


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 13-07-10 13:22
stealth- wrote:
Hmmm, it may be just me, but I'm not really seeing a question here. You seem to have it figured out.
Code
Map

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

Code
$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?

Edited by on 13-07-10 16:45
Author

RE: Creating a Basic Text/Image 2D game

stealth-
Member



Posts: 1003
Location: Eh?
Joined: 10.04.09
Rank:
Mad User
Posted on 13-07-10 20:24
If you only wanted a few different land types:

Code

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

Code

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

Code

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?


The irony of man's condition is that the deepest need is to be free of the anxiety of death and annihilation; but it is life itself which awakens it, and so we must shrink from being fully alive.
http://www.stealt. . .

Edited by stealth- on 13-07-10 20:28
http://www.stealth-x.com
Author

RE: Creating a Basic Text/Image 2D game


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 13-07-10 21:13
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.

Edited by on 13-07-10 21:26
Author

RE: Creating a Basic Text/Image 2D game

stealth-
Member



Posts: 1003
Location: Eh?
Joined: 10.04.09
Rank:
Mad User
Posted on 13-07-10 21:37
Although I don't see the issue with having a lot of image tags, this is what you'll want:

http://php.net/ma. . .gecopy.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.


The irony of man's condition is that the deepest need is to be free of the anxiety of death and annihilation; but it is life itself which awakens it, and so we must shrink from being fully alive.
http://www.stealt. . .

Edited by stealth- on 13-07-10 21:42
http://www.stealth-x.com
Author

RE: Creating a Basic Text/Image 2D game

GTADarkDude
Member



Posts: 142
Location: The Netherlands
Joined: 23.02.08
Rank:
Newbie
Posted on 13-07-10 21:47
gregorian wrote:
He said multiplayer mobile game.


import javax.bluetooth.* ?


...
- - -
Author

RE: Creating a Basic Text/Image 2D game


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 13-07-10 21:55
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/ma. . .gecopy.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.

Edited by on 14-07-10 00:19
Author

RE: Creating a Basic Text/Image 2D game

stealth-
Member



Posts: 1003
Location: Eh?
Joined: 10.04.09
Rank:
Mad User
Posted on 14-07-10 19:30
Alright, hope you've got a fast server at hand Wink
Good luck with your project.


The irony of man's condition is that the deepest need is to be free of the anxiety of death and annihilation; but it is life itself which awakens it, and so we must shrink from being fully alive.
http://www.stealt. . .
http://www.stealth-x.com
Author

RE: Woot.


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 16-07-10 01:48
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.