<commit_before>_ = require('lodash')
helper = require('./helpers');


_calculateInitialVelocity= (direction, initialSpeed, initialVelocity)->
  x = Math.cos(direction)
  y = Math.sin(direction)
  helper.addVectors(helper.multVector([x, y], initialSpeed), initialVelocity)


lastBulletId = 1

class Bullet
  constructor: (options = {})->
    defaultOptions =
      position: [Math.random(), Math.random()]
      velocity: [0.08, 0.09]
      maxLifeTime: 1
      direction: null
      shipId: 0
      active: true
      timeSinceStart: 0

    options = _.merge(defaultOptions, options)

    @maxTravelDistance = options.maxTravelDistance
    @position = options.position
    @shipId = options.shipId
    @maxLifeTime = options.maxLifeTime
    @velocity = _calculateInitialVelocity(options.direction,
                                          options.initialSpeed,
                                          options.velocity)
    @active = options.active

    @id= lastBulletId++

    console.log("created bullet with velocity: #{@velocity} position: #{@position} initialPosition: #{@initialPosition}")

  serialize: ->
    id: @id
    position: @position
    velocity: @velocity

  markForDeletion: ->
    @active = false

  isMarkedForDeletion: ->
    !@active

  runFrame: (timeDiff)->
    timeSinceStart += timeDiff
    velocityWithTime = helper.multVector(@velocity, timeDiff)
    @position = helper.addVectors(@position, velocityWithTime)

    @position[0] = @position[0] % 1
    @position[0] = 1 - @position[0] if @position[0] < 0
    @position[1] = @position[1] % 1
    @position[1] = 1 - @position[1] if @position[1] < 0

    @velocity[0] = Math.max(-1, Math.min(@velocity[0], 1));
    @velocity[1] = Math.max(-1, Math.min(@velocity[1], 1));
    needToRemove = timeSinceStart > @maxLifeTime
    console.log("Need to remove bullet") if needToRemove
    @markForDeletion() if needToRemove
    console.log("bullet moved to #{@position} with velocity #{@velocity}")



module.exports = Bullet<commit_msg>Fixed typo<commit_after>_ = require('lodash')
helper = require('./helpers');


_calculateInitialVelocity= (direction, initialSpeed, initialVelocity)->
  x = Math.cos(direction)
  y = Math.sin(direction)
  helper.addVectors(helper.multVector([x, y], initialSpeed), initialVelocity)


lastBulletId = 1

class Bullet
  constructor: (options = {})->
    defaultOptions =
      position: [Math.random(), Math.random()]
      velocity: [0.08, 0.09]
      maxLifeTime: 1
      direction: null
      shipId: 0
      active: true
      timeSinceStart: 0

    options = _.merge(defaultOptions, options)

    @timeSinceStart = options.timeSinceStart
    @position = options.position
    @shipId = options.shipId
    @maxLifeTime = options.maxLifeTime
    @velocity = _calculateInitialVelocity(options.direction,
                                          options.initialSpeed,
                                          options.velocity)
    @active = options.active

    @id= lastBulletId++

    console.log("created bullet with velocity: #{@velocity} position: #{@position} initialPosition: #{@initialPosition}")

  serialize: ->
    id: @id
    position: @position
    velocity: @velocity

  markForDeletion: ->
    @active = false

  isMarkedForDeletion: ->
    !@active

  runFrame: (timeDiff)->
    @timeSinceStart += timeDiff
    velocityWithTime = helper.multVector(@velocity, timeDiff)
    @position = helper.addVectors(@position, velocityWithTime)

    @position[0] = @position[0] % 1
    @position[0] = 1 - @position[0] if @position[0] < 0
    @position[1] = @position[1] % 1
    @position[1] = 1 - @position[1] if @position[1] < 0

    @velocity[0] = Math.max(-1, Math.min(@velocity[0], 1));
    @velocity[1] = Math.max(-1, Math.min(@velocity[1], 1));
    needToRemove = @timeSinceStart > @maxLifeTime
    console.log("Need to remove bullet") if needToRemove
    @markForDeletion() if needToRemove
    console.log("bullet moved to #{@position} with velocity #{@velocity}")



module.exports = Bullet
{'fraction_non_alphanumeric': 0.13290032475643268, 'fraction_numerical': 0.0169872595553335, 'mean_word_length': 3.1363636363636362, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3982940', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1194, 'n_words': 272}