Exemplo n.º 1
0
 public void OnRender(CompositionTargetBase target)
 {
     if (this.IsActive)
     {
         target.DrawPixel(this.XCenter, this.YCenter, Colors.Red);
     }
 }
Exemplo n.º 2
0
        public void OnRender(CompositionTargetBase target)
        {
            int bricks;

            if ((bricks = this.BricksAlive) != 0)
            {
                for (int y = 0; y < BarrierHeight; y++)
                {
                    int yy = this.YTop + y;

                    for (int x = 0; x < BarrierWidth; x++)
                    {
                        if ((bricks & 1) != 0)
                        {
                            target.DrawPixel(
                                this.XLeft + x,
                                yy,
                                Colors.Lime);
                        }

                        bricks >>= 1;
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void ComposePauseShowLevel(CompositionTargetBase target)
        {
            //draw a big bordered box
            target.FillRectangle(
                Brushes.Black,
                this._rectAlert);

            target.DrawRectangle(
                Pens.Lime,
                this._rectAlert);

            //draw a "Level" abbreviation
            target.DrawString(
                "Lv",
                Fonts.Fixed5x7,
                Brushes.Lime,
                this._rectAlert.Left + 2,
                this._rectAlert.Top + 2);

            //draw the number of the current level
            string text = this.Context.CurrentLevel.ToString();
            Size   sz   = target.MeasureString(text, Fonts.Fixed5x7);

            target.DrawString(
                text,
                Fonts.Fixed5x7,
                Brushes.Yellow,
                this._rectAlert.Right - 2 - sz.Width,
                this._rectAlert.Top + 2);
        }
Exemplo n.º 4
0
        private void ComposePauseSaucerHit(CompositionTargetBase target)
        {
            //draw a big bordered box
            target.FillRectangle(
                Brushes.Black,
                this._rectAlert);

            target.DrawRectangle(
                Pens.Lime,
                this._rectAlert);

            //draw the ship symbol
            target.DrawString(
                "LM",   //saucer
                AlienFont.Instance,
                Brushes.Lime,
                this._rectAlert.Left,
                this._rectAlert.Top + 2);

            //draw the number of ships left
            string text = this.Saucer.PromisedScore.ToString();
            Size   sz   = target.MeasureString(text, Fonts.Fixed5x7);

            target.DrawString(
                text,
                Fonts.Fixed5x7,
                Brushes.Yellow,
                this._rectAlert.Right - 2 - sz.Width,
                this._rectAlert.Top + 2);
        }
Exemplo n.º 5
0
        protected void RenderDeath(CompositionTargetBase target)
        {
            switch (this.Status)
            {
            case AlienStatus.ExplodeExpand:
            case AlienStatus.ExplodeCollapse:
                target.DrawPixel(this.XCenter, this.YCenter, Colors.Red);
                target.DrawPixel(this.XCenter + 1, this.YCenter, Colors.Red);

                target.DrawPixel(this.XCenter - 1, this.YCenter - 1, Colors.Yellow);
                target.DrawPixel(this.XCenter - 1, this.YCenter + 1, Colors.Yellow);
                target.DrawPixel(this.XCenter + 1, this.YCenter - 1, Colors.Yellow);
                break;


            case AlienStatus.ExplodeMax:
                target.DrawPixel(this.XCenter, this.YCenter, Colors.Red);
                target.DrawPixel(this.XCenter - 1, this.YCenter, Colors.Red);
                target.DrawPixel(this.XCenter, this.YCenter - 1, Colors.Red);
                target.DrawPixel(this.XCenter + 1, this.YCenter - 1, Colors.Red);

                target.DrawPixel(this.XCenter - 1, this.YCenter - 2, Colors.Yellow);
                target.DrawPixel(this.XCenter + 1, this.YCenter - 2, Colors.Yellow);
                target.DrawPixel(this.XCenter + 2, this.YCenter - 2, Colors.Yellow);
                target.DrawPixel(this.XCenter + 1, this.YCenter - 3, Colors.Yellow);
                target.DrawPixel(this.XCenter - 2, this.YCenter + 1, Colors.Yellow);
                target.DrawPixel(this.XCenter + 2, this.YCenter + 1, Colors.Yellow);
                break;
            }
        }
Exemplo n.º 6
0
        public override void OnRender(CompositionTargetBase target)
        {
            if (this.IsAlive)
            {
                //alien walking
                switch (this.Status)
                {
                case AlienStatus.Walk1:
                    //legs
                    target.DrawPixel(this.XCenter - 1, this.YCenter, Colors.Lime);
                    target.DrawPixel(this.XCenter + 1, this.YCenter, Colors.Lime);

                    //head
                    target.DrawPixel(this.XCenter, this.YCenter - 1, Colors.Red);
                    break;


                case AlienStatus.Walk2:
                    //leg(s)
                    target.DrawPixel(this.XCenter, this.YCenter, Colors.Lime);

                    //head
                    target.DrawPixel(this.XCenter, this.YCenter - 1, Colors.Red);
                    break;
                }
            }
            else
            {
                this.RenderDeath(target);
            }
        }
Exemplo n.º 7
0
        public static void Main()
        {
            //create a led-matrix driver instance
            _renderer = new SureHT1632(
                cspin: Pins.GPIO_PIN_D10,
                clkpin: Pins.GPIO_PIN_D9);

            //creates the target composition instance
            _composition = _renderer.CreateTarget();

            //creates a series of bouncing-ball instances
            var rnd = new Random();

            for (int i = 0; i < BallCount; i++)
            {
                _renderables[i] = new Ball(rnd.Next());
            }

            //start the timer for the demo loop
            const int LoopPeriod = 50; //ms

            _clock = new Timer(
                ClockTick,
                null,
                LoopPeriod,
                LoopPeriod);

            //keep alive
            Thread.Sleep(Timeout.Infinite);
        }
Exemplo n.º 8
0
        public void OnRender(CompositionTargetBase target)
        {
            switch (this.Status)
            {
            case SaucerStatus.Inactive:
                break;

            case SaucerStatus.Active:
                //cabin
                target.DrawPixel(this.XCenter, this.YCenter, Colors.Lime);
                target.DrawPixel(this.XCenter + 1, this.YCenter, Colors.Lime);

                //rockets
                int y      = this.YCenter + 1;
                int color1 = (this.XCenter & 1) != 0 ? Colors.Red : Colors.Yellow;
                int color2 = (this.XCenter & 1) == 0 ? Colors.Red : Colors.Yellow;

                target.DrawPixel(this.XCenter - 1, y, color1);
                target.DrawPixel(this.XCenter, y, color2);
                target.DrawPixel(this.XCenter + 1, y, color1);
                target.DrawPixel(this.XCenter + 2, y, color2);
                break;


            case SaucerStatus.ExplodeExpand:
            case SaucerStatus.ExplodeCollapse:
                target.DrawPixel(this.XCenter, this.YCenter, Colors.Red);
                target.DrawPixel(this.XCenter + 1, this.YCenter, Colors.Red);

                target.DrawPixel(this.XCenter - 1, this.YCenter - 1, Colors.Yellow);
                target.DrawPixel(this.XCenter - 1, this.YCenter + 1, Colors.Yellow);
                target.DrawPixel(this.XCenter + 1, this.YCenter - 1, Colors.Yellow);
                break;


            case SaucerStatus.ExplodeMax:
                target.DrawPixel(this.XCenter, this.YCenter, Colors.Red);
                target.DrawPixel(this.XCenter - 1, this.YCenter, Colors.Red);
                target.DrawPixel(this.XCenter, this.YCenter - 1, Colors.Red);
                target.DrawPixel(this.XCenter + 1, this.YCenter - 1, Colors.Red);

                target.DrawPixel(this.XCenter - 1, this.YCenter - 2, Colors.Yellow);
                target.DrawPixel(this.XCenter + 1, this.YCenter - 2, Colors.Yellow);
                target.DrawPixel(this.XCenter + 2, this.YCenter - 2, Colors.Yellow);
                target.DrawPixel(this.XCenter + 1, this.YCenter - 3, Colors.Yellow);
                target.DrawPixel(this.XCenter - 2, this.YCenter + 1, Colors.Yellow);
                target.DrawPixel(this.XCenter + 2, this.YCenter + 1, Colors.Yellow);
                break;
            }
        }
Exemplo n.º 9
0
        public void OnRender(CompositionTargetBase target)
        {
            //render the ball as a square at the current position
            this._rect.X = (int)(this._xpos + 0.5f);
            this._rect.Y = (int)(this._ypos + 0.5f);

            target.FillRectangle(
                this._brush,
                this._rect);

            target.DrawRectangle(
                this._pen,
                this._rect);

            //move the ball according to its speed
            this._xpos += this._xspeed;
            this._ypos += this._yspeed;

            //checks the viewport edges and makes the ball bouncing
            if (this._rightBound == 0)
            {
                Size vp = target.ViewportSize;
                this._rightBound  = vp.Width - EdgeLength;
                this._bottomBound = vp.Height - EdgeLength;
            }

            if (this._xpos < 0)
            {
                this._xspeed = -this._xspeed;
                this._xpos  += this._xspeed;
            }
            else if (this._xpos >= this._rightBound)
            {
                this._xspeed = -this._xspeed;
                this._xpos  += this._xspeed;
            }

            if (this._ypos < 0)
            {
                this._yspeed = -this._yspeed;
                this._ypos  += this._yspeed;
            }
            else if (this._ypos >= this._bottomBound)
            {
                this._yspeed = -this._yspeed;
                this._ypos  += this._yspeed;
            }
        }
Exemplo n.º 10
0
        void ICompositionRenderer.Dump(CompositionTargetBase composition)
        {
            //checks for driver initialization
            if (this._bufferIndex < 0)
            {
                this.Init();
            }

            //checks whether something in the cache has changed
            var target = composition as CompositionTargetHD44780;
            int hash   = target.GetCacheHash();

            if (hash == this._lastHash)
            {
                return;
            }
            else
            {
                this._lastHash = hash;
            }

            //physical row #0 (always present)
            int row = this._physicalRow0;

            int address = 0x80;

            WriteCommand(address);

            this.DumpPhysicalRow(
                target.GetBuffers(),
                (short)row,
                (row >> 16));

            //physical row #1
            if ((row = this._physicalRow1) != 0)
            {
                address += AddressStep;
                WriteCommand(address);

                this.DumpPhysicalRow(
                    target.GetBuffers(),
                    (short)row,
                    (row >> 16));
            }
        }
Exemplo n.º 11
0
        public static void Main()
        {
            //create a led-matrix driver instance
            _renderer = new SureHT1632(
                cspin: Pins.GPIO_PIN_D10,
                clkpin: Pins.GPIO_PIN_D9);

            //creates the target composition instance
            _composition = _renderer.CreateTarget();

            //start the timer for the demo loop
            const int LoopPeriod = 100; //ms

            _clock = new Timer(
                ClockTick,
                null,
                LoopPeriod,
                LoopPeriod);

            //keep alive
            Thread.Sleep(Timeout.Infinite);
        }
Exemplo n.º 12
0
        public void OnRender(CompositionTargetBase target)
        {
            switch (this.Status)
            {
            case ShipStatus.Alive:
                target.DrawPixel(this.XCenter, this.YCenter, Colors.Yellow);
                target.DrawPixel(this.XCenter, this.YCenter - 1, Colors.Yellow);
                target.DrawPixel(this.XCenter - 1, this.YCenter, Colors.Yellow);
                target.DrawPixel(this.XCenter + 1, this.YCenter, Colors.Yellow);
                break;


            case ShipStatus.ExplodeExpand:
            case ShipStatus.ExplodeCollapse:
                target.DrawPixel(this.XCenter, this.YCenter, Colors.Red);
                target.DrawPixel(this.XCenter + 1, this.YCenter, Colors.Red);

                target.DrawPixel(this.XCenter - 1, this.YCenter - 1, Colors.Yellow);
                target.DrawPixel(this.XCenter - 1, this.YCenter + 1, Colors.Yellow);
                target.DrawPixel(this.XCenter + 1, this.YCenter - 1, Colors.Yellow);
                break;


            case ShipStatus.ExplodeMax:
                target.DrawPixel(this.XCenter, this.YCenter, Colors.Red);
                target.DrawPixel(this.XCenter - 1, this.YCenter, Colors.Red);
                target.DrawPixel(this.XCenter, this.YCenter - 1, Colors.Red);
                target.DrawPixel(this.XCenter + 1, this.YCenter - 1, Colors.Red);

                target.DrawPixel(this.XCenter - 1, this.YCenter - 2, Colors.Yellow);
                target.DrawPixel(this.XCenter + 1, this.YCenter - 2, Colors.Yellow);
                target.DrawPixel(this.XCenter + 2, this.YCenter - 2, Colors.Yellow);
                target.DrawPixel(this.XCenter + 1, this.YCenter - 3, Colors.Yellow);
                target.DrawPixel(this.XCenter - 2, this.YCenter + 1, Colors.Yellow);
                target.DrawPixel(this.XCenter + 2, this.YCenter + 1, Colors.Yellow);
                break;
            }
        }
Exemplo n.º 13
0
        private void ComposePauseGameOver(CompositionTargetBase target)
        {
            //draw a big bordered box
            target.FillRectangle(
                Brushes.Black,
                this._rectAlert);

            target.DrawRectangle(
                Pens.Lime,
                this._rectAlert);

            //draw "game" then "over"
            var text = (this._pausedClock > PausedTimeShort)
                ? "GAME"
                : "OVER";

            target.DrawString(
                text,
                Fonts.Fixed5x7,
                Brushes.Red,
                this._rectAlert.Left + 2,
                this._rectAlert.Top + 2);
        }
Exemplo n.º 14
0
        public override GameStageBase OnCompose(CompositionTargetBase target)
        {
            GameStageBase result = null;

            if (this._pausedClock == 0)
            {
                //here is the normal flow during the playable game
                this.ShiftAliens = (this.Context.Clock & this._clockMask) == 0;

                //update objects
                this.Ship.Update(this);
                this.Missile.Update(this);
                this.Saucer.Update(this);

                for (int i = 0; i < AliensPerRow; i++)
                {
                    this.SmallAliens[i].Update(this);
                    this.LargeAliens[i].Update(this);
                }

                for (int i = 0; i < BombsCount; i++)
                {
                    this.Bombs[i].Update(this);
                }

                //check collisions
                if (this.Ship.DetectCollision(this))
                {
                }

                if (this.Saucer.DetectCollision(this))
                {
                }

                for (int i = 0; i < AliensPerRow; i++)
                {
                    if (this.SmallAliens[i].DetectCollision(this))
                    {
                        break;
                    }

                    if (this.LargeAliens[i].DetectCollision(this))
                    {
                        break;
                    }
                }

                for (int i = 0; i < BarriersCount; i++)
                {
                    if (this.Barriers[i].DetectCollision(this))
                    {
                        break;
                    }
                }

                //update context for next frame
                this.CurrentAlienDir = this.NextAlienDir;

                if (this.CurrentAlienDir == AlienDirection.GroundReached)
                {
                    //aliens grounded: the game is over!
                    this._pausedClock = PausedTimeLong;
                    this._pauseStage  = PauseStage.GameOver;
                }
            }
            //this happens when some event has paused the game
            else if (--this._pausedClock == 0)
            {
                //finalize the paused stage
                switch (this._pauseStage)
                {
                case PauseStage.ShipsLeft:
                    //resume the game where was broken
                    this.ResumeLevel();
                    break;

                case PauseStage.GameOver:
                    //back to the intro stage
                    result = new GameStageIntro(this.Context);
                    this.Context.Status = GameStatus.Registering;
                    break;
                }

                this._pauseStage = PauseStage.None;
            }

            //render the renderables
            for (int i = 0; i < RenderableCount; i++)
            {
                this._renderables[i].OnRender(target);
            }

            //when paused, compose the required stage
            if (this._pauseStage != PauseStage.None)
            {
                this._pauseStageHandlers[(int)this._pauseStage](target);
            }

            return(result);
        }
Exemplo n.º 15
0
 public abstract void OnRender(CompositionTargetBase target);
Exemplo n.º 16
0
        public override void OnLoad(CompositionTargetBase target)
        {
            //create and init the play-stage context
            Size vp = target.ViewportSize;

            this.ViewportRight  = vp.Width - 1;
            this.ViewportBottom = vp.Height - 1;

            this._rectAlert = new Rectangle(
                2,
                2,
                this.ViewportRight - 4,
                this.ViewportBottom - 4);

            this.Context.Status = GameStatus.Playing;

            //create barriers
            for (int i = 0; i < BarriersCount; i++)
            {
                Barrier barrier = this.Barriers[i] = new Barrier();
                barrier.XLeft = 3 + i * 10;
                barrier.YTop  = 10;
            }

            //create aliens
            for (int i = 0; i < AliensPerRow; i++)
            {
                AlienBase la = this.LargeAliens[i] = new AlienLarge();
                AlienBase sa = this.SmallAliens[i] = new AlienSmall();
                sa.AlienBelow = la;
            }

            //create bombs
            for (int i = 0; i < BombsCount; i++)
            {
                this.Bombs[i] = new Bomb();
            }

            //collect renderables
            int rc = 0;

            for (int i = 0; i < BarriersCount; i++)
            {
                this._renderables[rc++] = this.Barriers[i];
            }

            this._renderables[rc++] = this.Ship;
            this._renderables[rc++] = this.Missile;
            this._renderables[rc++] = this.Saucer;

            for (int i = 0; i < AliensPerRow; i++)
            {
                this._renderables[rc++] = this.SmallAliens[i];
                this._renderables[rc++] = this.LargeAliens[i];
            }

            for (int i = 0; i < BombsCount; i++)
            {
                this._renderables[rc++] = this.Bombs[i];
            }

            //sets the number of ships available
            this.Context.ShipsLeft = 3;

            //reset the score
            this.Context.CurrentScore = 0;

            //reset the level counter
            this.Context.CurrentLevel = 1;

            this.RestartLevel();
        }
Exemplo n.º 17
0
 public abstract GameStageBase OnCompose(CompositionTargetBase target);
Exemplo n.º 18
0
 public virtual void OnLoad(CompositionTargetBase target)
 {
     //do nothing
 }
Exemplo n.º 19
0
        public override GameStageBase OnCompose(CompositionTargetBase target)
        {
            GameStageBase result = null;

            //the game begins on any button pressed
            if (this.Context.FireButton ||
                this.Context.RightButton ||
                this.Context.LeftButton)
            {
                if (this.Context.Status == GameStatus.Idle)
                {
                    result = new GameStagePlay(this.Context);
                }
            }
            else if (this.Context.Status == GameStatus.RegComplete)
            {
                //this prevents the game to begin when
                //a button is still pressed since a prev stage
                this.Context.Status = GameStatus.Idle;
            }

            bool flasher = (this.Context.Clock & 8) != 0;

            if (this._frame == 0)
            {
                this._posT0    = new Point(34, 4);
                this._posT1    = new Point(40, 4);
                this._posAlien = new Point(-25, 4);
            }

            if (this._frame < 24)
            {
                target.DrawString("O", AlienFont.Instance, Brushes.Lime, _posT0);
                target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1);
                _posT0.X--;
                _posT1.X--;
            }
            else if (this._frame < 24)
            {
                target.DrawString("O", AlienFont.Instance, Brushes.Lime, _posT0);
                target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1);
            }
            else if (this._frame < 24 + 8)
            {
                target.DrawString("O", AlienFont.Instance, Brushes.Lime, _posT0);
                target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1);
                _posT0.X++;
                _posT1.X++;
            }
            else if (this._frame < 32 + 34)
            {
                string alien = string.Empty + (char)(0x50 + (this._frame & 1));
                target.DrawString(alien, AlienFont.Instance, Brushes.Yellow, _posAlien);
                target.DrawString("O", AlienFont.Instance, Brushes.Lime, _posT0);
                target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1);
                _posAlien.X++;
            }
            else if (this._frame < 66 + 34)
            {
                string alien = string.Empty + (char)(0x50 + (this._frame & 1));
                target.DrawString(alien, AlienFont.Instance, Brushes.Yellow, _posAlien);
                target.DrawString("O", AlienFont.Instance, Brushes.Lime, _posT0);
                target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1);
                _posAlien.X--;
                _posT0.X--;
            }
            else if (this._frame < 100 + 34)
            {
                string alien = string.Empty + (char)(0x50 + (this._frame & 1));
                target.DrawString(alien, AlienFont.Instance, Brushes.Yellow, _posAlien);
                target.DrawString("N", AlienFont.Instance, Brushes.Lime, _posT0);
                target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1);
                _posAlien.X++;
                _posT0.X++;
            }
            else if (this._frame < 134 + 100)
            {
                string alien = string.Empty + (char)(0x50 + (this._frame & 1));
                target.DrawString(alien, AlienFont.Instance, Brushes.Yellow, _posAlien);
                target.DrawString("N", AlienFont.Instance, Brushes.Lime, _posT0);
                target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1);
                _posAlien.X--;
                _posT0.X--;
                _posT1.X--;
            }
            else if (this._frame < 234 + 60)
            {
                if (this._frame == 234)
                {
                    this._posT0.X = 15;
                    this._posT0.Y = 0;
                    this._posT1.X = -15;
                    this._posT1.Y = 8;
                }

                //alien #2 is wider and yields less points
                string alien2 = flasher ? "RS" : "TU";
                target.DrawString(alien2, AlienFont.Instance, Brushes.Yellow, this._posT0);
                target.DrawString(AlienLarge.Score + "p", Fonts.Fixed5x7, Brushes.Lime, this._posT0.X + 12, this._posT0.Y);

                //alien #1 worth more
                string alien1 = flasher ? "P" : "Q";
                target.DrawString(alien1, AlienFont.Instance, Brushes.Yellow, this._posT1.X + 19, this._posT1.Y);
                target.DrawString(AlienSmall.Score + "p", Fonts.Fixed5x7, Brushes.Lime, this._posT1.X, this._posT1.Y + 1);

                if (this.Context.IsEvenClock)
                {
                    this._posT0.X--;
                    this._posT1.X++;
                }
            }
            else if (this._frame < 294 + 80)
            {
                if (flasher)
                {
                    target.DrawString("In ert", Fonts.Fixed5x7, Brushes.Lime, new Point(-1, 0));
                    target.DrawString("$", Fonts.Fixed5x7, Brushes.Red, new Point(11, 0));
                    target.DrawString("coin", Fonts.Fixed5x7, Brushes.Yellow, new Point(4, 9));
                }
            }
            else
            {
                this._frame = -1;
            }

            this._frame++;

            return(result);
        }
Exemplo n.º 20
0
        void ICompositionRenderer.Dump(CompositionTargetBase composition)
        {
            //checks for driver initialization
            if (this._spiBuffer == null)
            {
                this.Init();
            }

            //checks whether something in the cache has changed
            var target = composition as CompositionTargetSureHT1632;
            int hash   = target.GetCacheHash();

            if (hash == this._lastHash)
            {
                return;
            }
            else
            {
                this._lastHash = hash;
            }

            //retrieve the R+G buffers
            target.GetBuffers(
                this._rawR,
                this._rawG);

            //flushes the data out to the physical device
            using (var spi = new SPI(_spicfg))
            {
                this._htcs.Write(false);

                for (int i = 0; i < 64; i += 16)
                {
                    Array.Copy(
                        this._rawG,
                        i,
                        this._spiBuffer,
                        1,
                        16);

                    Array.Copy(
                        this._rawR,
                        i,
                        this._spiBuffer,
                        17,
                        16);

                    this._htclk.Write(false);
                    this._htclk.Write(true);

                    this._sck.Active = true;
                    this._sck.Active = false;

                    this._sck.Active = true;
                    this._sda.Active = true;
                    this._sck.Active = false;
                    this._sda.Active = false;

                    spi.Write(this._spiBuffer);

                    this._htcs.Write(true);
                }
            }

            this._htclk.Write(false);
            this._htclk.Write(true);
        }