Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Porting speed_counter

This thread is locked; no one can reply to it. rss feed Print
Porting speed_counter
Jefferson Almeida
Member #12,659
March 2011

In Allegro 4 I have to use this speed_counter, in the Allegro5 is automatically replaced by the functions of timer?

#SelectExpand
1volatile long speed_counter = 0; 2void increment_speed_counter() 3{ speed_counter++; 4} END_OF_FUNCTION(increment_speed_counter); 5 6 7int frames = 0; 8int desce = 0; 9void mais_frame() 10{ 11 if(frames==0) desce = 0; 12 if(frames==2) desce = 1; 13 if(desce==1) frames--; 14 else frames++; 15} END_OF_FUNCTION(mais_frame); 16 17 18void draw_character(BITMAP **layer, int my_pic_x, int my_pic_y, int move, int walking, int direction) 19{ 20 if(walking==1) 21 { 22 switch(move) 23 { 24 case 2: 25 if(frames==0) draw_sprite(*layer, p21, my_pic_x+5, my_pic_y+83); 26 else if(frames==1) draw_sprite(*layer, p22, my_pic_x+5, my_pic_y+83); 27 else if(frames==2) draw_sprite(*layer, p23, my_pic_x+5, my_pic_y+83); 28 else draw_sprite(*layer, p22, my_pic_x+5, my_pic_y+83); break; 29 case 4: 30 if(frames==0) draw_sprite(*layer, p41, my_pic_x+5, my_pic_y+83); 31 else if(frames==1) draw_sprite(*layer, p42, my_pic_x+5, my_pic_y+83); 32 else if(frames==2) draw_sprite(*layer, p43, my_pic_x+5, my_pic_y+83); 33 else draw_sprite(*layer, p42, my_pic_x+5, my_pic_y+83); break; 34 case 6: 35 if(frames==0) draw_sprite(*layer, p61, my_pic_x+5, my_pic_y+83); 36 else if(frames==1) draw_sprite(*layer, p62, my_pic_x+5, my_pic_y+83); 37 else if(frames==2) draw_sprite(*layer, p63, my_pic_x+5, my_pic_y+83); 38 else draw_sprite(*layer, p62, my_pic_x+5, my_pic_y+83); break; 39 case 8: 40 if(frames==0) draw_sprite(*layer, p81, my_pic_x+5, my_pic_y+83); 41 else if(frames==1) draw_sprite(*layer, p82, my_pic_x+5, my_pic_y+83); 42 else if(frames==2) draw_sprite(*layer, p83, my_pic_x+5, my_pic_y+83); 43 else draw_sprite(*layer, p82, my_pic_x+5, my_pic_y+83); break; 44 } 45 } 46 else if(walking == 0) 47 { 48 switch(direction) 49 { 50 case 2: draw_sprite(*layer, p22, my_pic_x+5, my_pic_y+83);break; 51 case 4: draw_sprite(*layer, p42, my_pic_x+5, my_pic_y+83);break; 52 case 6: draw_sprite(*layer, p62, my_pic_x+5, my_pic_y+83);break; 53 case 8: draw_sprite(*layer, p82, my_pic_x+5, my_pic_y+83);break; 54 } 55 } 56 } 57 ....

Trent Gamblin
Member #261
April 2000
avatar

I think you should look in the manual and at least make an attempt at a solution before getting people here to port your code for you section by section :P.

Jefferson Almeida
Member #12,659
March 2011

Me too... but the API reference from allegro 4... http://alleg.sourceforge.net/stabledocs/en/allegro.html/
edit1: and I already try a solution

Edgar Reynaldo
Member #8,592
May 2007
avatar

Trent Gamblin
Member #261
April 2000
avatar

Edgar's link is to the Allegro 5 reference manual. You can also use docs.liballeg.org as an easy to remember address.

Jefferson Almeida
Member #12,659
March 2011

Thanks guys! I changed the 5 for 4 : http://www.allegro.cc/manual/4/ and work!

Matthew Leverton
Supreme Loser
January 1999
avatar

An Allegro 4 timer that only increments a variable can be done like this with Allegro 5:

ALLEGRO_TIMER *t = al_create_timer(1 / 60.0);
al_start_timer(t);

al_get_timer_count(t); // same as speed_counter

However, in most cases you'll just use al_register_event_source(queue, timer) and watch for timer events.

Go to: