PDA

View Full Version : TBEM sample 1 - For whom the bell tolls



Michael Hartlef
21-03-2008, 01:51
Hi folks,

here is the first example that hopefully shows a little about the TBEM module. It feature a self repeating event.




' TBEM sample 1 by Michael Hartlef, 2008

USES "TBASS"
uses "TBEM"
USES "Console"
USES "FILE"

DIM sFile AS STRING '---Filename to load
DIM Channel AS DWORD '---Audio channel to use
DIM SamChannel AS DWORD '---Sample channel to use
dim count as long
dim eventSnd as long
dim retval as long

count = 13
%evt_sound = 1

function playsfx() as long
count -= 1
if count > 0 then
TBASS_ChannelPlay(SamChannel, %TBASS_TRUE)
console_writeline("Number of SoundFX left: "+count)
endif
end function

' Setup output for the default device
' n = TBASS_Init (Device, Frequency, Flags, Win, clsID)
IF TBASS_Init(-1, 44100, 0, 0, 0) = 0 THEN
console_Writeline("Can't initialize device. Program aborted")
else

' Set the volume level
TBASS_SetVolume(50)

' Now ask which file to load
sFile = APP_SourcePath+"soundfx\bells007.wav"

' Check if file exists
if file_exists(sFile) = %FALSE then
console_Writeline("File " & sFile & $crlf & "does not exixts.")
else
' File does exist now load as a sample using that filename
Channel = TBASS_SampleLoad(%TBASS_FALSE, sFile, 0, 0, 1, %TBASS_SAMPLE_FLOAT )
IF Channel = 0 THEN
' whatever it is, it isn't playable
console_Writeline( "Can't play the file " & sFile)
else
' Create a Sample playback Channel
SamChannel = TBASS_SAMPLEGetChannel(Channel,%TBASS_FALSE)
' File does exist now create a stream using that filename
' SamChannel = TBASS_StreamCreateFile(%TBASS_FALSE, sFile, 0, 0, %TBASS_SAMPLE_LOOP or %TBASS_STREAM_PRESCAN )
IF SamChannel = -1 THEN
' Error trying to get a channel
console_Writeline("No Channel. Can't play the file " & sFile)
else
' Valid File now set it to play

'Add an event to the event manager
eventSnd = TBEM_AddEvent("playsfx",%evt_sound)

'Repeat the sound every 5 seconds
TBEM_SetRepeat(eventSnd,%TRUE,5000)

'Fire a trigger to start runnign the event
TBEM_AddTrigger(%evt_sound)

Console_Writeline("It's 12 o'clock midnight...")
while count <> 0
'Check and run active events
retval = TBEM_Run
wend

ENDIF
ENDIF
ENDIF
endif
' Clearup TBASS
TBASS_Free


console_writeline("Press any key...")
console_waitkey

kryton9
21-03-2008, 04:28
Mike, thanks for this module and now sample script, help and source. Another major step into making thinBasic an awesome game development environment!

ErosOlmi
21-03-2008, 08:46
Mike I get GPF in module after 2 execution. See image.

Ciao
Eros

Petr Schreiber
21-03-2008, 09:00
Hi Mike,

fantastic, repeated events are very nice!
I also got GPF, but then I downloaded latest version and the "clock" works as expected.
The sound is like from horror movie :)


Thanks,
Petr

ErosOlmi
21-03-2008, 09:00
SORRY, MY FAULT.
I didn't download latest version from http://community.thinbasic.com/index.php?topic=1624.msg11718#msg11718

Now all is ok.
Thanks

Michael Hartlef
21-03-2008, 09:54
Sorry guys for the inconvenience, yes you had to download the latest version.

kryton9
22-03-2008, 00:05
Petr, "For whom the bell tolls" is a song by Metallica, and it has a similar bell sound in the song. You might want to check it out, it is a classic.

But the event module is new and very exciting that is for sure!

Michael Hartlef
22-03-2008, 09:31
:) Ahhh someone who knows ;) I'm big into Heavy Metal. It's my absolute favorite type of music.

On June 11th, my wife and me are going to see KISS. That will be awesome and probably the last chance to see them live. Who knows how long they are gonna playing and when they are back in germany the next time. I think it is allready 8 years since they were here the last time.

Petr Schreiber
22-03-2008, 12:14
Hi Mike,

hope you will enjoy the concert in summer, do will they still have the classic black and white mad shader on the faces? :)

Regarding the module, if I get it correctly, the eventIDs must be different across various eventGroups?


Thanks,
Petr

Michael Hartlef
22-03-2008, 14:28
Hi Petr,

yes, since around 1998 they are back in the masks after a long time wearing no masks.

The eventID is basically the memory location of the event structure. So each event gets a new ID. It has nothing to do with the eventGroup. I had the idea to have event groups if you need to make sure that certain events run before others. Like for an example,
you have events that draw the gui. Then there are events that deal with the game logic. Another one draws the game content. So you create three eventgroups




'Define eventgroups
%evg_gui = 1
%evg_gamelogic = 2
%evg_drawgame = 3

'Game loop
while gameactive = %TRUE

'... do some other stuff
TBEM_Run(%evg_gamelogic)
TBEM_Run(%evg_drawgame)
TBEM_Run(%evg_gui)

wend



It is not necessary to create and use groups, the default group is 0 and so if don't assign an event to a group, it will allways be in
the default group.

Ciao
Michael

Petr Schreiber
22-03-2008, 16:38
Now I get it,

thanks Mike! That can be very handy.


Petr

kryton9
22-03-2008, 23:44
about KISS: I saw them in Cleveland, Ohio I think it was 1975, it was one of the great concerts I did see. Their show was incredible.
Of course Fire Breathing, but what got me were 2 things I had never seen on top of that. The drummer playing a solo and the drums elevated way up into the air via hydraulics, I mean all the way up to the top of the Arena, It was an amazing site. The other was a guitar solo that in the middle of a very long sustained note, Ace Frehley set the guitar on a stand and it ignited on fire while holding the sustained note, and then he ran off into the darkness and the only thing lit was a small spot light on this burning guitar and then he picked up the solo again while climbed up on some equipment and then song kicked in heavy afterwards with the whole band with fireworks, it was amazing. Enjoy the concert Mike!