Results 1 to 10 of 10

Thread: Shooting at the Player

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Solved it I think :


    Code:
    procedure PlaySound(const SampleFilename : String);
    var mySound :  HStream;
    begin
      // free both MOD and stream, it must be one of them! :)
    // BASS_MusicFree(mySound);
    // BASS_StreamFree(mySound);
     mySound := BASS_StreamCreateFile(FALSE, PChar(SampleFilename), 0, 0, BASS_SAMPLE_FX {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF} or BASS_STREAM_AUTOFREE);
    // BASS_SetConfig(BASS_CONFIG_GVOL_STREAM, 4000);
     BASS_ChannelPlay(mySound, False);
     if BASS_ChannelIsActive(mySound) = 0 then
        begin
          BASS_ChannelStop(mySound);
          BASS_Streamfree(mySound);
        end;
    end;
    BASS_STREAM_AUTOFREE was needed , note though it stops it correctly but it was not freed no idea why....

    Thanx

  2. #2
    It's been a while since I used BASS, but unless the workflow has changed, you shouldn't really free streams while the program is running. Calling StreamCreateFile basically reads the file again from the disk, and that's bad. Instead, what you want is:
    1. Load file at program start
    2. Use channels to play the sound (the BASS Stream). If you want to change the volume, stop, pause, or however manipulate the playing sound, keep the channel number and use the BASS_ChannelSomething() functions. You don't have to free channels manually, as managing memory for channels is done automatically by BASS.
    3. Only free the Stream when you're closing the application, or for some reason need to load a different file to the same stream handle (say, your game hero underwent a transformation and now uses a different sound set)

  3. #3
    Super Vegeta , thank you!

    Now that you told me , it makes sense ... and a lot of sense. Especially the disk io part . My game hangs for a sec when the Music changes.

    I Need to rewrite the functions.

    Load all Sound and Music effects on Startup . And then just Play the appropriate channel instead.
    So if a Bullett is shoot by 5 different alliens instead of wasting disk i/o I just Play the channel from Memory when needed.


    Thank you for this great advice!!!

  4. #4
    Hi all,

    Just wanted to post, I managed to solve the bullet calculation . Not alone unfortunately... google helped. And I don't understand it 100%.... I think I may end up taking private Math Classes

    Code:
                        vx := (PlayerSprite.X+(PlayerSprite.ImageWidth/2)) - (Self.X+(Self.ImageWidth/2));
                        vy := (PlayerSprite.Y+(PlayerSprite.ImageHeight/2)) - (Self.Y+(Self.ImageHeight/2));
    
                        len := sqrt(sqr(vx) + sqr(vy));
    
                        vx := vx  / len;
                        vy := vy / len;
    
                        Bullet.Direction:= vx * 4;
                        Bullet.MoveSpeed:= vy * 4;
    What happens here is the vector lenth is calculated... then normalised , I understand what it does... goes from 0 to 1 .... but this formula is something I would have never figured out

    Also I realised my mistake...I need to alter the speed on both X and Y axis in order to work perfectly ... it even shots backwards...

    Greetings...

    ps.: I dont have any new material, I have level 1 done... altered the background, enemies use different attacks... level 2 is done..it turned out quiet cool... level 2 ending is done
    It took a while to come up with a crazy story... Its god damn hard, but I will try and not post anything until done....4 more levels

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •