I am making a Javascript game with the HTML5 canvas API and hit the checkpoint.
One of the game effects is a rocket moving up along the y axis, which is affected by gusts of wind (emitted by turbines) that move it along the x axis. I had no problems making one of these turbines, but when their number increased to 3, I ran into a problem. At a new level, I create these turbines as objects, which are then placed in an array, as can be seen here:
function gameStateNewLevel(){ for (var i = 0; i < 2; i++){ turbine = {}; turbine.width = 10; turbine.height = Math.floor(Math.random()*200);
Now, before they are visualized, they will also be updated through the updateTurbine function. All this function must be done to make sure that the turbines do not overlap with each other and move them up or down along the y axis as necessary (by cyclic moving around the array and comparing each of the objects in it). I did this function, but I completely lost all the loops. Itβs about the way I am, and I feel like I'm wrong:
function updateTurbines(){ tempTurbine = {} turbinePositionTop = tempTurbine.y; turbinePositionBottom = tempTurbine.y + tempTurbine.height; for (var i = turbineArrayLength; i < 2; i++){ tempTurbine = turbines[i]; for (var i = turbineArrayLength; i < 2; i++){ if (tempTurbine !== tempTurbines[i]){ while (){ } } } } }
You can find the source code and the farthest that I received without this thing breaking www.techgoldmine.com
styke source share