<commit_before><template>
  <canvas ref="canvas"></canvas>
</template>

<script>
  import store from './store'

  export default {
    data() {
      return {
        store,
        playerY: 200,
        aiY: 200,
      }
    },

    watch: {
      'store.playerY'(val) {
        this.playerY = val;
      },
      'store.aiY'(val) {
        this.aiY = val;
      }
    },

    mounted() {
      const canvas = this.$refs.canvas;
      const ctx = canvas.getContext('2d');

      canvas.width = 1000;
      canvas.height = 500;

      const cw = canvas.width;
      const ch = canvas.height;

      const ballSize = 20;

      let ballX = cw / 2 - ballSize / 2;
      let ballY = ch / 2 - ballSize / 2;

      const paddelHeight = 100;
      const paddelWidth = 20;

      const playerX = 70;
      const aiX = 910;

      const lineWidht = 6;
      const lineHeight = 16;

      let ballSpeedX = -1;
      let ballSpeedY = 1;


      let topCanvas = canvas.offsetTop;

      const self = this;

      function player() {
        ctx.fillStyle = '#7FFF00';
        ctx.fillRect(playerX, self.playerY, paddelWidth, paddelHeight);
      }

      function movePlayer(newY) {
        var newPlayerY = newY - topCanvas - paddelHeight / 2;
        if (newPlayerY >= ch - paddelHeight) {
          newPlayerY = ch - paddelHeight;
        }

        if (newPlayerY <= 0) {
          newPlayerY = 0;
        }

        self.store.playerY = newPlayerY;

        self.store.aiY = newPlayerY;
      }

      function ai() {
        ctx.fillStyle = 'yellow';
        ctx.fillRect(aiX, self.aiY, paddelWidth, paddelHeight);
      }

      function ball() {
        ctx.fillStyle = '#ffffff';
        ctx.fillRect(ballX, ballY, ballSize, ballSize);
        ballX += ballSpeedX;
        ballY += ballSpeedY;

        if (ballY + ballSize >= ch || ballY <= 0) {
          ballSpeedY = -ballSpeedY;
          speedUp();
        }
        if (ballX + ballSize >= cw || ballX <= 0) {
          ballSpeedX = -ballSpeedX;
          speedUp();
        }

        function speedUp() {
          if (ballSpeedX > 0) {
            ballSpeedX += .2;
          } else if (ballSpeedX < 0) {
            ballSpeedX -= .2;
          }

          if (ballSpeedY > 0) {
            ballSpeedY += .2;
          } else {
            ballSpeedY -= .2;
          }
        }
      }

      function table() {
        ctx.fillStyle = 'black';
        ctx.fillRect(0, 0, cw, ch);
        for (let linePosition = 20; linePosition < ch; linePosition += 30) {
          ctx.fillStyle = "gray";
          ctx.fillRect(cw / 2 - lineWidht / 2, linePosition, lineWidht, lineHeight)
        }
      }

      function mouseMove(e) {
        movePlayer(e.clientY);
      }

      canvas.addEventListener('mousemove', mouseMove);

      function game() {<commit_msg>Separating move logic for each player<commit_after><template>
  <canvas ref="canvas"></canvas>
</template>

<script>
  import store from './store'

  export default {
    data() {
      return {
        store,
        playerY: 200,
        aiY: 200,
      }
    },

    watch: {
      'store.playerY'(val) {
        this.playerY = val;
      },
      'store.aiY'(val) {
        this.aiY = val;
      }
    },

    mounted() {
      const canvas = this.$refs.canvas;
      const ctx = canvas.getContext('2d');

      canvas.width = 1000;
      canvas.height = 500;

      const cw = canvas.width;
      const ch = canvas.height;

      const ballSize = 20;

      let ballX = cw / 2 - ballSize / 2;
      let ballY = ch / 2 - ballSize / 2;

      const paddelHeight = 100;
      const paddelWidth = 20;

      const playerX = 70;
      const aiX = 910;

      const lineWidht = 6;
      const lineHeight = 16;

      let ballSpeedX = -1;
      let ballSpeedY = 1;


      let topCanvas = canvas.offsetTop;

      const self = this;

      function player() {
        ctx.fillStyle = '#7FFF00';
        ctx.fillRect(playerX, self.playerY, paddelWidth, paddelHeight);
      }

      function applyBoundings(requestedY) {
        var calculatedY = requestedY - topCanvas - paddelHeight / 2;
        if (calculatedY >= ch - paddelHeight) {
          calculatedY = ch - paddelHeight;
        }

        if (calculatedY <= 0) {
          calculatedY = 0;
        }
        return calculatedY;
      }

      function movePlayer(newY) {
        self.store.playerY = applyBoundings(newY);
      }

      function moveAi(newY) {
        self.store.aiY = applyBoundings(newY);
      }

      function ai() {
        ctx.fillStyle = 'yellow';
        ctx.fillRect(aiX, self.aiY, paddelWidth, paddelHeight);
      }

      function ball() {
        ctx.fillStyle = '#ffffff';
        ctx.fillRect(ballX, ballY, ballSize, ballSize);
        ballX += ballSpeedX;
        ballY += ballSpeedY;

        if (ballY + ballSize >= ch || ballY <= 0) {
          ballSpeedY = -ballSpeedY;
          speedUp();
        }
        if (ballX + ballSize >= cw || ballX <= 0) {
          ballSpeedX = -ballSpeedX;
          speedUp();
        }

        function speedUp() {
          if (ballSpeedX > 0) {
            ballSpeedX += .2;
          } else if (ballSpeedX < 0) {
            ballSpeedX -= .2;
          }

          if (ballSpeedY > 0) {
            ballSpeedY += .2;
          } else {
            ballSpeedY -= .2;
          }
        }
      }

      function table() {
        ctx.fillStyle = 'black';
        ctx.fillRect(0, 0, cw, ch);
        for (let linePosition = 20; linePosition < ch; linePosition += 30) {
          ctx.fillStyle = "gray";
          ctx.fillRect(cw / 2 - lineWidht / 2, linePosition, lineWidht, lineHeight)
        }
      }

      function mouseMove(e) {
        movePlayer(e.clientY);
        moveAi(e.clientY);
      }

      canvas.addEventListener('mousemove', mouseMove);

      function game() {
{'fraction_non_alphanumeric': 0.12054183813443073, 'fraction_numerical': 0.019890260631001373, 'mean_word_length': 1.5718694885361553, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3337485', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1821, 'n_words': 432}