<commit_before>'use strict';

import { Phaser } from 'phaser';

import { Shape, ShapeColors } from 'grid-util';

class GridEntity {
  constructor(game, grid, pos, color, shape) {
    this.game = game;
    this.grid = grid;

    // 'real' position on the grid (for collisions and stuff)
    this.pos = pos;

    // 'fake' position on the grid (for drawing and stuff)
    this.fakePos = null;

    this.color = color;

    this.shape = shape;
  }

  advance(tweenTime) {

  }

  update() {

  }

  draw(graphics) {
    const dispPos = this.fakePos || this.pos;
    const size = this.grid.squareSize;
    const pixpos = this.grid.gridToPixelPos(dispPos);

    graphics.beginFill(this.color);
    switch (this.shape || this.grid.getShapeAt(dispPos)) {
      case Shape.SQUARE:
        graphics.drawRect(pixpos.x - size / 2,
                          pixpos.y - size / 2,
                          size, size);
        break;
      case Shape.CIRCLE:
        graphics.drawCircle(pixpos.x, pixpos.y, size);
        break;
      default:
        break;
    }
    graphics.endFill();
  }
}

class EnemyGridEntity extends GridEntity {
  constructor(game, grid, pos, shape) {
    const color = ShapeColors[shape];
    super(game, grid, pos, color, shape);
  }

  advance(beatTime) {
    this.fakePos = {
      x: this.pos.x,
      y: this.pos.y,
    };
    this.game.add.tween(this.fakePos)
                 .to({ y: this.pos.y + 1 }, beatTime / 2.0, Phaser.Easing.Exponential.In, true)
                 .delay(beatTime / 2.0)
                 .onComplete.add(() => {
                   this.pos.y = this.fakePos.y;
                   this.fakePos = null;
                 });
  }

  collides(player, shouldShapesMatch) {
    let colliding = false;
    let shapesMatch = true;
    if (!this.fakePos) {
      if (this.pos.x === player.pos.x && this.pos.y === player.pos.y) {
        colliding = true;
        shapesMatch = this.shape === this.grid.getShapeAt(this.pos);
      }
    } else {
      // Do some special logic because we're moving
      const halfWayDown = (this.fakePos.y - this.pos.y) > 0.5;
      if (!halfWayDown) {
        // Use our old position to check collisions
        if (this.pos.x === player.pos.x && this.pos.y === player.pos.y) {
          colliding = true;
          shapesMatch = this.shape === this.grid.getShapeAt(this.pos);
        }
      } else {
        // User our new position to check collisions
        if (this.pos.x === player.pos.x && this.pos.y + 1 === player.pos.y) {
          colliding = true;
          shapesMatch = this.shape === this.grid.getShapeAt({ x: this.pos.x, y: this.pos.y + 1 });
        }
      }
    }<commit_msg>Byebye tweening<commit_after>'use strict';

import { Phaser } from 'phaser';

import { Shape, ShapeColors } from 'grid-util';

class GridEntity {
  constructor(game, grid, pos, color, shape) {
    this.game = game;
    this.grid = grid;

    // 'real' position on the grid (for collisions and stuff)
    this.pos = pos;

    // 'fake' position on the grid (for drawing and stuff)
    this.fakePos = null;

    this.color = color;

    this.shape = shape;
  }

  advance(tweenTime) {

  }

  update() {

  }

  draw(graphics) {
    const dispPos = this.fakePos || this.pos;
    const size = this.grid.squareSize;
    const pixpos = this.grid.gridToPixelPos(dispPos);

    graphics.beginFill(this.color);
    switch (this.shape || this.grid.getShapeAt(dispPos)) {
      case Shape.SQUARE:
        graphics.drawRect(pixpos.x - size / 2,
                          pixpos.y - size / 2,
                          size, size);
        break;
      case Shape.CIRCLE:
        graphics.drawCircle(pixpos.x, pixpos.y, size);
        break;
      default:
        break;
    }
    graphics.endFill();
  }
}

class EnemyGridEntity extends GridEntity {
  constructor(game, grid, pos, shape) {
    const color = ShapeColors[shape];
    super(game, grid, pos, color, shape);
  }

  advance(beatTime) {
    this.pos.y++;
  }

  collides(player, shouldShapesMatch) {
    let colliding = false;
    let shapesMatch = true;
    if (!this.fakePos) {
      if (this.pos.x === player.pos.x && this.pos.y === player.pos.y) {
        colliding = true;
        shapesMatch = this.shape === this.grid.getShapeAt(this.pos);
      }
    } else {
      // Do some special logic because we're moving
      const halfWayDown = (this.fakePos.y - this.pos.y) > 0.5;
      if (!halfWayDown) {
        // Use our old position to check collisions
        if (this.pos.x === player.pos.x && this.pos.y === player.pos.y) {
          colliding = true;
          shapesMatch = this.shape === this.grid.getShapeAt(this.pos);
        }
      } else {
        // User our new position to check collisions
        if (this.pos.x === player.pos.x && this.pos.y + 1 === player.pos.y) {
          colliding = true;
          shapesMatch = this.shape === this.grid.getShapeAt({ x: this.pos.x, y: this.pos.y + 1 });
        }
      }
    }
{'fraction_non_alphanumeric': 0.13766653209527654, 'fraction_numerical': 0.003431570448122729, 'mean_word_length': 1.975975975975976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '4965319', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1614, 'n_words': 379}