Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Strange C++ and Allegro
#1
Can someone check out this code. I'm having some problems with the getangle function. No errors, but it just isn't working correctly.

Code:
#include <allegro.h>
#include <math.h>
#define DEGREES(x) int((x)/360.0*0xFFFFFF)
#define RADIANS(x) int((x)/2/M_PI*0xFFFFFF)
#include <stdlib.h>

void init(int wdth, int hght, int cdepth, int fscreen);
float getAng(int x1, int y1, int x2, int y2);
void deinit();

int main() {
    init(640,480,16,0);
    BITMAP *buffer = create_bitmap(640, 480);
    
    
    BITMAP *Aimer = load_bitmap("Aimer.tga",0);
    BITMAP *Player= load_bitmap("Player.tga",0);
  
    int px=320;
    int py=240;
    float x;
    while (!key[KEY_ESC]) {
       clear(buffer);
      
       /* put your code here */
    
        
       pivot_sprite(buffer,Player,px,py,32,32,ftofix(getAng(px,py,mouse_x,mouse_y)));
       x-=.1;
      
       draw_sprite(buffer, Aimer,mouse_x-Aimer->w/2, mouse_y-Aimer->h/2);
       line(buffer,px,py,mouse_x,mouse_y,makecol(255,0,0));
        
       blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);    
    }

    deinit();
    return 0;
}
END_OF_MAIN()

void init(int wdth, int hght, int cdepth, int fscreen) {
    int depth, res;
    allegro_init();
    set_color_depth(cdepth);
    if (fscreen == 0)
    {
        res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, wdth, hght, 0, 0);
    }else
    {
        res = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, wdth, hght, 0, 0);
    }  
    if (res != 0) {
        allegro_message(allegro_error);
        exit(-1);
    }

    install_timer();
    install_keyboard();
    install_mouse();
    /* add other initializations here */
    
}
float getAng(int x1, int y1, int x2, int y2)
{
    float FaceRadians= atan2 (y2 - y1, x2 - x1);
    float FaceDegrees = FaceRadians * 180 / M_PI;
    return FaceDegrees+90;
}
void deinit() {
    clear_keybuf();
    /* add other deinitializations here */
}

Quote:pivot_sprite(buffer, Player, px, py, 32, 32, ftofix(getAng(px,py,mouse_x,mouse_y)));

the red part is the thing I believe is causing problems because allegro needed fixed angle but because I'm very new to C++, I am not sure how to fix this issue! I am trying to make the Player graphic rotate so it always faces the mouse. Again, I'd be very happy if anyone could give me a little help.:wtnod:
Reply


Messages In This Thread
Strange C++ and Allegro - by speedlemon - 12-23-2005, 09:18 AM
Strange C++ and Allegro - by thegrogen - 12-23-2005, 10:04 AM
Strange C++ and Allegro - by na_th_an - 12-23-2005, 02:05 PM
Strange C++ and Allegro - by speedlemon - 12-23-2005, 07:13 PM
Strange C++ and Allegro - by DrV - 12-23-2005, 10:12 PM
Strange C++ and Allegro - by speedlemon - 12-23-2005, 10:52 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)