ZFGC

Resources => Coding => Topic started by: Whitay on October 24, 2014, 01:48:20 am

Title: Coding in Music Zones
Post by: Whitay on October 24, 2014, 01:48:20 am
Hello all, i have a quick question. Basically, my main overworld is large and has different zones from mountains to forests etc. It is one big room. And now im on the step of implementing music and sound in the world, i want to make more than just one overworld theme. I was hoping to get songs for Mountains and then a different for Forest and a different for Desert, and when you walk into a new zone the old music fades out and the new music fades into play. The fading out and fading in can be done with sound_fade(index,value,time) but im more worried about the sound. The map is a bit more than some square zones, and so the only two solutions for checking if you are in a zone is having tons of if link.x > this and link.y < this and link.x < this and having it be very weird and lots of unnessesary x and y checks, or having a sort of border that you collide with, but this would lead to huge objects.

So, is there an easier way to check this and set music for different zones, or is checking tons of x and y the most simple way to go towards this? My map looks something like this, so you could see all the different zones. This is why i dont want to check x and y, so is there an easier way to do this?
(http://i61.tinypic.com/30mo1ns.png)

Game maker 8/8.1 here.
Title: Re: Coding in Music Zones
Post by: OniShounen on October 24, 2014, 05:07:49 pm
If you are using Gamemaker 8.1 standard you could use 3D sounds, I don't know if in studio you have to have professional.

Look through the manual for 3D sounds.

-This is all assuming you are using gamemaker-
Title: Re: Coding in Music Zones
Post by: Whitay on October 24, 2014, 07:34:02 pm
Wow i forgot to specify. Im in game maker 8.1, not studio.
Title: Re: Coding in Music Zones
Post by: Kami on October 24, 2014, 07:47:44 pm
Well I have a few ideas, but I have a few things I need to ask first.

Is it view based, similar to the zelda or links awakening locked screen, meaning the view stays within a set spot or is it more akin to minish cap views not being locked?

or is it the view just follows link and can overlap the biomes, meaning like for example, forest and lake hylia on the same screen?
Title: Re: Coding in Music Zones
Post by: Whitay on October 24, 2014, 09:00:34 pm
The view is not locked. Its more like LTTP, where you are in one big area and the camera follows link. The whole overworld is one map, with the view following link. Heres a picture of the level zoomed out from a while ago, as you can see everything is sort of connected and not blocky.
Show content
(http://i60.tinypic.com/rbllkh.png)
Title: Re: Coding in Music Zones
Post by: Kami on October 25, 2014, 12:39:27 am
Alright that map is splittible into a sort of grid, I'm working on a quick example that will actively check the imaginary map "grid" it'll check if it changes different types and if so it will then transition the music. I'll prob have the example done in a bit. The grid size would be fully modifiable with a simple variable change.
Title: Re: Coding in Music Zones
Post by: OniShounen on October 25, 2014, 03:50:08 am
You can have a few object around all of your map (mainly areas where the terrain changes) like this as well:

Code: [Select]
if(!sound_isplaying(yourBGM))
{
    sound_stop(otherBGM);
    sound_loop(yourBGM);
}
Title: Re: Coding in Music Zones
Post by: Whitay on October 25, 2014, 04:12:19 am
Alright that map is splittible into a sort of grid, I'm working on a quick example that will actively check the imaginary map "grid" it'll check if it changes different types and if so it will then transition the music. I'll prob have the example done in a bit. The grid size would be fully modifiable with a simple variable change.
This is similar to an idea i had to basically break up the zone into rectangles and check collisions, but i knew someone had an efficient/not badly-rigged together idea. This helps a lot more than just lots of objects checking music(it would not be a few, you would need lots and the collisions would be weird.) because if i ever need to add anything else based on biomes, such as titles or weather effects or enemy spawns or something this sort of is a check one check all.

Thank you much in advance for your help.
Title: Re: Coding in Music Zones
Post by: OniShounen on October 25, 2014, 05:04:22 am
How about deactivating the objects while outside the view?
That way it wouldn't be a collision based event, moreso just a if I'm on the same screen as Link kinda deal.

Also, you'd really only need two objects for every "doorway" between two zones.

Or you guys are suggesting the following:
I don't know if you can use ds_grid with GM8.1 Lite, but you could use that to break down your map into chunks.  After that, you can assign them ids, then check the ID of the location where Link is located and play music accordingly.

Code: [Select]
//Create the grid
musicGrid=ds_grid_create(room_width,room_height)
//This part will require some thought.
for(iX=0;iX<=room_width;iX+=1)
  {
  for(iY=0;iY<=room_height;iY+=1)
    {
    ds_grid_set(musicGrid,iX,iY,"bgmForest");
    }
  }

//In Link's step event.
//This bottom part should work in theory, if not some IF THEN ELSE will do, that may give you more control over the fading.
sound_play(ds_grid_get(musicGrid,Link.x,Link.y));

Title: Re: Coding in Music Zones
Post by: Whitay on October 25, 2014, 05:32:18 pm
The issues im trying to see with collisions is just the overuse of random objects and werid shaped sprites because everything is weirdly shaped. and hm. ive never heard about the ds_grid commands, but like Kami above me said about breaking it into grids may be a good idea. that was(depending on how small the grid is) i could get some pretty weird shapes in without creating a single object.
Title: Re: Coding in Music Zones
Post by: OniShounen on October 25, 2014, 05:38:46 pm
the for loop i gave as an example runs across individual pixels, but you could adjust it to increment any number you wanted say 4,8,12,16,32.

you just have to have link check the same increments on the grid
Title: Re: Coding in Music Zones
Post by: Whitay on October 25, 2014, 06:01:25 pm
I have yet to try that, as i need to get the coords to seperate some levels first. I will be able to test that in a few though and i will let you know. thank you!
Title: Re: Coding in Music Zones
Post by: OniShounen on October 26, 2014, 12:34:59 pm
Don't forget you have the d s _ set _ region function as well
Title: Re: Coding in Music Zones
Post by: Whitay on October 27, 2014, 12:10:28 am
Thank you all for the suggestions, I was able to figure it out. It was more of a which conceptual way should i go about this - not so much the coding aspect. Cutting the zones into various rectangles to accuratly cover them and then checking with those rectangular zones made this easier than using objects.
Title: Re: Coding in Music Zones
Post by: OniShounen on October 27, 2014, 12:29:50 am
No problem, glad you could figure it out.

I just got GM:Studio Professional today; time to go back to making click the clown for a couple days!
Title: Re: Coding in Music Zones
Post by: Wasabi on November 10, 2014, 03:33:23 am
I believe gamemaker has some kind of timer task type thing that you could probably use too, so it only does the check once per second or something like that.

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