<commit_before>"use strict";

function cast_to_edge(x, y, pos) {
   var d = Math.sqrt((pos.x - x) * (pos.x - x) + (pos.y - y) * (pos.y - y)); 
   var uv = {
       "x": (x-pos.x)/d,
       "y": (y-pos.y)/d
   }
   
   do {
       x+=uv.x;
       y+=uv.y;
   } while( x >= 0 && x <= data.canvas.width && y >= 0 && y <= data.canvas.height );
}

module.exports = function(entity, data) {

    var constants = data.entities.get(entity, "constants"); 
    var x = Math.floor(Math.random() * data.canvas.width)
    var y = Math.floor(Math.random() * data.canvas.height)

    var projectile = data.instantiatePrefab("projectile");

    cast_to_edge(x, y, constants.center);

    var timers = data.entities.get(entity, "timers");
    timers.spawn_projectile.time = 0;
    timers.spawn_projectile.running = true;
}<commit_msg>Set projectile positions to the edge of the screen<commit_after>"use strict";

function cast_to_edge(x, y, pos, data) {
   var d = Math.sqrt((pos.x - x) * (pos.x - x) + (pos.y - y) * (pos.y - y)); 
   var uv = {
       "x": (x-pos.x)/d,
       "y": (y-pos.y)/d
   }
   
   do {
       x+=uv.x;
       y+=uv.y;
   } while( x >= 0 && x <= data.canvas.width && y >= 0 && y <= data.canvas.height );

   return {"x": x, "y": y}

}

module.exports = function(entity, data) {

    var constants = data.entities.get(entity, "constants"); 
    var x = Math.floor(Math.random() * data.canvas.width)
    var y = Math.floor(Math.random() * data.canvas.height)

    var projectile = data.instantiatePrefab("projectile");

    var new_pos = cast_to_edge(x, y, constants.center, data);

    data.entities.set(projectile, "position", new_pos);

    var timers = data.entities.get(entity, "timers");
    timers.spawn_projectile.time = 0;
    timers.spawn_projectile.running = true;
}
{'fraction_non_alphanumeric': 0.18339876612450925, 'fraction_numerical': 0.0033651149747616375, 'mean_word_length': 2.7012448132780085, 'pattern_counts': {'":': 6, '<': 7, '<?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': '2209658', 'n_tokens_mistral': 687, 'n_tokens_neox': 666, 'n_words': 146}