Add a scene
This commit is contained in:
parent
b657d5286e
commit
61db842e61
|
|
@ -21,7 +21,7 @@ sub FindFile {
|
||||||
return $files{$filename}{'Location'};
|
return $files{$filename}{'Location'};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $full = FindFileInDir(GetOption('ResourceDir'), $filename);
|
my $full = FindFileInDir(GetGameVar('ResourceDir'), $filename);
|
||||||
if($full) {
|
if($full) {
|
||||||
$files{$filename}={
|
$files{$filename}={
|
||||||
'Loaded' => 0,
|
'Loaded' => 0,
|
||||||
|
|
@ -105,11 +105,12 @@ sub GetAssetType {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub UnloadAsset {
|
sub UnloadAsset {
|
||||||
my($file)=@_;
|
foreach my $file (@_) {
|
||||||
if(exists $files{$file}) {
|
if(exists $files{$file}) {
|
||||||
$files{$file}{'Loaded'} = 0;
|
$files{$file}{'Loaded'} = 0;
|
||||||
delete $files{$file}{ $files{$file}{'Type'} };
|
delete $files{$file}{ $files{$file}{'Type'} };
|
||||||
$files{$file}{'Type'} = '';
|
$files{$file}{'Type'} = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,7 +136,8 @@ sub LoadAsset {
|
||||||
|
|
||||||
if(!$filename && !($filename = FindFile($file))) {
|
if(!$filename && !($filename = FindFile($file))) {
|
||||||
LogData(FATAL, "Unable to load asset file '$file'; Unable to find file.");
|
LogData(FATAL, "Unable to load asset file '$file'; Unable to find file.");
|
||||||
SetOption('Running', 0);
|
ExitGame();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(exists $files{$file}) {
|
if(exists $files{$file}) {
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,10 @@ use vars qw/@ISA @EXPORT @EXPORT_OK %VisibleSprites/;
|
||||||
# FIXME - This should be exported already?
|
# FIXME - This should be exported already?
|
||||||
*GetOption = \&PerlRPG::Game::GetOption;
|
*GetOption = \&PerlRPG::Game::GetOption;
|
||||||
|
|
||||||
# FIXME - This should be a setable option
|
|
||||||
my $speech_border = 5;
|
|
||||||
|
|
||||||
sub DrawSpeech {
|
sub DrawSpeech {
|
||||||
my($sayer, $text)=@_;
|
my($sayer, $text)=@_;
|
||||||
my $app = GetOption('App');
|
my $app = GetOption('App');
|
||||||
|
my $speech_border = 3;
|
||||||
|
|
||||||
my $sprite = GetAsset($sayer->{'Sprite'});
|
my $sprite = GetAsset($sayer->{'Sprite'});
|
||||||
my $sprite_x = $app->width() - $sprite->clip()->w();
|
my $sprite_x = $app->width() - $sprite->clip()->w();
|
||||||
|
|
|
||||||
|
|
@ -14,28 +14,35 @@ use PerlRPG::Controls;
|
||||||
use vars qw/$app @ISA @EXPORT @EXPORT_OK/;
|
use vars qw/$app @ISA @EXPORT @EXPORT_OK/;
|
||||||
|
|
||||||
@ISA = qw/Exporter/;
|
@ISA = qw/Exporter/;
|
||||||
@EXPORT = qw/InitApp Run RunScript GetOption SetOption ExitGame/;
|
@EXPORT = qw/InitApp Run GetOption ExitGame/;
|
||||||
@EXPORT_OK = @EXPORT;
|
@EXPORT_OK = @EXPORT;
|
||||||
|
|
||||||
$app = undef;
|
$app = undef;
|
||||||
my %opt = (
|
my %opt = (
|
||||||
'App' => undef,
|
'App' => undef,
|
||||||
'Running' => 1,
|
|
||||||
'TargetFPS' => 5,
|
|
||||||
'ResourceDir' => '.',
|
|
||||||
'Status' => 'WaitForFrame',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
sub GetOption { return (exists $opt{$_[0]} ? $opt{$_[0]} : undef); }
|
sub GetOption {
|
||||||
sub SetOption { $opt{$_[0]} = $_[1]; }
|
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 {
|
sub InitApp {
|
||||||
my($width, $height)=@_;
|
my($width, $height)=@_;
|
||||||
|
|
||||||
return undef if($app);
|
return undef if($app);
|
||||||
|
|
||||||
LogData(INFO, "Creating SDL instance");
|
LogData(INFO, "Creating SDL instance");
|
||||||
|
|
||||||
|
DefGameVar('TargetFPS', 10);
|
||||||
|
DefGameVar('GameRunning', 1);
|
||||||
|
DefGameVar('ResourceDir', '"."');
|
||||||
|
|
||||||
$app = SDLx::App->new(
|
$app = SDLx::App->new(
|
||||||
width => $width,
|
width => $width,
|
||||||
height => $height,
|
height => $height,
|
||||||
|
|
@ -46,20 +53,20 @@ sub InitApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub ExitGame {
|
sub ExitGame {
|
||||||
SetOption('Running', 0);
|
SetGameVar('GameRunning', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub Run {
|
sub Run {
|
||||||
my $tick = SDL::get_ticks();
|
my $tick = SDL::get_ticks();
|
||||||
while($opt{'Running'}) {
|
while(GetGameVar('GameRunning')) {
|
||||||
EventDispatcher();
|
EventDispatcher();
|
||||||
RunScriptTick();
|
RunScriptTick();
|
||||||
RenderScreen();
|
RenderScreen();
|
||||||
|
|
||||||
my $ticktime = SDL::get_ticks() - $tick;
|
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);
|
SDL::delay($delta) if($delta > 0);
|
||||||
$tick = SDL::get_ticks();
|
$tick = SDL::get_ticks();
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +97,7 @@ sub EventDispatcher {
|
||||||
SDL::Events::get_mod_state()
|
SDL::Events::get_mod_state()
|
||||||
);
|
);
|
||||||
} elsif($event->type == SDL_QUIT) {
|
} elsif($event->type == SDL_QUIT) {
|
||||||
$opt{'Running'} = 0;
|
SetGameVar('GameRunning', 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -100,8 +107,4 @@ sub RenderScreen {
|
||||||
$app->update();
|
$app->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub RunScript {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ my %script_commands = (
|
||||||
'LoadAssets' => {'sub' => \&PerlRPG::Assets::LoadAssets, 'wait' => 0},
|
'LoadAssets' => {'sub' => \&PerlRPG::Assets::LoadAssets, 'wait' => 0},
|
||||||
'UnloadAsset' => {'sub' => \&PerlRPG::Assets::UnloadAsset, 'wait' => 0},
|
'UnloadAsset' => {'sub' => \&PerlRPG::Assets::UnloadAsset, 'wait' => 0},
|
||||||
'SetAssetOption' => {'sub' => \&PerlRPG::Assets::SetAssetOption, 'wait' => 0},
|
'SetAssetOption' => {'sub' => \&PerlRPG::Assets::SetAssetOption, 'wait' => 0},
|
||||||
|
'RecompileScripts' => {'sub' => \&RecompileScripts, 'wait' => 1},
|
||||||
);
|
);
|
||||||
|
|
||||||
my %sayers = ();
|
my %sayers = ();
|
||||||
|
|
@ -72,6 +73,16 @@ sub DefGameVar {
|
||||||
$game_vars{$key} = StringSubst($val);
|
$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
|
# Load script files, locate labels
|
||||||
sub CompileScripts {
|
sub CompileScripts {
|
||||||
|
|
@ -115,7 +126,7 @@ sub RunScriptTick {
|
||||||
my $line = $current_line++;
|
my $line = $current_line++;
|
||||||
if($line >= @$script) {
|
if($line >= @$script) {
|
||||||
LogData(ERROR, "Script file ended");
|
LogData(ERROR, "Script file ended");
|
||||||
SetOption('Running', 0);
|
SetGameVar('GameRunning', 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(RunScriptLine($file, $line, $script->[$line])) {
|
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 |
|
|
@ -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
|
||||||
|
|
@ -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 |
|
|
@ -1,26 +1,25 @@
|
||||||
__init__:
|
__init__:
|
||||||
SetBackground 128 128 128 255
|
SetBackground 128 128 128 255
|
||||||
SetAssetOption spritesheet.png Animated
|
SetAssetOption spritesheet.png Animated
|
||||||
Define LoopCount 0
|
AddSayer h "Hermione" aka01.png 200 200 200 255
|
||||||
Define TestVar 1
|
|
||||||
|
|
||||||
Show aka spritesheet.png 0 0 1 flip
|
TargetFPS = 30
|
||||||
Show aka2 aka.vs 100 0 2
|
ResourceDir = "Resources"
|
||||||
Show aka3 aka.vs 200 0 3 Reverse flip
|
|
||||||
Show aka4 spritesheet.png 300 0 1 max_loops=1
|
|
||||||
|
|
||||||
AddSayer h "Hermione" aka01.png 200 200 200 255 flip
|
drawroom:
|
||||||
AddSayer h2 "Topless\ Hermione" aka05.png 255 0 0 255
|
Show bg main_room_day.png 0 0 10
|
||||||
AddSayer h3 "Stripping\ Hermione" spritesheet.png 255 0 0 255 Reverse
|
Show window 05_window.png 350 100 11
|
||||||
|
Show cupboard cupboard.png 120 72 11
|
||||||
Jump donothing
|
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:
|
Show fireplacea fireplace_fire.vs 575 147 12
|
||||||
Wait
|
Show candlera fire.vs 400 95 12 flip
|
||||||
LoopCount=LoopCount+1
|
Show candlela fire.vs 240 95 12
|
||||||
h "Loop number [LoopCount]"
|
|
||||||
TestVar=lc("Foo").uc(lc("Foo"))
|
h "Continue..."
|
||||||
h2 "TestVar [TestVar]"
|
|
||||||
TestVar = uc("[TestVar]")
|
RecompileScripts drawroom
|
||||||
h3 "TestVar2 [TestVar]"
|
|
||||||
Jump donothing
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue