Computer Science Canada

Sound effects in mario

Author:  God [ Sun May 11, 2003 3:20 pm ]
Post subject:  Sound effects in mario

Alright, so im makin a Mario clone, it works fine for running and jumping and animations and so on. Problem is, i put in some coins that spin through animation, then i put in sound effects (ie. jumping, fireballs,background music...) but whenever mario jumps into a coin the coin sound plays over and over itself until he is out of the coin.
its a process and its not inside a loop or anything and i cant figure out how to fix it

Question Question Question
here is the if statement

Quote:
if mariox + mariowidth > coinx and mariox < coinx + coinradius and marioy + marioheight > coiny and marioy < coiny + coinradius then
fork PlaySound (CoinSound)
end if


i understand WHY it doesnt work, but i need to know HOW to fix it

Author:  Homer_simpson [ Sun May 11, 2003 3:51 pm ]
Post subject: 

you know when those sorta things happen to me i declare a boolean, check this to see what i mean

code:
var play_coin:boolean:=false

loop
%blah blah
%blah blah
%blah blah

if supposed to play the sound effect then
play_coin:=true
end if

%blah blah
%blah blah
%blah blah
if play_coin then
play("coin sound effect.wav")
play_coin:=false
end if
%blah blah
%blah blah
%blah blah
end loop


This usually solves my problem i dunno if it'll work for u or not... =/

Author:  hello [ Sun May 11, 2003 3:56 pm ]
Post subject:  hello

when u play the music u should have a checking statement that if u are in the coin u play the music
and then another if that when u are not in the coin u play another music

Author:  Homer_simpson [ Sun May 11, 2003 4:08 pm ]
Post subject: 

isn't that just what i said??!! Evil or Very Mad Mad Evil or Very Mad Mad

Author:  God [ Sun May 11, 2003 4:33 pm ]
Post subject: 

I got the sound working and the coin dissappears and so on now.... but i tried it with multiple coins and when i hit one they all dissappear.....
hmm....


Quote:
var hit : boolean := false
procedure coin (position, height : int)
if c > 8 then
c := 1
end if
coinx := maxx - coinpos + position - mariox
coiny := height
coinradius := Pic.Width (Coin (c))
if mariox + mariowidth > coinx and mariox < coinx + coinradius and marioy + marioheight > coiny and marioy < coiny + coinradius then
if hit = false then
fork PlaySound (CoinSound)
Pic.Draw (Coin (0), coinx, coiny, picMerge)
end if
hit := true
elsif hit = false then
if backx <= maxx - position then
Pic.Draw (Coin (c), coinx, coiny, picMerge)
end if
end if

end coin




Any help is much appreciated Coin(0) is a blank coin to make it dissappear...

Quote:
%draw procedure...
Pic.Draw (background, backx, backy, picCopy)
c += 1
coin (600, 200)
coin (750, 200)
Pic.Draw (marioBig (p), mariox, marioy, picMerge)
View.Update

Author:  Homer_simpson [ Sun May 11, 2003 4:36 pm ]
Post subject: 

process and fork stuff always confuses me that why i always use procedure and functions so sorry cant help with that but i could rewrite the whole code if u want...

Author:  Homer_simpson [ Sun May 11, 2003 4:40 pm ]
Post subject: 

but i can suggest one thing:
code:

type acoin:record
x,y:int
visibile:boolean
end record
var coins:array 1..10 of acoin

procedure draw

for i:1..10
if coins(i).visible then
Pic.Draw (coin,x,y, picCopy)
end if
end for

end draw


and everytime u want a coin to disappear simply make the coins(number).visible:=false

Author:  hello [ Sun May 11, 2003 4:45 pm ]
Post subject:  apology

sorry
i cant read
... Embarassed

well for the new prob u should have have each individual coin as a proc or fork or watever
and have it like this:

var x,y:array 1.. (num of coins) of int

fork coin(coinx,coiny:int)

so each coin has its own x and y value

then within the fork have the x and y value set it to an global variable
like:

x(_):=coinx
y(_):=coiny

after just check using ifs in a for loop
so its quicker
try it though but ijm not sure that im rite

Author:  God [ Sun May 11, 2003 8:03 pm ]
Post subject: 

hmm, i'd never used records before now... i was also trying to write it so i could call the procedure to make multiple coins repeatedly, but from the sounds of it this will work better... thanks... but keep watching the topic i dont doubt ill have many more problems soon


: