Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: a little problem involving sounds and sword fighting  (Read 1128 times)

0 Members and 1 Guest are viewing this topic.

CursedOne

a little problem involving sounds and sword figh...
« 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  ???
Logged
Re: a little problem involving sounds and sword ...
« Reply #1 on: November 24, 2006, 05:29:02 pm »
  • (y)(;>.<;)(y)
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3293
It'd be nice to know what you're using...GameMaker? MMF? C++? QuickBASIC *snigger*?
Logged
Re: a little problem involving sounds and sword ...
« Reply #2 on: November 24, 2006, 06:17:15 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2374
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.
« Last Edit: November 24, 2006, 06:18:52 pm by BlueMonkey »
Logged

CursedOne

Re: a little problem involving sounds and sword ...
« Reply #3 on: November 24, 2006, 06:40:04 pm »
sorry im using gamemaker 6.1. ;)
Logged
Re: a little problem involving sounds and sword ...
« Reply #4 on: November 24, 2006, 06:40:51 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2374
It still works. I use it too.
Logged

CursedOne

Re: a little problem involving sounds and sword ...
« Reply #5 on: November 24, 2006, 06:58:59 pm »
thanks ;)
Logged

Goodnight

Once and future Captain
Re: a little problem involving sounds and sword ...
« Reply #6 on: November 24, 2006, 08:54:14 pm »
  • With a Capital G
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 706
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));
Logged

Antidote

>.>
Re: a little problem involving sounds and sword ...
« Reply #7 on: November 24, 2006, 09:50:58 pm »
  • In all seriousness who's serious?
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1485
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
« Last Edit: November 24, 2006, 09:54:05 pm by Antidote »
Logged
  • Axiomatic Data Laboratories
Pages: [1]   Go Up

 


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



Page created in 0.125 seconds with 54 queries.

anything