//_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
//___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
//_|___|___|_B r i c k   B r e a k e r   P r o t o t y p e |___|___|___|
//___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
//_|___|___|___|___|___|___|f o r   M S  X  2__|___|___|___|___|___|___|
//___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
//_|___|___|___|___|Part of the Fusion-c Coding Tutorial___|___|___|___|
//___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
//_|___|___|___|___|___|___|__               __|___|___|___|___|___|___|
//___|___|___|___|___|___|__Eric Boez (c) 2018___|___|___|___|___|___|__
//_|___|___|___|___|___|___|___|           _|___|___|___|___|___|___|___|
//___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
//_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
//___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
//_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
//___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
//_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
//___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
//                 M a d e   w i t h     F U S I O N - C                        
//

#include "fusion-c/header/msx_fusion.h"
#include "fusion-c/header/vdp_sprites.h"
#include "fusion-c/header/vdp_graph2.h"


// Sprites Definition Patterns
//
static const unsigned char board_pattern[]={
  0b11111111,
  0b11111111,
  0b11111111,
  0b11111111,
  0b11111111,
  0b00000000,
  0b00000000,
  0b00000000
};

static const unsigned char ball_pattern[]={
    0b00111100,
    0b01111110,
    0b11111111,
    0b11111111,
    0b11111111,
    0b11111111,
    0b01111110,
    0b00111100
};

int x;
int y;
int dir_x;
int dir_y;

// Show Sprites on screen, and do graphic job
//
void FT_Srpites(void)
{
         PutSprite(0,1,x,y,10);           // Ball Sprite
}   

void FT_CalcPosition (void)
{
    // If the Ball is hurting left or right border of the screen
    if (x>247 || x<1)
    {
        dir_x *= -1;
    }
    
    // If the Ball is hurting up or bottom border of the screen
    if (y>187 || y<1)
    {
        dir_y *= -1;
    }

    x+=dir_x;
    y+=dir_y;
}




void main(void)
{
    char BallColors[8]= {15,8,8,8,8,8,8,15};
    char BoardColors[8]={15,15,15,15,15,15,15,15};
    
    x=170;
    y=110;
    dir_x=1;
    dir_y=-1;

    // Preparing Screen
    SetColors(15,0,1);
    Screen(8);
    SetColors(255,0,100);
    Cls();
    KeySound(0);
    VDP60Hz();

    // Check MSX
    if(ReadMSXtype()==3)  // If MSX is Turbo-R Switch CPU to Z80 Mode
    {
        ChangeCPU(0);
    }

    // Creating Sprites
    SpriteReset();
    SpriteSmall();
    SetSpritePattern(0, board_pattern,8);
    SetSpritePattern(1, ball_pattern,8);

    SC8SpriteColors(0,BallColors);
    SC8SpriteColors(1,BoardColors);
    SC8SpriteColors(2,BoardColors);
    SC8SpriteColors(3,BoardColors);

  while (1)
  {  

      FT_CalcPosition();

      FT_Srpites(); 
  }

}