@Override
  public void tick(Canvas c) {

    // moving the sliding background
    slicing1_x1 -= move;
    slicing1_x2 -= move;
    slicing2_x1 -= move;
    slicing2_x2 -= move;

    // if sliding background is out of the screen, chane the x coordinates to move it back again
    if (slicing1_x2 <= 0) {
      slicing1_x1 = slicing2_x2;
      slicing1_x2 = slicing1_x1 + getWidth();
    }
    if (slicing2_x2 <= 0) {
      slicing2_x1 = slicing1_x2;
      slicing2_x2 = slicing2_x1 + getWidth();
    }
    drawWallPaper(c); // calling to draw the sliding background

    spaceship_y1 += YDown + YVel;
    spaceship_y2 += YDown + YVel;

    if (spaceship_y1 <= 0) {
      spaceship_y1 = 0;
      spaceship_y2 = spaceship_size;
    }

    if (spaceship_y2 >= getHeight()) {
      spaceship_y2 = getHeight();
      spaceship_y1 = spaceship_y2 - spaceship_size;
    }
    pointY = spaceship_y1 + spaceship_size / 2;
    trajectory.tick(c); // calling trajectory tick for the trajectory
    cosmicfactory.tick(c); // calling cosmicfactory tick for the cosmic factory objects
    drawSpaceShip(c); // drawing the spaceship

    // counter for the score
    counter++;
    if (counter % 10 == 0) { // to slow down the counter
      score++; // the real score
    }

    // printing the score on the top left of the screen
    Paint paint2 = new Paint();
    paint2.setColor(Color.WHITE);
    paint2.setTextSize(100);
    c.drawText(Integer.toString(score), 50, 100, paint2);

    // cheking if spaceship is hitting any objects
    int distance;
    check:
    for (int i = 0; i < 10; i++) {
      CosmicObject obj1 = cosmicfactory.Clusters.get(0).get(i);
      CosmicObject obj2 = cosmicfactory.Clusters.get(1).get(i);
      if (obj1.centerX <= pointX + safe_distance && obj1.centerX >= pointX - safe_distance) {
        distance =
            (int)
                Math.sqrt(Math.pow(obj1.centerX - pointX, 2) + Math.pow(obj1.centerY - pointY, 2));
        if (distance < safe_distance) {
          lose = 1;
          break check;
        }
      }

      if (obj2.centerX <= pointX + safe_distance && obj2.centerX >= pointX - safe_distance) {
        distance =
            (int)
                Math.sqrt(Math.pow(obj2.centerX - pointX, 2) + Math.pow(obj2.centerY - pointY, 2));
        if (distance < safe_distance) {
          lose = 1;
          break check;
        }
      }
      /*
      if (obj2.x1 <= 350 && obj2.x2 >= 200) {
          if ((spaceship_y1 >= obj2.y1 && spaceship_y1 <= obj2.y2) ||
                  (spaceship_y2 >= obj2.y1 && spaceship_y2 <= obj2.y2))
          {
              lose = 1;
              break check;
          }
      }*/

    }

    // if lost print out gameover and the score and stop the program
    if (lose == 1) {
      Paint paint4 = new Paint();
      paint4.setColor(Color.WHITE);
      paint4.setTextSize(250);
      c.drawText("Game Over", getWidth() / 2 - 600, getHeight() / 2 - 50, paint4);

      Paint paint5 = new Paint();
      paint5.setColor(Color.WHITE);
      paint5.setTextSize(150);
      c.drawText(
          "Your Score  " + Integer.toString(score),
          getWidth() / 2 - 600,
          getHeight() / 2 + 100,
          paint5);
      renderThread.interrupt();
    }
  }