another bullet question
neil dwyer

There is no bullet, why?

1#include <allegro.h>
2#include <stdlib.h>
3#include <math.h>
4#include <iostream.h>
5 
6#define player_speed 1
7#define bullet_speed 2
8 
9 
10float player1_x = 320;
11float player1_y = 240;
12float player2_x;
13float player2_y;
14float player1_rotate;
15float player2_rotate;
16float bullet_x;
17float bullet_y;
18int mickeyx;
19int mickeyy;
20int RED = makecol(255,0,0);
21 
22BITMAP *player1;
23BITMAP *player2;
24BITMAP *buffer;
25 
26void bullet_move()
27{
28bullet_x += bullet_speed * fixtof(fcos(ftofix(player1_rotate)));
29bullet_y += bullet_speed * fixtof(fsin(ftofix(player1_rotate)));
30if(key[KEY_SPACE])
31{
32bullet_x = player1_x;
33bullet_y = player1_y;
34putpixel(buffer,bullet_x, bullet_y,RED);
35}
36}
37 
38void player1_movement()
39{
40 if(key[KEY_A] && player1_x > 0)
41 {
42 player1_x -= player_speed;
43 }
44 if(key[KEY_D] && player1_x < 640 - player1->w)
45 {
46 player1_x += player_speed;
47 }
48 if(key[KEY_W] && player1_x > 0 && player1_x < 640 - player1->w && player1_y > 0 && player1_y < 480 - player1->h)
49 {
50 player1_y -= player_speed * fixtof(fcos(ftofix(player1_rotate)));
51 player1_x += player_speed * fixtof(fsin(ftofix(player1_rotate)));
52 }
53 if(key[KEY_S] && player1_y < 480 - player1->h)
54 {
55 player1_y += player_speed;
56 }
57 if(player1_y + player1->h >= 480)
58 {
59 player1_y = 479 - player1->h;
60 }
61 if(player1_y <= 0)
62 {
63 player1_y = 1;
64 }
65 if(player1_x <= 0)
66 {
67 player1_x = 1;
68 }
69 if(player1_x + player1->w >= 640)
70 {
71 player1_x = 639 - player1->w;
72 }
73 get_mouse_mickeys(&mickeyx, &mickeyy);
74 player1_rotate += mickeyx;
75
76
77}
78 
79int main(int argc, char *argv[])
80{
81 allegro_init();
82 install_keyboard();
83 install_mouse();
84 set_mouse_speed(1,1);
85 set_color_depth(16);
86 set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);
87 cout << bullet_x << " " << bullet_y << endl;
88 
89 buffer = create_bitmap(640,480);
90 
91 player1 = load_bitmap("player.bmp", NULL);
92
93 player2 = load_bitmap("player.bmp", NULL);
94
95 
96
97
98 while(!key[KEY_ESC])
99 {
100 player1_movement();
101 bullet_move();
102 rotate_sprite(buffer, player1, player1_x, player1_y, ftofix(player1_rotate));
103 blit(buffer, screen,0,0,0,0,640,480);
104 clear_bitmap(buffer);
105 }
106 
107 destroy_bitmap(player1);
108 destroy_bitmap(player2);
109 destroy_bitmap(buffer);
110 
111 return 0;
112}
113END_OF_MAIN()

Myrdos

Well, I don't see any kind of delay in your code. My guess: the player's movement seems to be linked to the key repeat rate, which prevents it from moving at an insane speed. There is no such limiter for your bullet. Thus, it flies off the screen too quickly to see.

To make your game run at the same speed on different computers, see here.

neil dwyer

Hmm, that is seems to be it because my cout << bullet_x << bullet_y shows that the bullet moves very fast. How should I fix it, maybe a timer?

EDIT: oops, didn't see the end of your post.

Lucid Nightmare

Where's the timer for the code???

Thread #586220. Printed from Allegro.cc