ZFGC

Resources => Coding => Topic started by: CursedOne on November 24, 2006, 04:58:40 pm

Title: a little problem involving sounds and sword fighting
Post by: CursedOne on November 24, 2006, 04:58:40 pm
 :) hey. im now programming some of the key features of my game loz : moonwinter ages and need some help in the form of code. i have made the entire combat system for link. he can run, slash, spin, get his bow or shield out, shoot his bow and even move with his bow or shield! but the slashing is a problem... how would i make link make a random sound (out of three possible sounds) each time he slashes or spins? can any of you help me out  ???
Title: Re: a little problem involving sounds and sword fighting
Post by: TheDarkJay on November 24, 2006, 05:29:02 pm
It'd be nice to know what you're using...GameMaker? MMF? C++? QuickBASIC *snigger*?
Title: Re: a little problem involving sounds and sword fighting
Post by: Dumb_Ass on November 24, 2006, 06:17:15 pm
Maybe like this is you are using Game Maker 6.0+...

Code: GML
  1. sound = round(random(2))
  2. if sound = 0 sound_play(snd_attack1);
  3. if sound = 1 sound_play(snd_attack2);
  4. if sound = 2 sound_play(snd_attack3);
  5.  
OF course, you would put that in close to the code that actually makes him slash.
Title: Re: a little problem involving sounds and sword fighting
Post by: CursedOne on November 24, 2006, 06:40:04 pm
sorry im using gamemaker 6.1. ;)
Title: Re: a little problem involving sounds and sword fighting
Post by: Dumb_Ass on November 24, 2006, 06:40:51 pm
It still works. I use it too.
Title: Re: a little problem involving sounds and sword fighting
Post by: CursedOne on November 24, 2006, 06:58:59 pm
thanks ;)
Title: Re: a little problem involving sounds and sword fighting
Post by: Goodnight on November 24, 2006, 08:54:14 pm
You might notice after a little while that snd_attack2 is twice as likely to play as the other two. That's because you're rounding the random number to the nearest integer. Think about how that works.

Bump up the random by 1, and round down instead to get equal probability.
Code: [Select]
var sound;
sound = floor(random(3));
if sound = 0 sound_play(snd_attack1);
else if sound = 1 sound_play(snd_attack2);
else if sound = 2 sound_play(snd_attack3);

Or, GM6 has a new function called choose() that makes some cases of randomness much easier.
Code: [Select]
sound_play(choose(snd_attack1, snd_attack2, snd_attack3));
Title: Re: a little problem involving sounds and sword fighting
Post by: Antidote on November 24, 2006, 09:50:58 pm
I've run into a few problems using GM's choose() function >_> and that code doesn't have to be if statements I used a switch statement for my engine and it works like a charm :D.
this is how i set up the engine.

Code: GML
  1. if (objLink.state == objLink._SLASH_)
  2. {
  3.  _SLASH_SOUND_ = floor(random(3)); // used Goodnights rand code instead of my current >_>
  4.  switch(_SLASH_SOUND_)
  5.  {
  6.   case 0: sound_play(sndSwordSlash1);break;
  7.   case 1: sound_play(sndSwordSlash2);break;
  8.   case 2: sound_play(sndSwordSlash3);break;
  9.  }
  10. }
  11.  
Just so you know I only use capitalized vars for pieces of code that involve the player or enemy states. In my Engine _SLASH_ has the value of 3 Although it doesn't really weigh on the development of your game I figured that small bit of info may help also if you use this code you don't have to use obj*.* for anything I just put it there for S&G

Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved