OK, there is a game I am working on. It has some falling enemies, and if you right click some bullets appear. The bullets don't fall that fast. Well, they aren't supposed to. They fall at two different speeds on different machines. One at normal, one at craaaaaaaaazy fast. On both computers, the zombies fall at the same speed. Here is the (relevant) code:
1 | //this is part of game() which is called in main() |
2 | while((!key[KEY_ESC])&&(halive)){ |
3 | while(speed_counter > 0){ |
4 | for(int i = 0; i < BULLET_MAX; i++){ |
5 | if(bullets<i>.active){ |
6 | bullets<i>.move_bullet(); |
7 | } |
8 | } |
9 | /*===the end==========================*/ |
10 | speed_counter--; |
11 | } |
12 | /*###=====#=======#=====##############*/ |
13 | /*##=START=DRAWING=STUFF=#############*/ |
14 | /*###=====#=======#=====##############*/ |
15 | //draw stuff... |
16 | } |
17 | |
18 | //###################################### |
19 | //this is in a header |
20 | class bullet{ |
21 | public: |
22 | float x, y; |
23 | float speedx, speedy; |
24 | int active; |
25 | void init_bullet(float dx, float dy, int cur_x, int cur_y){ |
26 | active = 1; |
27 | x = cur_x; |
28 | y = cur_y; |
29 | speedx = dx; |
30 | speedy = dy; |
31 | } |
32 | void move_bullet(){ |
33 | speedy += 0.01; |
34 | if(speedy > 3) |
35 | speedy = 3; |
36 | x += speedx; |
37 | y += speedy; |
38 | if((x < 0)||(x > 480)||(y < 0)) |
39 | active = 0; |
40 | } |
41 | void kill(){ |
42 | x = y = -50; |
43 | active = speedx = speedy = 0; |
44 | } |
45 | }; |
Anyone know what is wrong?
i think you need to post more code,
for example, your timing and timing-initialization code.
also post the section moving the zombies.
make sure the zombies isn't moved inside the drawing loop, if you have any... ignore that for now.
also, set up a summary of you game loop.
I see no timer logic. Computers run at different speeds, so it's no surprise that incrementing/decrementing variables occurs at different rates across computers.
Hnggg...my code is long. Lets see...
and here is the header:
I tried to abbreviate...the drawing I just plain deleted. The titles should make it easier to wade through. Another (unmentioned) problem is that bullets don't go away when they hit an enemy. Yet another problem is when I quit, it complains abou some call-stack stuff, but that is irrelevant and I won't include what I think is the problem code (oddly, it is only sometimes). And yes there is timer logic.
You're not using the timer variable correctly. Try replacing the code around the "while((!key[KEY_ESC])&&(halive)){" with the following (<<<<<<< denotes the changed or added lines):
And get rid of the line that decrements speed_counter.
[edit]
The rest(1) is to give the OS some processing time.
[/edit]
I have no idea...at ALL what you are saying. Where would that go in my code? It is not clear at all. So all of that is before my logic? Because this code...
1 | int s_counter = 1; |
2 | while((!key[KEY_ESC])&&(halive)){ |
3 | if (speed_counter == 0) // <<<<<<< |
4 | rest(1); // <<<<<<< |
5 | s_counter = speed_counter; // <<<<<<< |
6 | speed_counter = 0; // <<<<<<< |
7 | while(s_counter > 0){ // <<<<<<< |
8 | //logic |
9 | /*===the end==========================*/ |
10 | //speed_counter--; |
11 | } |
12 | /*###=====#=======#=====##############*/ |
13 | /*##=START=DRAWING=STUFF=#############*/ |
14 | /*###=====#=======#=====##############*/ |
15 | //drawing |
16 | /*====================================*/ |
17 | blit(buffy, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); |
18 | } |
19 | return h_death(pc.score); |
20 | } |
...just makes the program not run. It freezes.
I used to find these threads so interesting... I can't seem to motivate myself to help out anymore.
I really should quit programming for a job, its corrupting me
Sorry, slightly incorrect instructions - put "s_counter--;" instead of the commented line "speed_counter--;".
Well, it works. The bullets should be falling at MOST twice as fast as the zombies. Can some people check it out? If so, se how fast the bullets fall. Instructions: Left click to auto shoot, right click to shrapnel blast. When the bar on the far right is dark red, you can shrapnel blast. Score is score, combo is combo, mines are mines. I would tell the story, but I can't now.
Bullets? I can't see any. But the zombies drop down at various rates. And the shrapnel fans out and drops at a reasonable rate.
Yeah, I meant the shrapnel. It just uses a class called "bullet" so thats what I think of it as. Thank you for testing it.
offtopic:
I used to find these threads so interesting... I can't seem to motivate myself to help out anymore.
My problem is that i don't even read threads.. but i glance.. hope i can help, and end up posting something completely irrevelevant.
Whats up with this depressing mood??... anyway, it work fine.