Hi..
I am trying to make a basic side scroller game and I am wondering how I should implement gravity.
I wrote something and it works but i am wondering if there is another or better way to do it.
vel_y, tmp_y, y, x, h, and w belong to the object that's subject to gravity.
Code:
if(vel_y < MAX_SPD) vel_y += G;
tmp_y += vel_y;
for(i = 0; i < 15; i++ ){
if((tmp_y+h > blocks[i].y) && (y+h < blocks[i].y + blocks[i].h) && (x > blocks[i].x) && (x < blocks[i].x + blocks[i].w)){
tmp_y = y;
vel_y = G;
y = blocks[i].y - h;
break;
}
y = tmp_y;
}
Also i would be grateful if you could recommend some books.