<?php

require_once "Node.php";

class Element extends Node
{
   public $_name = null;
   public function __construct($name=null, $value=null)
   {
      parent::__construct($value);
      $this->_name = $name;
   }
   public function __get($name)
   {
      $value = $this->search($name);
      if (!$value)
      {
         $value = null;
      }
      return $value;
   }
   public function adopt(
      $new, $name=null, $unique=True, $offset=0, $additional_unique_field="")
   {
      if (!is_object($new))
      {
         $new = new Element($name, $new);
      }
      elseif ($name)
      {
         $new->_name = $name;
      }
      parent::adopt($new, $unique, $offset, $additional_unique_field);
   }
   protected function inspect_token($token, $match_by_class=False)
   {
      if ($match_by_class == True)
      {
         return $this instanceof $token ? $this : null;
      }
      return $token == $this->_name ? $this : null;
   }
   public function convert_to_raw_string()
   {
      $message = "($this->_name";
      $message .= ($this->_value || $this->_next) ? " " : "";
      $message .= (is_object($this->_value)) ?
         $this->_value->convert_to_raw_string() : "";
      $message .= (!is_object($this->_value)) ? "$this->_value)" : ")";
      $message .= ($this->_next) ? $this->_next->convert_to_raw_string() : "";

      return $message;
   }
   public function convert_to_tabbed_string($level=0)
   {
      $string = str_repeat("   ", $level);
      $string .= "$this->_name";
      $string .= (is_object($this->_value)) ? ":\n" : ": $this->_value\n";

      $string .= (is_object($this->_value)) ?
         $this->_value->convert_to_tabbed_string($level+1) : "";
      $string .= ($this->_next) ?
         $this->_next->convert_to_tabbed_string($level) : "";

      return $string;
   }
}
<?php
namespace structures\html;

class Link extends Element
{
   public function __construct($rel=null, $href=null)
   {
      parent::__construct("link", null, null, false);
      $this->add_attribute("rel", $rel);
      $this->add_attribute("href", $href);
   }
}
<?php
namespace structures\html;

class Title extends Element
{
   public function __construct($title)
   {
      parent::__construct("title");
      $this->title = $title;
   }
   protected function build_content()
   {
      return $this->title;
   }
}
<?php
namespace structures\html;

class Tr extends Element
{
   private $cells = array();
   public function __construct($id=null, $class=null)
   {
      parent::__construct("tr", $id, $class);
   }
   protected function build_content()
   {
      $markup = "";
      foreach ($this->cells as $cell)
      {
         $markup .= $cell;
      }
      return $markup;
   }
   public function insert_cell($cell, $id=null, $class=null)
   {
      if (!($cell instanceof Td))
      {
         $cell = new Td($cell, $id, $class);
      }
      $this->cells[] = $cell;
   }
}
<?php
namespace structures\html;

class Div extends Element
{
   public function __construct($content=null, $id=null, $class=null)
   {
      parent::__construct("div", $id, $class);
      $this->content = $content;
   }
   protected function build_content()
   {
      return $this->content;
   }
}
<?php
namespace structures\html;

class Element
{
   private $attributes = array();
   private $style_assignments = array();

   public function __construct($name, $id=null, $class=null, $close=true)
   {
      $this->name = $name;
      $this->add_attribute("id", $id);
      $this->add_attribute("class", $class);
      $this->close = $close;
   }

   protected function add_attribute($name, $value)
   {
      $this->attributes[$name] = $value;
   }

   protected function add_style($name, $value)
   {
      $this->style_assignments[$name] = $value;
   }

   public function get_style($name)
   {
      return $this->style_assignments[$name];
   }

   protected function get_default($value, $name)
   {
      if (!is_null($value))
      {
         return $value;
      }
      if (array_key_exists($name, $GLOBALS))
      {
         return $GLOBALS[$name];
      }
   }

   public function __toString()
   {
      return $this->build_html();
   }

   protected function build_html()
   {
      $markup = $this->build_opening_tag();
      $markup .= $this->build_content();
      if ($this->close === true)
      {
         $markup .= $this->build_closing_tag();
      }
      return $markup;
   }

   private function build_opening_tag()
   {
      $tag = "<" . $this->name;
      $tag .= $this->build_attributes();
      $tag .= ">";
      return $tag;
   }

   protected function build_attributes()
   {
      $attributes = "";
      foreach ($this->attributes as $name => $value)
      {
         if (!is_null($value) && $value !== false)
         {
            $attributes .= " $name";
            if ($value !== true)
            {
               $attributes .= "=\"$value\"";
            }
         }
      }
      $attributes .= $this->build_style_attribute();
      return $attributes;
   }

   private function build_style_attribute()
   {
      $attribute = "";
      $assignments = $this->style_assignments;
      if (!empty($assignments))
      {
         $attribute .= " style=\"";
         foreach ($assignments as $name => $value)
         {
            $attribute .= "$name: $value;";
         }
         $attribute .= "\"";
      }
      return $attribute;
   }

   protected function build_content()
   {
      return null;
   }

   private function build_closing_tag()
   {
      return "</" . $this->name . ">";
   }

   protected function get_attribute($name)
   {
      return $this->attributes[$name];
   }

   protected function break_line()
   {
      return "\n";
   }

   protected function get_relative_path($path)
   {
      $root = dirname($_SERVER["SCRIPT_FILENAME"]) . "/";
      return str_replace($root, "", $path);
   }
}
216.73.216.119
216.73.216.119
216.73.216.119
 
June 29, 2013

A few weeks ago, for Fishing Jam, I made a fishing simulation from what was originally designed to be a time attack arcade game. In the program, Dark Stew, the player controls Aphids, an anthropod who fishes for aquatic creatures living in nine pools of black water.



Fishing means waiting by the pool with the line in. The longer you wait before pulling the line out, the more likely a creature will appear. Aside from walking, it's the only interaction in the game. The creatures are drawings of things you maybe could find underwater in a dream.

The background music is a mix of clips from licensed to share songs on the Free Music Archive. Particularly, Seed64 is an album I used a lot of songs from. The full list of music credits is in the game's README file.

I'm still planning to use the original design in a future version. There would be a reaction-based mini game for catching fish, and the goal would be to catch as many fish as possible within the time limit. I also want to add details and obstacles to the background, which is now a little boring, being a plain, tiled, white floor.

If you want to look at all the drawings or hear the music in the context of the program, there are Windows and source versions available. The source should work on any system with Python and Pygame. If it doesn't, bug reports are much appreciated. Comments are also welcome :)

Dark Stew: Windows, Pygame Source

I wrote in my last post that I would be working on an old prototype about searching a cloud for organisms for Fishing Jam. I decided to wait a while before developing that game, tentatively titled Xenographic Barrier. Its main interactive element is a first-person scope/flashlight, so I'd like to make a Wii version of it.

I'm about to start working on a complete version of Ball & Cup. If I make anything interesting for it, I'll post something. There are a lot of other things I want to write about, like game analyses, my new GP2X and arcades in Korea, and there's still music to release. Lots of fun stuff coming!