Musical Coin

Musical Coin

Postby Savs » 07 May 2016, 13:00

It's like a normal coin but it changes pitch of the sound when you collect them by going up or down the tiles. Correct the code if it does not compile with current git:
{l Code}: {l Select All Code}
    static Timer sound_timer;
    static int pitch_one = 128;
    static float last_pitch = 1;
    float pitch = 1;

    int tile = static_cast<int>(get_pos().y / 32);

    if (!sound_timer.started()) {
    pitch_one = tile;
    pitch = 1;
    last_pitch = 1;
    }
    else if (sound_timer.get_timegone() < 0.02) {
    pitch = last_pitch;
    }
    else
    {
    switch ((pitch_one - tile) % 7) {
    case -6:
    pitch = 1.0/2;
    break;
    case -5:
    pitch = 5.0/8;
    break;
    case -4:
    pitch = 4.0/6;
    break;
    case -3:
    pitch = 3.0/4;
    break;
    case -2:
    pitch = 5.0/6;
    break;
    case -1:
    pitch = 9.0/10;
    break;
    case 0:
    pitch = 1.0;
    break;
    case 1:
    pitch = 9.0/8;
    break;
    case 2:
    pitch = 5.0/4;
    break;
    case 3:
    pitch = 4.0/3;
    break;
    case 4:
    pitch = 3.0/2;
    break;
    case 5:
    pitch = 5.0/3;
    break;
    case 6:
    pitch = 9.0/5;
    break;
    }
    last_pitch = pitch;
    }
    sound_timer.start(1);

    std::unique_ptr<SoundSource> soundSource = SoundManager::current()->create_sound_source("sounds/coin.wav");
    soundSource->set_position(get_pos());
    soundSource->set_pitch(pitch);
    soundSource->play();
    SoundManager::current()->manage_source(std::move(soundSource));

  Sector::current()->player->get_status()->add_coins(1, false);
Last edited by Savs on 08 May 2016, 06:20, edited 2 times in total.
Savs
 
Posts: 36
Joined: 14 Mar 2016, 07:28

Re: Musical Coin

Postby Tobbi » 07 May 2016, 13:07

I think you might have just uncommented the lines in the coin.cpp source file.

Can you *please* create a pull request? We can then talk about it.
SuperTux developer.
User avatar
Tobbi
SuperTux Moderator
 
Posts: 353
Joined: 12 Oct 2013, 13:08

Re: Musical Coin

Postby brmbrmcar » 07 May 2016, 20:32

What does it sound like? Any video demonstrations?
brmbrmbrmbrmbrmbrmcar
User avatar
brmbrmcar
 
Posts: 357
Joined: 24 Oct 2015, 14:46

Re: Musical Coin

Postby Toufik » 22 Aug 2016, 21:37

Good luck, I like the idea :)
User avatar
Toufik
 
Posts: 51
Joined: 01 Sep 2014, 17:42

Re: Musical Coin

Postby mteufel » 29 Oct 2016, 11:57

This will be shipped in SuperTux v0.6.0.
SuperTux developer
mteufel
 
Posts: 139
Joined: 03 Jan 2016, 09:27

Re: Musical Coin

Postby TuxFan1979 » 17 Feb 2018, 19:42

User avatar
TuxFan1979
 
Posts: 22
Joined: 05 Feb 2018, 23:58

Who is online

Users browsing this forum: No registered users and 1 guest