summaryrefslogtreecommitdiffstats
path: root/src/Gameboy/DrawContext.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Gameboy/DrawContext.php')
-rw-r--r--src/Gameboy/DrawContext.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/Gameboy/DrawContext.php b/src/Gameboy/DrawContext.php
new file mode 100644
index 0000000..82c243d
--- /dev/null
+++ b/src/Gameboy/DrawContext.php
@@ -0,0 +1,52 @@
+<?php
+namespace GameBoy;
+
+use Drawille\Canvas;
+
+class DrawContext
+{
+ // 160 x 144
+
+ protected $canvas;
+
+ public function __construct()
+ {
+ $this->canvas = new Canvas();
+ }
+
+ /**
+ * Put image on canvas
+ * @param Object $canvasBuffer $data = Each pixel = 4 items on array (RGBA)
+ * @param int $left
+ * @param int $top
+ */
+ public function putImageData($canvasBuffer, $left, $top)
+ {
+ $canvasBuffer = $canvasBuffer->data;
+
+ for ($i = 0; $i < count($canvasBuffer); $i = $i + 4) {
+ // IGNORE ALPHA
+ $total = $canvasBuffer[$i] + $canvasBuffer[$i + 1] + $canvasBuffer[$i + 2]; // + $canvasBuffer[$i + 3];
+
+ $x = ($i / 4) % 160;
+ $y = ceil(($i / 4) / 160);
+
+ if ($total > 350) {
+ $this->canvas->set($x, $y);
+ // echo 'SET ' . $x . ' - ' . $y . PHP_EOL;
+ }
+ }
+
+ echo "\e[H\e[2J";
+ echo $this->canvas->frame();
+ $this->canvas->clear();
+
+ // echo 'Draw' . PHP_EOL;
+ }
+
+ public function fillRect($left, $top, $width, $height)
+ {
+ $this->canvas->clear();
+ // echo 'Fill' . PHP_EOL;
+ }
+} \ No newline at end of file