I am trying to use the mouse to make a bitmap rotate(if the mouse moves along the x axis, the bitmap rotates accordingly). I have been trying to do it with get_mouse_mickeys() and rotate_sprite() but now luck. I do have a feeling I am doing it all wrong. Here's the code:
1 | #include <allegro.h> |
2 | #include <stdlib.h> |
3 | |
4 | int player1_x = 320; |
5 | int player1_y = 240; |
6 | int player2_x; |
7 | int player2_y; |
8 | int player1_rotate; |
9 | int player2_rotate; |
10 | int mickeyx = 0; |
11 | int mickeyy = 0; |
12 | |
13 | int player1_movement() |
14 | { |
15 | if(key[KEY_A]) |
16 | { |
17 | player1_x --; |
18 | } |
19 | if(key[KEY_D]) |
20 | { |
21 | player1_x ++; |
22 | } |
23 | if(key[KEY_W]) |
24 | { |
25 | player1_y --; |
26 | } |
27 | if(key[KEY_S]) |
28 | { |
29 | player1_y ++; |
30 | } |
31 | position_mouse(320, 240); |
32 | get_mouse_mickeys(&mickeyx, &mickeyy); |
33 | if(mickeyx > 1) |
34 | { |
35 | player1_rotate ++; |
36 | } |
37 | if(mickeyx < 1) |
38 | { |
39 | player1_rotate --; |
40 | } |
41 | } |
42 | |
43 | int main(int argc, char *argv[]) |
44 | { |
45 | allegro_init(); |
46 | install_keyboard(); |
47 | install_mouse(); |
48 | set_color_depth(16); |
49 | set_gfx_mode(GFX_AUTODETECT,640,480,0,0); |
50 | |
51 | |
52 | BITMAP *buffer = create_bitmap(640,480); |
53 | |
54 | BITMAP *player1 = load_bitmap("player.bmp", NULL); |
55 | |
56 | BITMAP *player2 = load_bitmap("player.bmp", NULL); |
57 | |
58 | while(!key[KEY_ESC]) |
59 | { |
60 | player1_movement(); |
61 | |
62 | rotate_sprite(buffer, player1, player1_x, player1_y, player1_rotate); |
63 | blit(buffer, screen,0,0,0,0,640,480); |
64 | clear_bitmap(buffer); |
65 | } |
66 | |
67 | destroy_bitmap(player1); |
68 | destroy_bitmap(player2); |
69 | destroy_bitmap(buffer); |
70 | |
71 | return 0; |
72 | |
73 | } |
74 | END_OF_MAIN() |
Right now I am focusing on player1 just to get it working properly.
You should have "if(mickeyx > 0)" and "if(mickeyx < 0)". And if you want it to rotate accordingly to the speed you move the mouse, you should have something like "player1_rotate += mickeyx * SPEED;". Probably there's something else wrong but that's all I see now. What happens when you try to rotate the bitmap?
Yes I was going to do your idea but I wanted to see if I could get it to rotate first.
The program is working exactly as if I would have used draw_sprite instead of rotate_sprite.
Edit: Ok, it wasn't rotating because it had to be fixed, but the mouse isn't working.
you are giving it an int. It wants a fixed. use itofix(plater1_rotate) in the rotate_sprite last argument