About Store Forum Documentation Contact



Post Reply 
[Solved] Shooting exactly 2 bullets in a second
Author Message
Kreved Offline
Member

Post: #1
[Solved] Shooting exactly 2 bullets in a second
Hi all.

At first, I wanna say, that I'm not a professional game developer or even programmer, so my question could be very, very dumb.

I'm making some kind of a prototype of an arcade arena shooter (a bit lika a Geometry Wars clone smile), and my problem is shooting.

I need fire to be full auto (binded on the left mouse button) with a rate of fire 2 bullets in a second.

So my Input section is like:
Code:
        if(Ms.b(0) && Time.curTime()-lastB>0.5)
        {    
            lastB=Time.curTime();
        //checking free bullet obj
            for (int i=0; i<300; i++)
            //free?
                if (!Bl[i].Check())
                {
                //givin params to bullets, not so important
                    Vec2 temp;
                    temp = -Getpos()+Ms.pos();
                    float =sqrt(temp.x*temp.x+temp.y*temp.y);
                    temp.x/=g;
                    temp.y/=g;
                    Bl[i].Set(Getpos(), temp);
                    break;
                }
       }
So, as you can see, I use Ms.b(0) event and I check if the differenct between current time in seconds and time of last shot is more then 0.5 seconds.

Completly doesn't work. It is shooting >9000 bullets in a second :(

What I am doing wrong?

P.S. Sory for my poor english
(This post was last modified: 03-09-2011 12:09 PM by Kreved.)
03-09-2011 10:51 AM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #2
RE: Shooting exactly 2 bullets in a second
well you need to change the timer:

PHP Code:
lastB+=Time.d();

if(
Ms.b(0) && lastB>0.5)
{
//do checks here

lastB 0//reset bullet timer.


There is always evil somewhere, you just have to look for it properly.
03-09-2011 11:10 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Mardok Offline
Member

Post: #3
RE: Shooting exactly 2 bullets in a second
PHP Code:
//global------------------
Flt time_to_shot 0.5;
//------------------------

update()
{
     
time_to_shot -= Time.d();

     if( (
Ms.b(0)) && (time_to_shot <=0) )
     {
          
shot();
          
time_to_shot 0.5;
     }

03-09-2011 11:14 AM
Find all posts by this user Quote this message in a reply
Kreved Offline
Member

Post: #4
RE: Shooting exactly 2 bullets in a second
Thx, it's all working correct now!

It's nice to see, how fast I can get help here. Thx again (:
03-09-2011 12:04 PM
Find all posts by this user Quote this message in a reply
Post Reply