<commit_before>class Player extends GameObject

    constructor: (x, y, state) ->
        super(state)
        cursors = game.input.keyboard.createCursorKeys()

        @controls = {}
        @controls.left = cursors.left
        @controls.down = cursors.down
        @controls.right = cursors.right
        @controls.up = cursors.up
        @controls.W = game.input.keyboard.addKey Phaser.Keyboard.W
        @controls.A = game.input.keyboard.addKey Phaser.Keyboard.A
        @controls.S = game.input.keyboard.addKey Phaser.Keyboard.S
        @controls.D = game.input.keyboard.addKey Phaser.Keyboard.D

        @WALKING_SPEED = 100

        @sprite = game.add.sprite x, y, "player"
        @sprite.wrapper = @
        game.physics.arcade.enable(@sprite)
        @sprite.body.collideWorldBounds = true
        @sprite.anchor.x = .5
        @sprite.anchor.y = .75
        @i = 0
        @footstepCountdown = 3000
        @gunCountdown = 0

        @shadow = game.add.sprite x-game.width, y-game.height, "shadowmask"

    update: ->

        @shadow.x = @sprite.x - 800
        @shadow.y = @sprite.y - 600
        @shadow.bringToTop()

        currSpeed = Utils.dist(@sprite.body.velocity, {x: 0, y: 0})

        loud = false

        # Die if you hit an alien
        for k, v of @state.GameObjects
            if v.type == 'alien'
                game.physics.arcade.collide @sprite, v.sprite, @destroy, null, @

                # You're being loud if you're too close to an alien and moving too fast
                d = Utils.dist v.sprite.body.position, @sprite.body.position
                if (currSpeed - @WALKING_SPEED >= d/2)
                    loud = true

        if loud then @state.GameState.playerLocation = {x: @sprite.body.position.x, y: @sprite.body.position.y}

        # reset acceleration to start
        @sprite.body.acceleration.x = 0
        @sprite.body.acceleration.y = 0

        # check controls
        dx = 0
        dx = if @controls.left.isDown or @controls.A.isDown then dx - 1 else dx
        dx = if @controls.right.isDown or @controls.D.isDown then dx + 1 else dx
        dy = 0
        dy = if @controls.down.isDown or @controls.S.isDown then dy + 1 else dy
        dy = if @controls.up.isDown or @controls.W.isDown then dy - 1 else dy

        # adjust acceleration if controls used
        @sprite.body.acceleration.x = if @sprite.body.velocity.x > 0 then dx*600 else dx*300
        @sprite.body.acceleration.y = if @sprite.body.velocity.y > 0 then dy*600 else dy*300

        # drag if no controls in use
        @sprite.body.acceleration.x = -5 * @sprite.body.velocity.x if @sprite.body.acceleration.x == 0
        @sprite.body.acceleration.y = -5 * @sprite.body.velocity.y if @sprite.body.acceleration.y == 0

        # rotate sprite towards mouse and move around that periodically
        @i = @i + 1
        dx = @sprite.body.x + @sprite.body.width * @sprite.anchor.x - game.input.mousePointer.x
        dy = @sprite.body.y + @sprite.body.height * @sprite.anchor.y - game.input.mousePointer.y
        @sprite.angle = -100 + 180 * Math.atan2(dy, dx) / Math.PI + 15 * Math.sin(@i / 100.0)

        # move sprite forward so footstep circles don't obscure player
        @sprite.bringToTop()

        @_footstep()

        # fire if the gun hasn't been used too recently
        @gunCountdown = @gunCountdown - 1 if @gunCountdown > 0
        if @gunCountdown == 0 and game.input.activePointer.isDown
            @_fire()

        # our own version of collision with the bounding box
        x = @sprite.body.x + @sprite.body.width * @sprite.anchor.x
        y = @sprite.body.y + @sprite.body.height * @sprite.anchor.y


        if x < 20
            @sprite.body.x = @sprite.body.x + 20 - x
            @sprite.body.velocity.x = 0
            @sprite.body.acceleration.x = 0
        if x > game.width - 20
            @sprite.body.x = @sprite.body.x - x + game.width - 20<commit_msg>Added player recoil<commit_after>class Player extends GameObject

    constructor: (x, y, state) ->
        super(state)
        cursors = game.input.keyboard.createCursorKeys()

        @controls = {}
        @controls.left = cursors.left
        @controls.down = cursors.down
        @controls.right = cursors.right
        @controls.up = cursors.up
        @controls.W = game.input.keyboard.addKey Phaser.Keyboard.W
        @controls.A = game.input.keyboard.addKey Phaser.Keyboard.A
        @controls.S = game.input.keyboard.addKey Phaser.Keyboard.S
        @controls.D = game.input.keyboard.addKey Phaser.Keyboard.D

        @WALKING_SPEED = 100

        @sprite = game.add.sprite x, y, "player"
        @sprite.wrapper = @
        game.physics.arcade.enable(@sprite)
        @sprite.body.collideWorldBounds = true
        @sprite.anchor.x = .5
        @sprite.anchor.y = .75
        @i = 0
        @footstepCountdown = 3000
        @gunCountdown = 0

        @shadow = game.add.sprite x-game.width, y-game.height, "shadowmask"

    update: ->

        @shadow.x = @sprite.x - 800
        @shadow.y = @sprite.y - 600
        @shadow.bringToTop()

        currSpeed = Utils.dist(@sprite.body.velocity, {x: 0, y: 0})

        loud = false

        # Die if you hit an alien
        for k, v of @state.GameObjects
            if v.type == 'alien'
                game.physics.arcade.collide @sprite, v.sprite, @destroy, null, @

                # You're being loud if you're too close to an alien and moving too fast
                d = Utils.dist v.sprite.body.position, @sprite.body.position
                if (currSpeed - @WALKING_SPEED >= d/2)
                    loud = true

        if loud then @state.GameState.playerLocation = {x: @sprite.body.position.x, y: @sprite.body.position.y}

        # reset acceleration to start
        @sprite.body.acceleration.x = 0
        @sprite.body.acceleration.y = 0

        # check controls
        dx = 0
        dx = if @controls.left.isDown or @controls.A.isDown then dx - 1 else dx
        dx = if @controls.right.isDown or @controls.D.isDown then dx + 1 else dx
        dy = 0
        dy = if @controls.down.isDown or @controls.S.isDown then dy + 1 else dy
        dy = if @controls.up.isDown or @controls.W.isDown then dy - 1 else dy

        # adjust acceleration if controls used
        @sprite.body.acceleration.x = if @sprite.body.velocity.x > 0 then dx*600 else dx*300
        @sprite.body.acceleration.y = if @sprite.body.velocity.y > 0 then dy*600 else dy*300

        # drag if no controls in use
        @sprite.body.acceleration.x = -5 * @sprite.body.velocity.x if @sprite.body.acceleration.x == 0
        @sprite.body.acceleration.y = -5 * @sprite.body.velocity.y if @sprite.body.acceleration.y == 0

        # rotate sprite towards mouse and move around that periodically
        @i = @i + 1
        dx = @sprite.body.x + @sprite.body.width * @sprite.anchor.x - game.input.mousePointer.x
        dy = @sprite.body.y + @sprite.body.height * @sprite.anchor.y - game.input.mousePointer.y
        @sprite.angle = -100 + 180 * Math.atan2(dy, dx) / Math.PI + 15 * Math.sin(@i / 100.0) + Math.max(170, @gunCountdown) - 170

        # move sprite forward so footstep circles don't obscure player
        @sprite.bringToTop()

        @_footstep()

        # fire if the gun hasn't been used too recently
        @gunCountdown = @gunCountdown - 1 if @gunCountdown > 0
        if @gunCountdown == 0 and game.input.activePointer.isDown
            @_fire()

        # our own version of collision with the bounding box
        x = @sprite.body.x + @sprite.body.width * @sprite.anchor.x
        y = @sprite.body.y + @sprite.body.height * @sprite.anchor.y


        if x < 20
            @sprite.body.x = @sprite.body.x + 20 - x
            @sprite.body.velocity.x = 0
            @sprite.body.acceleration.x = 0
        if x > game.width - 20
            @sprite.body.x = @sprite.body.x - x + game.width - 20
{'fraction_non_alphanumeric': 0.11756499682942295, 'fraction_numerical': 0.019530754597336716, 'mean_word_length': 1.9803476946334089, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3615493', 'n_tokens_mistral': 2802, 'n_tokens_neox': 2535, 'n_words': 640}