Skip to content

Instantly share code, notes, and snippets.

@koorchik
Created February 11, 2010 12:18
Show Gist options
  • Save koorchik/301464 to your computer and use it in GitHub Desktop.
Save koorchik/301464 to your computer and use it in GitHub Desktop.
use Getopt::Long;
use Data::Dumper;
use Locale::gettext;
use POSIX();
use Math::Trig;
use IO::File;
use Time::HiRes qw(gettimeofday);
use SDL;
use SDL::App;
use SDL::Surface;
use SDL::Event;
use SDL::Cursor;
use SDL::Mixer;
use fb_stuff;
use fb_net;
use fb_net_discover;
use fbsyms;
use FBLE;
$| = 1;
$TARGET_ANIM_SPEED = 20; # number of milliseconds that should last between two animation frames
$LAUNCHER_SPEED = 0.03; # speed of rotation of launchers
$BUBBLE_SPEED = 10; # speed of movement of launched bubbles
$MALUS_BUBBLE_SPEED = 30; # speed of movement of "malus" launched bubbles
$CANON_ROTATIONS_NB = 100; # number of rotations of images for canon
$TIMEOUT_PINGUIN_SLEEP = 200;
$FREE_FALL_CONSTANT = 0.5;
$KEYS = { p1 => { left => SDLK_LEFT, right => SDLK_RIGHT, fire => SDLK_UP, center => SDLK_DOWN },
p2 => { left => SDLK_x, right => SDLK_v, fire => SDLK_c, center => SDLK_d },
misc => { fs => SDLK_f, chat => SDLK_RETURN, send_malus_to_rp1 => SDLK_F1, send_malus_to_rp2 => SDLK_F2, send_malus_to_rp3 => SDLK_F3,
send_malus_to_rp4 => SDLK_F4, send_malus_to_all => SDLK_F10, next_playlist_elem => SDLK_TAB, save_record => SDLK_PRINT,
toggle_music => SDLK_F11, toggle_sound => SDLK_F12, raise_volume => SDLK_KP_PLUS, lower_volume => SDLK_KP_MINUS } };
$sdl_flags = SDL_ANYFORMAT | SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL | SDL_ASYNCBLIT;
$mixer = 0;
$graphics_level = 3;
@PLAYERS = qw(p1 p2);
@ALL_PLAYERS = qw(p1 p2 rp1 rp2 rp3 rp4);
$playermalus = 0;
$mptrainingdiff = 30;
$chainreaction = 0;
$mynick = $ENV{USER};
$HISCORES = [];
$HISCORES_MPTRAIN = [];
$HISCORES_MPTRAIN_CHAINREACTION = [];
my $RECORD_PROTOCOL_LEVEL = 0;
$rcfile = "$FBHOME/rc";
my $keys_orig = $KEYS;
eval(cat_($rcfile));
$KEYS->{misc}{chat} or ($KEYS->{p1}, $KEYS->{p2}) = ($KEYS->{p2}, $KEYS->{p1}); #- for upgrades
$KEYS->{misc}{$_} ||= $keys_orig->{misc}{$_} foreach keys %{$keys_orig->{misc}}; #-
eval(cat_($hiscorefiles{levels} = "$FBHOME/highscores"));
eval(cat_($hiscorefiles{mptrain} = "$FBHOME/highscores-mptrain"));
textdomain("frozen-bubble");
$ENV{GETTEXT_DIRNAME} and bindtextdomain("frozen-bubble", $ENV{GETTEXT_DIRNAME});
bind_textdomain_codeset("frozen-bubble", "UTF-8"); #- we're going to use SDL_Pango which uses UTF-8 input
our $is_rtl = $ENV{LANGUAGE} =~ /^fa/;
print " [[ Frozen-Bubble-$version ]]\n\n";
print ' http://www.frozen-bubble.org/
Copyright (c) 2000-2008 The Frozen-Bubble Team.
Artwork: Alexis Younes
Amaury Amblard-Ladurantie
Soundtrack: Matthias Le Bidan
Design & Programming: Guillaume Cottenceau
Level Editor: Kim and David Joham
Additional network programming: Mark Glines
Originally sponsored by Mandriva <http://www.mandriva.com/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2, as
published by the Free Software Foundation.
';
#- become a friend of BooK
GetOptions("fullscreen|fs!" => \$fullscreen,
"no-sound|ns" => sub { $mixer = 'SOUND_DISABLED' },
"no-music|nm" => \$music_disabled,
"no-sfx" => \$sfx_disabled,
"playlist=s" => sub { @playlist = -d $_[1] ? glob("$_[1]/*") : cat_($_[1]) },
"slow-machine" => sub { $graphics_level = 2 },
"very-slow-machine" => sub { $graphics_level = 1 },
"direct" => \$direct,
"solo" => sub { $direct = 1; @PLAYERS = ('p1') },
"chain-reaction" => \$chainreaction,
"colour-blind|cb" => \$colourblind,
"player-malus=i" => \$playermalus,
"mp-training-difficulty=i" => \$mptrainingdiff,
"level|l=i" => sub { $levels{current} = $_[1]; $direct = 1; @PLAYERS = ('p1') },
"levelset=s" => sub { $direct_levelset = $_[1]; $levels{current} = 1; $direct = 1; @PLAYERS = ('p1') },
"no-time-limit" => \$no_time_limit,
"master-server=s" => \$fb_net::masterserver,
"gameserver|gs=s" => sub { $gameserver = $_[1]; $direct = 1; @PLAYERS = qw(p1 rp1); $pdata{gametype} = 'net' },
"no-echo" => \$no_echo,
"my-nick=s" => \$mynick,
"private" => \$private,
"joysticks-info" => \$joysticksinfo,
"record=s" => sub { if (!-d $_[1]) { die("$_[1] does not exist.\n") } else { $recorddir = $_[1] } },
"auto-record" => \$autorecord,
"replay=s" => \$replayparam,
"save-frames=s" => sub { if (!-d $_[1]) { die("$_[1] does not exist.\n") } else { $saveframes = $_[1] } },
"comment=s" => \$comment,
"help" => sub { print "Usage: ", basename($0), " [OPTION]...
--fullscreen start in fullscreen mode
--no-fullscreen don't start in fullscreen mode
--no-sound don't try to start any sound stuff
--no-music disable music (only)
--no-sfx disable sound effects (only)
--playlist <file> use all files listed in the given file as music files and play them
--playlist <directory> use all files inside the given directory as music files and play them
--slow-machine enable slow machine mode (disable a few animations)
--very-slow-machine enable very slow machine mode (disable all that can be disabled)
--solo directly start solo (1p) game, with random levels if no -l<#n> is given
--direct directly start (2p) game (don't display menu)
--gameserver <host[:port]> directly start NET/LAN game connecting to this game server (if port is omitted, default port is used)
--level <#n> directly start the n-th level (implies -so)
--levelset<name> directly start with the specified levelset name
--no-time-limit disable time limit for shooting (e.g. kids mode)
--chain-reaction enable chain-reaction (when applicable)
--player-malus <#n> add a malus of n to the left player (can be negative)
--mp-training-difficulty <#n> set the average duration between receiving malus bubbles in 1 player multiplayer training (default 30 (= every 30 seconds on average), the lower the harder)
--colour-blind use bubbles for colourblind people
--joysticks-info print information about detected joystick(s) on startup
--no-echo when sound is enabled, disable echoing each typed character with a typewriter sound
--my-nick <nick> for net/lan games, use this nick instead of username (max 10 chars, ASCII alphanumeric plus dash and underscore only)
--private when starting a net game, don't use http://hostip.info/ to retrieve your geographical position to send it to other players
--record <dir> specify the recording directory (normally, records are saved in the directory '$FBHOME/records')
--auto-record automatically record all applicable games (normally, a record is triggered by hitting the Print Screen key during a game)
--comment '...' add the comment enclosed between simple quotes to records (must not contain anything else than ASCII), it will be shown on console when playing back the record later
--replay <file|URL> replay the specified savegame
--save-frames <dir> specify a directory where all (game) frames will be recorded; as the game is slowed down, can only be used with --replay; typical use case is then to build a video out of the frames (see manpage)
";
exit(0);
});
$mynick = sanitize_nick($mynick);
$saveframes && !$replayparam and print STDERR "--save-frames can only be used with --replay\n";
#- ------------------------------------------------------------------------
sub i18n_number {
my ($number) = @_;
my $out = '';
foreach my $char (split //, $number) {
if ($char eq '0') { $out .= t("0"); }
elsif ($char eq '1') { $out .= t("1"); }
elsif ($char eq '2') { $out .= t("2"); }
elsif ($char eq '3') { $out .= t("3"); }
elsif ($char eq '4') { $out .= t("4"); }
elsif ($char eq '5') { $out .= t("5"); }
elsif ($char eq '6') { $out .= t("6"); }
elsif ($char eq '7') { $out .= t("7"); }
elsif ($char eq '8') { $out .= t("8"); }
elsif ($char eq '9') { $out .= t("9"); }
elsif ($char eq '.') { $out .= t("."); }
else { $out .= $char; }
}
return $out;
}
sub format_addiction {
my ($seconds, $i18n) = @_;
my $h = int($seconds/3600);
my $m = int(($seconds-$h*3600)/60);
my $s = int($seconds-$h*3600-$m*60);
if (!$i18n) {
return ($h ? "${h}h " : '') . ($m ? sprintf('%'.($h ? '02' : '').'dm ', $m) : '') . sprintf('%'.($m ? '02' : '').'ds', $s);
} else {
if ($h) {
$m = sprintf("%02d", $m);
}
if ($m) {
$s = sprintf("%02d", $s);
}
$h = i18n_number($h);
$m = i18n_number($m);
$s = i18n_number($s);
if ($h) {
return t("%sh %sm %ss", $h, $m, $s);
} elsif ($m) {
return t("%sm %ss", $m, $s);
} else {
return t("%ss", $s);
}
}
}
END {
if ($app && $addicted_time) {
print "\nAddicted for ", format_addiction($addicted_time/1000, 0), "\n";
}
}
#- ----------- sound related stuff ----------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment