Hey guys, I am pretty new to allegro5 and made a simple program of a bouncing ball using the "Physics for Lazy Game Developers" (labs.skookum.com/demos/barcampclt_physics/newton/4) as a guide and well the ball is bouncing well enough but it doesn't stop bouncing.Here is my program:
#include<allegro5\allegro.h>
#include<allegro5\allegro_primitives.h>
#include <stdlib.h>
int main(void){
const int FPS = 60;
int w = 640;
int h = 480;
float x = w/2;
float y = 2;
float a = 40;
float velx = 0;
float vely = 0;
int elastic = 1;
int temp
al_init();
al_init_primitives_addon();
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
ALLEGRO_TIMER *timer = NULL;
al_create_display(w,h);
event_queue = al_create_event_queue();
timer = al_create_timer(1.0 / FPS);
al_register_event_source(event_queue,al_get_timer_event_source(timer));
al_start_timer(timer);
bool done = false;
while(!done){
ALLEGRO_EVENT ev;
al_wait_for_event(event_queue,&ev);
al_draw_circle(x,y,15,al_map_rgb(0,255,0),2);
//al_draw_line(0,480,640,480,al_map_rgb(0,255,0),5);
al_flip_display();
al_clear_to_color(al_map_rgb(0,0,0));
if(y+15>h){
y = h - 15;
temp = vely;
vely = -abs(temp) * elastic;
//vely = 0;
}
x += velx;
y += vely;
velx *= .99;
vely *= .99;
vely += .25;
}
al_destroy_display(display);
}
I know that i didn't put any code that will stop it bouncing and the site used this: ball.vy *= ball.elasticy; .. but i can't understand what this "elasticy" of the ball is and how do i use it. Is there any other way of stopping the ball? i tried doing different stuff but couldn't find the solution.
Any help would be appreciated :)
P.S sorry about the messy source code, i made this program in a hurry :p oh and also, i am new to this site and so sorry if i am in the wrong section..