HeySofie / Capy-caring

school project, a simple web game
0 stars 0 forks source link

More efficient way to make the plants grow? #2

Closed HeySofie closed 1 year ago

HeySofie commented 1 year ago

So! the way the plants grow is un effcient and only actully works one time, which is more then just un effcient, its a issue. This needs to be looked at and the code needs to be worked at.

What needs to be fixed is; 1: making it so it runs more then one time. 2: making the code more effcient.

ide: make the code more effcient by instead having a function that runs one time on start, and that has the timers where the plant changes img to a more grown plant, and after u have collected the food from the full grown plant the funtions runs again.

problimatic code:

` // after a time the farm changes to another img/growing time function grow_33() { farm.src ="/assets/imgs/plantV2many.png"; }

function grow_66() { farm.src ="/assets/imgs/plantV3many.png"; }

function grow_done() { farm_grown = true; console.log(farm_grown); farm.src = "/assets/imgs/plant-finish.png" }

// for when the food has grown and player clicks and stores the food function collect_food() {

if(farm_grown == true && food == false)
{
    food = true;
    farm_grown = false;
    growing_time = setTimeout(grow_done, 10000);
    console.log('food collected?',food);
    farm.src ="/assets/imgs/plantV2many.png";

}

else if(farm_grown == false)
{
    console.log('farm ready to be harvested?',farm_grown);
}

}`

HeySofie commented 1 year ago

isent important right now, and probably wont work on making the code more efficient