Android Marshmallow Easter Egg Game on a LED Matrix

INTRODUCTION


First, let’s address the elephant in the room. You must be wondering why I used a LED matrix for the game display at a time where OLEDs and TFTs are the go-to displays for projects.(Even a Nokia 5110!-the game itself is retro enough, adding a Nokia tag in my project would have made it too old-school).
When I first started off, I bought it quite enthusiastically but never used it(this is not the only one though). So, I decided to do something with it(yes, this is the best I could come up with).

Why this game?

Simple. I wanted to have a score more than 11 in the Android version of this game. No wonder there are so many YouTube tutorials(yes, that’s a hack)/articles out there showing you how to score more. It has some serious gravity issues.

SCHEMATICS


Screenshot from 2017-06-23 22-51-23

Pretty straight forward connections – a button for user input, and standard SPI connections.

GAMEPLAY-THE CODE

THE DROID

 

The head and legs will occupy a pixel each.

THE GITHUB REPO

THE DYNAMICS

    • It is confined in the 3rd(head) and 2nd(tail) column, oscillating there.
    • Movement is governed by up (uplift when the button is pressed)andgrav constants.

void MoveBird()
{
	static float y = 0.5;
	game.BirdVel = game.BirdVel + grav;
	float initY = game.BirdCrd;

  	game.BirdCrd = game.BirdCrd + game.BirdVel;

  if (game.BirdCrd > 1) 
  {
    game.BirdCrd = 1;
    game.BirdVel = 0;
  }
  else if (game.BirdCrd < 0) 
  {
    game.BirdCrd = 0;
    game.BirdVel = 0;
  }

  byte yCrd = 7 * game.BirdCrd;  

  Dir dir;
  if (abs(initY - game.BirdCrd) < 0.01) 
  {
    dir = STRAIGHT;
  }
  else if (initY < game.BirdCrd) 
  {
    dir = UP;
  }
  else 
  {
    dir = DOWN;
  }
  
  BirdForm(dir, yCrd);

}

 

PIPE(obstacle)MOVEMENT

  • The generation and sideways movement of the pipes are controlled simply by bit manipulation.

byte PipeGen()
{
  byte hole = random(4, 7);
  byte holeBits = (1 << hole) - 1;
  byte offset = random(1, 8 - hole);
  return 0xff & ~(holeBits << offset);
}

void PipeMove(Pipe *pipe)
{
  if (pipe->Xcrd == 255) 
  {
    PipeDelete(pipe, 0);
    pipe->parts = PipeGen();
    pipe->Xcrd = 7;
  }
  else if (pipe->Xcrd < 7) 
  {
    PipeDelete(pipe, pipe->Xcrd + 1);    
  }

  PipeDraw(pipe, pipe->Xcrd);

    if (pipe->Xcrd == 2) 
    {
    byte yCrd = 7 * game.BirdCrd;  
    if (pipe->parts & (0x80 >> yCrd)) 
    {
      screenburst();
      gameOver();
    }
    else 
    {
      game.score++;
    }
  }

 

TIMINGS

  • All thanks to this awesome timer library which kept all the complexities hidden under the hood, and enabled me to implement the timer events viz,Update(which updated the bird’s position), Pipe1(/2)MoveTimer( pipe movement from right to left) with ease.

LIGHTING IT UP

  • MAX7219 saved me both processor pins and processing time.
    This LED driver, complemented by its library prevented the code from crossing 400 lines.

These were the crucial sections of the code.
Rest of the functions are mostly self-explanatory. I’ll put comments soon.

And finally, the game in action can be viewed here!

Here’s a few pictures of the project:

Advertisements

2 thoughts on “Android Marshmallow Easter Egg Game on a LED Matrix

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: