none
Play sound at attack RRS feed

  • Question

  • hi there! i need some help with my game again...
    heres the game:
    http://rapidshare.com/files/271441983/Zombiegame.rar.html

    i have following aim:
    i want a zombie slash sound to be played all the time the player gets attacked by the zombies.(a loop)
    i want the player to "scream in pain" everytime he gets hit by a zombie. (doesnt have to be synchronized with the zombie slash sound, but would be cool^^)

    but i cant manage do code this... is there a way to set multiple timers with different intervals?(cuz it would be easy that way)

    atm, the sound just gets played when the player STOPS touching the enemy.. cuz its looping playsound and stopsound all the time the player is touching the enemy... so you cant hear anything.. and playandwait wont work, cuz that would delay the whole game..

    thx so much guys!
    Live for nothing, OR CODE FOR SOMETHING! (Happy now vijaye?^^)
    • Edited by Dudeson Tuesday, August 25, 2009 8:00 PM
    Tuesday, August 25, 2009 7:53 PM

Answers

  • Some experimentation in a small sub program should help.

    Timer.Tick = OnTimer
    Timer.Interval = 1000 ' Tick interval should be slow enough to do most of the required stuff in the main loop

    iTimer = 0
    iTick1 = 0
    iTick3 = 0
    iTick7 = 0

    While ("True")
      If (iTick1 = 1) Then 'every tick
        TextWindow.WriteLine("Tick 1")
        iTick1 = 0
      EndIf
      If (iTick3 = 1) Then 'every 3rd tick
        TextWindow.WriteLine("Tick 3")
        iTick3 = 0
      EndIf
      If (iTick7 = 1) Then 'every 7th tick
        TextWindow.WriteLine("Tick 7")
        iTick7 = 0
      EndIf
    EndWhile

    Sub OnTimer
      iTimer = iTimer+1
      If (iTick1 = 0 And Math.Remainder(iTimer,1) = 0) Then 'every tick
        iTick1 = 1
      EndIf
      If (
    iTick3 = 0 And Math.Remainder(iTimer,3) = 0) Then 'every 3rd tick
        iTick3 = 1
      EndIf
      If (
    iTick7 = 0 And Math.Remainder(iTimer,7) = 0) Then 'every 7th tick
        iTick7 = 1
      EndIf
    EndSub


    • Edited by litdevModerator Tuesday, August 25, 2009 8:56 PM better logic to cope with fast tick and slow code
    • Marked as answer by Dudeson Tuesday, August 25, 2009 9:26 PM
    Tuesday, August 25, 2009 8:29 PM
    Moderator

All replies

  • Some experimentation in a small sub program should help.

    Timer.Tick = OnTimer
    Timer.Interval = 1000 ' Tick interval should be slow enough to do most of the required stuff in the main loop

    iTimer = 0
    iTick1 = 0
    iTick3 = 0
    iTick7 = 0

    While ("True")
      If (iTick1 = 1) Then 'every tick
        TextWindow.WriteLine("Tick 1")
        iTick1 = 0
      EndIf
      If (iTick3 = 1) Then 'every 3rd tick
        TextWindow.WriteLine("Tick 3")
        iTick3 = 0
      EndIf
      If (iTick7 = 1) Then 'every 7th tick
        TextWindow.WriteLine("Tick 7")
        iTick7 = 0
      EndIf
    EndWhile

    Sub OnTimer
      iTimer = iTimer+1
      If (iTick1 = 0 And Math.Remainder(iTimer,1) = 0) Then 'every tick
        iTick1 = 1
      EndIf
      If (
    iTick3 = 0 And Math.Remainder(iTimer,3) = 0) Then 'every 3rd tick
        iTick3 = 1
      EndIf
      If (
    iTick7 = 0 And Math.Remainder(iTimer,7) = 0) Then 'every 7th tick
        iTick7 = 1
      EndIf
    EndSub


    • Edited by litdevModerator Tuesday, August 25, 2009 8:56 PM better logic to cope with fast tick and slow code
    • Marked as answer by Dudeson Tuesday, August 25, 2009 9:26 PM
    Tuesday, August 25, 2009 8:29 PM
    Moderator
  • hmmm.. i'll take a look at this! thx!
    Live for nothing, OR CODE FOR SOMETHING! (Happy now vijaye?^^)
    Tuesday, August 25, 2009 8:42 PM
  • looks like you solved the animation timing problem and the sound problem at once! thx man! i'll try to implement it! (sound is already pretty much done...)
    Live for nothing, OR CODE FOR SOMETHING! (Happy now vijaye?^^)
    Tuesday, August 25, 2009 9:27 PM