post

PHP Build a Webgame Tutorial Part 1

Finally the first part has arrived!

Hello guys,

Let me introduce you what we will be doing the first part of this tutorial:

  • Download all the stuff we need.
  • Install it and set up the project.
  • First look at what we are working with.
  • Make a template in our own style with basic HTML & CSS code.
  • Explaining what we have done and what you can do before the next part.

License Agreement by downloading.
——————–
You may not sell this nor making a tutorial with the same code as i do.
You may alter the code and sell a complete php game without having to pay or credit me (only if you want to ;))
This is an open source project please share your modifications with the rest of the readers.
You must have fun scripting!
By downloading the files you agree with these terms.

Live DemoCheck it!

DownloadIts free!

 

Can’t open file? Download the extractor
——————–

Files – What do we need to get started ?

First of all we need something to compile the PHP code on our local machine.
PHP is a server side script that needs to be compiled by the server and then sended to the viewing user in propper HTML.
HTML code is a browser/client script that can be viewed with it need to be compiled by a server first.

For this we dont really need a compiler for the PHP as we won’t be using PHP in now but we will be using it in the next part!

While doing the whole tutorial we will be using a few library’s:

1. CodeIgniter (an Application Development Framework, for clean scripting in MVC)

2. Smarty (a Template Engine for PHP this will be used as the (V)iew in CodeIgniter)

3. jQuery (a JavaScript library for some nice and easy to code effects)

4. And HTML and CSS.


If you like to customize your website other then the tutorial, you should read the documents here to know what you can with it. Also if i forget to explain something they got a full documentation on their sites where you can check it out.

Lets get started!
First we need Xampp go to www.apachefriends.org/en/xampp.html and download the version you need (Windows / Linux etc.) install the program by following the instructions given.

After you have installed it with success you should have a directory like “C:\xampp\htdocs\
this is the directory where you should put your projects in to access them with your browser.
For more information about Xampp please read it on the website.

Now lets go to your directory “C:\xampp\htdocs\” and create a new folder.
Name this foldermygame” (or whatever you like to call it, but do not use spacebar, numbers or uppercase characters)

I created a basic template for you with all the connections and Database we will be using during this tutorial.
Download it and place the files in the folder you just created.

After you have placed this in “C:\xampp\htdocs\{your_folder_name}\” we will need to adjust some config files to get it working propper.

  • Open C:\xampp\htdocs\{your_folder_name}\.htaccess, change line 3 “tutorial” with {your_folder_name}
  • Open C:\xampp\htdocs\{your_folder_name}\application\config\constants.php, change line 40 “tutorial” with {your_folder_name}
  • Open C:\xampp\htdocs\{your_folder_name}\application\config\database.php, change the variables with your database setup, also on line 47 change “tutorial” to the database name you like to use (We will set the database after this).


Now lets go to your database.

Open your browser and go to “http://localhost/phpmyadmin/” this should open the database screen for you.

Create a database with the name you earlier picked in the database.php file.
Go to import and select the database file i created for you. “C:\xampp\htdocs\{your_folder_name}\database\complete.sql

At this point we have done all we need for now.
Lets try to open the website: “http://localhost/{your_folder_name}/” if you did it all right, then you should see: “This will be you template file.” on your screen.

You can grab a cup of coffee now or some food cause you completed the first part,

Lets go further with the real thing now!

Lets go to the template file and start designing our webgame!
Open “c:/xampp/htdocs{your_folder_name}/application/views/template.tpl“.

You will see the next lines in it:

Here we will begin with creating our style.
If you don’t have any knowledge with basic HTML i like to reffer you to my other tutorials i have some basic HTML tutorials there.

Click here for the first HTML tutorial
Click here for the second HTML tutorial
Click here for the third HTML tutorial
Click here for the fourth HTML tutorial

Lets create the frame for the website first, we will need the page to be centered and have a menu at the top and when a player logged in we want a menu at the left aswell.
We will create a page with this setup.

Logo and menu
Menu
if
logged
in
Here all the information will go.
Your copyright etc.

Lets start with writing a wrapper to keep it all together and in the center.

template.tpl

{* Header will be inserted at the very beginning of every page as it will always be the same. *}
{include file='template_header.tpl'}

{* Content will be diffrent and keep every page that is called *}
<div id="wrapper">
  <div id="weblayout">
    <div id="header">Logo and menu</div>
    <div>
      <div id="menu">Menu if logged in</div>
      <div id="content">Here all the information will go.{$content}</div>
    </div>
    <div id="footer">Your copyright etc.</div>
  </div>
</div>
{* Footer will be inserted at the end of every page as it is always the same. *}

{include file='template_footer.tpl'}

What we have done here is created some blocks with text in it, it will look like some simple text rules now if you open your website but we will fix this!
We gave every div an unique name so we can reconize what it will be (aswell as the code will reconize this).

Lets give the website some color!
Open “c:/xampp/htdocs/{your_folder_name}/public/css/default_style.css“.

You will see 4 things in there:

  1. body{}
  2. a{}
  3. a:link{}
  4. a:hover{}

Lets put our just created blocks in it and give them some color  (If you give an element the Tag id=”” you can call them with # in your css file)

default_style.css

body {
  background-color: #000000;
  color: #000000;
  font-family: arial;
  font-size: 12px;
  margin: 0px;
  padding: 0px;
}

a {

}

a:link {

}

a:hover {

}

#wrapper {
  /* we need the full screen so we can center easly in the browser */
  width:100%;
}

#weblayout {
  width: 950px; /* width of our website */
  border: 1px solid #FFFFFF;
  margin: 0px auto;
}

#header{
  height:225px;
  width: 100%;
  background-color: #FF0000;
}

#menu {
  float:left;
  width:225px;
  min-height: 300px;
  background-color: #00FF00;
}

#content {
  float:right;
  width:725px;
  min-height: 300px;
  background-color: #FFFF00;
}

#footer {
  clear: both;
  height:30px;
  width: 100%;
  background-color: #0000FF;
}

If you save our work and try to open you website again you will see a big difference with the last time you visited.
We gave the blocks some style and created the first part of our mockup.
Do you want to know more about css? Try my tutorial or visit w3schools for more information about what you can do with it.

At this point i will stop with part 1, now it is time for you guy’s to play with your website (mockup) create something nice for the game you got on your mind!
The next tutorial we will be creating many things for the website like the menu, the contents, and more! so be sure to check often for updates!

Leave a message or screenshots please, i would like to see how other’s are doing or if you are stuck at a point i could help you out with it.

Good luck and have fun!

License Agreement by downloading.
——————–
You may not sell this nor making a tutorial with the same code as i do.
You may alter the code and sell a complete php game without having to pay or credit me (only if you want to ;))
This is an open source project please share your modifications with the rest of the readers.
You must have fun scripting!
By downloading the files you agree with these terms.

Live DemoCheck it!

DownloadIts free!

 

Can’t open file? Download the extractor
——————–