Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Unity scripts converted for use with Game Maker 2.3

A topic by Gizmo199 created Sep 17, 2020 Views: 168
Viewing posts 1 to 1
(4 edits) (+1)

Obviously you can tweak these as needed, but I took the time to convert the basic idea of the unity scripts for use with Game maker studio 2.3. 


I made the 3 scripts ( the spawn script should be pretty self explanatory.

scr_break_social_distance( wearing_mask, player_objects, other_objects)

scr_calculate_infected()

scr_timer()

HERE you can download a .YYZ file of the scripts and a simple little example of how they can be used to create infected and non infected players and how you can use the percentages to calculate each objects chance of infection. Hope you find some use for it! :D


**NOTE**

the MASK_ON variable is just a global variable I setup in a control object when the game starts. basically you can set this to either true or false.

-------------------- scr_break_social_distance() -------------------
function scr_break_social_distance( wearing_mask, player_objects, other_objects ){
        
    //A rough estimate of transmission according to our model is 5% when in contact with an infected individual. If everyone
    //in the space is wearing a mask, this decreases the risk by roughly 60%. A rough estimate of risk can be:
    transmission_risk = 2 + ( 3 * wearing_mask );
    
    // Create functions to increase risk
    function increase_risk(risk){
        player_risk += risk;    
    }
    
    //One method is to use a collision event to determine when the player has broken social distancing measures.
    function has_tag( _object, tag_name){
        
        var _tag = asset_get_tags(_object, asset_object);
        for ( var i=0; array_length(_tag); i++ ){
            if ( _tag[i] == tag_name ){
                return true;
            }
        }
        
        return false;
    }
    function on_collision(){
        return collision_rectangle(
            bbox_left, bbox_top,
            bbox_right, bbox_bottom,
            all, false, true
        );
    }
    
    var col = on_collision();
    if ( col && has_tag(col, "player") ){
        increase_risk(transmission_risk);    
    }
    
    //Another method is to simply see if the distance between two gameobjects is less than 6ft (what this could mean in your game
    //may vary drastically.
    var dist = point_distance(player_objects.x, player_objects.y, other_objects.x, other_objects.y);
    if ( dist <= 6 ){
        increase_risk(transmission_risk);    
    }
}
-------------------- scr_calculate_infected() -------------------
globalvar total_infected, total_healthy, percent_of_total_infected, total_population_num, population_infected_percent;
// Here we initialize all the variables necessary for our calculations. You may need to add more depending on your needed parameters.
total_infected = 0;
total_healthy = 0;
percent_of_total_infected = 0;
// Change these if needed for caluclations
total_population_num = 250;
population_infected_percent = 7;
// This script is responsible for determining how many individuals in the game's population are infected and healthy
function scr_calculate_infected(){
    //Here we roll to see how many people within the total population are infected. This assumes a 7% chance of infection within
    //the general population of your game world. If 50% of everyone in your game world were infected, for example,
    //you should adjust the population_infected_percent variable accordingly.
    
    static do_roll = false;
    
    if ( do_roll == false ){
    var percent_of_general_population_infected = population_infected_percent;
    for ( var i=0; i < total_population_num; i++ ){
        
        var infection_roll = random_range(1, 101);
        
        if ( infection_roll <= percent_of_general_population_infected ){
            total_infected++;
        }
        else
        {
            total_healthy++;    
        }
        
        percent_of_total_infected = ( total_infected / total_population_num ) * 100;
        do_roll = true;
    }
    
        show_debug_message("The number of infected individuals is " + string(total_infected) + " out of " + string(total_population_num) );
    }
}
-------------------- scr_timer() -------------------
//This example uses a game length of 90 ms. Feel free to adjust as needed
globalvar start_time, game_time; 
game_time = 90;
start_time = game_time;
function scr_timer(){
    
    
    //Calling in the script that calculates infected numbers.
    calculate_infected();
    
    //To calculate risk over time, we can multiply the chosen risk vector times the number of infected in the space, times the
    //transmission risk (which is impacted by the usage of PPE. We then add this to the player's total risk of infection.
    function increase_risk_with_time(){
        var risk_vector;
        risk_vector = choose(0.486582881, 0.249819981, 0.128261855, 0.065851832, 0.033809458, 0.017358354, 0.008912076, 0.004575613, 0.002349198);
        
        // Check if breaking social distancing
        break_social_distance(MASK_ON, id, other);
        
        // Increase risk if so
        player_risk += ( risk_vector * total_infected * transmission_risk );
    }
    
    //For this example, the 90 seconds selected represents 30 minute of real time.
    //As a result, each second represents 20 seconds of real time. We increase the risk of infection every 10 seconds(roughly every 3 minutes
    //of real time.
    
    start_time ++;
    if ( start_time > 90 ){
        start_time = 0;
        increase_risk_with_time();
    }
}