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

   if (abs($id - $center) < = $r['sight']) {
      $ccx = $coordx + ($id - $center);
      $ccy = $coordy;
	$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. (: