<commit_before>Crafty.c 'PlayerSpaceship',
  init: ->
    @requires '2D, WebGL, playerShip, ColorEffects, Listener, Collision, SunBlock, WaterSplashes, PlayerControlledShip, Accelleration'
    @attr w: 71, h: 45
    #@addComponent 'SolidHitBox'
    @collision [
      21, 13
      56, 13
      66, 32
      35, 32
    ]

    @bind 'Moved', (from) ->
      if @hit('Edge') or @hit('Solid') # Contain player within playfield
        setBack = {}
        setBack[from.axis] = from.oldValue
        @attr setBack
    @primaryWeapon = undefined
    @primaryWeapons = []
    @secondaryWeapon = undefined
    @superUsed = 0
    @weaponsEnabled = yes
    @currentRenderedSpeed = 0

  _updateFlyingSpeed: (newSpeed, dt) ->
    if newSpeed < 50
      correction = newSpeed / 2
    else
      correction = 25 + ((newSpeed / 400) * 100)

    if @currentRenderedSpeed > correction
      @currentRenderedSpeed -= 4
    else if @currentRenderedSpeed < correction
      @currentRenderedSpeed += 4
    if @currentRenderedSpeed < 0
      @currentRenderedSpeed = 0

    w = @currentRenderedSpeed

    h = Math.min(w / 3, 15)
    @backFire.attr(
      x: @x - w + 9
      y: @y + 20 - (h // 2)
      w: w
      h: h
    )

  start: ->
    @backFire = Crafty.e('2D, WebGL, shipEngineFire, ColorEffects')
    @backFire.timing = 0
    w = 60
    h = 10

    @backFire.attr(
      x: @x - w + 9
      y: @y + 20 - (h // 2)
      w: w
      h: h
      alpha: .8
      z: @z - 1
    )
    @attach @backFire

    c = {}
    basicC = {
      _red: 255
      _green: 255
      _blue: 255
    }
    Crafty.assignColor(@playerColor, c)
    for comp in ['_red', '_green', '_blue']
      newC = (c[comp] + basicC[comp] + basicC[comp]) / 3
      c[comp] = newC

    @backFire.colorOverride(c)

    @addComponent('Invincible').invincibleDuration(2000)

    @setSealevel(Crafty.viewport.height - 20)
    @setDetectionOffset 40, 0
    @onHit 'Enemy', (collision) ->
      return if Game.paused
      return if @has('Invincible')
      hit = no
      for e in collision
        hit = yes unless e.obj.hidden
      @trigger('Hit') if hit

    @onHit 'PowerUp', (e) ->
      return if Game.paused
      for pu in e
        @pickUp(pu.obj)
        @trigger('PowerUp', pu.obj)

    @bind 'Hit', ->
      Crafty.e('Blast, Explosion').explode(
        x: @x + (@w / 2)
        y: @y + (@h / 2)
        radius: @w
      )
      Crafty.audio.play("explosion")
      Crafty('ScrollWall').get(0).screenShake(10, 1000)
      @trigger 'Destroyed', this

    @bind 'GameLoop', (fd) ->
      motionX = (@_currentSpeed.x / 1000.0) * fd.dt
      motionY = (@_currentSpeed.y / 1000.0) * fd.dt

      shipSpeedX = @_currentSpeed.x + @vx
      shipSpeedY = @_currentSpeed.y + @vy
      @updateAcceleration()

      r = @rotation
      @rotation = 0
      newR = shipSpeedY / 20
      nr = r
      if r < newR
        nr += 1
      else if r > newR
        nr -= 1

      nr = r if @hit('Edge') or @hit('Solid')

      @_updateFlyingSpeed shipSpeedX, fd.dt
      @rotation = nr

      @x += motionX
      @y += motionY
      # Move player back if flying into an object
      if @hit('Edge') or @hit('Solid')
        @x -= motionX
        @y -= motionY

      # still hitting an object? then we where forced in
      # and are crashed (squashed probably)
      @trigger('Hit') if @hit('Edge') or @hit('Solid')

    this

  forcedSpeed: (speed, options = {}) ->
    @targetSpeed(speed, options)
<commit_msg>Fix rotation to water surface<commit_after>Crafty.c 'PlayerSpaceship',
  init: ->
    @requires '2D, WebGL, playerShip, ColorEffects, Listener, Collision, SunBlock, WaterSplashes, PlayerControlledShip, Accelleration'
    @attr w: 71, h: 45
    #@addComponent 'SolidHitBox'
    @collision [
      21, 13
      56, 13
      66, 32
      35, 32
    ]

    @bind 'Moved', (from) ->
      if @hit('Edge') or @hit('Solid') # Contain player within playfield
        setBack = {}
        setBack[from.axis] = from.oldValue
        @attr setBack
    @primaryWeapon = undefined
    @primaryWeapons = []
    @secondaryWeapon = undefined
    @superUsed = 0
    @weaponsEnabled = yes
    @currentRenderedSpeed = 0

  _updateFlyingSpeed: (newSpeed, dt) ->
    if newSpeed < 50
      correction = newSpeed / 2
    else
      correction = 25 + ((newSpeed / 400) * 100)

    if @currentRenderedSpeed > correction
      @currentRenderedSpeed -= 4
    else if @currentRenderedSpeed < correction
      @currentRenderedSpeed += 4
    if @currentRenderedSpeed < 0
      @currentRenderedSpeed = 0

    w = @currentRenderedSpeed

    h = Math.min(w / 3, 15)
    @backFire.attr(
      x: @x - w + 9
      y: @y + 20 - (h // 2)
      w: w
      h: h
    )

  start: ->
    @backFire = Crafty.e('2D, WebGL, shipEngineFire, ColorEffects')
    @backFire.timing = 0
    w = 60
    h = 10

    @backFire.attr(
      x: @x - w + 9
      y: @y + 20 - (h // 2)
      w: w
      h: h
      alpha: .8
      z: @z - 1
    )
    @attach @backFire

    c = {}
    basicC = {
      _red: 255
      _green: 255
      _blue: 255
    }
    Crafty.assignColor(@playerColor, c)
    for comp in ['_red', '_green', '_blue']
      newC = (c[comp] + basicC[comp] + basicC[comp]) / 3
      c[comp] = newC

    @backFire.colorOverride(c)

    @addComponent('Invincible').invincibleDuration(2000)

    @setSealevel(Crafty.viewport.height - 20)
    @setDetectionOffset 40, 0
    @onHit 'Enemy', (collision) ->
      return if Game.paused
      return if @has('Invincible')
      hit = no
      for e in collision
        hit = yes unless e.obj.hidden
      @trigger('Hit') if hit

    @onHit 'PowerUp', (e) ->
      return if Game.paused
      for pu in e
        @pickUp(pu.obj)
        @trigger('PowerUp', pu.obj)

    @bind 'Hit', ->
      Crafty.e('Blast, Explosion').explode(
        x: @x + (@w / 2)
        y: @y + (@h / 2)
        radius: @w
      )
      Crafty.audio.play("explosion")
      Crafty('ScrollWall').get(0).screenShake(10, 1000)
      @trigger 'Destroyed', this

    @bind 'GameLoop', (fd) ->
      motionX = (@_currentSpeed.x / 1000.0) * fd.dt
      motionY = (@_currentSpeed.y / 1000.0) * fd.dt

      shipSpeedX = @_currentSpeed.x + @vx
      shipSpeedY = @_currentSpeed.y + @vy
      @updateAcceleration()

      r = @rotation
      newR = shipSpeedY / 20
      nr = r
      if r < newR
        nr += 1
      else if r > newR
        nr -= 1

      @rotation = nr
      nr = r if @hit('Edge') or @hit('Solid')

      @rotation = 0
      @_updateFlyingSpeed shipSpeedX, fd.dt
      @rotation = nr

      @x += motionX
      @y += motionY
      # Move player back if flying into an object
      if @hit('Edge') or @hit('Solid')
        @x -= motionX
        @y -= motionY

      # still hitting an object? then we where forced in
      # and are crashed (squashed probably)
      @trigger('Hit') if @hit('Edge') or @hit('Solid')

    this

  forcedSpeed: (speed, options = {}) ->
    @targetSpeed(speed, options)

{'fraction_non_alphanumeric': 0.13215986149184822, 'fraction_numerical': 0.028855864954552012, 'mean_word_length': 2.011294526498697, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '1785535', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2360, 'n_words': 646}