/*

 * app_video_lib.c

 *

 * Created: 2014/10/8 18:23:55

 *  Author: leo20_000

 */

 

#include "functions.h"

#include "app_fontset.h"

 

#include <avr/pgmspace.h>

#include <stdint.h>

#include <stdio.h>

#include <util/delay.h>

 

#define maxkeys 16

#define PORTDIR DDRB

#define PORTDATA PORTB

#define PORTIN PINB

#define right 20

#define down 30

#define left 40

#define cw 50

#define ccw 60

char  str;

 

 

uint8_t screen[screen_array_size];

//One bit masks

uint8_t pos[8] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};

int cri; //change to floats

int no_syl; 

int syl_dur;

int sri;

int bf;

int dc;

 

int calc_val[8];

int index;

int cnt;

int fp;

 

//timeout value for LCD task

#define t2 100

 

// The raw keyscan

unsigned char key, debounce_key ;  

// The decoded button number

unsigned char butnum ;

 

 

int enter;

int butval;

 

 

//*************************************************

// Draw and Delete Squares

//*************************************************

 

void draw_square(int x, int y) {

       int new_x = x * 10;

       int new_y = y * 10;

       video_line(new_x,      new_y,      new_x + 9, new_y,      1);

       video_line(new_x + 9, new_y,      new_x + 9, new_y + 9, 1);

       video_line(new_x + 9, new_y + 9, new_x,      new_y + 9, 1);

       video_line(new_x,      new_y + 9, new_x,      new_y,      1);

}

 

void draw_square_tp(int x, int y) {

       int new_x = x * 6;

       int new_y = y * 6;

       video_line(new_x,      new_y,      new_x + 5, new_y,      1);

       video_line(new_x + 5, new_y,      new_x + 5, new_y + 5, 1);

       video_line(new_x + 5, new_y + 5, new_x,      new_y + 5, 1);

       video_line(new_x,      new_y + 5, new_x,      new_y,      1);

}

 

 

void delete_square(int x, int y) {

       int new_x = x * 10;

       int new_y = y * 10;

       video_line(new_x,      new_y,      new_x + 9, new_y,      0);

       video_line(new_x + 9, new_y,      new_x + 9, new_y + 9, 0);

       video_line(new_x + 9, new_y + 9, new_x,      new_y + 9, 0);

       video_line(new_x,      new_y + 9, new_x,      new_y,      0);

}

 

void delete_square_tp(int x, int y) {

       int new_x = x * 6;

       int new_y = y * 6;

       video_line(new_x,      new_y,      new_x + 5, new_y,      0);

       video_line(new_x + 5, new_y,      new_x + 5, new_y + 5, 0);

       video_line(new_x + 5, new_y + 5, new_x,      new_y + 5, 0);

       video_line(new_x,      new_y + 5, new_x,      new_y,      0);

}

 

 

space spin_shape(int x, int y, int rand, int spin)

{

             space s;

             if( rand == 0 ){

                    if (spin == 0 || spin == 2)

                    {

            

                           s.a[0][0]= x - 2;

                           s.a[1][0] = y;

            

                           s.a[0][1] = x - 1;

                           s.a[1][1] = y;

            

                           s.a[0][2] = x;

                           s.a[1][2] = y;

            

                           s.a[0][3] = x + 1;

                           s.a[1][3] = y;

 

                           s.r_wall = 1;

                           s.l_wall = 2;

                           s.floor  = 0;

                    }

                    else

                    {

                          

                           s.a[0][0]= x;

                           s.a[1][0] = y - 2;

                          

                           s.a[0][1] = x;

                           s.a[1][1] = y - 1;

            

                           s.a[0][2] = x;

                           s.a[1][2] = y;

            

                           s.a[0][3] = x;

                           s.a[1][3] = y + 1;

      

                           s.r_wall = 0;

                           s.l_wall = 0;

                           s.floor  = 1;

                    }

             }//if (rand == 0)

             else if ( rand == 1 ) {

                   

                    s.a[0][0] = x - 1;

                    s.a[1][0] = y;

                   

                    s.a[0][1] = x;

                    s.a[1][1] = y;

                   

                    s.a[0][2] = x;

                    s.a[1][2] = y + 1;

                   

                    s.a[0][3] = x - 1;

                    s.a[1][3] = y + 1;

 

                    s.r_wall = 0;

                    s.l_wall = 1;

                    s.floor  = 1;

             }//else if (rand == 1)

             else if ( rand == 2 ) {

                    if(spin == 0)

                    {

                   

                           s.a[0][0] = x;

                           s.a[1][0] = y;

                   

                           s.a[0][1] = x - 1;

                           s.a[1][1] = y;

                   

                           s.a[0][2] = x + 1;

                           s.a[1][2] = y;

                   

                           s.a[0][3] = x;

                           s.a[1][3] = y + 1;

 

                           s.r_wall = 1;

                           s.l_wall = 1;

                           s.floor  = 1;

                    }

                    else if (spin == 1)

                    {

                   

                           s.a[0][0] = x;

                           s.a[1][0] = y;

                   

                           s.a[0][1] = x;

                           s.a[1][1] = y - 1;

                   

                           s.a[0][2] = x - 1;

                           s.a[1][2] = y;

                          

                           s.a[0][3] = x;

                           s.a[1][3] = y + 1;

            

                           s.r_wall = 0;

                           s.l_wall = 1;

                           s.floor  = 1;

                    }

                    else if(spin == 2)

                    {

                          

                           s.a[0][0] = x;

                           s.a[1][0] = y;

                          

                           s.a[0][1] = x - 1;

                           s.a[1][1] = y;

                          

                           s.a[0][2] = x + 1;

                           s.a[1][2] = y;

                          

                           s.a[0][3] = x;

                           s.a[1][3] = y - 1;

            

                           s.r_wall = 1;

                           s.l_wall = 1;

                           s.floor  = 0;

                    }

      

                    else if (spin == 3)

                    {

                          

                           s.a[0][0] = x;

                           s.a[1][0] = y;

                          

                           s.a[0][1] = x;

                           s.a[1][1] = y - 1;

                          

                           s.a[0][2] = x + 1;

                           s.a[1][2] = y;

                          

                           s.a[0][3] = x;

                           s.a[1][3] = y + 1;

            

                           s.r_wall = 1;

                           s.l_wall = 0;

                           s.floor  = 1;

                    }

             }//else if (rand == 2)

             else if ( rand == 3 ) {

                    if (spin == 0)

                    {

                          

                           s.a[0][0] = x - 1;

                           s.a[1][0] = y;

                          

                           s.a[0][1] = x - 1;

                           s.a[1][1] = y + 1;

                          

                           s.a[0][2] = x - 1;

                           s.a[1][2] = y + 2;

                          

                           s.a[0][3] = x;

                           s.a[1][3] = y + 2;

      

                           s.r_wall = 0;

                           s.l_wall = 1;

                           s.floor  = 2;

                    }

 

                    if (spin == 1)

                    {

                          

                           s.a[0][0] = x;

                           s.a[1][0] = y + 1;

                          

                           s.a[0][1] = x - 1;

                           s.a[1][1] = y + 1;

                          

                           s.a[0][2] = x - 2;

                           s.a[1][2] = y + 1;

                          

                           s.a[0][3] = x - 2;

                           s.a[1][3] = y + 2;

                   

                           s.r_wall = 0;

                           s.l_wall = 2;

                           s.floor  = 2;

                    }

                    if (spin == 2)

                    {

                          

                           s.a[0][0] = x - 1;

                           s.a[1][0] = y;

                          

                           s.a[0][1] = x - 1;

                           s.a[1][1] = y + 1;

                          

                           s.a[0][2] = x - 1;

                           s.a[1][2] = y + 2;

                          

                           s.a[0][3] = x - 2;

                           s.a[1][3] = y;

            

                           s.r_wall = -1;

                           s.l_wall = 2;

                           s.floor  = 2;

                    }

                    else if (spin == 3)

                    {

                          

                           s.a[0][0] = x;

                           s.a[1][0] = y + 1;

                          

                           s.a[0][1] = x - 1;

                           s.a[1][1] = y + 1;

                          

                           s.a[0][2] = x - 2;

                           s.a[1][2] = y + 1;

                          

                           s.a[0][3] = x;

                           s.a[1][3] = y;

      

                           s.r_wall = 0;

                           s.l_wall = 2;

                           s.floor  = 1;

                    }

             }//else if (rand == 3)

             else if ( rand == 4 ) {

                    if (spin == 0)

                    {

                          

                           s.a[0][0] = x - 1;

                           s.a[1][0] = y;

            

                           s.a[0][1] = x - 1;

                           s.a[1][1] = y + 1;

            

                           s.a[0][2] = x - 1;

                           s.a[1][2] = y + 2;

            

                           s.a[0][3] = x - 2;

                           s.a[1][3] = y + 2;

      

                           s.r_wall = -1;

                           s.l_wall = 2;

                           s.floor  = 2;

                    }

 

                    if (spin == 1)

                    {

            

                           s.a[0][0] = x;

                           s.a[1][0] = y + 1;

                          

                           s.a[0][1] = x - 1;

                           s.a[1][1] = y + 1;

                          

                           s.a[0][2] = x - 2;

                           s.a[1][2] = y + 1;

                          

                           s.a[0][3] = x - 2;

                           s.a[1][3] = y;

                   

                           s.r_wall = 0;

                           s.l_wall = 2;

                           s.floor  = 1;

                    }

                    if (spin == 2)

                    {

                          

                           s.a[0][0] = x - 1;

                           s.a[1][0] = y;

                          

                           s.a[0][1] = x - 1;

                           s.a[1][1] = y + 1;

                          

                           s.a[0][2] = x - 1;

                           s.a[1][2] = y + 2;

                                

                           s.a[0][3] = x;

                           s.a[1][3] = y;

                   

                           s.r_wall = 0;

                           s.l_wall = 1;

                           s.floor  = 2;

                    }

                    else if (spin == 3)

                    {

                          

                           s.a[0][0] = x;

                           s.a[1][0] = y + 1;

                   

                           s.a[0][1] = x - 1;

                           s.a[1][1] = y + 1;

                          

                           s.a[0][2] = x - 2;

                           s.a[1][2] = y + 1;

                          

                           s.a[0][3] = x;

                           s.a[1][3] = y + 2;

                   

                           s.r_wall = 0;

                           s.l_wall = 2;

                           s.floor  = 2;

                    }

             }//else if (rand == 4)

             else if ( rand == 5 ) {

                    if (spin == 0 || spin == 2)

                    {

                          

                           s.a[0][0] = x;

                           s.a[1][0] = y;

            

                           s.a[0][1] = x + 1;

                           s.a[1][1] = y;

            

                           s.a[0][2] = x;

                           s.a[1][2] = y - 1;

            

                           s.a[0][3] = x - 1;

                           s.a[1][3] = y - 1;

            

                           s.r_wall = 1;

                           s.l_wall = 1;

                           s.floor  = 0;

                    }

                    else

                    {

            

                           s.a[0][0] = x;

                           s.a[1][0] = y;

            

                           s.a[0][1] = x + 1;

                           s.a[1][1] = y;

      

                           s.a[0][2] = x;

                           s.a[1][2] = y - 1;

            

                           s.a[0][3] = x + 1;

                           s.a[1][3] = y + 1;

            

                           s.r_wall = 1;

                           s.l_wall = 0;

                           s.floor  = 1;

 

                    }

             }//else if (rand ==5)

             else if ( rand == 6 ) {

                    if (spin == 0 || spin == 2)

                    {

            

                           s.a[0][0] = x;

                           s.a[1][0] = y;

            

                           s.a[0][1] = x - 1;

                           s.a[1][1] = y;

            

                           s.a[0][2] = x;

                           s.a[1][2] = y + 1;

            

                           s.a[0][3] = x + 1;

                           s.a[1][3] = y + 1;

            

                           s.r_wall = 1;

                           s.l_wall = 1;

                           s.floor  = 1;

                    }

                    else

                    {

                          

 

                           s.a[0][0] = x;

                           s.a[1][0] = y;

 

                           s.a[0][1] = x + 1;

                           s.a[1][1] = y;

      

                           s.a[0][2] = x;

                           s.a[1][2] = y + 1;

      

                           s.a[0][3] = x + 1;

                           s.a[1][3] = y - 1;

 

                           s.r_wall = 1;

                           s.l_wall = 0;

                           s.floor  = 1;

                    }

             }//else if (rand == 6)

             return s;

}//space spin_shape(...

space draw_shape(int x, int y, int rand, int spin, int two_player) {

       space s;

       if(!two_player)

       {     

             if( rand == 0 ){

                    s = draw_four_by_one(x, y, spin);

             }

             else if ( rand == 1 ) {

                    s = draw_two_by_two (x, y);

             }

             else if ( rand == 2 ) {

                    s = draw_T(x, y, spin);

             }

             else if ( rand == 3 ) {

                    s = draw_L(x, y, spin);

             }

             else if ( rand == 4 ) {

                    s = draw_backward_L(x, y, spin);

             }

             else if ( rand == 5 ) {

                    s = draw_s(x, y, spin);

             }

             else if ( rand == 6 ) {

                    s = draw_z(x, y, spin);

             }

             return s;

       }

       else

       {

             if( rand == 0 ){

                    s = draw_four_by_one_tp(x, y, spin);

             }

             else if ( rand == 1 ) {

                    s = draw_two_by_two_tp (x, y);

             }

             else if ( rand == 2 ) {

                    s = draw_T_tp(x, y, spin);

             }

             else if ( rand == 3 ) {

                    s = draw_L_tp(x, y, spin);

             }

             else if ( rand == 4 ) {

                    s = draw_backward_L_tp(x, y, spin);

             }

             else if ( rand == 5 ) {

                    s = draw_s_tp(x, y, spin);

             }

             else if ( rand == 6 ) {

                    s = draw_z_tp(x, y, spin);

             }

             return s;

       }

}//space draw_shape(...

   

//*************************************************

// One Player Shapes

//*************************************************

 

space draw_four_by_one(int x, int y, int spin) {

       space s;

       if (spin == 0 || spin == 2)

       {

             draw_square(x - 2, y);

             s.a[0][0]= x - 2;

             s.a[1][0] = y;

             draw_square(x - 1, y);

             s.a[0][1] = x - 1;

             s.a[1][1] = y;

             draw_square(x,     y);

             s.a[0][2] = x;

             s.a[1][2] = y;

             draw_square(x + 1, y);

             s.a[0][3] = x + 1;

             s.a[1][3] = y;

 

             s.r_wall = 1;

             s.l_wall = 2;

             s.floor  = 0;

       }

       else

       {

             draw_square(x, y - 2);

             s.a[0][0]= x;

             s.a[1][0] = y - 2;

             draw_square(x, y - 1);

             s.a[0][1] = x;

             s.a[1][1] = y - 1;

             draw_square(x,     y);

             s.a[0][2] = x;

             s.a[1][2] = y;

             draw_square(x, y + 1);

             s.a[0][3] = x;

             s.a[1][3] = y + 1;

 

             s.r_wall = 0;

             s.l_wall = 0;

             s.floor  = 1;

       }

       return s;

      

 

}

 

space draw_two_by_two(int x, int y) {

       space s;

       draw_square(x - 1, y    );

       s.a[0][0] = x - 1;

       s.a[1][0] = y;

       draw_square(x,     y    );

       s.a[0][1] = x;

       s.a[1][1] = y;

       draw_square(x, y + 1);

       s.a[0][2] = x;

       s.a[1][2] = y + 1;

       draw_square(x - 1, y + 1);

       s.a[0][3] = x - 1;

       s.a[1][3] = y + 1;

 

       s.r_wall = 0;

       s.l_wall = 1;

       s.floor  = 1;

       return s;

}

 

space draw_T(int x, int y, int spin) {

       space s;

       if(spin == 0)

       {

             draw_square(x    , y    );

             s.a[0][0] = x;

             s.a[1][0] = y;

             draw_square(x - 1, y    );

             s.a[0][1] = x - 1;

             s.a[1][1] = y;

             draw_square(x + 1, y    );

             s.a[0][2] = x + 1;

             s.a[1][2] = y;

             draw_square(x    , y + 1);

             s.a[0][3] = x;

             s.a[1][3] = y + 1;

 

             s.r_wall = 1;

             s.l_wall = 1;

             s.floor  = 1;

       }

       else if (spin == 1)

       {

             draw_square(x    , y    );

             s.a[0][0] = x;

             s.a[1][0] = y;

             draw_square(x    , y - 1);

             s.a[0][1] = x;

             s.a[1][1] = y - 1;

             draw_square(x - 1, y    );

             s.a[0][2] = x - 1;

             s.a[1][2] = y;

             draw_square(x    , y + 1);

             s.a[0][3] = x;

             s.a[1][3] = y + 1;

 

             s.r_wall = 0;

             s.l_wall = 1;

             s.floor  = 1;

       }

       else if(spin == 2)

       {

             draw_square(x    , y    );

             s.a[0][0] = x;

             s.a[1][0] = y;

             draw_square(x - 1, y    );

             s.a[0][1] = x - 1;

             s.a[1][1] = y;

             draw_square(x + 1, y    );

             s.a[0][2] = x + 1;

             s.a[1][2] = y;

             draw_square(x    , y - 1);

             s.a[0][3] = x;

             s.a[1][3] = y - 1;

 

             s.r_wall = 1;

             s.l_wall = 1;

             s.floor  = 0;

       }

      

       else if (spin == 3)

       {

             draw_square(x    , y    );

             s.a[0][0] = x;

             s.a[1][0] = y;

             draw_square(x    , y - 1);

             s.a[0][1] = x;

             s.a[1][1] = y - 1;

             draw_square(x + 1, y    );

             s.a[0][2] = x + 1;

             s.a[1][2] = y;

             draw_square(x    , y + 1);

             s.a[0][3] = x;

             s.a[1][3] = y + 1;

 

             s.r_wall = 1;

             s.l_wall = 0;

             s.floor  = 1;

       }

       return s;

 

 

}

 

space draw_L(int x, int y, int spin) {

       space s;

       if (spin == 0)

       {

             draw_square(x - 1, y    );

             s.a[0][0] = x - 1;

             s.a[1][0] = y;

             draw_square(x - 1, y + 1);

             s.a[0][1] = x - 1;

             s.a[1][1] = y + 1;

             draw_square(x - 1, y + 2);

             s.a[0][2] = x - 1;

             s.a[1][2] = y + 2;

             draw_square(x    , y + 2);

             s.a[0][3] = x;

             s.a[1][3] = y + 2;

      

             s.r_wall = 0;

             s.l_wall = 1;

             s.floor  = 2;

       }

 

       if (spin == 1)

       {

             draw_square(x    , y + 1);

             s.a[0][0] = x;

             s.a[1][0] = y + 1;

             draw_square(x - 1, y + 1);

             s.a[0][1] = x - 1;

             s.a[1][1] = y + 1;

             draw_square(x - 2, y + 1);

             s.a[0][2] = x - 2;

             s.a[1][2] = y + 1;

             draw_square(x - 2, y + 2);

             s.a[0][3] = x - 2;

             s.a[1][3] = y + 2;

      

             s.r_wall = 0;

             s.l_wall = 2;

             s.floor  = 2;

       }

       if (spin == 2)

       {

             draw_square(x - 1, y    );

             s.a[0][0] = x - 1;

             s.a[1][0] = y;

             draw_square(x - 1, y + 1);

             s.a[0][1] = x - 1;

             s.a[1][1] = y + 1;

             draw_square(x - 1, y + 2);

             s.a[0][2] = x - 1;

             s.a[1][2] = y + 2;

             draw_square(x - 2, y    );

             s.a[0][3] = x - 2;

             s.a[1][3] = y;

      

             s.r_wall = -1;

             s.l_wall = 2;

             s.floor  = 2;

       }

       else if (spin == 3)

       {

             draw_square(x    , y + 1);

             s.a[0][0] = x;

             s.a[1][0] = y + 1;

             draw_square(x - 1, y + 1);

             s.a[0][1] = x - 1;

             s.a[1][1] = y + 1;

             draw_square(x - 2, y + 1);

             s.a[0][2] = x - 2;

             s.a[1][2] = y + 1;

             draw_square(x    , y    );

             s.a[0][3] = x;

             s.a[1][3] = y;

      

             s.r_wall = 0;

             s.l_wall = 2;

             s.floor  = 1;

       }

 

       return s;

}

 

space draw_backward_L(int x, int y, int spin) {

       space s;

       if (spin == 0)

       {

             draw_square(x - 1, y    );

             s.a[0][0] = x - 1;

             s.a[1][0] = y;

             draw_square(x - 1, y + 1);

             s.a[0][1] = x - 1;

             s.a[1][1] = y + 1;

             draw_square(x - 1, y + 2);

             s.a[0][2] = x - 1;

             s.a[1][2] = y + 2;

             draw_square(x - 2, y + 2);

             s.a[0][3] = x - 2;

             s.a[1][3] = y + 2;

      

             s.r_wall = -1;

             s.l_wall = 2;

             s.floor  = 2;

       }

 

       if (spin == 1)

       {

             draw_square(x    , y + 1);

             s.a[0][0] = x;

             s.a[1][0] = y + 1;

             draw_square(x - 1, y + 1);

             s.a[0][1] = x - 1;

             s.a[1][1] = y + 1;

             draw_square(x - 2, y + 1);

             s.a[0][2] = x - 2;

             s.a[1][2] = y + 1;

             draw_square(x - 2, y    );

             s.a[0][3] = x - 2;

             s.a[1][3] = y;

      

             s.r_wall = 0;

             s.l_wall = 2;

             s.floor  = 1;

       }

       if (spin == 2)

       {

             draw_square(x - 1, y    );

             s.a[0][0] = x - 1;

             s.a[1][0] = y;

             draw_square(x - 1, y + 1);

             s.a[0][1] = x - 1;

             s.a[1][1] = y + 1;

             draw_square(x - 1, y + 2);

             s.a[0][2] = x - 1;

             s.a[1][2] = y + 2;

             draw_square(x    , y    );

             s.a[0][3] = x;

             s.a[1][3] = y;

      

             s.r_wall = 0;

             s.l_wall = 1;

             s.floor  = 2;

       }

       else if (spin == 3)

       {

             draw_square(x    , y + 1);

             s.a[0][0] = x;

             s.a[1][0] = y + 1;

             draw_square(x - 1, y + 1);

             s.a[0][1] = x - 1;

             s.a[1][1] = y + 1;

             draw_square(x - 2, y + 1);

             s.a[0][2] = x - 2;

             s.a[1][2] = y + 1;

             draw_square(x    , y + 2);

             s.a[0][3] = x;

             s.a[1][3] = y + 2;

      

             s.r_wall = 0;

             s.l_wall = 2;

             s.floor  = 2;

       }

      

       return s;

}

 

space draw_s(int x, int y, int spin) {

       space s;

       if (spin == 0 || spin == 2)

       {

             draw_square(x    , y    );

             s.a[0][0] = x;

             s.a[1][0] = y;

             draw_square(x - 1, y    );

             s.a[0][1] = x - 1;

             s.a[1][1] = y;

             draw_square(x    , y - 1);

             s.a[0][2] = x;

             s.a[1][2] = y - 1;

             draw_square(x + 1, y - 1);

             s.a[0][3] = x + 1;

             s.a[1][3] = y - 1;

 

             s.r_wall = 1;

             s.l_wall = 1;

             s.floor  = 0;

       }

       else

       {

             draw_square(x    , y    );

             s.a[0][0] = x;

             s.a[1][0] = y;

             draw_square(x + 1, y    );

             s.a[0][1] = x + 1;

             s.a[1][1] = y;

             draw_square(x    , y - 1);

             s.a[0][2] = x;

             s.a[1][2] = y - 1;

             draw_square(x + 1, y + 1);

             s.a[0][3] = x + 1;

             s.a[1][3] = y + 1;

 

             s.r_wall = 1;

             s.l_wall = 0;

             s.floor  = 1;

 

       }

       return s;

}

 

space draw_z(int x, int y, int spin) {

       space s;

       if (spin == 0 || spin == 2)

       {

             draw_square(x    , y    );

             s.a[0][0] = x;

             s.a[1][0] = y;

             draw_square(x - 1, y    );

             s.a[0][1] = x - 1;

             s.a[1][1] = y;

             draw_square(x    , y + 1);

             s.a[0][2] = x;

             s.a[1][2] = y + 1;

             draw_square(x + 1, y + 1);

             s.a[0][3] = x + 1;

             s.a[1][3] = y + 1;

 

             s.r_wall = 1;

             s.l_wall = 1;

             s.floor  = 1;

       }

       else

       {

            

             draw_square(x    , y    );

             s.a[0][0] = x;

             s.a[1][0] = y;

             draw_square(x + 1, y    );

             s.a[0][1] = x + 1;

             s.a[1][1] = y;

             draw_square(x    , y + 1);

             s.a[0][2] = x;

             s.a[1][2] = y + 1;

             draw_square(x + 1, y - 1);

             s.a[0][3] = x + 1;

             s.a[1][3] = y - 1;

 

             s.r_wall = 1;

             s.l_wall = 0;

             s.floor  = 1;

       }

       return s;

}

 

//*************************************************

// Two Player Shapes

//*************************************************

 

space draw_four_by_one_tp(int x, int y, int spin) {

       space s;

       if (spin == 0 || spin == 2)

       {

             draw_square_tp(x - 2, y);

             s.a[0][0]= x - 2;

             s.a[1][0] = y;

             draw_square_tp(x - 1, y);

             s.a[0][1] = x - 1;

             s.a[1][1] = y;

             draw_square_tp(x,     y);

             s.a[0][2] = x;

             s.a[1][2] = y;

             draw_square_tp(x + 1, y);

             s.a[0][3] = x + 1;

             s.a[1][3] = y;

 

             s.r_wall = 1;

             s.l_wall = 2;

             s.floor  = 0;

       }

       else

       {

             draw_square_tp(x, y - 2);

             s.a[0][0]= x;

             s.a[1][0] = y - 2;

             draw_square_tp(x, y - 1);

             s.a[0][1] = x;

             s.a[1][1] = y - 1;

             draw_square_tp(x,     y);

             s.a[0][2] = x;

             s.a[1][2] = y;

             draw_square_tp(x, y + 1);

             s.a[0][3] = x;

             s.a[1][3] = y + 1;

 

             s.r_wall = 0;

             s.l_wall = 0;

             s.floor  = 1;

       }

       return s;

      

 

}

 

space draw_two_by_two_tp(int x, int y) {

       space s;

       draw_square_tp(x - 1, y    );

       s.a[0][0] = x - 1;

       s.a[1][0] = y;

       draw_square_tp(x,     y    );

       s.a[0][1] = x;

       s.a[1][1] = y;

       draw_square_tp(x, y + 1);

       s.a[0][2] = x;

       s.a[1][2] = y + 1;

       draw_square_tp(x - 1, y + 1);

       s.a[0][3] = x - 1;

       s.a[1][3] = y + 1;

 

       s.r_wall = 0;

       s.l_wall = 1;

       s.floor  = 1;

       return s;

}

 

space draw_T_tp(int x, int y, int spin) {

       space s;

       if(spin == 0)

       {

             draw_square_tp(x    , y    );

             s.a[0][0] = x;

             s.a[1][0] = y;

             draw_square_tp(x - 1, y    );

             s.a[0][1] = x - 1;

             s.a[1][1] = y;

             draw_square_tp(x + 1, y    );

             s.a[0][2] = x + 1;

             s.a[1][2] = y;

             draw_square_tp(x    , y + 1);

             s.a[0][3] = x;

             s.a[1][3] = y + 1;

 

             s.r_wall = 1;

             s.l_wall = 1;

             s.floor  = 1;

       }

       else if (spin == 1)

       {

             draw_square_tp(x    , y    );

             s.a[0][0] = x;

             s.a[1][0] = y;

             draw_square_tp(x    , y - 1);

             s.a[0][1] = x;

             s.a[1][1] = y - 1;

             draw_square_tp(x - 1, y    );

             s.a[0][2] = x - 1;

             s.a[1][2] = y;

             draw_square_tp(x    , y + 1);

             s.a[0][3] = x;

             s.a[1][3] = y + 1;

 

             s.r_wall = 0;

             s.l_wall = 1;

             s.floor  = 1;

       }

       else if(spin == 2)

       {

             draw_square_tp(x    , y    );

             s.a[0][0] = x;

             s.a[1][0] = y;

             draw_square_tp(x - 1, y    );

             s.a[0][1] = x - 1;

             s.a[1][1] = y;

             draw_square_tp(x + 1, y    );

             s.a[0][2] = x + 1;

             s.a[1][2] = y;

             draw_square_tp(x    , y - 1);

             s.a[0][3] = x;

             s.a[1][3] = y - 1;

 

             s.r_wall = 1;

             s.l_wall = 1;

             s.floor  = 0;

       }

      

       else if (spin == 3)

       {

             draw_square_tp(x    , y    );

             s.a[0][0] = x;

             s.a[1][0] = y;

             draw_square_tp(x    , y - 1);

             s.a[0][1] = x;

             s.a[1][1] = y - 1;

             draw_square_tp(x + 1, y    );

             s.a[0][2] = x + 1;

             s.a[1][2] = y;

             draw_square_tp(x    , y + 1);

             s.a[0][3] = x;

             s.a[1][3] = y + 1;

 

             s.r_wall = 1;

             s.l_wall = 0;

             s.floor  = 1;

       }

       return s;

 

 

}

 

space draw_L_tp(int x, int y, int spin) {

       space s;

       if (spin == 0)

       {

             draw_square_tp(x - 1, y    );

             s.a[0][0] = x - 1;

             s.a[1][0] = y;

             draw_square_tp(x - 1, y + 1);

             s.a[0][1] = x - 1;

             s.a[1][1] = y + 1;

             draw_square_tp(x - 1, y + 2);

             s.a[0][2] = x - 1;

             s.a[1][2] = y + 2;

             draw_square_tp(x    , y + 2);

             s.a[0][3] = x;

             s.a[1][3] = y + 2;

      

             s.r_wall = 0;

             s.l_wall = 1;

             s.floor  = 2;

       }

 

       if (spin == 1)

       {

             draw_square_tp(x    , y + 1);

             s.a[0][0] = x;

             s.a[1][0] = y + 1;

             draw_square_tp(x - 1, y + 1);

             s.a[0][1] = x - 1;

             s.a[1][1] = y + 1;

             draw_square_tp(x - 2, y + 1);

             s.a[0][2] = x - 2;

             s.a[1][2] = y + 1;

             draw_square_tp(x - 2, y + 2);

             s.a[0][3