Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another Mouse Issue?
#6
(04-25-2024, 01:42 AM)bplus Wrote: i approached that problem by timing bullets fired

also you could limit number of bullets, waiting until bullet off screen before reactivating that bullet slot to fire again.
I use a similar approach. The code below is a snippet from my Widescreen Asteroids game that controls bullet fire. I tend to set up frame counters as timers.

In the second line of code I first check to see if Clock.shipBullet is zero. If it is that means I can fire again. If not toward the end of the snippet you'll see I decrement Clock.shipBullet by one with each passing frame.

The game runs at 60 frames per second and setting Clock.shipBullet to 10 after each bullet fired ensures that the player can fire no more than 6 bullets per second.

Code: (Select All)
        IF Clock.warp = 0 THEN '                                                  warping to next level?
            IF Clock.shipBullet = 0 THEN '                                        no, ready to fire again?
                IF _KEYDOWN(Keys.fire) THEN '                                    yes, fire bullet key pressed?
                    Clock.shipBullet = 10 '                                      yes, set bullet interval
                    c = 0
                    DO '                                                          cycle through bullets
                        IF ShipBullet(c).life = 0 THEN '                          bullet active?

                            '*******************
                            '* Add ship bullet *
                            '*******************

                            '**
                            '** NOTE: player ship bullet lifespan below (70)
                            '**

                            ShipBullet(c).life = 70 '                            set bullet lifespan
                            ShipBullet(c).x = ObjX1(Ship, 0) '                    set bullet X,Y origin
                            ShipBullet(c).y = ObjY1(Ship, 0) '                    (front tip of player ship)

                            '**
                            '** NOTE: player ship bullet speed below (9)
                            '**

                            ShipBullet(c).xv = ObjVectorX(Ship) + 9 * ObjPSine(ObjAngle(Ship)) '  bullet X,Y vectors
                            ShipBullet(c).yv = ObjVectorY(Ship) + 9 * -ObjPCosine(ObjAngle(Ship))
                            PlaySound Sounds.fire, TRUE
                            c = 4
                        END IF
                        c = c + 1
                    LOOP UNTIL c = 5
                END IF
            ELSE
                Clock.shipBullet = Clock.shipBullet - 1 '                        decrement bullet interval timer
            END IF
        END IF
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply


Messages In This Thread
Another Mouse Issue? - by NakedApe - 04-25-2024, 12:54 AM
RE: Another Mouse Issue? - by SMcNeill - 04-25-2024, 01:06 AM
RE: Another Mouse Issue? - by TerryRitchie - 04-25-2024, 01:40 AM
RE: Another Mouse Issue? - by NakedApe - 05-01-2024, 11:42 PM
RE: Another Mouse Issue? - by SMcNeill - 05-02-2024, 12:23 AM
RE: Another Mouse Issue? - by Pete - 04-25-2024, 01:27 AM
RE: Another Mouse Issue? - by bplus - 04-25-2024, 01:42 AM
RE: Another Mouse Issue? - by TerryRitchie - 04-25-2024, 02:08 AM
RE: Another Mouse Issue? - by NakedApe - 04-25-2024, 02:16 AM
RE: Another Mouse Issue? - by TerryRitchie - 04-25-2024, 05:33 AM
RE: Another Mouse Issue? - by a740g - 04-26-2024, 02:23 AM
RE: Another Mouse Issue? - by bplus - 04-25-2024, 11:50 AM
RE: Another Mouse Issue? - by NakedApe - 04-25-2024, 04:11 PM
RE: Another Mouse Issue? - by TerryRitchie - 04-25-2024, 05:43 PM
RE: Another Mouse Issue? - by NakedApe - 04-26-2024, 06:19 AM
RE: Another Mouse Issue? - by TerryRitchie - 05-02-2024, 12:31 AM
RE: Another Mouse Issue? - by SMcNeill - 05-02-2024, 12:31 AM
RE: Another Mouse Issue? - by NakedApe - 05-02-2024, 03:16 AM



Users browsing this thread: 3 Guest(s)