<commit_before>function bindResize($canvas){
  var canvas = $canvas[0];
  var canvasRatio = canvas.width / canvas.height;
  var $window = $(window).resize(function(){
    resizeCanvas();
  });
  function resizeCanvas(){
    var width = $window.width();
    var height = $window.height();
    $canvas.css({
      width: height * canvasRatio,
      height: height
    });
  }
  resizeCanvas();
}
$(function(){
  var $canvas = $('#game_canvas');
  var canvas = $canvas[0];
  var ctx = canvas.getContext("2d");
  sceneManager.goto(new MenuScene()); //first scene //TODO game menu scene
  bindResize($canvas);
  ;(function(fps){
    var interval = 1000 / fps;
    var prevTime = Date.now();
    ;(function loop(){
      window.requestAnimFrame(loop);
      var now = Date.now();
      var delta = now - prevTime;
      if (delta < interval) return;
      var deltaRatio = delta / interval; //經過的時間與預計的時間的比例。數字越高代表越LAG。
      prevTime += delta - (delta % interval); //若requestAnimFrame是60FPS時，delta會是16ms的倍數。要減掉delta % interval否則會多算時間。
      Input.update();
      sceneManager.update(deltaRatio);
      ctx.clearRect(0, 0, canvas.width, canvas.height);
      sceneManager.render(canvas);
    })();
  }(40));
});
//-------------------------------------
//  MenuScene
//-------------------------------------
function MenuScene(){
  return {
    update: function(deltaRatio){
      if (Input.pressed(Input.KEYS.ENTER)){
        //TODO sound && animation?
        sceneManager.goto(new MapScene());
      } 
    },
    render: function(canvas){
      var ctx = canvas.getContext("2d");
      drawImageWithXRepeat(canvas, 0, 0.1, 'images/background.jpg');
      drawImageWithXRepeat(canvas, 0, 1.0, 'images/ground.png');
      imageCacher.ifloaded('images/menu/title.png', function(image){
        ctx.drawImage(image, (canvas.width - image.width) / 2, 152 - image.height / 2, image.width, image.height);  
      }, 0.48);
      imageCacher.ifloaded('images/menu/jump.png', function(image){
        ctx.drawImage(image, (canvas.width - image.width) / 2, 324 - image.height / 2, image.width, image.height);  
      }, 0.242);
    }
  };
}
//-------------------------------------
//  MapScene
//-------------------------------------
function MapScene(){
  var VIEWPORT_X = 90; //視角讓狼固定在的X位置
  var BASE_Y = 80;     //地面高度
//-------------------------------------
//  player
//-------------------------------------
  var player = (function(){
    var vx = 0, vy = 0;
    return characterFoctory.create('images/characters/wolf.png', {
      x: 0, 
      y: BASE_Y,
      hp: 100,
      atk: 100
    }, function(){
      if (Input.pressed(Input.KEYS.RIGHT)) vx = 6;
      else if (Input.pressed(Input.KEYS.LEFT)) vx = 3;
      else vx = 4;
      if (Input.pressed(Input.KEYS.UP) && player.attrs.y == BASE_Y) vy = 15;
      if (player.attrs.y > BASE_Y){
        vy -= 1; //gravity
      }
      player.attrs.x += vx;
      player.attrs.y += vy;
      if (player.attrs.y < BASE_Y){
        player.attrs.y = BASE_Y;
        vy = 0;
      }
    });
  })();
//-------------------------------------
//  enemy
//-------------------------------------<commit_msg>prevent background shake between menu and game<commit_after>function bindResize($canvas){
  var canvas = $canvas[0];
  var canvasRatio = canvas.width / canvas.height;
  var $window = $(window).resize(function(){
    resizeCanvas();
  });
  function resizeCanvas(){
    var width = $window.width();
    var height = $window.height();
    $canvas.css({
      width: Math.floor(height * canvasRatio),
      height: height
    });
  }
  resizeCanvas();
}
$(function(){
  var $canvas = $('#game_canvas');
  var canvas = $canvas[0];
  var ctx = canvas.getContext("2d");
  sceneManager.goto(new MenuScene()); //first scene //TODO game menu scene
  bindResize($canvas);
  ;(function(fps){
    var interval = 1000 / fps;
    var prevTime = Date.now();
    ;(function loop(){
      window.requestAnimFrame(loop);
      var now = Date.now();
      var delta = now - prevTime;
      if (delta < interval) return;
      var deltaRatio = delta / interval; //經過的時間與預計的時間的比例。數字越高代表越LAG。
      prevTime += delta - (delta % interval); //若requestAnimFrame是60FPS時，delta會是16ms的倍數。要減掉delta % interval否則會多算時間。
      Input.update();
      sceneManager.update(deltaRatio);
      ctx.clearRect(0, 0, canvas.width, canvas.height);
      sceneManager.render(canvas);
    })();
  }(40));
});
//-------------------------------------
//  MenuScene
//-------------------------------------
function MenuScene(){
  return {
    update: function(deltaRatio){
      if (Input.pressed(Input.KEYS.ENTER)){
        //TODO sound && animation?
        sceneManager.goto(new MapScene());
      } 
    },
    render: function(canvas){
      var ctx = canvas.getContext("2d");
      drawImageWithXRepeat(canvas, 0, 0.1, 'images/background.jpg');
      drawImageWithXRepeat(canvas, 0, 1.0, 'images/ground.png');
      imageCacher.ifloaded('images/menu/title.png', function(image){
        ctx.drawImage(image, (canvas.width - image.width) / 2, 152 - image.height / 2, image.width, image.height);  
      }, 0.48);
      imageCacher.ifloaded('images/menu/jump.png', function(image){
        ctx.drawImage(image, (canvas.width - image.width) / 2, 324 - image.height / 2, image.width, image.height);  
      }, 0.242);
    }
  };
}
//-------------------------------------
//  MapScene
//-------------------------------------
function MapScene(){
  var VIEWPORT_X = 90; //視角讓狼固定在的X位置
  var BASE_Y = 80;     //地面高度
//-------------------------------------
//  player
//-------------------------------------
  var player = (function(){
    var vx = 0, vy = 0;
    return characterFoctory.create('images/characters/wolf.png', {
      x: VIEWPORT_X, 
      y: BASE_Y,
      hp: 100,
      atk: 100
    }, function(){
      if (Input.pressed(Input.KEYS.RIGHT)) vx = 6;
      else if (Input.pressed(Input.KEYS.LEFT)) vx = 3;
      else vx = 4;
      if (Input.pressed(Input.KEYS.UP) && player.attrs.y == BASE_Y) vy = 15;
      if (player.attrs.y > BASE_Y){
        vy -= 1; //gravity
      }
      player.attrs.x += vx;
      player.attrs.y += vy;
      if (player.attrs.y < BASE_Y){
        player.attrs.y = BASE_Y;
        vy = 0;
      }
    });
  })();
//-------------------------------------
//  enemy
//-------------------------------------
{'fraction_non_alphanumeric': 0.24328169459374013, 'fraction_numerical': 0.018495099588997786, 'mean_word_length': 1.8654891304347827, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1909321', 'n_tokens_mistral': 2122, 'n_tokens_neox': 2052, 'n_words': 416}