Author Topic: Need help starting on a browser-based game  (Read 2545 times)

ShieldHeart

  • Regular Member
  • **
  • Posts: 38
  • Karma: 0
    • View Profile
Re: Need help starting on a browser-based game
« Reply #30 on: May 08, 2012, 02:14:05 PM »
I appreciate your interest in this projects Gears, I would love to have a paid team to develop and maintain this site. Unfortunately I'm still a student, barely have enough money for my self haha. I'm mostly doing this as a hobby, maybe one day if the site gets enough traffic and generates actual income I may hire some people to manage the site, but that's a long time from now. Though your thoughts and suggestions on the project are always welcome :)

As for my previous problem Ernie, my png files are 50x50 pixels, and I checked my CSS multiple times, so I'm not sure why it's creating vertical spaces between the rows. I'm actually considering changing the way I draw the map, I've been looking into PHP's graphics functions from this site:

http://www.ibm.com/developerworks/library/os-objorient/

So I'm trying to look for other possible ways of doing this. Let me know if there are other good sites you know of that might help me learn about PHP's graphics options.

Right now I'm experimenting with ways on drawing the world map. I think PHP's graphics functions will come in handy for this. The world map will show the entire 1000x1000 map in a very compressed form. 1 tile will be the equivalent of 1 pixel on the screen. So my new task is to draw this map on a 1000x1000 pixel grid in the most efficient way possible. My biggest worry is that I use up so much resources and the map takes forever to load. Though I've seen similar games generate much bigger maps at lightning speeds, so I guess there is a perfectly efficient way of doing this. Let me know if you guys have any ideas about how this should be done. And as always, thanks in advance.

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1864
  • Karma: 32
    • View Profile
Re: Need help starting on a browser-based game
« Reply #31 on: May 08, 2012, 02:29:40 PM »
Well, maybe I wasn't clear.  You are using a HTML 'IMG" tag to display.  Just add width and height into it and adjust as needed.  The actual size of your PNG's do not matter if you are using HTML.  You can set the size there and the image will be resized to fit it.  Then, you can see what your background looks like.  Try something like this just for testing:

PHP Code: [Select]

echo '<img src="Images/Forest1.png" width=50 height=50 alt="Block" />';

  (You can raise the amount to 51 or 52 to fill in the gaps.)

   The problem is that this is is 81 squares, with no rows and cols going by your display you posted.
Therefore, there must be a setting where you set the the width and height of the DIV.  this is most likely
your error area.  You set it 10x9 instead of 9x9 or whatever.  And, the CSS and display IMG's are trying
to center all the cells.  So, there are a lot of possible areas for errors.
  So, post the CSS code and the display area of the code if the above does not work so we can review it.

Good luck!

ShieldHeart

  • Regular Member
  • **
  • Posts: 38
  • Karma: 0
    • View Profile
Re: Need help starting on a browser-based game
« Reply #32 on: May 08, 2012, 03:20:25 PM »
I tried your code and fiddled around with the height and width settings as well but still no luck. If it helps the DIV with the class of "map" which holds the images is 450x450 pixels, which should fit the 9x9 of 50x50 pixel images in perfectly. Here is the CSS of the DIV:

PHP Code: [Select]
#content {
	
floatright;
	
width550px;
	
padding-right50px;
	

}

.
map {
	
height450px;
	
width450px;
	
margin-top50px;
	
margin-left50px;
	
positionabsolute;
	
text-alignleft;
}


and again the PHP code that generates the map:

PHP Code: [Select]

<div id="content">            
   <
div class="map">
      <?
php 
         
for ($x=1$x<=81$x++) {
	
    echo 
'<img src="Images/Forest1.png" width=50 height=50 alt="Block" />';
	
}
       
?>
    </div>
</div>


Let me know if you see anything that might be causing a problem. The only solution I can think of is creating a different DIV for each row of map and making sure there is no space or padding between those DIVs.

Gears

  • Regular Member
  • **
  • Posts: 55
  • Karma: 3
  • Freelance PHP Programmer
    • View Profile
Re: Need help starting on a browser-based game
« Reply #33 on: May 08, 2012, 04:18:12 PM »
Quote
I appreciate your interest in this projects Gears, I would love to have a paid team to develop and maintain this site.

I am willing to help free of charge, as I love working on php back-ended games.

also I can not remember where in the topic you said it but I could help you with the gen of the map, its a lot easier then you would think, well using mysql/sqlite it's as easy as pie, and I can also show you how to make the gen of the make lightning fast.

I know quite a lot on how to use php (not all functions but human ingenuity comes into play ^.^ ) and if we can talk in a more instant fashion with accesses to the source and you tell me what needs to be done we can work together/ compare code and see how things end up.

I don't have any work to be done this month as I can't find any good php projects to work on so I got free time and my brains always aching to code.

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1864
  • Karma: 32
    • View Profile
Re: Need help starting on a browser-based game
« Reply #34 on: May 08, 2012, 04:40:49 PM »
ShieldHeart,
   I just wrote 3 paragraphs explaining things to test, then, I remembered something and researched it.
I found a note that said two things can cause the white-space between cells.  First, if you set a size for
the DIV, CSS will attempt to fill it with the smallest area used if you use "float: left;" for the CSS.  You
should remove the HTML width/height I had you try.  CSS will over-ride that anyways.  You are using
absolute positioning and they said to use floating, left positioning.
   Another note said to use "white-space: nowrap;" for the CSS.  One other issue is parent/child CSS
issues.  If you declare something above the current version and do not over-ride it, that might be
telling the CSS to put in spacing or padding.  So, if the parent DIV has padding of 5px, and you do not
set current padding to 0px, then it would add the 5px in.  So, I think, try these two and let us know.
Ernie

ShieldHeart

  • Regular Member
  • **
  • Posts: 38
  • Karma: 0
    • View Profile
Re: Need help starting on a browser-based game
« Reply #35 on: May 08, 2012, 05:47:50 PM »
Fixed! :D Looks much better:

http://i1063.photobucket.com/albums/t508/ShieldHeart123/Solved.png

Turns out it was the font-size style. Who knows why that was affecting it but setting the font-size to 0px in my map class solved the problem. Thanks again Ernie.

Oh and Gears, I'll send you a private message later tonight, I would definitely appreciate the help. I've been wondering what the most efficient way of generating the maps would be for a while now, if you could show me a few tricks about that it would be great! 

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1864
  • Karma: 32
    • View Profile
Re: Need help starting on a browser-based game
« Reply #36 on: May 08, 2012, 06:25:09 PM »
Great!   Glad to hear it...  It's always something simple!  As always this post will stay open...

Oh, your map page looks great!

Gears

  • Regular Member
  • **
  • Posts: 55
  • Karma: 3
  • Freelance PHP Programmer
    • View Profile
Re: Need help starting on a browser-based game
« Reply #37 on: May 08, 2012, 06:32:00 PM »
Quote
Oh and Gears, I'll send you a private message later tonight, I would definitely appreciate the help. I've been wondering what the most efficient way of generating the maps would be for a while now, if you could show me a few tricks about that it would be great!

oky dokie, if you got YIM or MSN I would love to chat and help u then, it's easier when u can try something then ask them right away if it works/ is what they were thinking.

skype would be a + as then you could see my screen and make working even faster.

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1864
  • Karma: 32
    • View Profile
Re: Need help starting on a browser-based game
« Reply #38 on: May 08, 2012, 06:36:57 PM »
Actually, I was planning on putting Skype on this system soon.  I have another person on this site that needs that type of help.  When I do, I will let you know.  I am just too busy today..  perhaps tomorrow!

Gears

  • Regular Member
  • **
  • Posts: 55
  • Karma: 3
  • Freelance PHP Programmer
    • View Profile
Re: Need help starting on a browser-based game
« Reply #39 on: May 08, 2012, 06:38:55 PM »
Actually, I was planning on putting Skype on this system soon.  I have another person on this site that needs that type of help.  When I do, I will let you know.  I am just too busy today..  perhaps tomorrow!

Yet you can reply to this board pretty quickly, hmmmm...  :D

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1864
  • Karma: 32
    • View Profile
Re: Need help starting on a browser-based game
« Reply #40 on: May 08, 2012, 06:44:47 PM »
Well, only because I am sitting here typing to another member, LOL...   Will get Skype up soon...

Gears

  • Regular Member
  • **
  • Posts: 55
  • Karma: 3
  • Freelance PHP Programmer
    • View Profile
Re: Need help starting on a browser-based game
« Reply #41 on: May 09, 2012, 12:23:47 PM »
I have a lot of free time today, so if you want just throw me a skype/YIM/MSN contact add and I can start helping with stuff ^.^

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1864
  • Karma: 32
    • View Profile
Re: Need help starting on a browser-based game
« Reply #42 on: May 09, 2012, 12:33:28 PM »
Well Gears, ShieldHeart is the boss... It's his game, I am just helping too, like you.

If you have any ideas for him, post away and I am sure he will respond when he is free.

Look at his last post, there is a link to a picture of his current game page.  You can look at it and then let him/us know what you think would improve it.    I am sure any good idea will help!

Gears

  • Regular Member
  • **
  • Posts: 55
  • Karma: 3
  • Freelance PHP Programmer
    • View Profile
Re: Need help starting on a browser-based game
« Reply #43 on: May 09, 2012, 01:06:27 PM »
@ErnieAlex
 Not sure if you can or a mod needs to but the topic "Old script trying to make current" needs to be marked as solved.
________________-----

well after some time what you would do in the map data in the database is

auto_id, x, y, other values.....

and run through it like

PHP Code: [Select]
$stop 1;
while (
$stop != 1000){
echo 
"<img src'./img/forest-pixel.png' alt='forest' />";
$stop++;
}

//use CSS to format is all into a grid.
//OR
//set it into a grid by php like...

$stop 1;
$row 1;
while (
$stop != 1000){
if(
$row 100){
echo 
"<img src'./img/forest-pixel.png' alt='forest' /><br>";
$row0;
}
$row++;
$stop++;
}


this can be expanded by adding more ifs for the type of pixel needed but the basic idea is their. Next post will show you how to save system resource and from having to call the database again on each call of the map.
« Last Edit: May 09, 2012, 01:27:23 PM by Gears »

Gears

  • Regular Member
  • **
  • Posts: 55
  • Karma: 3
  • Freelance PHP Programmer
    • View Profile
Re: Need help starting on a browser-based game
« Reply #44 on: May 09, 2012, 01:18:28 PM »
here is how to make is fast

PHP Code: [Select]
<?php session_start();

if(!isset(
$_SESSION['time_now'])){
$_SESSION['time_now'] = time() + (60 60);
} else {
$time_check time();
if(
$time_check $_SESSION['time_now']){
$stop 1;
$row 1;
unset(
$_SESSION['map']);
$_SESSION['map'] = array();
while (
$stop != 1000){
if(
$row 100){
$data =  "<img src'./img/forest-pixel.png' alt='forest' /><br>";
} else {
$data "<img src'./img/forest-pixel.png' alt='forest' />";
}
echo 
$data;
$_SESSION['map'][] = $data;
$row0;
}
$row++;
$stop++;
}
} else {
foreach (
$pos as $_SESSION['map']){
echo 
$pos;
}
}


}
?>


tada!
« Last Edit: May 09, 2012, 01:26:24 PM by Gears »