Coordinates, Coordinates, Coordinates

Took me quite a while to write this block of code:

(Note: You will want to compare this chuck of code with the screenshot of yesterday’s source code – otherwise it wouldn’t make sense.)

do
{
   if (abs($id - $center) < = $r['sight']) {
      $ccx = $coordx + ($id - $center);
      $ccy = $coordy;
   }
   else 
   {
	$rowadj = ($id-$center)/$sight;
	$rowadj = round ($rowadj);
	$ccy = $coordy - $rowadj;
	$newid = $id - ($rowadj*$sight);
	$ccx = $coordx + ($newid - $center);
   }
   $cellcoord = $ccx.','.$ccy;
   $content[$id] = $id.'
('.$cellcoord.')'; .....

And the end result? Now we know the coordinates of each individual cell that is displayed on screen. This means that I can soon add in events as the character traverse the “world”.

Not the cleanest code, but it will serve its purpose for now. Awesome stuff. (:

The beginnings

I finally worked out how to display a table with individual cell IDs representing the coordinates for my current project (It’s called Kingdom of Might – cliché, but then again it’s just a project name for now). And now it is just a simple matter of displaying the content in each individual cell using an array like $content[$id]. Took a while to figure out the math and the centre cell positioning, but now I got it worked out.

(There will be a sight attribute to the game, which decides how many grids you can actually see.)

Stage 1: Labeling each individual cell with an ID. Note that the first cell is blank due to it having a value of 0.

Stage 2: Determining the ID of the center cell.

I use this formula: c = [s(1+2s)] + s
where c is the centre cell id and s is the sight attribute from the database

Stage 3: Putting everything together.

And the code that made it work:

When I am bored

I was feeling a little bored and so I challenged myself to fix get Project Extension running (in some functional sense at least), and I surprised myself at how quickly I managed to patch together some hacks to get it online again.

As you can see, it is not fully functional – the character stats for some reason don’t show – nor do I have the intention to fix it (at this point in time). However, what I really wanted to do was actually to look for some form of inspiration for a new project, something more complex than an online authentication system or a contact form. What I have come up with is a coordinates based online RPG. Even though I realized that this genre has sort of been done to death, the intent of this project is nothing more than a practical exercise in planning and coding an interactive site.

To be updated. (:

Advanced Login System – Available for download

I have finally found sometime to update the code for Advanced Login System, bringing the version build up to 20091220. I have also removed the password salt (since I figured they don’t really do much), so there is only 1 standard version and you should be able to upgrade from any previous version of ALS starting from v0.02B.

You can download it here.

As usual, source code is encoded but available for purchase at USD$20. Contact me for more information or to report bugs in the script.

UPDATE: An updated version is available for download here.

Modular Development

I am really glad I used modular development for ALS now. It makes it so easy to reuse code from ALS in my Integrated Contact Form. I am currently using the update module (by the way, I just realized the fgetcsv() function requires a length parameter in PHP 4 (optional in PHP 5) – eg. fgetcsv ($fp,256). Refer to here for more details. ) and I do have plans to reuse my CAPTCHA module as well. I should really adopt modular programming as the basis of all my future scripts and projects.

I realized I do make lots of careless mistakes in my coding sometimes. For example – in my CAPTCHA module, I defined the file as a gif in the headers, but I used imagepng() to generate the actual image, so I suppose it’s a png file in a gif container (though I am not perfectly sure).

Anyway, I was basically cleaning up the ICF code in the past few days. It’s really a mess after not having touched it for 2 years (the latest build was 20071011 – meaning it was realized on the 11th Oct 2007). Keep you guys updated.

UPDATE
A quick peek at one of the themes. Sadly, I have to remove support for ALS themes and singular stylesheets (meaning you have to create a theme in order to customize the look) – but the whole thing is a lot more flexible now.
Integrated Contact Form Black Theme