<commit_before>function Penguin(textures) {
  this.penguinTextures         = loadFrames();
  this.penguinSurpriseTextures = loadSurpriseFrames();
  var penguinStage            = new PIXI.Stage();

  PIXI.MovieClip.call(this,this.penguinTextures);

  this.animationSpeed  = 0.05;
  this.position.x =  150;
  this.position.y =  300;
  this.scale.x    =  0.35;
  this.scale.y    =  0.35;
  this.anchor.x   = 0.5;
  this.anchor.y   = 1;
  this.movement   = { up:false, down:false, left:false, right:false, waddleRight:false, surprise:false, stop:false };
  this.surpriseFramesLoaded = false;

  this.gotoAndPlay(0);
  penguinStage.addChild(this);

  function loadFrames()
  {
    var penguinTextures = [];
    var len             = 4;
    var i               = 0;
    var texture         = null;

    for(;i<len;i++){
      texture = PIXI.Texture.fromImage("images/frame_" + i + "_512x512.png");
      penguinTextures.push(texture);
    }
    for(i=3;i>=0;i--){
      texture = PIXI.Texture.fromImage("images/frame_" + i + "_512x512.png");
      penguinTextures.push(texture);
    }

    return penguinTextures;
  }

  function loadSurpriseFrames()
  {
    var penguinTextures = [];
    var len             = 9;
    var i               = 0;
    var texture         = null;

    for(;i<len;i++){
      texture = PIXI.Texture.fromImage("images/surprise_frame_" + i + "_512x512.png");
      penguinTextures.push(texture);
    }

    return penguinTextures;
  }
}

Penguin.constructor = Penguin;
Penguin.prototype   = Object.create(PIXI.MovieClip.prototype);

Penguin.prototype.switchToSurpriseFrames = function(){
  this.textures = this.penguinSurpriseTextures;
  this.play();
}
Penguin.prototype.switchToNormalFrames  = function(){
  this.textures = this.penguinTextures;
  this.play();
}
Penguin.prototype.reset = function(){
  this.position.y = 300;
  this.scale.x = penguin.scale.y = 0.35;
  this.movement.surprise = false;
  this.movement.stop = false;
  this.switchToNormalFrames();
  this.surpriseFramesLoaded=false;
}
Penguin.prototype.getSurprised = function(){
    var center = 400;
    var movePerFrame = 5;
    if(this.position.x < (center - movePerFrame) && !this.movement.stop){
      this.movement.right = true;
      this.movement.left  = false;
    }
    if(this.position.x > (center + movePerFrame) && !this.movement.stop){
      this.movement.right = false;
      this.movement.left  = true;
    }
    if(this.position.x >= center - movePerFrame && this.position.x <= center + movePerFrame){
      this.movement.right = false;
      this.movement.left  = false;
      this.movement.stop  = true;
      // change frames
      if(!this.surpriseFramesLoaded){
        this.switchToSurpriseFrames();
        this.surpriseFramesLoaded = true;
        this.rotation = 0;
      }
      else{
        this.scale.x = this.scale.y = (this.scale.x += 0.05);
        this.position.y += 15;
        if(this.scale.x >= 10){
          this.reset();
        }
      }
    }
}<commit_msg>Fix scale so face is always centered on 'surprise'<commit_after>function Penguin(textures) {
  this.penguinTextures         = loadFrames();
  this.penguinSurpriseTextures = loadSurpriseFrames();
  var penguinStage            = new PIXI.Stage();

  PIXI.MovieClip.call(this,this.penguinTextures);

  this.animationSpeed  = 0.05;
  this.position.x =  150;
  this.position.y =  300;
  this.scale.x    =  0.35;
  this.scale.y    =  0.35;
  this.anchor.x   = 0.5;
  this.anchor.y   = 1;
  this.movement   = { up:false, down:false, left:false, right:false, waddleRight:false, surprise:false, stop:false };
  this.surpriseFramesLoaded = false;

  this.gotoAndPlay(0);
  penguinStage.addChild(this);

  function loadFrames()
  {
    var penguinTextures = [];
    var len             = 4;
    var i               = 0;
    var texture         = null;

    for(;i<len;i++){
      texture = PIXI.Texture.fromImage("images/frame_" + i + "_512x512.png");
      penguinTextures.push(texture);
    }
    for(i=3;i>=0;i--){
      texture = PIXI.Texture.fromImage("images/frame_" + i + "_512x512.png");
      penguinTextures.push(texture);
    }

    return penguinTextures;
  }

  function loadSurpriseFrames()
  {
    var penguinTextures = [];
    var len             = 9;
    var i               = 0;
    var texture         = null;

    for(;i<len;i++){
      texture = PIXI.Texture.fromImage("images/surprise_frame_" + i + "_512x512.png");
      penguinTextures.push(texture);
    }

    return penguinTextures;
  }
}

Penguin.constructor = Penguin;
Penguin.prototype   = Object.create(PIXI.MovieClip.prototype);

Penguin.prototype.switchToSurpriseFrames = function(){
  this.textures = this.penguinSurpriseTextures;
  this.play();
}
Penguin.prototype.switchToNormalFrames  = function(){
  this.textures = this.penguinTextures;
  this.play();
}
Penguin.prototype.reset = function(){
  this.position.y = 300;
  this.scale.x = penguin.scale.y = 0.35;
  this.movement.surprise = false;
  this.movement.stop = false;
  this.switchToNormalFrames();
  this.surpriseFramesLoaded=false;
}
Penguin.prototype.getSurprised = function(){
    var center = 400;
    var movePerFrame = 5;
    if(this.position.x < (center - movePerFrame) && !this.movement.stop){
      this.movement.right = true;
      this.movement.left  = false;
    }
    if(this.position.x > (center + movePerFrame) && !this.movement.stop){
      this.movement.right = false;
      this.movement.left  = true;
    }
    if(this.position.x >= center - movePerFrame && this.position.x <= center + movePerFrame){
      this.movement.right = false;
      this.movement.left  = false;
      this.movement.stop  = true;
      // change frames
      if(!this.surpriseFramesLoaded){
        this.switchToSurpriseFrames();
        this.surpriseFramesLoaded = true;
        this.rotation = 0;
      }
      else{
        this.scale.x = this.scale.y = Math.abs(this.scale.x += 0.05);
        this.position.y += 15;
        if(this.scale.x >= 10){
          this.reset();
        }
      }
    }
}
{'fraction_non_alphanumeric': 0.13791382465479954, 'fraction_numerical': 0.02029612377308268, 'mean_word_length': 2.5828367103694876, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '465363', 'n_tokens_mistral': 2219, 'n_tokens_neox': 2057, 'n_words': 340}