예제 #1
0
 public function __construct(FrameBuffer $frameBuffer)
 {
     $this->width = $frameBuffer->getWidth();
     $this->height = $frameBuffer->getHeight();
     // need room for each pixel as a char, and newlines between them
     $encodedSize = $this->height * ($this->width + 1) - 1;
     $this->blankEncodedFrame = str_repeat(self::ENCODED_PIXEL_OFF, $encodedSize);
     for ($i = $this->width; $i < $encodedSize; $i += $this->width + 1) {
         $this->blankEncodedFrame[$i] = "\n";
     }
     $this->colorCharMap = array_flip(BitmapLoader::$colorMap);
 }
예제 #2
0
 /**
  * @param FrameBuffer $frameBuffer
  * @return string
  */
 public function encodeFrameInfo(FrameBuffer $frameBuffer)
 {
     return json_encode(['frameInfo' => ['width' => $frameBuffer->getWidth(), 'height' => $frameBuffer->getHeight(), 'palette' => Color::getPalette()]]);
 }
예제 #3
0
 protected function initializeGame(FrameBuffer $frameBuffer)
 {
     $this->background = $this->bitmapLoader->loadBitmap('main_game');
     $this->displayHeight = $frameBuffer->getHeight();
     $this->displayWidth = $frameBuffer->getWidth();
     $this->paddles = [self::LEFT => $this->bitmapLoader->loadSprite('paddle'), self::RIGHT => $this->bitmapLoader->loadSprite('paddle')];
     $this->addSprite($this->paddles[self::LEFT]);
     $this->addSprite($this->paddles[self::RIGHT]);
     $this->paddleHeight = $this->paddles[self::LEFT]->getBitmap()->getHeight();
     $this->paddleWidth = $this->paddles[self::LEFT]->getBitmap()->getWidth();
     $this->paddleMinY = self::FRAME_EDGE_SIZE;
     $this->paddleMaxY = $this->displayHeight - $this->paddleHeight - self::FRAME_EDGE_SIZE;
     $this->ball = $this->bitmapLoader->loadSprite('ball');
     $this->addSprite($this->ball);
     $this->ballHeight = $this->ball->getBitmap()->getHeight();
     $this->ballWidth = $this->ball->getBitmap()->getWidth();
     self::$paddlePosX[self::RIGHT] = $this->displayWidth - 1.0 - $this->paddleWidth;
     $this->ballPaddleLimitX = [self::LEFT => (double) (self::$paddlePosX[self::LEFT] + $this->paddleWidth), self::RIGHT => (double) (self::$paddlePosX[self::RIGHT] - $this->paddleWidth)];
     $this->ballEdgeLimitY = [self::TOP => 1.0, self::BOTTOM => (double) ($this->displayHeight - $this->ballHeight)];
     $this->frameTimestamp = microtime(true);
     $this->gameState = self::GAMESTATE_INITIALIZING;
 }