From: Jan "Yenya" Kasprzak Date: Fri, 6 Dec 2013 23:22:26 +0000 (+0100) Subject: Sound support X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=1f216af4258c635bda3ebc3b3b4af65b392aa37d;p=slotcarman.git Sound support --- diff --git a/SCX/Car.pm b/SCX/Car.pm index 2bb6761..5a1f90e 100644 --- a/SCX/Car.pm +++ b/SCX/Car.pm @@ -75,6 +75,13 @@ sub set_fuel { $self->{id}, ' missed pit lane entry', "\n"; $self->enter_pit_lane; } + if ($val == $prev - 1 && $val <= 2 && !$self->{in_pit_lane}) { + $self->track->{sound}->box($self->{id}); + } + } + if (defined $val && defined $prev && $val == 8 && $prev == 7 + && $self->{in_pit_lane}) { + $self->track->{sound}->filled($self->{id}); } $self->gui->set_fuel($self->{order}, $val); diff --git a/SCX/Sound.pm b/SCX/Sound.pm new file mode 100644 index 0000000..5c501c3 --- /dev/null +++ b/SCX/Sound.pm @@ -0,0 +1,47 @@ +#!/usr/bin/perl -w + +package SCX::Sound; + +use strict; + +sub new { + my ($class, $args) = @_; + + my $self = { + data_dir => $args->{data_dir} || './sounds/', + }; + + bless $self, $class; + + return $self; +} + +sub _play { + my ($self, @names) = @_; + + @names = map { $self->{data_dir} . '/' . $_ . '.wav' } @names; + system (join(' ', 'aplay', @names). ' &'); +} + +sub start { shift->_play('start'); } +sub filled { shift->_play('filled'); } + +sub winner { + my ($self, $car_id) = @_; + + $self->_play('winner', $car_id, 'winner'); +} + +sub box { + my ($self, $car_id) = @_; + + $self->_play('box', $car_id, 'box'); +} + +sub best_lap { + my ($self, $car_id) = @_; + + $self->_play('bestlap', $car_id); +} + +1; diff --git a/SCX/Track.pm b/SCX/Track.pm index 097dde8..9072429 100644 --- a/SCX/Track.pm +++ b/SCX/Track.pm @@ -7,6 +7,7 @@ use Carp; use Glib qw(TRUE FALSE); use SCX::Car; +use SCX::Sound; our $SEMAPHORE_STEP = 1000; @@ -37,6 +38,8 @@ sub new { $self->{gui}->time(undef); $self->{gui}->best_lap(undef, undef); + $self->{sound} = new SCX::Sound; + return $self; } @@ -87,6 +90,7 @@ sub semaphore_step { } else { $self->{gui}->show_semaphore(undef); $self->{semaphore} = undef; + $self->{sound}->start(); } return FALSE; } @@ -162,6 +166,11 @@ sub notify_best_lap { $self->car($car)->set_global_best($car == $id); $self->car($car)->print_best_lap; } + + if (!$self->{race_running} || $self->{round} > 1) { + # skip the first round in the race + $self->{sound}->best_lap($id); + } return 1; } return 0; @@ -226,6 +235,9 @@ sub recalc_order { if ($self->{round} && $self->{race_rounds} && $self->{round} > $self->{race_rounds}) { + if (!$self->{race_finishing}) { + $self->{sound}->winner($new_order[0]); + } $self->{race_finishing} = 1; } diff --git a/sounds/0.wav b/sounds/0.wav new file mode 100644 index 0000000..d3abf30 Binary files /dev/null and b/sounds/0.wav differ diff --git a/sounds/1.wav b/sounds/1.wav new file mode 100644 index 0000000..feeac1b Binary files /dev/null and b/sounds/1.wav differ diff --git a/sounds/2.wav b/sounds/2.wav new file mode 100644 index 0000000..b9ce6fb Binary files /dev/null and b/sounds/2.wav differ diff --git a/sounds/3.wav b/sounds/3.wav new file mode 100644 index 0000000..56b6004 Binary files /dev/null and b/sounds/3.wav differ diff --git a/sounds/4.wav b/sounds/4.wav new file mode 100644 index 0000000..e929777 Binary files /dev/null and b/sounds/4.wav differ diff --git a/sounds/5.wav b/sounds/5.wav new file mode 100644 index 0000000..505990d Binary files /dev/null and b/sounds/5.wav differ diff --git a/sounds/bestlap.wav b/sounds/bestlap.wav new file mode 100644 index 0000000..8bcb4a3 Binary files /dev/null and b/sounds/bestlap.wav differ diff --git a/sounds/box.wav b/sounds/box.wav new file mode 100644 index 0000000..3b3ede1 Binary files /dev/null and b/sounds/box.wav differ diff --git a/sounds/filled.wav b/sounds/filled.wav new file mode 100644 index 0000000..a6930f8 Binary files /dev/null and b/sounds/filled.wav differ diff --git a/sounds/start.wav b/sounds/start.wav new file mode 100644 index 0000000..599e6e1 Binary files /dev/null and b/sounds/start.wav differ diff --git a/sounds/winner.wav b/sounds/winner.wav new file mode 100644 index 0000000..75e7942 Binary files /dev/null and b/sounds/winner.wav differ