<?php

require_once "operations/file/find_file.php";

class Labeled_Segmented_Image extends Segmented_Image
{
   private $_labels;
   private $_font_name;
   private $_font_weight;
   private $_text_color;
   private $_font_size;
   private $_text_background;
   private $_text_horizontal_padding;
   private $_text_vertical_padding;
   private $_text_stroke_width;
   private $_text_stroke_color;
   private $_label_alignment;
   private $_labeled_segments_directory_path;

   public function __construct(
      $file_path, $labels, $width=null, $height=null, $cut_orientation=null,
      $text_color=null, $font_size=null, $font_name=null, $label_alignment=null,
      $segment_count=null)
   {
      $this->_labels = $labels;
      $this->_label_alignment = $label_alignment;
      $this->construct_parent(
         $file_path, $segment_count, $cut_orientation, $width, $height);
      $this->build_labeled_segments_directory();
      $this->draw_labels();
   }

   private function construct_parent(
      $file_path, $segment_count, $cut_orientation, $width, $height)
   {
      $segment_count = $this->determine_segment_count($segment_count);
      parent::__construct(
         $file_path, $segment_count, $cut_orientation, $width, $height);
   }


   private function determine_segment_count($segment_count)
   {
      if ($segment_count === null)
      {
         $segment_count = sizeof($this->_labels);
      }
      return $segment_count;
   }

   private function build_labeled_segments_directory()
   {
      $path = $this->_segments_directory_path . "/";
      $path .= $GLOBALS["LABELED_SEGMENTS_DIRECTORY_NAME"];
      if (!is_dir($path))
      {
         mkdir($path);
      }
      $this->_labeled_segments_directory_path = $path;
   }

   private function draw_labels()
   {
      $ii = 0;
      foreach ($this->_labels as $label)
      {
         $this->add_label_to_segment($label, $ii++);
      }
   }

   private function add_label_to_segment($label, $segment_index)
   {
      if ($label instanceof Entity)
      {
         $this->add_entity_to_segment($label, $segment_index);
      }
      else
      {
         $this->add_annotation_to_segment($label, $segment_index);
      }
   }

   private function add_entity_to_segment($entity, $segment_index)
   {
      $segment = $this->segments[$segment_index];
      $entity = $this->build_replacement_entity($entity, $segment);
      $this->segments[$segment_index] = $entity;
   }

   private function build_replacement_entity($label, $segment)
   {
      $file_path = $segment->path;
      $entity = new Div($segment->width, $segment->height);
      $entity->background = $file_path;
      $entity->content = $label;
      $entity->overflow = "hidden";
      if ($this->_cut_orientation == "vertical")
      {
         $entity->float = "left";
      }
      $label->line_height = $segment->height . "px";
      return $entity;
   }

   private function add_annotation_to_segment($text, $index)
   {
      $segment = $this->segments[$index];
      $annotation = $this->build_label($text);
      $labeled_segment_image = new Imagick($segment->path);
      $this->draw_annotation($labeled_segment_image, $annotation);
      $this->save_labeled_segment_image($labeled_segment_image, $index);
   }

   private function build_label($text)
   {
      $label = new Label(
         $text, null, $this->_font_size, $this->_font_weight,
         $this->_text_color, $this->_font_name, $this->_text_background,
         $this->_text_horizontal_padding, $this->_text_vertical_padding,
         $this->_stroke_width, $this->_stroke_color);
      return $label->_image;
   }

   private function draw_annotation($image, $annotation)
   {
      $x = $this->determine_annotation_horizontal_offset($image, $annotation);
      $y = $this->determine_annotation_vertical_offset($image, $annotation);
      $image->compositeImage($annotation, Imagick::COMPOSITE_DEFAULT, $x, $y);
   }

   private function determine_annotation_horizontal_offset($image, $annotation)
   {
      $offset = 0;
      $image_width = $image->getImageWidth();
      $annotation_width = $annotation->getImageWidth();
      if ($this->_label_alignment == "center")
      {
         $offset = $image_width/2 - $annotation_width/2;
      }
      elseif ($this->_label_alignment == "right")
      {
         $offset = $image_width - $annotation_width;
      }
      return $offset;
   }

   private function determine_annotation_vertical_offset($image, $annotation)
   {
      $offset = $image->getImageHeight()/2 - $annotation->getImageHeight()/2;
      return $offset;
   }

   private function save_labeled_segment_image($image, $index)
   {
      $path = $this->build_labeled_segment_path($index);
      $image->writeImage($path);
      $this->segments[$index]->path = $path;
   }

   private function build_labeled_segment_path($index)
   {
      return $this->_labeled_segments_directory_path . "/" . $index;
   }
}
<?php

define("LABEL_CONSTANT_PREFIX", "LABEL_");
define("LABEL_FONT_CONSTANT_SUFFIX", "_FONT");
define("LABEL_SIZE_CONSTANT_SUFFIX", "_SIZE");

class Navigation_Map extends Div
{
   private $labels = array();

   public function __construct()
   {
      parent::__construct();
      $this->import_labels();
      $this->segmented_image = new Labeled_Segmented_Image(
         "src/img/jimjilbbang.jpg", $this->labels, 400, 500, "horizontal");
      $this->width = 400;
      $this->text_align = "left";
      $this->margin = "20 auto";
   }

   private function import_labels()
   {
      for ($ii = 1; isset($GLOBALS[LABEL_CONSTANT_PREFIX . $ii]); $ii++)
      {
         $this->include_label($ii);
      }
   }

   private function include_label($ii)
   {
      $label_constant_name = LABEL_CONSTANT_PREFIX . $ii;
      $font_constant_name = $label_constant_name . LABEL_FONT_CONSTANT_SUFFIX;
      $size_constant_name = $label_constant_name . LABEL_SIZE_CONSTANT_SUFFIX;
      $text = $GLOBALS[$label_constant_name];
      $font = $this->get_constant_value($font_constant_name);
      $size = $this->get_constant_value($size_constant_name);
      $statement = new Statement($text, $size, "bold", null, "black", "white", $font);
      $statement->padding = 3;
/*       $statement = $text; */
      $this->labels[] = $statement;
   }

   private function get_constant_value($constant_name)
   {
      if (isset($GLOBALS[$constant_name]))
      {
         return $GLOBALS[$constant_name];
      }
      return null;
   }
}
98.80.143.34
98.80.143.34
98.80.143.34
 
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!