<commit_before>var MENU_STATE_00 = 0;
var MENU_STATE_01 = 1;
var MENU_STATE_02 = 2;

var PLAY_STATE = 3;
var GAMEOVER_STATE = 4;
var WIN_STATE = 5;

var BABBY_COUNT = 1;

var the_gameState = MENU_STATE_00;
var the_babbySpiders = new Array(BABBY_COUNT);
var the_spider = null;
var the_font;
var the_ground;
var the_grass;
var the_pink;
var the_keyboardImage;
var the_babbyImage;
var the_body0Image;
var the_body1Image;
var the_headImage;
var the_leg0Image;
var the_leg1Image;
var the_leg2Image;
var the_mandibleImage;

var the_transitionTimer = 2;
var the_screen_offset = 0;
var the_screenShakeTimer = 0;
var the_doOnce = true;
var the_canvas = null;
var the_fullscreenIcon;

function preload() 
{
  the_grass = loadImage("grass.png");
  the_keyboardImage = loadImage("keyboard.png");
  the_pink = loadImage("background.png"); 
  the_font = loadFont("AmaticSC-Regular.ttf");
  the_babbyImage = loadImage("babby.png");
  the_body0Image = loadImage("body0.png");
  the_body1Image = loadImage("body1.png");
  the_headImage = loadImage("head.png");
  the_leg0Image = loadImage("leg0.png");
  the_leg1Image = loadImage("leg1.png");
  the_leg2Image = loadImage("leg2.png");
  the_mandibleImage = loadImage("mandible.png");
}

function scaleToWindow()
{ 
  var aspectCorrectScale = window.innerWidth / 800.0;
  var heightScale = window.innerHeight / 600.0;
  if (heightScale < aspectCorrectScale)
    aspectCorrectScale = heightScale;

  document.getElementById("defaultCanvas0").style.width = 800.0 * aspectCorrectScale;
  document.getElementById("defaultCanvas0").style.height = 600.0 * aspectCorrectScale;
  document.getElementById("defaultCanvas0").style.marginLeft = "auto";
  document.getElementById("defaultCanvas0").style.marginRight = "auto";
}

window.onresize = function() 
{ 
  scaleToWindow();
}

function gameStart()
{
  the_transitionTimer = 2;
  the_gameState = PLAY_STATE;
  stroke(255, 100);
  the_spider = new Spider();
}

function setup() 
{
  MENU_STATE_00 = 0;
  MENU_STATE_01 = 1;
  MENU_STATE_02 = 2;
  PLAY_STATE = 3;
  GAMEOVER_STATE = 4;
  WIN_STATE = 5;
  BABBY_COUNT = 1;
  the_gameState = MENU_STATE_00;  
  the_babbySpiders = new Array(BABBY_COUNT);
  the_screenShakeTimer = 0;
  the_transitionTimer = 2;
  the_doOnce = true;
  the_canvas = createCanvas(800, 600);
  scaleToWindow();
  
  the_fullscreenIcon = new FullscreenIcon(width - 20, height - 20, 12);
  
  frameRate(30);
  the_ground = height-35;
  //the_grass = requestImage("grass.png");
  //the_font = createFont("Amatic SC Regular", 32);
  //the_keyboardImage = requestImage("keyboard.png");
  //the_pink = requestImage("background.png");
}

function draw() 
{
  //push();
  //scale((width / 800.0), (width / 800.0));
  if (the_gameState == MENU_STATE_00)
  {
    drawGradient(0, width, 0, height, 120);
    textFont(the_font);
    textAlign(CENTER, CENTER);
    textSize(128);
    fill("#3a0e05");
    text("SPIDREN", width/2 + random(-5, 5), height/2 + random(-5, 5));
    textSize(64);
    text("@devonsoft", width/2 + random(-5, 5), height/2 + random(-5, 5) + 100);
  } 
  else if (the_gameState == MENU_STATE_01)
  {
    drawGradient(0, width, 0, height, 255);
    if (the_keyboardImage.width > 0)
    {
      imageMode(CORNER);
      image(the_keyboardImage, 0, 0, width, height);
    }
  } 
  else if (the_gameState == MENU_STATE_02)
  {
    drawGradient(0, width, 0, height, 255);
    textFont(the_font);
    textAlign(CENTER, CENTER);
    textSize(128);
    fill("#3a0e05");
    textSize(64);
    text("FOCUS ON ONE LEG AT A TIME (R + D, C)", width/2 + random(-5, 5), height/2 + random(-5, 5));
    textSize(32);
    text("most keyboards do not allow enough simultaneous keys for more than one leg", width/2, height/2 + 50);
  } 
  else if (the_gameState == PLAY_STATE)
  {
    if (the_doOnce)
    {
      gameStart();
      the_doOnce = false;
    }
    push();
    translate(random(-the_screen_offset, the_screen_offset), random(-the_screen_offset, the_screen_offset));
    drawGradient(0, width, 0, height, 255);

    the_spider.draw();
    var deadBabbyCount = 0;
    for (var i = the_babbySpiders.length-1; i >= 0 && !the_spider.buttExploding; i--)
    {
      the_babbySpiders[i].draw();
      if (the_babbySpiders[i].isDead)
        deadBabbyCount += 1;
    }
    if (deadBabbyCount >= BABBY_COUNT)
    {
      the_gameState = WIN_STATE;

      if (BABBY_COUNT < 3)
        BABBY_COUNT += 1;
      else if (BABBY_COUNT < 7)
        BABBY_COUNT += 2;
      else if (BABBY_COUNT >= 7)
        BABBY_COUNT *= 2;
      the_babbySpiders = new Array(BABBY_COUNT);
    } else
    {     
      for (var i = 0; i < the_babbySpiders.length && !the_spider.buttExploding; i++)
      {
        var isFeeding = false;
        var isHit = false;
        babby = the_babbySpiders[i];
        for (var j = 0; j < the_spider.m_legs.length; j++)
        {
          leg = the_spider.m_legs[j];

          var isOverlapping = false;
          if (!leg.m_isReaching && !babby.isStabbed && (babby.y >= the_ground || babby.carriedSegment == null)) 
            isOverlapping = leg.isOverlappingTipSegment(babby);

          /*if (!isOverlapping && the_spider.tipCount == 1 && !babby.isStabbed && dist(babby.x, babby.y, leg.m_segments[2].m_x, leg.m_segments[2].m_y) < babby.radius * 3)
           {
           isOverlapping = true;
           }
           else
           println("not dist" + frameCount);*/

          if (isOverlapping)
          {
            if (leg.m_dx != 0)
            { 
              isHit = true;
              babby.speed = 20;
              babby.x += leg.m_dx;
              if (leg.m_dx > 0)
                babby.direction.x = 1;
              else if (leg.m_dx < 0)
                babby.direction.x = -1;
            } else if (babby.speed <= babby.normalSpeed ||  the_spider.tipCount == 1)
            {
              isFeeding = true;

              if (babby.isClimbing)
              {
                babby.stabLeg = null;
                babby.isClimbing = false;
              }
              if (babby.carriedSegment == null && dist(babby.x, babby.y, leg.m_segments[2].m_x, leg.m_segments[2].m_y) < babby.radius)
              { 
                leg.shouldRemoveHealth = true;

                //leg.health -= 0.02;
              }

              babby.stabLeg = leg;

              if (leg.health <= 0)
              {
                babby.stabLeg = null;
                isFeeding = false;
                the_screenShakeTimer = 0.75;
                if (leg.stabbedBabby != null)
                {
                  leg.stabbedBabby.isDead = true;
                }

                babby.carriedSegment = leg.getTipSegment();
                leg.getTipSegment().isBeingCarried = true;
                leg.getTipSegment().m_angle = -HALF_PI;
              }
            }
          } else if (leg.m_isReaching && leg.stabbedBabby == null && leg.getTipSegment().isBeingCarried == false)
          {
            isOverlapping = dist(leg.m_tipX, leg.m_tipY, babby.x, babby.y) < babby.radius * 2;
            if (isOverlapping)
            {
              babby.isStabbed = true;
              babby.isClimbing = false;
              if (babby.carriedSegment != null)
              {
                babby.carriedSegment.isBeingCarried = false;
              }
              babby.stabLeg = leg;
              leg.stabbedBabby = babby;
            }
          } else if (the_spider.tipCount == 1 && !babby.isFeeding && !babby.isStabbed)
          {
            if (!leg.isBeingCarried())
            {
              var distSQ = (leg.m_tipX - babby.x) * (leg.m_tipX - babby.x);
              if (distSQ < babby.speed * babby.speed)
              {
                babby.isClimbing = true;
                babby.stabLeg = leg;
              }
            }
          }
        }
        babby.isFeeding = isFeeding;
        if (isHit)
          babby.isFeeding = false;
      }
    }
    imageMode(CORNER);
    if (the_grass.width > 0)
    {
      var h =  float(width) / float(the_grass.width) * the_grass.height;
      image(the_grass, 0, height - h + 8, width, h);
    }

    imageMode(CENTER);
    push();
    translate(the_spider.x, the_spider.y);
    scale(0.5, 0.5);
    if (the_spider.mandible.startFrame == 1)
      the_spider.mandible.draw();
    pop();

    the_screenShakeTimer -= 1 / 30.0;
    //print(the_screenShakeTimer);
    if (the_screenShakeTimer > 0)
    {
      //imageMode(CENTER);
      the_screen_offset = 20.0 * the_screenShakeTimer;
      //print(offset);
      //the_screen = get(0, 0, 45, 45);
      //image(the_screen, width/2 +random(-offset, offset), height/2+random(-offset, offset));
    } else
      the_screen_offset = 0.0;
    pop();
  } else if (the_gameState == GAMEOVER_STATE)
  {
    the_transitionTimer -= 1 / 30.0;
    if (the_transitionTimer > 0)
    {
      drawGradient(0, width, 0, height, 10);
    } else
    {
      drawGradient(0, width, 0, height, 120);
      textFont(the_font);
      textAlign(CENTER, CENTER);
      textSize(80);
      fill("#3a0e05");

      text("THE CHILD BECOMES THE PARENT", width/2 + random(-5, 5), height/2 + random(-5, 5));
    }
  } else if (the_gameState == WIN_STATE)
  {
    the_transitionTimer -= 1 / 30.0;
    if (the_transitionTimer > 0)
    {
      drawGradient(0, width, 0, height, 10);
    } else
    {
      drawGradient(0, width, 0, height, 120);
      textFont(the_font);
      textAlign(CENTER, CENTER);
      textSize(80);
      fill("#3a0e05");
      text("YOU CAN BREED AGAIN", width/2 + random(-5, 5), height/2 + random(-5, 5));
    }
  }
  
  the_fullscreenIcon.draw();
  
  /*textFont("Arial");
  textAlign(RIGHT, TOP);
  textSize(80);
  fill(255, 255, 255);

  text(int(frameRate()), width - 12, 0);*/
  //pop();
}

function mouseReleased()
{
  if (the_gameState < PLAY_STATE)
  {
    the_gameState++;
  } else if (the_gameState > PLAY_STATE && the_transitionTimer <= 0)
  {
    the_gameState = PLAY_STATE;
    the_doOnce = true;
  }
  
  if (the_fullscreenIcon)
  {
    the_fullscreenIcon.setFullscreen();
  }
}

function keyPressed()
{
  if (the_gameState < PLAY_STATE)
  {
    return;
  } else if (the_gameState > PLAY_STATE)
  {
    return;
  }
  print(key);

  if (key == 't' || key == 'T')
    the_spider.m_legs[0].pressBkeyutton(0);
  else if (key == 'f' || key == 'F')
    the_spider.m_legs[0].pressButton(1); 
  else if (key == 'v' || key == 'V')
    the_spider.m_legs[0].pressButton(2);

  else if (key == 'y' || key == 'Y')
    the_spider.m_legs[1].pressButton(0);
  else if (key == 'j' || key == 'J')
    the_spider.m_legs[1].pressButton(1);
  else if (key == 'n' || key == 'N')
    the_spider.m_legs[1].pressButton(2);<commit_msg>keycode fix<commit_after>var MENU_STATE_00 = 0;
var MENU_STATE_01 = 1;
var MENU_STATE_02 = 2;

var PLAY_STATE = 3;
var GAMEOVER_STATE = 4;
var WIN_STATE = 5;

var BABBY_COUNT = 1;

var the_gameState = MENU_STATE_00;
var the_babbySpiders = new Array(BABBY_COUNT);
var the_spider = null;
var the_font;
var the_ground;
var the_grass;
var the_pink;
var the_keyboardImage;
var the_babbyImage;
var the_body0Image;
var the_body1Image;
var the_headImage;
var the_leg0Image;
var the_leg1Image;
var the_leg2Image;
var the_mandibleImage;

var the_transitionTimer = 2;
var the_screen_offset = 0;
var the_screenShakeTimer = 0;
var the_doOnce = true;
var the_canvas = null;
var the_fullscreenIcon;

function preload() 
{
  the_grass = loadImage("grass.png");
  the_keyboardImage = loadImage("keyboard.png");
  the_pink = loadImage("background.png"); 
  the_font = loadFont("AmaticSC-Regular.ttf");
  the_babbyImage = loadImage("babby.png");
  the_body0Image = loadImage("body0.png");
  the_body1Image = loadImage("body1.png");
  the_headImage = loadImage("head.png");
  the_leg0Image = loadImage("leg0.png");
  the_leg1Image = loadImage("leg1.png");
  the_leg2Image = loadImage("leg2.png");
  the_mandibleImage = loadImage("mandible.png");
}

function scaleToWindow()
{ 
  var aspectCorrectScale = window.innerWidth / 800.0;
  var heightScale = window.innerHeight / 600.0;
  if (heightScale < aspectCorrectScale)
    aspectCorrectScale = heightScale;

  document.getElementById("defaultCanvas0").style.width = 800.0 * aspectCorrectScale;
  document.getElementById("defaultCanvas0").style.height = 600.0 * aspectCorrectScale;
  document.getElementById("defaultCanvas0").style.marginLeft = "auto";
  document.getElementById("defaultCanvas0").style.marginRight = "auto";
}

window.onresize = function() 
{ 
  scaleToWindow();
}

function gameStart()
{
  the_transitionTimer = 2;
  the_gameState = PLAY_STATE;
  stroke(255, 100);
  the_spider = new Spider();
}

function setup() 
{
  MENU_STATE_00 = 0;
  MENU_STATE_01 = 1;
  MENU_STATE_02 = 2;
  PLAY_STATE = 3;
  GAMEOVER_STATE = 4;
  WIN_STATE = 5;
  BABBY_COUNT = 1;
  the_gameState = MENU_STATE_00;  
  the_babbySpiders = new Array(BABBY_COUNT);
  the_screenShakeTimer = 0;
  the_transitionTimer = 2;
  the_doOnce = true;
  the_canvas = createCanvas(800, 600);
  scaleToWindow();
  
  the_fullscreenIcon = new FullscreenIcon(width - 20, height - 20, 12);
  
  frameRate(30);
  the_ground = height-35;
  //the_grass = requestImage("grass.png");
  //the_font = createFont("Amatic SC Regular", 32);
  //the_keyboardImage = requestImage("keyboard.png");
  //the_pink = requestImage("background.png");
}

function draw() 
{
  //push();
  //scale((width / 800.0), (width / 800.0));
  if (the_gameState == MENU_STATE_00)
  {
    drawGradient(0, width, 0, height, 120);
    textFont(the_font);
    textAlign(CENTER, CENTER);
    textSize(128);
    fill("#3a0e05");
    text("SPIDREN", width/2 + random(-5, 5), height/2 + random(-5, 5));
    textSize(64);
    text("@devonsoft", width/2 + random(-5, 5), height/2 + random(-5, 5) + 100);
  } 
  else if (the_gameState == MENU_STATE_01)
  {
    drawGradient(0, width, 0, height, 255);
    if (the_keyboardImage.width > 0)
    {
      imageMode(CORNER);
      image(the_keyboardImage, 0, 0, width, height);
    }
  } 
  else if (the_gameState == MENU_STATE_02)
  {
    drawGradient(0, width, 0, height, 255);
    textFont(the_font);
    textAlign(CENTER, CENTER);
    textSize(128);
    fill("#3a0e05");
    textSize(64);
    text("FOCUS ON ONE LEG AT A TIME (R + D, C)", width/2 + random(-5, 5), height/2 + random(-5, 5));
    textSize(32);
    text("most keyboards do not allow enough simultaneous keys for more than one leg", width/2, height/2 + 50);
  } 
  else if (the_gameState == PLAY_STATE)
  {
    if (the_doOnce)
    {
      gameStart();
      the_doOnce = false;
    }
    push();
    translate(random(-the_screen_offset, the_screen_offset), random(-the_screen_offset, the_screen_offset));
    drawGradient(0, width, 0, height, 255);

    the_spider.draw();
    var deadBabbyCount = 0;
    for (var i = the_babbySpiders.length-1; i >= 0 && !the_spider.buttExploding; i--)
    {
      the_babbySpiders[i].draw();
      if (the_babbySpiders[i].isDead)
        deadBabbyCount += 1;
    }
    if (deadBabbyCount >= BABBY_COUNT)
    {
      the_gameState = WIN_STATE;

      if (BABBY_COUNT < 3)
        BABBY_COUNT += 1;
      else if (BABBY_COUNT < 7)
        BABBY_COUNT += 2;
      else if (BABBY_COUNT >= 7)
        BABBY_COUNT *= 2;
      the_babbySpiders = new Array(BABBY_COUNT);
    } else
    {     
      for (var i = 0; i < the_babbySpiders.length && !the_spider.buttExploding; i++)
      {
        var isFeeding = false;
        var isHit = false;
        babby = the_babbySpiders[i];
        for (var j = 0; j < the_spider.m_legs.length; j++)
        {
          leg = the_spider.m_legs[j];

          var isOverlapping = false;
          if (!leg.m_isReaching && !babby.isStabbed && (babby.y >= the_ground || babby.carriedSegment == null)) 
            isOverlapping = leg.isOverlappingTipSegment(babby);

          /*if (!isOverlapping && the_spider.tipCount == 1 && !babby.isStabbed && dist(babby.x, babby.y, leg.m_segments[2].m_x, leg.m_segments[2].m_y) < babby.radius * 3)
           {
           isOverlapping = true;
           }
           else
           println("not dist" + frameCount);*/

          if (isOverlapping)
          {
            if (leg.m_dx != 0)
            { 
              isHit = true;
              babby.speed = 20;
              babby.x += leg.m_dx;
              if (leg.m_dx > 0)
                babby.direction.x = 1;
              else if (leg.m_dx < 0)
                babby.direction.x = -1;
            } else if (babby.speed <= babby.normalSpeed ||  the_spider.tipCount == 1)
            {
              isFeeding = true;

              if (babby.isClimbing)
              {
                babby.stabLeg = null;
                babby.isClimbing = false;
              }
              if (babby.carriedSegment == null && dist(babby.x, babby.y, leg.m_segments[2].m_x, leg.m_segments[2].m_y) < babby.radius)
              { 
                leg.shouldRemoveHealth = true;

                //leg.health -= 0.02;
              }

              babby.stabLeg = leg;

              if (leg.health <= 0)
              {
                babby.stabLeg = null;
                isFeeding = false;
                the_screenShakeTimer = 0.75;
                if (leg.stabbedBabby != null)
                {
                  leg.stabbedBabby.isDead = true;
                }

                babby.carriedSegment = leg.getTipSegment();
                leg.getTipSegment().isBeingCarried = true;
                leg.getTipSegment().m_angle = -HALF_PI;
              }
            }
          } else if (leg.m_isReaching && leg.stabbedBabby == null && leg.getTipSegment().isBeingCarried == false)
          {
            isOverlapping = dist(leg.m_tipX, leg.m_tipY, babby.x, babby.y) < babby.radius * 2;
            if (isOverlapping)
            {
              babby.isStabbed = true;
              babby.isClimbing = false;
              if (babby.carriedSegment != null)
              {
                babby.carriedSegment.isBeingCarried = false;
              }
              babby.stabLeg = leg;
              leg.stabbedBabby = babby;
            }
          } else if (the_spider.tipCount == 1 && !babby.isFeeding && !babby.isStabbed)
          {
            if (!leg.isBeingCarried())
            {
              var distSQ = (leg.m_tipX - babby.x) * (leg.m_tipX - babby.x);
              if (distSQ < babby.speed * babby.speed)
              {
                babby.isClimbing = true;
                babby.stabLeg = leg;
              }
            }
          }
        }
        babby.isFeeding = isFeeding;
        if (isHit)
          babby.isFeeding = false;
      }
    }
    imageMode(CORNER);
    if (the_grass.width > 0)
    {
      var h =  float(width) / float(the_grass.width) * the_grass.height;
      image(the_grass, 0, height - h + 8, width, h);
    }

    imageMode(CENTER);
    push();
    translate(the_spider.x, the_spider.y);
    scale(0.5, 0.5);
    if (the_spider.mandible.startFrame == 1)
      the_spider.mandible.draw();
    pop();

    the_screenShakeTimer -= 1 / 30.0;
    //print(the_screenShakeTimer);
    if (the_screenShakeTimer > 0)
    {
      //imageMode(CENTER);
      the_screen_offset = 20.0 * the_screenShakeTimer;
      //print(offset);
      //the_screen = get(0, 0, 45, 45);
      //image(the_screen, width/2 +random(-offset, offset), height/2+random(-offset, offset));
    } else
      the_screen_offset = 0.0;
    pop();
  } else if (the_gameState == GAMEOVER_STATE)
  {
    the_transitionTimer -= 1 / 30.0;
    if (the_transitionTimer > 0)
    {
      drawGradient(0, width, 0, height, 10);
    } else
    {
      drawGradient(0, width, 0, height, 120);
      textFont(the_font);
      textAlign(CENTER, CENTER);
      textSize(80);
      fill("#3a0e05");

      text("THE CHILD BECOMES THE PARENT", width/2 + random(-5, 5), height/2 + random(-5, 5));
    }
  } else if (the_gameState == WIN_STATE)
  {
    the_transitionTimer -= 1 / 30.0;
    if (the_transitionTimer > 0)
    {
      drawGradient(0, width, 0, height, 10);
    } else
    {
      drawGradient(0, width, 0, height, 120);
      textFont(the_font);
      textAlign(CENTER, CENTER);
      textSize(80);
      fill("#3a0e05");
      text("YOU CAN BREED AGAIN", width/2 + random(-5, 5), height/2 + random(-5, 5));
    }
  }
  
  the_fullscreenIcon.draw();
  
  /*textFont("Arial");
  textAlign(RIGHT, TOP);
  textSize(80);
  fill(255, 255, 255);

  text(int(frameRate()), width - 12, 0);*/
  //pop();
}

function mouseReleased()
{
  if (the_gameState < PLAY_STATE)
  {
    the_gameState++;
  } else if (the_gameState > PLAY_STATE && the_transitionTimer <= 0)
  {
    the_gameState = PLAY_STATE;
    the_doOnce = true;
  }
  
  if (the_fullscreenIcon)
  {
    the_fullscreenIcon.setFullscreen();
  }
}

function keyPressed()
{
  if (the_gameState < PLAY_STATE)
  {
    return;
  } else if (the_gameState > PLAY_STATE)
  {
    return;
  }
  //print(key);

  if (key == 't' || key == 'T')
    the_spider.m_legs[0].pressBkeyutton(0);
  else if (key == 'f' || key == 'F')
    the_spider.m_legs[0].pressButton(1); 
  else if (key == 'v' || key == 'V')
    the_spider.m_legs[0].pressButton(2);

  else if (key == 'y' || key == 'Y')
    the_spider.m_legs[1].pressButton(0);
  else if (key == 'j' || key == 'J')
    the_spider.m_legs[1].pressButton(1);
  else if (key == 'n' || key == 'N')
    the_spider.m_legs[1].pressButton(2);
{'fraction_non_alphanumeric': 0.13638495450708188, 'fraction_numerical': 0.02973454647781634, 'mean_word_length': 2.3285981891976273, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 27, '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': '6011551', 'n_tokens_mistral': 8264, 'n_tokens_neox': 7601, 'n_words': 1496}