<commit_before>// Enemies our player must avoid
var Enemy = function(x,y) {
    // Variables applied to each of our instances go here,
    // we've provided one for you to get started

    // The image/sprite for our enemies, this uses
    // a helper we've provided to easily load images
    this.sprite = 'images/enemy-bug.png';
    this.x = x;
    this.y = y;
    this.enemySpeed = Math.floor(Math.random() * 250) + 100;
};

// Update the enemy's position, required method for game
// Parameter: dt, a time delta between ticks
Enemy.prototype.update = function(dt) {
    // You should multiply any movement by the dt parameter
    // which will ensure the game runs at the same speed for
    // all computers.

    this.x += (dt * this.enemySpeed);

    if (this.x > 600) {
        this.x = -100;
        this.enemySpeed = Math.floor(Math.random() * 300) + 150;
        this.y = randomY();
    };
};

// Draw the enemy on the screen, required method for game
Enemy.prototype.render = function() {
    ctx.drawImage(Resources.get(this.sprite), this.x, this.y);
};

// Now write your own player class
// This class requires an update(), render() and
// a handleInput() method.

var ThePlayer = function(x,y) {

    this.x = x;
    this.y = y;
    this.sprite = 'images/char-boy.png';
};


ThePlayer.prototype.update = function(dt) {
    // movement (multiplying dt) updating loc x & y
};

ThePlayer.prototype.render = function() {
    ctx.drawImage(Resources.get(this.sprite), this.x, this.y);
};

ThePlayer.prototype.handleInput = function (userInput) {

    //player inputs up down left right
    if  (userInput === 'left') {
        this.x -= 101;
    };

    if  (userInput === 'right') {
        this.x += 101;
    };

    if  (userInput === 'up') {
        this.y -= 83;
    };

    if  (userInput === 'down') {
        this.y += 83;
    };
};


// Now instantiate your objects.
// Place all enemy objects in an array called allEnemies
var randomY = function() {
    var randomise = [60, 145, 230][Math.floor(Math.random() * 3)];
    return randomise;
};
var allEnemies = [new Enemy(-100,randomY()), new Enemy(-100,randomY()), new Enemy(-100,randomY())];

// Place the player object in a variable called player
var player = new ThePlayer(200,400);


// This listens for key presses and sends the keys to your
// Player.handleInput() method. You don't need to modify this.
document.addEventListener('keyup', function(e) {
    var allowedKeys = {
        37: 'left',
        38: 'up',
        39: 'right',
        40: 'down'
    };

    player.handleInput(allowedKeys[e.keyCode]);
});
<commit_msg>add boundaries to player movement and refine enemy respawn<commit_after>// Enemies our player must avoid
var Enemy = function(x,y) {
    // Variables applied to each of our instances go here,
    // we've provided one for you to get started

    // The image/sprite for our enemies, this uses
    // a helper we've provided to easily load images
    this.sprite = 'images/enemy-bug.png';
    this.x = x;
    this.y = y;
    this.enemySpeed = Math.floor(Math.random() * 250) + 100;
};

// Update the enemy's position, required method for game
// Parameter: dt, a time delta between ticks
Enemy.prototype.update = function(dt) {
    // You should multiply any movement by the dt parameter
    // which will ensure the game runs at the same speed for
    // all computers.

    this.x += (dt * this.enemySpeed);

    if (this.x > 503) {
        this.x = -100;
        this.enemySpeed = Math.floor(Math.random() * 300) + 150;
        this.y = randomY();
    };
};

// Draw the enemy on the screen, required method for game
Enemy.prototype.render = function() {
    ctx.drawImage(Resources.get(this.sprite), this.x, this.y);
};

// Now write your own player class
// This class requires an update(), render() and
// a handleInput() method.

var ThePlayer = function(x,y) {

    this.x = x;
    this.y = y;
    this.sprite = 'images/char-boy.png';
};


ThePlayer.prototype.update = function(dt) {
    // movement (multiplying dt) updating loc x & y
};

ThePlayer.prototype.render = function() {
    ctx.drawImage(Resources.get(this.sprite), this.x, this.y);
};

ThePlayer.prototype.handleInput = function (userInput) {

    //player inputs up down left right
    if  (userInput === 'left') {
        if (this.x <= -2) {

        } else {
        this.x -= 101;
        };
    };

    if  (userInput === 'right') {
        if (this.x >= 402) {

        } else {
        this.x += 101;
        };
    };

    if  (userInput === 'up') {
        if (this.y <= 0) {

        } else {
        this.y -= 83;
        };
    };

    if  (userInput === 'down') {
        if (this.y >= 405) {
        } else {
        this.y += 83;
        };
    };

};


// Now instantiate your objects.
// Place all enemy objects in an array called allEnemies
var randomY = function() {
    var randomise = [60, 145, 230][Math.floor(Math.random() * 3)];
    return randomise;
};
var allEnemies = [new Enemy(-10,randomY()), new Enemy(-10,randomY()), new Enemy(-10,randomY())];

// Place the player object in a variable called player
var player = new ThePlayer(200,405);


// This listens for key presses and sends the keys to your
// Player.handleInput() method. You don't need to modify this.
document.addEventListener('keyup', function(e) {
    var allowedKeys = {
        37: 'left',
        38: 'up',
        39: 'right',
        40: 'down'
    };

    player.handleInput(allowedKeys[e.keyCode]);
});

{'fraction_non_alphanumeric': 0.14264840182648403, 'fraction_numerical': 0.0228310502283105, 'mean_word_length': 2.49234693877551, 'pattern_counts': {'":': 0, '<': 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': '3330718', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1715, 'n_words': 552}