Add a scene

This commit is contained in:
Ryan Shepherd 2018-10-02 10:50:50 -04:00
parent b657d5286e
commit 61db842e61
11 changed files with 81 additions and 50 deletions

View File

@ -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,13 +105,14 @@ sub GetAssetType {
}
sub UnloadAsset {
my($file)=@_;
foreach my $file (@_) {
if(exists $files{$file}) {
$files{$file}{'Loaded'} = 0;
delete $files{$file}{ $files{$file}{'Type'} };
$files{$file}{'Type'} = '';
}
}
}
sub SetAssetOption {
my($file, $opt)=@_;
@ -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}) {

View File

@ -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();

View File

@ -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;

View File

@ -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 = ();
@ -73,6 +74,16 @@ sub DefGameVar {
}
}
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 {
my @scripts = sort { $a cmp $b } LoadAssets('gs');
@ -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])) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

10
Resources/fire.vs Normal file
View File

@ -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

View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

View File

@ -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
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
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
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
h "Continue..."
RecompileScripts drawroom