All pastes #616768 Raw Edit

Something

public text v1 · immutable
·published 2007-07-12 20:54 UTC
rendered paste body
<?php

// An example of Object Oriented Programming
// for a browser-based MMORPG
// (C) 2007 by Peter M. Flor for Sophisteria, All Rights Reserved
// 2007-07-12

abstract class Sprite
{
	protected $visible;
	
	function __construct($visibility) {
		$this->visible = $visibility;
	}
	
	function __destruct() {
	}
	
	public function SetVisibility($param) {
		$this->visible = $param;
	}
	
	public function IsVisible() {
		return $this->visible;
	}
	
	abstract public function DrawSprite();
}

class Sprite2D extends Sprite
{
	protected $width, $height;
	protected $locx, $locy;
	
	function __construct($width, $height, $x, $y, $visible) {
		parent::__construct($visible);
		$this->width = $width;
		$this->height = $height;
		$this->locx = $x;
		$this->locy = $y;
	}
	
	function __destruct() {
	}
	
	public function SetWidth($width) {
		$this->width = $width;
	}
	
	public function GetWidth() {
		return $this->width;
	}
	
	public function SetHeight($height) {
		$this->height = $height;
	}
	
	public function GetHeight() {
		return $this->height;
	}
	
	public function SetXCoord($x) {
		$this->locx = $x;
	}
	
	public function GetXCoord() {
		return $this->locx;
	}
	
	public function SetYCoord($y) {
		$this->locy = $y;
	}
	
	public function GetYCoord() {
		return $this->locy;
	}
	
	public function DrawSprite() {}
}

class Sprite2DHTML extends Sprite2D
{
	protected $htmlid;
	
	function __construct($width, $height, $x, $y, $visible, $htmlid) {
		parent::__construct($width, $height, $x, $y, $visible);
		$this->htmlid = $htmlid;
	}
	
	function __destruct() {
	}
	
	public function DrawSprite() {
		echo	"<div id=\"{$this->htmlid}\" " .
				"style=\"position:absolute;width:{$this->width}px;height:{$this->height}px;" .
				"top:{$this->locx};left:{$this->locy};" .
				(($this->IsVisible()) ? "" : "display:none;") .
				"\">&nbsp;</div>";
	}
}

class Sprite2DImageHTML extends Sprite2DHTML
{
	private $imageurl;
	
	function __construct($width, $height, $x, $y, $visible, $htmlid, $imageurl) {
		parent::__construct($width, $height, $x, $y, $visible, $htmlid);
		$this->imageurl = $imageurl;
	}
	
	function __destruct() {
	}
	
	public function DrawSprite() {
		echo	"<div id=\"{$this->htmlid}\" " .
				"style=\"position:absolute;width:{$this->width}px;height:{$this->height}px;" .
				"top:{$this->locx};left:{$this->locy};background-image:url('{$this->imageurl}');" .
				(($this->IsVisible()) ? "" : "display:none;") .
				"\">&nbsp;</div>";
	}
}

// Implementation

$test = new Sprite2DImageHTML(100, 100, 100, 100, true, "test", "/images/chocobo_tales.gif");
$test->DrawSprite();

?>