diff --git a/PerlRPG/Assets.pm b/PerlRPG/Assets.pm index 5382c38..181fcaa 100644 --- a/PerlRPG/Assets.pm +++ b/PerlRPG/Assets.pm @@ -21,7 +21,7 @@ sub FindFile { return $files{$filename}{'Location'}; } - my $full = FindFileInDir(GetOption('ResourceDir'), $filename); + my $full = FindFileInDir(GetGameVar('ResourceDir'), $filename); if($full) { $files{$filename}={ 'Loaded' => 0, @@ -105,11 +105,12 @@ sub GetAssetType { } sub UnloadAsset { - my($file)=@_; - if(exists $files{$file}) { - $files{$file}{'Loaded'} = 0; - delete $files{$file}{ $files{$file}{'Type'} }; - $files{$file}{'Type'} = ''; + foreach my $file (@_) { + if(exists $files{$file}) { + $files{$file}{'Loaded'} = 0; + delete $files{$file}{ $files{$file}{'Type'} }; + $files{$file}{'Type'} = ''; + } } } @@ -135,7 +136,8 @@ sub LoadAsset { if(!$filename && !($filename = FindFile($file))) { LogData(FATAL, "Unable to load asset file '$file'; Unable to find file."); - SetOption('Running', 0); + ExitGame(); + return; } if(exists $files{$file}) { diff --git a/PerlRPG/Drawing.pm b/PerlRPG/Drawing.pm index 4d85a90..8ed5d4f 100644 --- a/PerlRPG/Drawing.pm +++ b/PerlRPG/Drawing.pm @@ -19,12 +19,10 @@ use vars qw/@ISA @EXPORT @EXPORT_OK %VisibleSprites/; # FIXME - This should be exported already? *GetOption = \&PerlRPG::Game::GetOption; -# FIXME - This should be a setable option -my $speech_border = 5; - sub DrawSpeech { my($sayer, $text)=@_; my $app = GetOption('App'); + my $speech_border = 3; my $sprite = GetAsset($sayer->{'Sprite'}); my $sprite_x = $app->width() - $sprite->clip()->w(); diff --git a/PerlRPG/Game.pm b/PerlRPG/Game.pm index 6433c37..8baf342 100644 --- a/PerlRPG/Game.pm +++ b/PerlRPG/Game.pm @@ -14,28 +14,35 @@ use PerlRPG::Controls; use vars qw/$app @ISA @EXPORT @EXPORT_OK/; @ISA = qw/Exporter/; -@EXPORT = qw/InitApp Run RunScript GetOption SetOption ExitGame/; +@EXPORT = qw/InitApp Run GetOption ExitGame/; @EXPORT_OK = @EXPORT; $app = undef; my %opt = ( 'App' => undef, - 'Running' => 1, - 'TargetFPS' => 5, - 'ResourceDir' => '.', - 'Status' => 'WaitForFrame', ); -sub GetOption { return (exists $opt{$_[0]} ? $opt{$_[0]} : undef); } -sub SetOption { $opt{$_[0]} = $_[1]; } - +sub GetOption { + my $key = shift(@_); + if(exists($opt{$key})) { + return $opt{$key}; + } elsif(exists $PerlRPG::Script::game_vars{$key}) { + return GetGameVar($key); + } else { + LogData(WARN, "Request for unknown option '$key'"); + return undef; + } +} sub InitApp { my($width, $height)=@_; - return undef if($app); - LogData(INFO, "Creating SDL instance"); + + DefGameVar('TargetFPS', 10); + DefGameVar('GameRunning', 1); + DefGameVar('ResourceDir', '"."'); + $app = SDLx::App->new( width => $width, height => $height, @@ -46,20 +53,20 @@ sub InitApp { } sub ExitGame { - SetOption('Running', 0); + SetGameVar('GameRunning', 0); } sub Run { my $tick = SDL::get_ticks(); - while($opt{'Running'}) { + while(GetGameVar('GameRunning')) { EventDispatcher(); RunScriptTick(); RenderScreen(); my $ticktime = SDL::get_ticks() - $tick; - my $delta = 1000/$opt{'TargetFPS'} - $ticktime; + my $delta = 1000/GetGameVar('TargetFPS') - $ticktime; - LogData(DEVALL, "TickTime = $ticktime, Delta = $delta"); + LogData(DEBUG, "TickTime = $ticktime, Delta = $delta"); SDL::delay($delta) if($delta > 0); $tick = SDL::get_ticks(); } @@ -90,7 +97,7 @@ sub EventDispatcher { SDL::Events::get_mod_state() ); } elsif($event->type == SDL_QUIT) { - $opt{'Running'} = 0; + SetGameVar('GameRunning', 0); } } } @@ -100,8 +107,4 @@ sub RenderScreen { $app->update(); } -sub RunScript { - -} - 1; diff --git a/PerlRPG/Script.pm b/PerlRPG/Script.pm index cbea50b..23ecb0f 100644 --- a/PerlRPG/Script.pm +++ b/PerlRPG/Script.pm @@ -36,6 +36,7 @@ my %script_commands = ( 'LoadAssets' => {'sub' => \&PerlRPG::Assets::LoadAssets, 'wait' => 0}, 'UnloadAsset' => {'sub' => \&PerlRPG::Assets::UnloadAsset, 'wait' => 0}, 'SetAssetOption' => {'sub' => \&PerlRPG::Assets::SetAssetOption, 'wait' => 0}, + 'RecompileScripts' => {'sub' => \&RecompileScripts, 'wait' => 1}, ); my %sayers = (); @@ -72,6 +73,16 @@ sub DefGameVar { $game_vars{$key} = StringSubst($val); } } + +sub RecompileScripts { + my $jumpto = (shift(@_) || '__init__'); + my @scripts = LoadAssets('gs'); + + LogData(INFO, "Doing full script recompile and jumping to '$jumpto'"); + UnloadAsset(@scripts); + CompileScripts(); + RunScript($jumpto); +} # Load script files, locate labels sub CompileScripts { @@ -115,7 +126,7 @@ sub RunScriptTick { my $line = $current_line++; if($line >= @$script) { LogData(ERROR, "Script file ended"); - SetOption('Running', 0); + SetGameVar('GameRunning', 0); return; } if(RunScriptLine($file, $line, $script->[$line])) { diff --git a/Resources/cupboard_hover.png b/Resources/cupboard_hover.png deleted file mode 100644 index 5302e04..0000000 Binary files a/Resources/cupboard_hover.png and /dev/null differ diff --git a/Resources/door_hover.png b/Resources/door_hover.png deleted file mode 100644 index 493a879..0000000 Binary files a/Resources/door_hover.png and /dev/null differ diff --git a/Resources/fire.vs b/Resources/fire.vs new file mode 100644 index 0000000..fa01b90 --- /dev/null +++ b/Resources/fire.vs @@ -0,0 +1,10 @@ +fire_01.png +fire_02.png +fire_03.png +fire_04.png +fire_05.png +fire_06.png +fire_07.png +fire_08.png +fire_09.png +fire_10.png diff --git a/Resources/fireplace_fire.vs b/Resources/fireplace_fire.vs new file mode 100644 index 0000000..148e600 --- /dev/null +++ b/Resources/fireplace_fire.vs @@ -0,0 +1,8 @@ +fireplace_fire_01.png +fireplace_fire_02.png +fireplace_fire_03.png +fireplace_fire_04.png +fireplace_fire_05.png +fireplace_fire_06.png +fireplace_fire_07.png +fireplace_fire_08.png diff --git a/Resources/fireplace_hover.png b/Resources/fireplace_hover.png deleted file mode 100644 index ac010d3..0000000 Binary files a/Resources/fireplace_hover.png and /dev/null differ diff --git a/Resources/phoenix_hover.png b/Resources/phoenix_hover.png deleted file mode 100644 index 0abd627..0000000 Binary files a/Resources/phoenix_hover.png and /dev/null differ diff --git a/Resources/script.gs b/Resources/script.gs index 6680923..f4c2b1b 100644 --- a/Resources/script.gs +++ b/Resources/script.gs @@ -1,26 +1,25 @@ __init__: SetBackground 128 128 128 255 SetAssetOption spritesheet.png Animated - Define LoopCount 0 - Define TestVar 1 + AddSayer h "Hermione" aka01.png 200 200 200 255 - Show aka spritesheet.png 0 0 1 flip - Show aka2 aka.vs 100 0 2 - Show aka3 aka.vs 200 0 3 Reverse flip - Show aka4 spritesheet.png 300 0 1 max_loops=1 + TargetFPS = 30 + ResourceDir = "Resources" - AddSayer h "Hermione" aka01.png 200 200 200 255 flip - AddSayer h2 "Topless\ Hermione" aka05.png 255 0 0 255 - AddSayer h3 "Stripping\ Hermione" spritesheet.png 255 0 0 255 Reverse - - Jump donothing +drawroom: + Show bg main_room_day.png 0 0 10 + Show window 05_window.png 350 100 11 + Show cupboard cupboard.png 120 72 11 + Show door door.png 840 177 11 + Show fireplace fireplace.png 600 150 11 + Show candler candle.png 400 100 11 flip + Show candlel candle.png 240 100 11 + Show desk 11_genie_00.png 230 220 13 -donothing: - Wait - LoopCount=LoopCount+1 - h "Loop number [LoopCount]" - TestVar=lc("Foo").uc(lc("Foo")) - h2 "TestVar [TestVar]" - TestVar = uc("[TestVar]") - h3 "TestVar2 [TestVar]" - Jump donothing + Show fireplacea fireplace_fire.vs 575 147 12 + Show candlera fire.vs 400 95 12 flip + Show candlela fire.vs 240 95 12 + + h "Continue..." + + RecompileScripts drawroom