Intranet Catprocess
  1. news...
  2. about Blackvoxel
  3. download
  4. manual
  5. videos
  6. about us
  1. Auto Brick Breaker

     

    // AUTO BRICK BREAKER
    
    init<-0;
    ball_x<-0;
    ball_y<-0;
    old_ball_x<-0;
    old_ball_y<-0;
    v_x<-0;
    v_y<-0;
    r_x<-0;
    r_y<-0;

    // Init display makes a voxel display wall using special display voxels.

    function Init_Display(Size)
    {
    local x,y;

    // Clear Zone

    for (x=0;x<32;x++)
    for (y=0;y<64;y++) UNF_PlaceVoxel3D(x+1,y,0,0);

    // Setup the screen

    for (x=0;x<Size;x++)
    for (y=0;y<Size;y++) UNF_PlaceVoxel3D(x+1,y,0,223);
    }

    // This function is called repeatedly for each step of the robot.

    function Voxel_Step()
    {
    local x,y,i,j, col_t, col_b, col_l, col_r;

    // Startup code, build the environnment. Executes only once.

    if (init == 0)
    {
    init = 1;
    Init_Display(32);
    r_x = 5;
    r_y = 29;
    v_x =1;
    v_y =-1;
    ball_x = 5;
    ball_y = 25;
    Image_New(0,32,32);
    Image_Clear(0,7);

    // Make brick walls.

    for (j=8;j<14;j++)
    for (i=0;i<15;i++)
    {
    Image_SetPixel(0, i*2 + 1 , j*2 - 14, j);
    Image_SetPixel(0, i*2 + 2 , j*2 - 14, j);
    }
    }

    Image_Line(0,0,0,31,0,6);
    Image_Line(0,0,0,0,31,6);
    Image_Line(0,31,0,31,31,6);

    col_t = Image_GetPixel(0, ball_x , ball_y - 1);
    col_b = Image_GetPixel(0, ball_x , ball_y + 1);
    col_l = Image_GetPixel(0, ball_x-1, ball_y );
    col_r = Image_GetPixel(0, ball_x+1, ball_y );

    if (col_t != 7) {Image_SetPixel(0, ball_x , ball_y - 1,7); v_y = 1; }
    if (col_b != 7) {Image_SetPixel(0, ball_x , ball_y + 1,7); v_y = -1; }
    if (col_l != 7) {Image_SetPixel(0, ball_x-1, ball_y ,7); v_x = 1; }
    if (col_r != 7) {Image_SetPixel(0, ball_x+1, ball_y ,7); v_x = -1; }

    Image_SetPixel(0,old_ball_x, old_ball_y, 7);
    Image_SetPixel(0,ball_x, ball_y, 0);

    old_ball_x = ball_x;
    old_ball_y = ball_y;
    ball_x += v_x;
    ball_y += v_y;

    if (ball_y > 13)
    {
    if ( (ball_x > (r_x+2)) && r_x < 25 ) r_x++;
    if ( (ball_x < (r_x+2)) && r_x > 1 ) r_x--;
    }

    if (ball_y>29) Init=0;

    Image_Line( 0, 1,r_y, 30, r_y, 7);
    Image_Line( 0, r_x, r_y, r_x+5, r_y, 0 );

    // Render the canva to the voxel wall

    for (x=0;x<32;x++)
    for (y=0;y<32;y++)
    {
    i = Image_GetPixel(0,31-x,31-y);
    Voxel_SetInfo(1+x,0+y,0,1,i);
    }

    }
     
  2. Google+