<commit_before>/**
 * @param {ThunderTanks} tt ThunderTanks instace.
 * @param {Object} data  Tank data (id, x, y)
 * @param {Boolean} remote True if the tank is a remote player
 *
 */
function Tank(tt, data, remote) {
    var SELF = this;

    /** @type ThunderTanks */
    this.tt = tt;

    this.id = data.id;

    /** @type JSGameSoup */
    this.game = tt.game;

    var _private = {
        length: 43,
        width: 36,
        x: data.x || 100,
        y: data.y || 100,
        angle: MathUtil.degreesToRadians(45), // angle in radians
        speed: 0,
        maxSpeed: 4,
        aimAngle: MathUtil.degreesToRadians(0),
        firing: false,
        fireRate: 5, // number of shots per sec
        fireCooldown: 0,
        remote: remote,
        tankSprite: new Sprite(["center", "center"], {
            "still": [[SELF.tt.urlPath + '/images/tank/tanksprite1.png', 1] , [SELF.tt.urlPath + '/images/tank/tanksprite1.png'], 1],
            "forward": [[SELF.tt.urlPath + '/images/tank/tanksprite1.png', 1] , [SELF.tt.urlPath + '/images/tank/tanksprite1.png'], 1]
        },
        function() {
            _private.tankSprite.action("still");
            _private.tankSprite.angle(_private.angle);
        })
    }

    /**
     * @param {JSGameSoup} gs JSGameSoup instance
     */
    this.update = function(gs) {
        // move tank
        _private.x = _private.x + _private.speed * Math.cos(_private.angle);
        _private.y = _private.y + _private.speed * Math.sin(_private.angle);

        if (!_private.remote) {
            // update aim
            var mouseposition = gs.pointerPosition,
                mousex = mouseposition[0],
                mousey = mouseposition[1];
            _private.aimAngle = MathUtil.getAngle(_private.x,_private.y,mousex,mousey);
        }

        if (_private.firing && _private.fireCooldown === 0) {
            this.fireBullet();
        }
        if (_private.fireCooldown > 0) {
            _private.fireCooldown--;
        }

        if (!_private.remote && typeof multiplayerConn != 'undefined') {
            multiplayerConn.emit('player-tank-update', this.getData());
        }

        _private.tankSprite.angle(_private.angle);
        _private.tankSprite.update();
    };

    /**
     * @param {CanvasRenderingContext2D} c canvas context
     * @param {JSGameSoup} gs JSGameSoup instance
     */
    this.draw = function(c, gs) {
        // draw tank
        c.save(); //save the current draw state
        c.translate(_private.x,_private.y); //set drawing area to where the tank is
        c.rotate(_private.angle); //rotate drawing area to tank's angle
        c.fillRect(-_private.length/2, -_private.width/2, _private.length, _private.width); // draw the tank
        c.restore(); //restore the previous draw state

        // draw tank sprite
        c.save(); //save the current draw state
        _private.tankSprite.draw(c, [_private.x, _private.y]);
        c.restore(); //restore the previous draw state

        // draw cannon
        c.save();
        c.translate(_private.x,_private.y);
        c.rotate(_private.aimAngle);
        c.fillRect(0, 0, _private.length, 5);
        c.restore();

        c.fillRect(_private.x - _private.length/2, _private.y - _private.width/2, _private.length, _private.width);


    }

    // if its not a remote player, add controls
    if (!_private.remote) {

        // up (W)
        this.keyDown_38 = this.keyDown_87 = function () {
            _private.speed = 1;
        }
        this.keyHeld_38 = this.keyHeld_87 = function () {
            if (_private.speed < _private.maxSpeed)
                _private.speed += 1;
        }
        this.keyUp_38 = this.keyUp_87 = function () {
            _private.speed = 0;
        }

        // down (S)
        this.keyDown_40 = this.keyDown_83 = function () {
            _private.speed = -0.3;
        }
        this.keyHeld_40 = this.keyHeld_83 = function () {
            if (_private.speed > -_private.maxSpeed)
                _private.speed -= 0.3;
        }
        this.keyUp_40 = this.keyUp_83 = function () {<commit_msg>removed drawing tank collision box<commit_after>/**
 * @param {ThunderTanks} tt ThunderTanks instace.
 * @param {Object} data  Tank data (id, x, y)
 * @param {Boolean} remote True if the tank is a remote player
 *
 */
function Tank(tt, data, remote) {
    var SELF = this;

    /** @type ThunderTanks */
    this.tt = tt;

    this.id = data.id;

    /** @type JSGameSoup */
    this.game = tt.game;

    var _private = {
        length: 43,
        width: 36,
        x: data.x || 100,
        y: data.y || 100,
        angle: MathUtil.degreesToRadians(45), // angle in radians
        speed: 0,
        maxSpeed: 4,
        aimAngle: MathUtil.degreesToRadians(0),
        firing: false,
        fireRate: 5, // number of shots per sec
        fireCooldown: 0,
        remote: remote,
        tankSprite: new Sprite(["center", "center"], {
            "still": [[SELF.tt.urlPath + '/images/tank/tanksprite1.png', 1] , [SELF.tt.urlPath + '/images/tank/tanksprite1.png'], 1],
            "forward": [[SELF.tt.urlPath + '/images/tank/tanksprite1.png', 1] , [SELF.tt.urlPath + '/images/tank/tanksprite1.png'], 1]
        },
        function() {
            _private.tankSprite.action("still");
            _private.tankSprite.angle(_private.angle);
        })
    }

    /**
     * @param {JSGameSoup} gs JSGameSoup instance
     */
    this.update = function(gs) {
        // move tank
        _private.x = _private.x + _private.speed * Math.cos(_private.angle);
        _private.y = _private.y + _private.speed * Math.sin(_private.angle);

        if (!_private.remote) {
            // update aim
            var mouseposition = gs.pointerPosition,
                mousex = mouseposition[0],
                mousey = mouseposition[1];
            _private.aimAngle = MathUtil.getAngle(_private.x,_private.y,mousex,mousey);
        }

        if (_private.firing && _private.fireCooldown === 0) {
            this.fireBullet();
        }
        if (_private.fireCooldown > 0) {
            _private.fireCooldown--;
        }

        if (!_private.remote && typeof multiplayerConn != 'undefined') {
            multiplayerConn.emit('player-tank-update', this.getData());
        }

        _private.tankSprite.angle(_private.angle);
        _private.tankSprite.update();
    };

    /**
     * @param {CanvasRenderingContext2D} c canvas context
     * @param {JSGameSoup} gs JSGameSoup instance
     */
    this.draw = function(c, gs) {
        // draw tank
        c.save(); //save the current draw state
        c.translate(_private.x,_private.y); //set drawing area to where the tank is
        c.rotate(_private.angle); //rotate drawing area to tank's angle
        c.fillRect(-_private.length/2, -_private.width/2, _private.length, _private.width); // draw the tank
        c.restore(); //restore the previous draw state

        // draw tank sprite
        c.save(); //save the current draw state
        _private.tankSprite.draw(c, [_private.x, _private.y]);
        c.restore(); //restore the previous draw state

        // draw cannon
        c.save();
        c.translate(_private.x,_private.y);
        c.rotate(_private.aimAngle);
        c.fillRect(0, 0, _private.length, 5);
        c.restore();
    }

    // if its not a remote player, add controls
    if (!_private.remote) {

        // up (W)
        this.keyDown_38 = this.keyDown_87 = function () {
            _private.speed = 1;
        }
        this.keyHeld_38 = this.keyHeld_87 = function () {
            if (_private.speed < _private.maxSpeed)
                _private.speed += 1;
        }
        this.keyUp_38 = this.keyUp_87 = function () {
            _private.speed = 0;
        }

        // down (S)
        this.keyDown_40 = this.keyDown_83 = function () {
            _private.speed = -0.3;
        }
        this.keyHeld_40 = this.keyHeld_83 = function () {
            if (_private.speed > -_private.maxSpeed)
                _private.speed -= 0.3;
        }
        this.keyUp_40 = this.keyUp_83 = function () {
{'fraction_non_alphanumeric': 0.13487166831194472, 'fraction_numerical': 0.016535044422507403, 'mean_word_length': 1.9018976011457214, 'pattern_counts': {'":': 4, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2033762', 'n_tokens_mistral': 2658, 'n_tokens_neox': 2547, 'n_words': 556}