I'm sure this is a simple question but I'm asking it anyways. Basically I'm trying to do the following in javascript (no jquery) with less code:
var Ground = [];
function gameLoop()
{
Gravity += 0.2
if(Ground[0].isCollided(Player))
{
Player.dy = 0;
Gravity = 0;
}
if(Ground[1].isCollided(Player))
{
Player.dy = 0;
Gravity = 0;
}
if(Ground[2].isCollided(Player))
{
Player.dy = 0;
Gravity = 0;
}
Player.dy = Gravity;
}
I've simplified the code extremely from the code in my game I'm making using javascript and the html5 canvas. What you see is my Ground mechanic as it stands. When the player collides with the Ground Block, the Player's .dy value will no longer change along with the Gravity.
What you saw above is how I would normally do it however this can take up a large amount of space if I have 50 FallingM variables. Is it possible to do something like:
if(Ground[i].isCollided(Player))
{
Player.dy = 0;
Gravity = 0;
}
So that the function will still run no matter how many Ground variables I add? Thanks ahead of time!