<commit_before>import Phaser from 'phaser';

import Behaviour from './Behaviour';

const SIDEWAYS_FRICTION = 0.987;
const IMMOBILISE_LERP = 0.007;
const STOP_OFFSET = 1.5;
const MAX_THRUST_DELAY = 1550;
const MAX_THRUST_RATE = 0.95;
const ROTATION_THRUST_FRICTION = 0.55;

export default class extends Behaviour {

  constructor(game, owner) {
    super(game, owner);

    this.cursors = game.input.keyboard.createCursorKeys();
    this.initKeyboard();
    this.thrustDownAt = 0;
  }

  initKeyboard() {
    this.key_left = this.game.input.keyboard.addKey(Phaser.Keyboard.LEFT);
    this.key_right = this.game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);
    this.key_thrust = this.game.input.keyboard.addKey(Phaser.Keyboard.UP);
    this.key_reverse = this.game.input.keyboard.addKey(Phaser.Keyboard.DOWN);
  }

  update() {
    // Move
    if (this.key_left.isDown || this.key_right.isDown) {
      let rotationSpeed = this.owner.movement.rotationSpeed;
      if (this.key_thrust.isDown) {
        rotationSpeed *= ROTATION_THRUST_FRICTION;
      }
      if (this.key_left.isDown) {
        this.owner.body.angularVelocity = -rotationSpeed;
      } else {
        this.owner.body.angularVelocity = rotationSpeed;
      }
    } else {
      this.owner.body.angularVelocity = 0;
    }

    if (this.key_thrust.isDown) {
      if (this.thrustDownAt === 0) {
        this.thrustDownAt = this.game.time.now;
      }

      const magnitude = this.owner.body.velocity.getMagnitude();
      this.game.physics.arcade.accelerationFromRotation(this.owner.rotation,
                                                        this.owner.movement.acceleration,
                                                        this.owner.body.acceleration);
      this.owner.body.velocity.setMagnitude(Math.min(this.owner.movement.maxVelocity,
                                                     magnitude));

      if (((magnitude / this.owner.movement.maxVelocity) >
           MAX_THRUST_RATE) ||
          ((this.game.time.now - this.thrustDownAt) > MAX_THRUST_DELAY)) {
        this.owner.frame = 2;<commit_msg>Add turn friction on reverse<commit_after>import Phaser from 'phaser';

import Behaviour from './Behaviour';

const SIDEWAYS_FRICTION = 0.987;
const IMMOBILISE_LERP = 0.007;
const STOP_OFFSET = 1.5;
const MAX_THRUST_DELAY = 1550;
const MAX_THRUST_RATE = 0.95;
const ROTATION_THRUST_FRICTION = 0.45;

export default class extends Behaviour {

  constructor(game, owner) {
    super(game, owner);

    this.cursors = game.input.keyboard.createCursorKeys();
    this.initKeyboard();
    this.thrustDownAt = 0;
  }

  initKeyboard() {
    this.key_left = this.game.input.keyboard.addKey(Phaser.Keyboard.LEFT);
    this.key_right = this.game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);
    this.key_thrust = this.game.input.keyboard.addKey(Phaser.Keyboard.UP);
    this.key_reverse = this.game.input.keyboard.addKey(Phaser.Keyboard.DOWN);
  }

  update() {
    // Move
    if (this.key_left.isDown || this.key_right.isDown) {
      let rotationSpeed = this.owner.movement.rotationSpeed;
      if (this.key_thrust.isDown || this.key_reverse.isDown) {
        rotationSpeed *= ROTATION_THRUST_FRICTION;
      }
      if (this.key_left.isDown) {
        this.owner.body.angularVelocity = -rotationSpeed;
      } else {
        this.owner.body.angularVelocity = rotationSpeed;
      }
    } else {
      this.owner.body.angularVelocity = 0;
    }

    if (this.key_thrust.isDown) {
      if (this.thrustDownAt === 0) {
        this.thrustDownAt = this.game.time.now;
      }

      const magnitude = this.owner.body.velocity.getMagnitude();
      this.game.physics.arcade.accelerationFromRotation(this.owner.rotation,
                                                        this.owner.movement.acceleration,
                                                        this.owner.body.acceleration);
      this.owner.body.velocity.setMagnitude(Math.min(this.owner.movement.maxVelocity,
                                                     magnitude));

      if (((magnitude / this.owner.movement.maxVelocity) >
           MAX_THRUST_RATE) ||
          ((this.game.time.now - this.thrustDownAt) > MAX_THRUST_DELAY)) {
        this.owner.frame = 2;
{'fraction_non_alphanumeric': 0.11542100283822138, 'fraction_numerical': 0.011352885525070956, 'mean_word_length': 2.3643595863166267, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3188352', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1354, 'n_words': 194}