• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

seconds counter

Dubbsta

Active member
Joined
Jul 13, 2017
Messages
208
im trying to do something like shoot bullets every second on keydown, so far i have this

timer = Millisecs()
seconds = timer / 1000

i am using a delta timer
i dont know what else from here...help needed
 
I would just treat 'bullet-power' as a resource that you add every update - your update function might contain something like:

' How much time passed since last update, use for delta timing etc.
Local millisPassed:Int = Millisecs() - lastMillis
lastMillis = Millisecs()

' Handle bullets
bulletPower += millisPassed
If bulletPower > 1000
If KeyDown( KEY_SPACE )
FireBullet()
bulletPower -= 1000
End
bulletPower = Min( 1000, bulletPower )
End

[lastMillis and bulletPower are fields or globals]

I haven't tested this but that is the general idea. If you aren't firing at the moment, bulletPower will build up so when you do press space again the first bullet will be immediate. But you don't want it to build up indefinitely or loads of bullets will be fired - one every update until bullet power runs out - so you cap the stored power at one bullet's worth.

The above allows you to easily implement Pause or Fast Fire modes too (in Pause mode bulletPower doesn't build up; in fast Fire mode bullets cost less than 1000)
 
Last edited:
thanks Gerry i got it to work as a test with drawtext to see exactly whats happening. will this work with a list? also bulletpower min gave an error, what exactly is it supposed to do?
 
thanks Gerry i got it to work as a test with drawtext to see exactly whats happening. will this work with a list? also bulletpower min gave an error, what exactly is it supposed to do?

The Min( x, y ) function returns whichever value is smaller. Maybe auto-conversion fails if one is float and one is int? Anyway the purpose is that if you are not firing, bulletPower builds up to 1000 and goes no further.

Anyhoo... here's a code example. The bar shows current bulletPower, press SPACE to fire when on full power, hold SPACE to fire whenever bar fills. I'm not sure what you mean about a list. Certainly you could add bullets to a list instead of just flashing the screen like in my example.

Code:
Global theApp:BulletApp


Function Main:Int()
    New BulletApp()
    Return 0
End



Class BulletApp Extends App

    Field lastMillis:Int
  
    Field bulletPower:Int
  
    Field firedBullet:Bool
  

    Method OnCreate:Int()
        lastMillis = Millisecs()
        SetUpdateRate( 60 )
        Return 0
    End
  
  
    Method OnUpdate:Int()
        Local millisPassed:Int = Millisecs() - lastMillis
        lastMillis = Millisecs()
        bulletPower += millisPassed
        If KeyDown( KEY_SPACE )
            If bulletPower >= 1000
                firedBullet = True  
                bulletPower -= 1000
            End
        End
        bulletPower = Min( 1000, bulletPower )
        Return 0
    End
  
  
    Method OnRender:Int()
        If firedBullet
            Cls( 255, 0, 0 )
            firedBullet = False
        Else
            Cls( 0, 0, 0 )
        End
        SetColor( 255, 255, 255 )
        DrawRect( 15, 15, 410, 90 )
        SetColor( 0, 0, 0 )
        DrawRect( 20, 20, 400, 80 )
        SetColor( 255, 255, 255 )
        DrawRect( 20, 20, bulletPower * 0.4, 80 )      
        Return 0
    End

End
 
awesome thanks for your help! what i meant was i had a list of bullets and put this around the list and it fired the whole list at once, im sure i just put stuff in the wrong place
 
It will work fine with a list. In my code, bullets are very simplistic: I set firedBullet to True, and then the next OnRender() flashes the screen and sets it to false again. But you could do away with firedBullet (or leave it if you want the flash) and instead add a new bullet to a list. It's up to you what sort of life cycle bullets on the list will have.
 
Back
Top Bottom