]> www.fi.muni.cz Git - slotcarman.git/commitdiff
Sound support
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 6 Dec 2013 23:22:26 +0000 (00:22 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 6 Dec 2013 23:23:51 +0000 (00:23 +0100)
14 files changed:
SCX/Car.pm
SCX/Sound.pm [new file with mode: 0644]
SCX/Track.pm
sounds/0.wav [new file with mode: 0644]
sounds/1.wav [new file with mode: 0644]
sounds/2.wav [new file with mode: 0644]
sounds/3.wav [new file with mode: 0644]
sounds/4.wav [new file with mode: 0644]
sounds/5.wav [new file with mode: 0644]
sounds/bestlap.wav [new file with mode: 0644]
sounds/box.wav [new file with mode: 0644]
sounds/filled.wav [new file with mode: 0644]
sounds/start.wav [new file with mode: 0644]
sounds/winner.wav [new file with mode: 0644]

index 2bb67617e2222aaa9f164bc80d7d8e3c7d089ce9..5a1f90e7bb5b052653643d0e1b74c6870972f83d 100644 (file)
@@ -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 (file)
index 0000000..5c501c3
--- /dev/null
@@ -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;
index 097dde88cf565be597ed55bfda6b069f6b44956d..90724290bc5252bd2bb7b897486d7ec23d3ef72c 100644 (file)
@@ -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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
index 0000000..75e7942
Binary files /dev/null and b/sounds/winner.wav differ