Page MenuHomePhabricator (Chris)

No OneTemporary

Size
54 KB
Referenced Files
None
Subscribers
None
diff --git a/data/script/Backend.pl b/data/script/Backend.pl
index d86c8ea..299a677 100644
--- a/data/script/Backend.pl
+++ b/data/script/Backend.pl
@@ -1,517 +1,593 @@
#!/usr/bin/perl -w
# PERL backend for the game
=comment
This is the main perl backend for Mortal Szombat. It loads the other files,
compiles characters, creates shared variables.
1. FIGHTER ACTIONS
1.1. BASIC MOVEMENT 1.2. OFFENSIVE MOVES 1.3. HURT MOVES
Start KneelingPunch Falling
Stand KneelingKick Laying
Walk KneelingUppercut Getup
Back HighPunch HighPunched
Turn LowPunch LowPunched
Hurt HighKick GroinKicked
Block LowKick KneelingPunched
Kneeling Sweep KneelingKicked
Onknees GroinKick Thrown
Jump KneeKick Dead
JumpFW Elbow
JumpBW Grenade
Fun Uppercut
Threat Throw
[fighter-specific stuff]
=cut
=comment
MAIN CONSTANTS
=cut
$GAMEBITS = 3; # Number of oversampling bits in coordinates
$GAMEBITS2 = 1 << $GAMEBITS; # 2^(oversampling)
$SCRWIDTH = 640; # The physical horizontal screen resolution
$SCRHEIGHT = 480; # The physical vertical screen resolution
$SCRWIDTH2 = ($SCRWIDTH << $GAMEBITS); # The logical horizontal screen resolution
$SCRHEIGHT2 = ($SCRHEIGHT << $GAMEBITS); # The logical vertical screen resolution
$MOVEMARGIN2= 50 << $GAMEBITS; # The logical border for figthers.
$BGWIDTH2 = 1920 << $GAMEBITS; # The logical background width
$BGHEIGHT2 = 480 << $GAMEBITS; # The logical background height
$GROUND2 = 160 << $GAMEBITS; # The logical ground level.
$DELMULTIPLIER = 1; # DEL values in states are multiplied by this.
$BgMax = $BGWIDTH2 - $SCRWIDTH2; # The logical maximum camera position
$BgSpeed = 0; # The current speed of the background movement
$BgPosition = $BgMax >> 1; # The logical camera position
$BgScrollEnabled = 1; # Can the background scroll?
$HitPointScale = 10; # Scale the hit points by this.
$NextDoodad = 0; # The next doodad to process
+$Debug = 0;
require 'PlayerInput.pl';
require 'Fighter.pl';
require 'FighterStats.pl';
require 'Doodad.pl';
require 'Keys.pl';
require 'State.pl';
=comment
#require 'Kolos.pl';
require 'Zoli.pl';
require 'UPi.pl';
#require 'Ulmar.pl';
#require 'Cumi.pl';
print "Kolos frames :", scalar @KolosFrames,"\n";
print "Kolos states :", scalar keys %KolosStates,"\n";
print "Zoli frames :", scalar @ZoliFrames,"\n";
print "Zoli states :", scalar keys %ZoliStates,"\n";
print "UPi frames :", scalar @UPiFrames,"\n";
print "UPi states :", scalar keys %UPiStates,"\n";
print "Ulmar frames :", scalar @UlmarFrames,"\n";
print "Ulmar states :", scalar keys %UlmarStates,"\n";
print "Cumi frames :", scalar @CumiFrames,"\n";
print "Cumi states :", scalar keys %CumiStates,"\n";
=cut
=comment
MAIN OBJECTS
=cut
$Fighter1 = Fighter->new();
$Fighter2 = Fighter->new();
$Fighter1->{NUMBER} = 0;
$Fighter1->{OTHER} = $Fighter2;
$Fighter2->{NUMBER} = 1;
$Fighter2->{OTHER} = $Fighter1;
@Fighters = ( $Fighter1, $Fighter2 );
=comment
VARIABLES FOR DRAWING THE SCENE
=cut
$p1x = 10; # Player 1 X position
$p1y = 100; # Player 1 Y position
$p1f = 10; # Player 1 frame
$p1h = 100; # Player 1 HP
$p2x = 400; # Player 2 X position
$p2y = 100; # Player 2 Y position
$p2f = -40; # Player 2 frame. Negative means flipped.
$p2h = 100; # Player 2 HP
$bgx = 0; # Background X position
$bgy = 0; # Background Y position
$time = 0; # Current game time
$over = 0; # Is the game over?
$ko = 0; # Is one fighter knocked down?
$dx = 0; # Doodad X position
$dy = 0; # Doodad Y position
$dt = 0; # Doodad type
$df = 0; # Doodad frame number
=comment
JUDGEMENT METHODS
=cut
sub JudgementStart
{
$bgx = 0;
$bgy = ( $SCRHEIGHT2 - $BGHEIGHT2 ) >> 1;
$BgSpeed = 0;
$BgPosition = 0;
$BgScrollEnabled = 0;
$OverTimer = 0;
$JudgementMode = 1;
+ $Debug = 0;
($JudgementWinner) = @_;
+ ResetEarthquake();
$time = 0;
$over = 0;
$Fighter1->Reset();
$Fighter1->{X} = ($JudgementWinner ? 150 : 520 ) * $GAMEBITS2;
$Fighter1->{DIR} = ($JudgementWinner ? 1 : -1 );
$Fighter1->{NEXTST} = 'Stand';
$Fighter1->Update();
$Fighter2->Reset();
$Fighter2->{X} = ($JudgementWinner ? 520 : 150 ) * $GAMEBITS2;
$Fighter2->{DIR} = ($JudgementWinner ? -1 : 1 );
$Fighter2->{NEXTST} = 'Stand';
$Fighter2->Update();
$Input1->Reset();
$Input2->Reset();
}
=comment
PLAYER SELECTION METHODS
=cut
sub SelectStart
{
$bgx = 0;
$bgy = ( $SCRHEIGHT2 - $BGHEIGHT2 ) >> 1;
$BgSpeed = 0;
$BgPosition = 0;
$BgScrollEnabled = 0;
$OverTimer = 0;
- $JudgementMode = 0;
+ $JudgementMode = 0;
+ $Debug = 0;
+ ResetEarthquake();
$time = 0;
$over = 0;
$Fighter1->Reset(); #\@ZoliFrames,\%ZoliStates);
$Fighter1->{X} = 80 * $GAMEBITS2;
$Fighter1->{NEXTST} = 'Stand';
$Fighter1->Update();
$Fighter2->Reset(); #\@ZoliFrames,\%ZoliStates);
$Fighter2->{X} = 560 * $GAMEBITS2;
$Fighter2->{NEXTST} = 'Stand';
$Fighter2->Update();
$Input1->Reset();
$Input2->Reset();
}
sub SetPlayerNumber
{
my ($player, $number) = @_;
my ($f);
$f = $player ? $Fighter2 : $Fighter1;
if ( $number eq 1 ) { $f->Reset('Ulmar', \@UlmarFrames,\%UlmarStates); }
elsif ( $number eq 2 ) { $f->Reset('UPi', \@UPiFrames,\%UPiStates); }
elsif ( $number eq 3 ) { $f->Reset('Zoli', \@ZoliFrames,\%ZoliStates); }
elsif ( $number eq 4 ) { $f->Reset('Cumi', \@CumiFrames,\%CumiStates); }
elsif ( $number eq 5 ) { $f->Reset('Sirpi', \@SirpiFrames,\%SirpiStates); }
elsif ( $number eq 6 ) { $f->Reset('Maci', \@MaciFrames,\%MaciStates); }
elsif ( $number eq 7 ) { $f->Reset('Bence', \@BenceFrames,\%BenceStates); }
elsif ( $number eq 9 ) { $f->Reset('Descant', \@DescantFrames,\%DescantStates); }
elsif ( $number eq 8 ) { $f->Reset('Grizli', \@GrizliFrames,\%GrizliStates); }
else {
# Fallback
$f->Reset('Zoli', \@ZoliFrames,\%ZoliStates);
}
$f->{NEXTST} = 'Stand';
$f->Update();
+
+ $::PlayerName = $::FighterStats[$number]->{NAME};
}
sub PlayerSelected
{
my ($number) = @_;
my ($f) = $number ? $Fighter2 : $Fighter1;
$f->Event( 'Won' );
$f->Update();
}
+=comment
+
+EARTHQUAKE RELATED METHODS
+
+=cut
+
+
+
+@QUAKEOFFSET = ( 0, 6, 11, 15,
+ 16, 15, 11, 6,
+ 0, -6,-11,-15,
+ -16,-15,-11, -6, 0, 6 );
+
+
+sub ResetEarthquake
+{
+ $QuakeAmplitude = 0;
+ $QuakeOffset = 0;
+ $QuakeX = 0;
+ $QuakeY = 0;
+}
+
+
+sub AddEarthquake
+{
+ my ($amplitude) = @_;
+ $QuakeAmplitude += $amplitude;
+ $QuakeAmplitude = 20 if ( $QuakeAmplitude > 20 );
+}
+
+
+sub AdvanceEarthquake
+{
+ if ( $QuakeAmplitude <= 0.2 )
+ {
+ $QuakeAmplitude = $QuakeX = $QuakeY = 0;
+ return;
+ }
+
+ $QuakeAmplitude -= $QuakeAmplitude / 30 + 0.1;
+ $QuakeOffset = ( $QuakeOffset + 1 ) % 16;
+ $QuakeX = $QUAKEOFFSET[$QuakeOffset] * $QuakeAmplitude / 16;
+ $QuakeY = $QUAKEOFFSET[$QuakeOffset + 1] * $QuakeAmplitude / 16;
+
+ $bgx -= $QuakeX;
+ $bgy -= $QuakeY;
+ $p1x += $QuakeX;
+ $p1y += $QuakeY;
+ $p2x += $QuakeX;
+ $p2y += $QuakeY;
+
+ # Do not quake doodads for now.
+}
+
+
+
=comment
GAME BACKEND METHODS
=cut
sub GameStart
{
- my ( $MaxHP ) = @_;
+ my ( $MaxHP, $debug ) = @_;
$bgx = ( $SCRWIDTH2 - $BGWIDTH2) >> 1;
$bgy = ( $SCRHEIGHT2 - $BGHEIGHT2 ) >> 1;
$BgSpeed = 0;
$BgPosition = $BgMax >> 1;
$BgScrollEnabled = 1;
$HitPointScale = 1000 / $MaxHP;
+ $Debug = $debug;
+ ResetEarthquake();
$time = 0;
$Fighter1->Reset();
$Fighter1->{HP} = $MaxHP;
$Input1->Reset();
$Fighter2->Reset();
$Fighter2->{HP} = $MaxHP;
$Input2->Reset();
$over = 0;
$ko = 0;
$OverTimer = 0;
$JudgementMode = 0;
@Doodads = ();
@Sounds = ();
$p1h = $p2h = 0;
}
sub GetFighterData
{
my ($fighter) = @_;
my ($x, $y, $fnum, $f, $hp);
$fnum = $fighter->{FR};
$f = $fighter->{FRAMES}->[$fnum];
$x = $fighter->{X} / $GAMEBITS2 + $f->{'x'};
$y = $fighter->{Y} / $GAMEBITS2 + $f->{'y'};
if ($fighter->{DIR}<0)
{
$fnum = -$fnum;
$x -= $f->{x}*2 + $f->{w};
}
return ($x, $y, $fnum);
}
sub GetNextDoodadData
{
if ( $NextDoodad >= scalar @Doodads )
{
$doodad_x = $doodad_y = $doodad_t = $doodad_f = -1;
return;
}
my ($doodad) = $Doodads[$NextDoodad];
$doodad_x = $doodad->{X} / $GAMEBITS2 - $bgx;
$doodad_y = $doodad->{Y} / $GAMEBITS2 - $bgy;
$doodad_t = $doodad->{T};
$doodad_f = $doodad->{F};
$doodad_text = $doodad->{TEXT};
++$NextDoodad;
}
sub UpdateDoodads
{
my ($i, $j, $doodad);
for ($i=0; $i<scalar @Doodads; ++$i)
{
$doodad = $Doodads[$i];
$j = UpdateDoodad( $doodad );
if ( $j )
{
# Remove this Doodad
splice @Doodads, $i, 1;
--$i;
}
}
}
sub GetNextSoundData()
{
# print "GetSoundData: ", scalar @Sounds, join ' ,', @Sounds, "\n";
$sound = pop @Sounds;
$sound = '' unless defined $sound;
}
sub DoFighterEvents
{
my ($fighter, $hit) = @_;
if ( $JudgementMode )
{
if ( $fighter->{NUMBER} == $JudgementWinner )
{
$fighter->Event("Won");
}
else
{
$fighter->Event("Hurt");
}
return;
}
if ( $hit )
{
$fighter->HitEvent( $fighter->{OTHER}->GetCurrentState()->{HIT}, $hit );
return;
}
#if ( ($fighter->{X} - $fighter->{OTHER}->{X}) * ($fighter->{DIR}) > 0 )
if ( $fighter->IsBackTurned )
{
$fighter->Event("Turn");
}
if ( $fighter->{OTHER}->{ST} eq 'Dead' )
{
$fighter->Event("Won");
}
if ( ($fighter->{IDLE} > 150) and (rand(350) < 1) )
{
$fighter->Event("Fun");
}
if ( ($fighter->{IDLE} > 150) and (rand(350) < 1) )
{
$fighter->Event("Threat");
}
}
sub GameAdvance
{
+ # $::adv += 1;
+ # return if ( $::adv % 3 );
+
my ($hit1, $hit2);
$time += 4/1000;
$NextDoodad = 0;
$NextSound = 0;
# 1. ADVANCE THE PLAYERS
$Input1->Advance();
$Input2->Advance();
$Fighter1->Advance( $Input1 );
$Fighter2->Advance( $Input2 );
$hit2 = $Fighter1->CheckHit();
$hit1 = $Fighter2->CheckHit();
# 2. Events come here
DoFighterEvents( $Fighter1, $hit1 );
DoFighterEvents( $Fighter2, $hit2 );
UpdateDoodads();
$Fighter1->Update();
$Fighter2->Update();
if ( $OverTimer == 0 and
($Fighter1->{ST} eq 'Dead' or $Fighter1->{ST} eq 'Won2') and
($Fighter2->{ST} eq 'Dead' or $Fighter2->{ST} eq 'Won2') )
{
$OverTimer = 1;
}
elsif ( $OverTimer > 0 )
{
$OverTimer++;
$over = 1 if ( $OverTimer > 200 )
}
# 3. DO THE BACKGROUND SCROLLING THING
if ( $BgScrollEnabled )
{
$BgOpt = ($Fighter1->{X} + $Fighter2->{X}) / 2; # 1/1 Stupid kdevelop syntax hightlight.
if ( ($BgOpt - $BgSpeed*50 - $BgPosition) > (320 << $GAMEBITS)) { $BgSpeed++; }
if ( ($BgOpt - $BgSpeed*50 - $BgPosition) < (320 << $GAMEBITS)) { $BgSpeed--; }
$BgPosition+=$BgSpeed;
if ($BgPosition<0) { $BgPosition = $BgSpeed = 0; }
if ($BgPosition>$BgMax) { $BgPosition = $BgMax; $BgSpeed = 0; }
# print "Pos:$BgPosition\tOpt:$BgOpt\tSpd:$BgSpeed\t";
}
# 4. SET GLOBAL VARIABLES FOR THE C++ DRAWING TO READ
($p1x, $p1y, $p1f) = GetFighterData( $Fighter1 );
($p2x, $p2y, $p2f) = GetFighterData( $Fighter2 );
$phTarget = $Fighter1->{HP}*$HitPointScale;
if ( $p1h < $phTarget ) { $p1h += 5; }
if ( $p1h > $phTarget ) { $p1h -= 3; }
$p1h = $phTarget if abs($p1h - $phTarget) < 3;
$p1h = 0 if $p1h < 0;
$phTarget = $Fighter2->{HP}*$HitPointScale;
if ( $p2h < $phTarget ) { $p2h += 5; }
if ( $p2h > $phTarget ) { $p2h -= 3; }
$p2h = $phTarget if abs($p2h - $phTarget) < 3;
$p2h = 0 if $p2h < 0;
$bgx = $BgPosition >> $GAMEBITS;
$p1x -= $bgx;
$p2x -= $bgx;
$bgy = 0;
+
+ AdvanceEarthquake();
+
+ # 5. DEBUG POLYGONS
+
+ return unless $Debug;
$fr1 = $Fighter1->{FRAMES}->[ $Fighter1->{FR} ];
@p1head = @{ $fr1->{head} };
MirrorPolygon( \@p1head ) if $Fighter1->{DIR} < 0;
OffsetPolygon( \@p1head, $Fighter1->{X} / $GAMEBITS2 - $bgx, $Fighter1->{Y} / $GAMEBITS2 - $bgy );
@p1body = @{ $fr1->{body} };
MirrorPolygon( \@p1body ) if $Fighter1->{DIR} < 0;
OffsetPolygon( \@p1body, $Fighter1->{X} / $GAMEBITS2 - $bgx, $Fighter1->{Y} / $GAMEBITS2 - $bgy );
@p1legs = @{ $fr1->{legs} };
MirrorPolygon( \@p1legs) if $Fighter1->{DIR} < 0;
OffsetPolygon( \@p1legs, $Fighter1->{X} / $GAMEBITS2 - $bgx, $Fighter1->{Y} / $GAMEBITS2 - $bgy );
if ( defined $fr1->{hit} )
{
@p1hit = @{ $fr1->{hit} };
MirrorPolygon( \@p1hit ) if $Fighter1->{DIR} < 0;
OffsetPolygon( \@p1hit, $Fighter1->{X} / $GAMEBITS2 - $bgx, $Fighter1->{Y} / $GAMEBITS2 - $bgy );
}
else
{
undef @p1hit;
}
$fr2 = $Fighter2->{FRAMES}->[ $Fighter2->{FR} ];
@p2head = @{ $fr2->{head} };
MirrorPolygon( \@p2head ) if $Fighter2->{DIR} < 0;
OffsetPolygon( \@p2head, $Fighter2->{X} / $GAMEBITS2 - $bgx, $Fighter2->{Y} / $GAMEBITS2 - $bgy );
@p2body = @{ $fr2->{body} };
MirrorPolygon( \@p2body ) if $Fighter2->{DIR} < 0;
OffsetPolygon( \@p2body, $Fighter2->{X} / $GAMEBITS2 - $bgx, $Fighter2->{Y} / $GAMEBITS2 - $bgy );
@p2legs = @{ $fr2->{legs} };
MirrorPolygon( \@p2legs) if $Fighter2->{DIR} < 0;
OffsetPolygon( \@p2legs, $Fighter2->{X} / $GAMEBITS2 - $bgx, $Fighter2->{Y} / $GAMEBITS2 - $bgy );
if ( defined $fr2->{hit} )
{
@p2hit = @{ $fr2->{hit} };
MirrorPolygon( \@p2hit ) if $Fighter2->{DIR} < 0;
OffsetPolygon( \@p2hit, $Fighter2->{X} / $GAMEBITS2 - $bgx, $Fighter2->{Y} / $GAMEBITS2 - $bgy );
}
else
{
undef @p2hit;
}
+
+
}
diff --git a/data/script/DataHelper.pl b/data/script/DataHelper.pl
index 4fe0eb6..8772de4 100644
--- a/data/script/DataHelper.pl
+++ b/data/script/DataHelper.pl
@@ -1,620 +1,622 @@
# DataHelper contains subroutines useful for loading a character's
# frames, and creating his states.
use strict;
=comment
SITUATIONS ARE:
Ready, Stand, Crouch, (Midair = any + character is flying), Falling
SITUATION DEPENDENT EVENTS ARE:
Highhit, Uppercut, Hit, Groinhit, Leghit, Fall
STANDBY EVENTS ARE:
Won, Hurt, Threat, Fun, Turn
________|___Ready___________Block___Stand___________Crouch______________Midair______Falling
Highhit | HighPunched - HighPunched KneelingPunched (...) (...)
Uppercut| Falling - Falling KneelingPunched (...) (...)
Hit | LowPunched - LowPunched KneelingKicked
Groinhit| GroinKicked - GroinKicked KneelingKicked
Leghit | Swept - Swept KneelingKicked
Fall | Falling - Falling KneelingPunched
FRAME MEMBER DESCRIPTION IS:
x int X coordinate offset of the image relative to the character's anchor.
y int Y coordinate offset of the image relative to the character's anchor.
w int The width of the image.
h int The height of the image.
head array The coordinates of a polygon marking the head within the image, relative to the anchor.
body array The coordinates of a polygon marking the body within the image, relative to the anchor.
legs array The coordinates of a polygon marking the legs within the image, relative to the anchor.
hit array The coordinates of a polygon marking the hit within the image, relative to the anchor.
STATE MEMBER DESCRIPTION IS:
F int The number of the visible frame.
SITU string The situation associated with this state (Ready, Stand, Crouch, Falling)
DEL int The delay before moving to the next state.
NEXTST string The name of the state which follows this state, if none of the CONs is used.
CON hash Connections from this state. The keys are either events or keyboard input.
HIT ? The hit delivered at the beginning of this state.
BLOCK int If true, the character is blocking in his current state.
MOVE int The character's anchor should continously move this much during this state.
DELTAX int The character's anchor should immediately change by this much after this state.
PUSHX int The character is pushed, with this much momentum upon entering this state.
TURN int If true, the character's facing direction changes after this state.
JUMP int The character leaps into the air, with this much initial momentum upon entering this state.
DOODAD string A doodad is created at the beginning of this state. The string contains the doodad's type and speed.
SOUND string The sound effect associated with this state (if any);
HITSND string The sound effect if the HIT is successful.
MISSSND string The sound effect if the HIT fails.
+CODE string This code will be evaled at the beginning of this state.
=cut
# Loads the frame data (x, y, w, h) from the given datafile.
# The path to the datafile is inserted automatically. The frame data will
# be shifted by (-PivotX,-PivotY).
#
# Returns an array of frame data. The first element in the array is
# a dummy entry, the second is the first real entry. This is because
# the first thing in the datafile is a PAL entry.
#
# Example: LoadFrames( "ZOLIDATA.DAT.txt" );
sub LoadFrames ($$$)
{
my ($DataName, $PivotX, $PivotY) = @_;
my (@Frames, $data, $frame);
open DATAFILE, "../characters/$DataName" || die ("Couldn't open ../characters/$DataName");
$data = '';
while ( read DATAFILE, $data, 16384, length($data) )
{
}
close DATAFILE;
print "$DataName file is ", length($data), " bytes long.\n";
# Insert a dummy first row for the palette entry
eval ("\@Frames = ( {}, $data);");
die $@ if $@;
foreach $frame (@Frames)
{
OffsetFrame( $frame, -$PivotX, -$PivotY );
}
print "$DataName loaded, ", scalar @Frames, " frames.\n";
return @Frames;
}
# Creates a frame lookup from a descriptor array.
# The first parameter is the expected number of frames.
# The descriptor array should have frame base names in even positions,
# and lengths at odd. positions. For example:
# ("start", 6, "stand", 4, ... )
#
# The routine will return a lookup which will contain the frame's logical
# name as a key, and its physical index as a value. The logical names are
# simply the basename plus a number. The example above would return:
# ("start1"=>1, "start2"=>2, ..., "start6"=>6, "stand1"=>6, "stand2"=>7, ...)
sub CreateFrameLookup
{
my ($ExpectedCount, @FrameDesc) = @_;
my ($FrameName, $NumFrames);
my ($i, $j);
my (%FrameLookup);
for ( $i=0; $i<scalar @FrameDesc; $i +=2 )
{
$FrameName = $FrameDesc[$i];
$NumFrames = $FrameDesc[$i+1];
for ( $j = 1; $j<=$NumFrames; ++$j )
{
# print "Frame ", (scalar keys %FrameLookup) + 1, " is now called $FrameName$j\n";
$FrameLookup{ "$FrameName$j" } = (scalar keys %FrameLookup) + 1;
}
}
if ( $ExpectedCount != scalar keys( %FrameLookup ) )
{
die( "Expected number of frames ($ExpectedCount) doesn't equal the actual number of frames: ".
scalar keys(%FrameLookup) );
}
return %FrameLookup;
}
# Helper function. Finds the last frame with a given name in a frame
# lookup structure. Return the index of the last frame (1-based), or
# 0 if none with the given name were found.
#
# Example: If there are 6 "highpunch" frames (highpunch1 to highpunch6),
# FindLastFrame(\%FrameLookup, "highpunch") returns 6.
sub FindLastFrame($$) {
my ($FrameLookup, $FrameName) = @_;
my ($i) = (1);
while ( exists ${$FrameLookup}{"$FrameName$i"} ) { $i++; }
return $i-1;
}
sub OffsetPolygon($$$)
{
my ($poly, $dx, $dy) = @_;
my ($i, $n);
$n = scalar @{$poly};
for ( $i=0; $i < $n; $i+=2 )
{
$poly->[$i] += $dx;
$poly->[$i+1] += $dy;
}
}
sub MirrorPolygon($)
{
my ($poly) = @_;
my ($i, $n);
$n = scalar @{$poly};
for ( $i=0; $i < $n; $i+=2 )
{
$poly->[$i] = - $poly->[$i];
}
}
sub OffsetFrame($$$) {
my ($frame, $dx, $dy) = @_;
$frame->{'x'} += $dx;
$frame->{'y'} += $dy;
OffsetPolygon( $frame->{head}, $dx, $dy ) if defined ($frame->{head});
OffsetPolygon( $frame->{body}, $dx, $dy ) if defined ($frame->{body});
OffsetPolygon( $frame->{legs}, $dx, $dy ) if defined ($frame->{legs});
OffsetPolygon( $frame->{hit}, $dx, $dy ) if defined ($frame->{hit});
}
# FindLastState returns the last index of a given state.
# For example, if Punch4 is the last in Punch, FindLastState("Punch") is 4.
sub FindLastState($$) {
my ( $States, $StateName ) = @_;
my ( $i ) = ( 1 );
while ( exists ${$States}{ "$StateName $i" } ) { $i++; }
return $i-1;
}
# Translates an abbreviated sequence to a full sequence.
# "-punch" is every punch frame backwards.
# "_punch" is every punch frame except the last one backwards.
# "+punch" is every punch frame forwards.
sub TranslateSequence($$) {
my ($FrameLookup, $Sequence) = @_;
my ($pre, $frame) = $Sequence =~ /^([+-_]{0,1})(\w+)/;
my ($LastFrame) = (FindLastFrame( $FrameLookup, $frame ) );
#$LastFrame = (FindLastFrame( $FrameLookup, "$pre$frame" ) ) if $LastFrame == 0;
#print "Last frame of $frame is $LastFrame.\n";
return "$frame 1-$LastFrame" if ( $pre eq '+' );
return "$frame $LastFrame-1" if ( $pre eq '-' );
return "$frame " . ($LastFrame-1) . "-1" if ( $pre eq '_' );
$Sequence =~ s/\sn(-{0,1})/ $LastFrame$1/; # Replace n- with last frame
$Sequence =~ s/-n/-$LastFrame/; # Replace -n with last frame
return $Sequence;
}
sub SetStateData($$$)
{
my ($state, $FrameDesc, $suffix) = @_;
$state->{DEL} = $FrameDesc->{"DEL$suffix"} if defined $FrameDesc->{"DEL$suffix"};
$state->{HIT} = $FrameDesc->{"HIT$suffix"} if defined $FrameDesc->{"HIT$suffix"};
$state->{CON} = $FrameDesc->{"CON$suffix"} if defined $FrameDesc->{"CON$suffix"};
$state->{BLOCK} = $FrameDesc->{"BLOCK$suffix"} if defined $FrameDesc->{"BLOCK$suffix"};
$state->{NEXTST} = $FrameDesc->{"NEXTST$suffix"} if defined $FrameDesc->{"NEXTST$suffix"};
$state->{MOVE} = $FrameDesc->{"MOVE$suffix"} if defined $FrameDesc->{"MOVE$suffix"};
$state->{DELTAX} = $FrameDesc->{"DELTAX$suffix"} if defined $FrameDesc->{"DELTAX$suffix"};
$state->{PUSHX} = $FrameDesc->{"PUSHX$suffix"} if defined $FrameDesc->{"PUSHX$suffix"};
$state->{TURN} = $FrameDesc->{"TURN$suffix"} if defined $FrameDesc->{"TURN$suffix"};
$state->{JUMP} = $FrameDesc->{"JUMP$suffix"} if defined $FrameDesc->{"JUMP$suffix"};
$state->{SITU} = $FrameDesc->{"SITU$suffix"} if defined $FrameDesc->{"SITU$suffix"};
$state->{DOODAD} = $FrameDesc->{"DOODAD$suffix"} if defined $FrameDesc->{"DOODAD$suffix"};
$state->{SOUND} = $FrameDesc->{"SOUND$suffix"} if defined $FrameDesc->{"SOUND$suffix"};
+ $state->{CODE} = $FrameDesc->{"CODE$suffix"} if defined $FrameDesc->{"CODE$suffix"};
}
# Adds a sequence to the end of a state
# Sequences are: e.g. "throw 10-14, throw 16, throw 14-10"
# Each piece of the sequence will have $Delay delay.
sub AddStates($$$) {
my ( $States, $Frames, $FrameDesc ) = @_;
my ( $StateName, $SequenceString, $LastState, $i, $sloop, $s, @Sequences );
my ( $from, $to, $frame, $state );
$StateName = $FrameDesc->{'N'};
$SequenceString = $FrameDesc->{'S'};
$FrameDesc->{SITU} = 'Stand' unless defined $FrameDesc->{SITU};
$LastState = FindLastState($States,$StateName)+1;
@Sequences = split ( /\s*,\s*/, $SequenceString );
for ( $sloop = 0; $sloop < scalar @Sequences; ++$sloop )
{
$s = TranslateSequence( $Frames, $Sequences[$sloop] );
#print "Sequence is $s\n";
if ( $s =~ /^\s*(\w+)\s+(\d+)-(\d+)\s*$/ )
{
# Sequence is '<frame> <from>-<to>'
$frame = $1;
$from = $2;
$to = $3;
}
elsif ( $s =~ /^\s*(\w+)\s+(\d+)\s*$/ )
{
# Sequence is '<frame> <number>'
$frame = $1;
$from = $to = $2;
}
else
{
die "Sequence '$s' incorrect.\n";
}
$i = $from;
while (1)
{
die "Error: Frame $frame$i doesn't exist.\n"
unless defined ${$Frames}{"$frame$i"};
$state = { 'F'=>"$frame$i" };
SetStateData( $state, $FrameDesc, '' );
SetStateData( $state, $FrameDesc, $LastState );
if ( ( $sloop == scalar @Sequences -1 ) and ( $i == $to ) )
{
SetStateData( $state, $FrameDesc, 'N' );
}
$States->{"$StateName $LastState"} = $state;
# print "Added state '$StateName $LastState' as frame '$frame$i', delay $Delay\n";
$LastState++;
if ( $from < $to )
{
$i++;
last if $i > $to;
}
else
{
$i--;
last if $i < $to;
}
}
}
}
sub BlockStates($$)
{
my ( $frames, $del) = @_;
my ( $retval, $i );
$retval = { 'N'=>'Block', 'DEL'=>$del, 'S'=>'+block', "BLOCK$frames"=>1 };
for ($i = 1; $i <= $frames; ++$i )
{
$retval->{"NEXTST$i"} = "Block " . ($i-1);
$retval->{"CON$i"} = { 'block'=> "Block " . ($i+1) };
}
$retval->{'NEXTST1'} = 'Stand';
$retval->{"CON$frames"} = { 'block'=> "Block " . $frames };
return $retval;
}
sub KneelingStates($$$$)
{
my ( $frames, $frames2, $del, $con ) = @_;
my ( $retval, $retval2, $i, $j );
$retval = { 'N'=>'Kneeling', 'DEL'=> $del, 'S' => '+kneeling', 'SITU'=>'Crouch' };
for ( $i = 1; $i <= $frames; ++$i )
{
$retval->{"NEXTST$i"} = "Kneeling " . ($i-1);
$retval->{"CON$i"} = { 'down' => "Kneeling " . ($i+1) };
}
$retval->{'NEXTST1'} = 'Stand';
$retval->{"CON$frames"} = { 'down' => "Onknees" };
$retval2 = { 'N'=>'Onknees', 'DEL'=>$del, 'S' => '+onknees,-onknees', 'SITU'=>'Crouch',
'NEXTST' => "Kneeling $frames" };
$frames2 *= 2;
for ( $i = 1; $i <= $frames2; ++$i )
{
$j = ($i % $frames2) + 1;
$retval2->{"CON$i"} = { %{$con}, 'down'=>"Onknees $j", 'forw'=>"Onknees $j", 'back'=>"Onknees $j" };
}
return ($retval, $retval2);
}
sub JumpStates($$)
{
my ( $frames, $con ) = @_;
my ( $kneelingframes, $onkneesframes,
$kickframes, $punchframes ) = (
FindLastFrame( $frames, 'kneeling' ),
FindLastFrame( $frames, 'onknees' ),
FindLastFrame( $frames, 'kneelingkick' ),
FindLastFrame( $frames, 'kneelingpunch' ) );
my ( $jump ) = 120;
my ( $i, $j, $statestotal, $statesdown, $statesknees, $deldown,
$jumpfw, $jumpbw, $flying, $flyingsequence, $jumpkick, $jumppunch );
# The jump's first part is going down on knees, second part is
# on knees, third part is getting up.
if ( $::DELMULTIPLIER )
{
$statestotal = $jump * 2 / 3 / $::DELMULTIPLIER; # 1/1
}
else
{
$statestotal = $jump * 2 / 3;
}
$statesdown = $statestotal / 4;
$deldown = int($statesdown / $kneelingframes + 0.1); # 1/1
$statesdown = $deldown * $kneelingframes;
$statesknees = $statestotal - $statesdown * 2;
$jump = { 'N'=>'Jump', 'DEL'=> $deldown, 'S'=>'kneeling 1-2, kneeling 1',
'JUMPN'=>$jump, NEXTSTN=>'JumpFly', 'SOUND1'=>'slip4.voc', };
$jumpfw = { %{$jump}, 'N'=>'JumpFW', 'PUSHX3'=>18*16 };
$jumpbw = { %{$jump}, 'N'=>'JumpBW', 'PUSHX3'=>-9*16 };
$flyingsequence = '';
$flying = {};
for ( $i = 0; $i < $statesknees / $deldown; ++$i ) #1/1
{
$j = $i + $statesdown / $deldown; #1/1
$flyingsequence .= 'onknees 1,';
$flying->{"CON$j"} = $con;
# $flying->{"DEL$j"} = 1;
}
$flyingsequence = "+kneeling, $flyingsequence -kneeling";
$flying = { %{$flying}, 'N'=>'JumpFly', 'DEL'=> $deldown, 'S'=>$flyingsequence,
'DELN'=>100 };
print join( ',', %{$flying}), "\n";
$jumpkick = { 'N'=>'JumpKick', 'HIT'=>'Fall',
'DEL'=> int( $statestotal * 2 / 3 / ( $kickframes + $kneelingframes*2 + 3 ) ), # 1/1
'S'=> '+kneelingkick,kneelingkick n, kneelingkick n, kneelingkick n,-kneelingkick,-kneeling',
'HIT'=>'Fall', 'DELN'=>100 };
$jumppunch = { 'N'=>'JumpPunch', 'HIT'=>'Highhit',
'DEL'=> int( $statestotal * 2 / 3 / ( $punchframes + $kneelingframes*2 + 3 ) ), # 1/1
'S'=> '+kneelingpunch,kneelingpunch n, kneelingpunch n, kneelingpunch n,-kneelingpunch,-kneeling',
'HIT'=>'Fall', 'DELN'=>100 };
return ($jump, $jumpfw, $jumpbw, $flying, $jumpkick, $jumppunch);
}
sub WalkingFrames($$$$$)
{
my ( $frameLookup, $frameArray, $preFrames, $distance, $con ) = @_;
my ( $walkFrames, $totalFrames, $seq, $seq2, $distPerFrame,
$walk, $back, $walkNextst, $backNextst,
$i, $j, );
$totalFrames = FindLastFrame( $frameLookup, 'walk' );
$walkFrames = $totalFrames - $preFrames;
if ( $preFrames > 0 ) {
$seq = "+walk, walk $preFrames-1";
$seq2 = "walk 1-$preFrames, -walk";
} else {
$seq = "+walk";
$seq2 = "-walk";
}
$walk = { 'N'=>'Walk', 'S'=>$seq, 'DEL'=>5, 'CON'=>$con };
$back = { 'N'=>'Back', 'S'=>$seq2, 'DEL'=>5, };
# Add attributes for the 'pre' states.
for ( $i=1; $i <= $preFrames; ++$i )
{
$j = $i + 1;
$walk->{"CON$i"} = { %{$con}, 'forw' => "Walk $j" };
$walk->{"NEXTST$i"} = 'Stand';
$back->{"CON$i"} = { %{$con}, 'back' => "Back $j" };
$back->{"NEXTST$i"} = 'Stand';
}
# Add attributes for the 'walk' states.
$walkNextst = $preFrames ? 'Walk ' . ($totalFrames+1) : 'Stand';
$backNextst = $preFrames ? 'Back ' . ($totalFrames+1) : 'Stand';
$distPerFrame = $distance / $walkFrames; # 1/1
print "*** $preFrames $walkFrames $totalFrames $walkNextst $backNextst\n";
for ( $i=$preFrames+1; $i <= $totalFrames; ++$i )
{
$j = ($i == $totalFrames) ? $preFrames+1 : $i+1;
$walk->{"MOVE$i"} = 4;
$walk->{"NEXTST$i"} = $walkNextst;
$walk->{"CON$i"} = { %{$con}, 'forw' => "Walk $j" };
$back->{"MOVE$i"} = -4;
$back->{"NEXTST$i"} = $backNextst;
$back->{"CON$i"} = { %{$con}, 'back' => "Back $j" };
OffsetFrame( $frameArray->[$frameLookup->{"walk$i"}],
- ($i-$preFrames-1) * $distPerFrame, 0 );
}
return ( $walk, $back );
}
sub TravelingStates( $$$$$$ )
{
my ( $frameLookup, $frameArray, $states, $frameName, $from, $to ) = @_;
$from = 1 unless $from;
$to = FindLastFrame( $frameLookup, $frameName ) unless $to;
my ( $fromIndex, $toIndex, $fromFrame, $toFrame, $fromOffset, $toOffset,
$deltax, $i, $state, $nextst );
# 1. Calculate the 'deltax' and 'fromOffset'.
$fromIndex = $frameLookup->{"$frameName$from"};
die "couldn't find frame $frameName$from" unless defined $fromIndex;
$toIndex = $fromIndex - $from + $to;
$fromFrame = $frameArray-> [ $fromIndex ];
$toFrame = $frameArray-> [ $toIndex ];
$fromOffset = $fromFrame->{x} + ($fromFrame->{w} >> 1);
$toOffset = $toFrame->{x} + ($toFrame->{w} >> 1);
$deltax = ( $toOffset - $fromOffset ) / ( $to - $from ); #1/1
# print "Offsets: $fromOffset $toOffset $deltax\n";
# 2. Offset every relevant frame.
for ( $i=$fromIndex; $i<=$toIndex; ++$i )
{
# print "Offsetting frame $i by ", - $fromOffset - $deltax * ($i-$fromIndex), "\n";
OffsetFrame( $frameArray->[$i],
- $fromOffset - $deltax * ($i-$fromIndex), 0 );
}
# 3. Apply deltax to every relevant state.
while ( ($i, $state) = each %{$states} )
{
if ( $state->{F} >= $fromIndex and $state->{F} <= $toIndex )
{
$nextst = $states->{$state->{NEXTST}};
if ( $nextst->{F} >= $fromIndex and $nextst->{F} <= $toIndex )
{
$state->{DELTAX} = $deltax * ($nextst->{F} - $state->{F});
# print "Fixing state $i : deltax = ", $state->{DELTAX}, "\n";
}
}
}
}
sub FixStates($$)
{
my ( $frameLookup, $states ) = @_;
my ( $framename, $st, $lastchar, $key, $value, $nextchar, $nextst );
while (($key, $value) = each %{$states})
{
$framename = $value->{'F'};
unless ( $framename =~/^\d+$/ )
{
# Convert non-numeric frames to their numeric counterparts.
die "Can't find image $framename in frame $key" unless defined $frameLookup->{ $framename };
$value->{'F'} = $frameLookup->{ $framename };
}
($st,$lastchar) = $key =~ /(\w+)\s+(\d+)/;
unless ( defined $value->{'NEXTST'} )
{
$nextchar = $lastchar + 1;
$nextst = "$st $nextchar";
unless ( defined $states->{$nextst} ) {
# print "Go to Standby after $key\n";
$nextst = 'Stand';
}
$value->{'NEXTST'} = $nextst;
}
}
}
sub FindShorthands($)
{
my ( $states ) = @_;
my ( $key, $value, $st, $lastchar, %Shorthands );
while (($key, $value) = each %{$states})
{
($st,$lastchar) = $key =~ /(\w+)\s+(\d+)/;
print "$key has no lastchar" unless defined $lastchar;
if ( $lastchar == 1 )
{
$Shorthands{$st} = $states->{$key};
}
}
return %Shorthands;
}
return 1;
diff --git a/data/script/Fighter.pl b/data/script/Fighter.pl
index 1b4cde7..c825bb6 100644
--- a/data/script/Fighter.pl
+++ b/data/script/Fighter.pl
@@ -1,728 +1,740 @@
require 'Collision.pl';
require 'DataHelper.pl';
require 'Damage.pl';
package Fighter;
use strict;
=comment
Fighter's members are:
NAME string The name of the character, e.g. "Ulmar".
FRAMES array The character's frame description.
STATES hash The character's state description.
NUMBER int Player number (either 0 or 1)
X int The fighter's current anchor, horizontal coordinate.
Y int The fighter's current anchor, vertical coordinate.
ST string The name of the fighter's current state.
FR int The number of the fighter's current frame (same as STATES->{ST}->{F}).
DEL int The amount of time before the character moves to the next state.
NEXTST string The name of the next state after this one (calculated by Advance and Event, user by Update).
DIR int -1: the character is facing left; 1: if the character is facing right.
PUSHY int The character's vertical momentum, from jumping/hits.
PUSHX int The character's horizontal momentum, from hits.
HP int Hit points, from 100 down to 0.
IDLE int The amount of game time since the player is ready.
CHECKEHIT int 1 if the hit needs to be checked soon.
DELIVERED int 1 if a hit was delivered in this state.
COMBO int The number of consecutive hits delivered to this fighter.
COMBOHP int The amount of HP delivered in the last combo.
OTHER hash A reference to the other Fighter
new
Reset
Advance
CheckHit
IsHitAt
Event
Update
Needs to be subclassed: Reset, NextState
=cut
sub new {
my ($class) = @_;
my $self = {
'NUMBER'=> 0,
'ST' => 'Start',
'FR' => 0,
'DEL' => 0,
'DIR' => 1,
'PUSHY' => 0,
'PUSHX' => 0,
};
bless $self, $class;
return $self;
}
sub Reset {
my ($self, $name, $frames, $states) = @_;
die "Insufficient parameters." unless defined $self;# and defined $frames and defined $states;
my ($number);
$number = $self->{NUMBER};
print STDERR "Resetting fighter $number\n";
$self->{NAME} = $name if defined $name;
$self->{FRAMES} = $frames if defined $frames;
$self->{STATES} = $states if defined $states;
$self->{X} = (( $number ? 540 : 100 ) << $::GAMEBITS) + $::BgPosition;
$self->{Y} = $::GROUND2;
$self->{ST} = 'Start';
$self->{FR} = $self->GetCurrentState()->{F};
$self->{DEL} = 0;
$self->{DIR} = ($number ? -1 : 1);
$self->{PUSHY} = 0;
$self->{PUSHX} = 0;
$self->{HP} = 100;
$self->{IDLE} = 0;
$self->{CHECKHIT} = 0;
$self->{DELIVERED} = 0;
$self->{COMBO} = 0;
$self->{COMBOHP}= 0;
}
=comment
Advance should be called once every game tick. It advances the fighter,
preparing his variables for drawing him in the next tick. Advance also
processes the input if it is appropriate to do so in the current state.
Advance prepares the NEXTST attribute of the player. It does not modify
the current ST yet, because that may depend on hits, event, etc. Advance
should be followed by CheckHit and Event calls, and finally Update.
=cut
sub Advance {
my ($self, $in) = @_;
my ($stname, # The name of the current state.
$st, # The descriptor of the current state.
$move, # The move associated with the current state.
$i, $j, # temp var.
@body ); # collision detection
$self->{NEXTST} = '';
$stname = $self->{ST};
$st = $self->{'STATES'}->{$stname};
# 1. DECREMENT 'DEL' PROPERTY
$self->{'DEL'}--;
if ( $st->{SITU} eq 'Ready' )
{
$self->{IDLE} = $self->{IDLE} + 1;
}
else
{
$self->{IDLE} = 0;
}
# 2. UPDATE THE HORIZONTAL POSITION
# 2.1. 'MOVE' PLAYER IF NECESSARY
if ( defined $st->{'MOVE'} )
{
$move = $st->{'MOVE'}*$self->{'DIR'} * 6;
$self->{'X'} += $move;
}
# 2.2. 'PUSH' PLAYER IF NECESSARY
if ( $self->{PUSHX} )
{
$i = ($self->{PUSHX}+7) / 8; # 1/1; syntax highlight..
$self->{X} += $i;
$self->{PUSHX} -= $i if $self->{PUSHY} == 0;
}
# 2.3. MAKE SURE THE TWO FIGHTERS DON'T "WALK" INTO EACH OTHER
if ( $self->{Y} >= $::GROUND2 and
$self->{OTHER}->{Y} >= $::GROUND2 )
{
my ( $centerX, $centerOtherX, $pushDir );
$centerX = $self->GetCenterX;
$centerOtherX = $self->{OTHER}->GetCenterX;
if ( abs($centerX - $centerOtherX) < 60 )
{
$pushDir = ($centerX > $centerOtherX) ? 1 : -1;
$self->{X} += 10 * $pushDir;
$self->{OTHER}->{X} -= 10 * $pushDir;
}
}
# 2.4. HORIZONTAL BOUNDS CHECKING
$self->{X} = $::BgPosition + $::MOVEMARGIN2
if $self->{X} < $::BgPosition + $::MOVEMARGIN2;
$self->{X} = $::BgPosition + $::SCRWIDTH2 - $::MOVEMARGIN2
if $self->{X} > $::BgPosition + $::SCRWIDTH2 - $::MOVEMARGIN2;
# 3. FLYING OR FALLING
if ( $self->{Y} < $::GROUND2 )
{
$self->{PUSHY} += 3;
$self->{Y} += $self->{PUSHY};
if ($self->{Y} >= $::GROUND2)
{
# LANDING
if ( $st->{SITU} eq 'Falling')
{
+ ::AddEarthquake( $self->{PUSHY} / 20 );
push @::Sounds, ('splat.wav') if $self->{PUSHY} > 40;
# print "PUSHY = ", $self->{PUSHY}, "; ";
if ( $self->{PUSHY} > 30 )
{
# Bouncing after a fall
$self->{PUSHY} = - $self->{PUSHY} / 2; # 1/1
$self->{Y} = $::GROUND2 - 1;
}
else
{
# Getting up after a fall.
$self->{PUSHY} = 0;
$self->{Y} = $::GROUND2;
$self->{DEL} = 0;
$self->{NEXTST} = 'Getup';
$self->{NEXTST} = 'Dead' if $self->{HP} <= 0;
}
return;
}
else
{
push @::Sounds, ('thump.wav');
$self->{PUSHY} = 0;
$self->{Y} = $::GROUND2;
if ( substr($self->{ST},0,4) eq 'Jump' )
{
# Landing after a jump
$self->{DEL} = 0;
$self->{NEXTST} = 'Stand';
}
else
{
print "Landed; state: ", $self->{ST}, "\n";
}
return;
}
}
}
return if $self->{'DEL'} > 0;
# 4. DELAYING OVER. MAKE END-OF-STATE CHANGES.
# 4.1. 'DELTAX' displacement if so specified
if ($st->{DELTAX})
{
$self->{X} += $st->{DELTAX} * $self->{DIR} * $::GAMEBITS2;
}
# 4.2. 'TURN' if so specified
if ($st->{TURN})
{
$self->{DIR} = - $self->{DIR};
# Swap input keys..
$i = $in->{Keys}->[2];
$in->{Keys}->[2] = $in->{Keys}->[3];
$in->{Keys}->[3] = $i;
}
# 5. CALCULATE THE NEXT STATE
my ($nextst, $con, $input, $mod, $action, $dist);
$nextst = $st->{NEXTST};
$con = $st->{CON};
$dist = ($self->{OTHER}->{X} - $self->{X}) * $self->{DIR};
if ( defined $con )
{
$self->ComboEnds();
# 5.1. The current state has connections!
($input,$mod) = $in->GetAction();
$mod = '' unless defined $mod;
$action = $input;
# Try to find the best matching connection.
for ( $i = length($mod); $i>=0; --$i )
{
$action = $input . substr( $mod, 0, $i );
last if defined $con->{$action};
}
if ( defined $con->{$action} )
{
# print "dist = $dist. ";
if ( ($action eq 'hpunch' or $action eq 'lpunch') and ($dist>=0) and ($dist<800) )
{
$action = 'hpunchF' if defined $con->{'hpunchF'};
}
elsif ( ($action eq 'hkick' or $action eq 'lkick') and ($dist>=0) and ($dist<900) )
{
$action = 'lkickF' if defined $con->{'lkickF'};
}
$nextst = $con->{$action};
$in->ActionAccepted;
}
}
$self->{'NEXTST'} = $nextst;
}
sub CheckHit
{
my ($self) = @_;
return 0 unless $self->{CHECKHIT};
$self->{CHECKHIT} = 0;
my ($st, # A reference to the next state.
$nextst, # The name of the next state.
@hit, # The hit array
$i,
);
$st = $self->{STATES}->{$self->{ST}};
return 0 unless $st->{HIT};
return 0 unless defined $self->{FRAMES}->[$st->{F}]->{hit};
@hit = @{$self->{FRAMES}->[$st->{F}]->{hit}};
if ( $self->{DIR}<0 )
{
::MirrorPolygon( \@hit );
}
::OffsetPolygon( \@hit,
$self->{X} / $::GAMEBITS2,
$self->{Y} / $::GAMEBITS2 );
$i = $self->{OTHER}->IsHitAt( \@hit );
$self->{DELIVERED} = 1 if $i;
print "Collision = $i; ";
if ( $i == 0 )
{
# Make the 'Woosh' sound - maybe.
$nextst = $st->{NEXTST};
print "NEXTST = $nextst";
$nextst = $self->{STATES}->{$nextst};
print "NEXTST->HIT = ", $nextst->{HIT}, "\n";
push @::Sounds, ('woosh.wav') unless $nextst->{HIT} and defined $self->{FRAMES}->[$nextst->{F}]->{hit};
}
return $i;
}
sub IsHitAt
{
my ($self, $poly) = @_;
my ($frame, @a);
$frame = $self->{FRAMES}->[$self->{FR}];
::OffsetPolygon( $poly, -$self->{X} / $::GAMEBITS2, -$self->{Y} / $::GAMEBITS2 );
if ( $self->{DIR}<0 )
{
::MirrorPolygon( $poly );
}
# print "IsHitAt (", join(',',@{$poly}),")\n (",
# join(',',@{$frame->{head}}),")\n (",
# join(',',@{$frame->{body}}),")\n (",
# join(',',@{$frame->{legs}}),")\n";
return 1 if ::Collisions( $poly, $frame->{head} );
return 2 if ::Collisions( $poly, $frame->{body} );
return 3 if ::Collisions( $poly, $frame->{legs} );
return 0;
}
=comment
Event($self, $event, $eventpar): Handles the following events:
'Won', 'Hurt', 'Thread', 'Fun', 'Turn'
=cut
sub Event($$$)
{
my ($self, $event, $eventpar) = @_;
my ($st);
$st = $self->GetCurrentState();
if ( ($st->{SITU} eq 'Ready' or $st->{SITU} eq 'Stand') and $event eq 'Won' )
{
$self->{NEXTST} = 'Won' unless substr($self->{ST}, 0, 3) eq 'Won' ;
return;
}
if ( $st->{SITU} eq 'Ready' and $self->{NEXTST} eq '' )
{
if ( $event =~ /Hurt|Threat|Fun|Turn/ )
{
if ( $event eq 'Fun' and defined $self->{STATES}->{'Funb'} and rand() < 0.5 )
{
$event = 'Funb';
}
$self->{NEXTST} = $event;
}
}
}
=comment
Event($self, $event, $eventpar): Handles the following events:
'Highhit', 'Uppercut', 'Hit', 'Groinhit', 'Leghit', 'Fall'
=cut
sub HitEvent($$$)
{
my ($self, $event, $eventpar) = @_;
my ($st, $blocked, $damage);
$st = $self->GetCurrentState();
# Do events: Highhit, Uppercut, Hit, Groinhit, Leghit, Fall
$eventpar = '' unless defined $eventpar; # Supress useless warning
$damage = ::GetDamage( $self->{OTHER}->{NAME}, $self->{OTHER}->{ST} );
$blocked = $st->{BLOCK};
$blocked = 0 if ( $self->IsBackTurned() );
print "Event '$event', '$eventpar'\n";
print "Blocked.\n" if ( $blocked );
# Hit point adjustment here.
$self->{HP} -= $blocked ? $damage >> 3 : $damage;
# Turn if we must.
$self->{DIR} = ( $self->{X} > $self->{OTHER}->{X} ) ? -1 : 1;
# Handle the unfortunate event of the player "dying".
if ( $self->{HP} <= 0 )
{
push @::Sounds, ('bowling.voc');
$self->{NEXTST} = 'Falling';
$self->{PUSHX} = -20 * 3 * $self->{DIR};
$self->{PUSHY} = -80;
$self->{Y} -= 10;
$self->{COMBO} += 1;
$self->{COMBOHP} += $damage;
$self->ComboEnds();
$::ko = 1;
return;
}
# Handle blocked attacks.
if ( $blocked )
{
push @::Sounds, ('thump.wav');
$self->{PUSHX} = - $damage * 5 * $self->{DIR};
return;
}
# Handle the rest of the events.
- if ( $event eq 'Uppercut' ) { push @::Sounds, ('evil_laughter.voc'); }
+ if ( $event eq 'Uppercut' )
+ {
+ push @::Sounds, ('evil_laughter.voc');
+ ::AddEarthquake( 20 );
+ }
elsif ($event eq 'Groinhit') { push @::Sounds, ('woman_screams.voc'); }
{ push @::Sounds, ('thump3.voc'); }
$self->{COMBO} += 1;
$self->{COMBOHP} += $damage;
$damage *= $self->{COMBO}; # Only for the purpose of pushing
if ( $st->{SITU} eq 'Crouch' )
{
if ( $event eq 'Uppercut' or $event eq 'Fall' )
{
$self->{NEXTST} = 'Falling';
$self->{PUSHX} = -48 * 3 * $self->{DIR};
$self->{PUSHY} = -100;
$self->{Y} -= 10;
}
else
{
if ($eventpar == 1) {
$self->{NEXTST} = 'KneelingPunched';
} else {
$self->{NEXTST} = 'KneelingKicked';
}
$self->{PUSHX} = - $damage * 20 * $self->{DIR};
}
return;
}
if ( $st->{SITU} eq 'Falling' )
{
$self->{PUSHY} -= 50;
$self->{PUSHY} = -80 if $self->{PUSHY} > -80;
$self->{Y} -= 10;
return;
}
if ( $self->{Y} < $::GROUND2 )
{
$self->{NEXTST} = 'Falling';
$self->{PUSHY} -= 50;
$self->{PUSHX} = -48 * 3 * $self->{DIR};
return;
}
if ( $event eq 'Highhit' )
{
$self->{NEXTST} = 'HighPunched';
$self->{PUSHX} = - $damage * 20 * $self->{DIR};
}
elsif ( $event eq 'Hit' )
{
if ($eventpar == 1) {
$self->{NEXTST} = 'HighPunched';
} elsif ($eventpar == 2) {
$self->{NEXTST} = 'LowPunched';
} else {
$self->{NEXTST} = 'Swept';
}
$self->{PUSHX} = - $damage * 20 * $self->{DIR};
}
elsif ( $event eq 'Groinhit' )
{
$self->{NEXTST} = 'GroinKicked';
$self->{PUSHX} = - $damage * 20 * $self->{DIR};
}
elsif ( $event eq 'Leghit' )
{
$self->{NEXTST} = 'Swept';
$self->{PUSHX} = - $damage * 20 * $self->{DIR};
}
elsif ( $event eq 'Uppercut' or $event eq 'Fall' )
{
$self->{NEXTST} = 'Falling';
$self->{PUSHX} = -48 * 3 * $self->{DIR};
$self->{PUSHY} = -100;
$self->{Y} -= 10;
}
else
{
die "Unknown event: $event, $eventpar";
}
}
sub GetCurrentState
{
my ($self, $statename) = @_;
my ($stateref);
die unless defined $self;
$statename = $self->{ST} unless defined $statename;
$stateref = $self->{STATES}->{$statename};
return $stateref;
}
sub ComboEnds
{
my ($self) = @_;
if ($self->{COMBO})
{
if ( $self->{COMBO} > 1 )
{
my ( $head, $doodad, $x, $y );
$head = $self->{FRAMES}->[$self->{FR}]->{head};
$x = $self->{X} + $head->[0] * $::GAMEBITS2 * $self->{DIR};
$y = $self->{Y} + $head->[1] * $::GAMEBITS2;
$doodad = ::CreateTextDoodad( $x, $y - 30 * $::GAMEBITS2,
$self->{NUMBER},
$self->{COMBO} . "-hit combo!" );
$doodad->{LIFETIME} = 80;
$doodad->{SY} = -3;
$doodad->{SX} = -3;
$doodad = ::CreateTextDoodad( $x, $y - 10 * $::GAMEBITS2,
$self->{NUMBER},
int($self->{COMBOHP}*$::HitPointScale/10) . "% damage" );
$doodad->{LIFETIME} = 80;
$doodad->{SY} = -3;
$doodad->{SX} = +3;
print $self->{COMBO}, "-hit combo for ", $self->{COMBOHP}, " damage.\n";
push @::Sounds, ('ba_gooock.voc');
}
$self->{COMBO} = 0;
$self->{COMBOHP} = 0;
}
}
=comment
Update moves the fighter to his next state, if there is a NEXTST set.
NEXTST should be calculated before calling this method. No further
branching or CON checking is done.
If the next state has JUMP, the character is set aflying.
=cut
sub Update
{
my ($self) = @_;
my ($nextst, # The name of the next state
$st); # The descriptor of the next state.
# Is there a next state defined?
$nextst = $self->{'NEXTST'};
# If there isn't, no updating is necessary.
return unless $nextst;
# ADMINISTER THE MOVING TO THE NEXT STATE
$st = $self->GetCurrentState( $nextst );
$self->{'ST'} = $nextst;
$self->{'FR'} = $st->{'F'};
die "ERROR IN STATE $nextst" unless defined $st->{DEL};
$self->{'DEL'} = $st->{'DEL'} * $::DELMULTIPLIER;
# HANDLE THE JUMP and PUSH ATTRIBUTE
if ( defined ($st->{'JUMP'}) )
{
$self->{'PUSHY'} = -($st->{'JUMP'});
$self->{'Y'} += $self->{'PUSHY'};
}
if ( defined ($st->{'PUSHX'}) )
{
$self->{'PUSHX'} += $st->{'PUSHX'} * $self->{DIR};
}
# HANDLE THE HIT ATTRIBUTE
if ( defined ($st->{HIT}) )
{
$self->{CHECKHIT} = 1 unless $self->{DELIVERED};
}
else
{
$self->{DELIVERED} = 0;
}
# HANDLE THE SOUND ATTRIBUTE
if ( defined $st->{SOUND} )
{
push @::Sounds, ($st->{SOUND});
}
+
+ # HANDLE THE CODE ATTRIBUTE
+
+ if ( defined ($st->{CODE}) )
+ {
+ eval ($st->{CODE}); print $@ if $@;
+ }
# HANDLE DOODADS
if ( defined ($st->{DOODAD}) )
{
# Create a doodad (probably a shot)
my ($frame, $hit, $doodad, $ddata);
$frame = $self->{FRAMES}->[$self->{FR}];
$hit = $frame->{hit};
if ( defined $hit )
{
$ddata = $st->{DOODAD};
$doodad = ::CreateDoodad(
$self->{X} + $hit->[0] * $::GAMEBITS2 * $self->{DIR},
$self->{Y} + $hit->[1] * $::GAMEBITS2,
$ddata->{W},
$ddata->{H},
$ddata->{T},
$self->{NUMBER} );
$doodad->{SX} = $ddata->{SX} * $self->{DIR};
$doodad->{SY} = $ddata->{SY} * $self->{DIR};
$doodad->{FRAMES} = $ddata->{FRAMES};
$doodad->{SA} = $ddata->{SA};
}
}
}
=comment
Returns the characters 'centerline' in physical coordinates.
=cut
sub GetCenterX
{
my ($self) = @_;
my ($body, $x);
$body = $self->{FRAMES}->[$self->{FR}]->{body};
$x = $body->[0] + $body->[2] + $body->[4] + $body->[6];
return $self->{X} / $::GAMEBITS2 + $x / 4 * $self->{DIR};
}
=comment
Is my back turned to my opponent? Returns true if it is.
=cut
sub IsBackTurned
{
my ($self) = @_;
return ( ($self->{X} - $self->{OTHER}->{X}) * ($self->{DIR}) > 0 );
}
return 1;
diff --git a/data/script/Grizli.pl b/data/script/Grizli.pl
index 705c29e..257490c 100644
--- a/data/script/Grizli.pl
+++ b/data/script/Grizli.pl
@@ -1,196 +1,196 @@
# package Grizli;
# Grizli's images are scaled by a factor of 0.763
require 'DataHelper.pl';
use strict;
sub LoadGrizli
{
my ( @Frames, %FrameLookup, %Frames, %States, %Shorthands,
$Doodad, $Con, $Con2,
@States1,
$framedesc, $key, $value, $framename, $nextst, $st, $lastchar, $nextchar );
@Frames = LoadFrames( "GRIZLIDATA.DAT.pl", 250, 100 );
%FrameLookup = CreateFrameLookup( scalar @Frames -1,
"start", 14, "stand", 6, "walk", 15,
"turn", 9, "falling", 15, "laying", 1,
"getup", 16, "hurt", 9, "kneeling", 4,
"onknees", 5, "kneelingpunch",5, "kneelingkick", 5,
"fun", 9,
"highpunch", 9, "lowpunch", 6, "highkick", 6,
"lowkick", 6, "sweep", 15, "groinkick", 7,
"kneekick", 8, "elbow", 12, "spin", 17,
"grenade", 10, "uppercut", 17, "throw", 19,
"highpunched", 11, "lowpunched", 6, "groinkicked", 8,
"kneelingpunched",5, "kneelingkicked", 4, "thrown", 14,
"specpunch", 6, "nunchaku", 15,
"swept", 16, "won", 20, "threat", 12,
"block", 6, "stomp", 11,
);
$Doodad =
{ 'T' => 1,
'W' => 64,
'H' => 64,
'SX' => 15,
'SY' => 0,
'FRAMES'=> 6,
'SA' => 1/25,
};
$Con = {
'forw'=>'Walk',
'back'=>'Back',
'jump'=>'Jump',
'jumpfw'=>'JumpFW',
'jumpbw'=>'JumpBW',
'block'=>'Block',
'down'=>'Kneeling',
'hpunch'=>'HighPunch',
'lpunch'=>'LowPunch',
'hkick'=>'HighKick',
'lkick'=>'LowKick',
'lkickBF'=>'GroinKick',
'lkickF'=>'KneeKick',
'hpunchD'=>'Uppercut',
'hpunchF'=>'Elbow',
'hkickB'=>'Spin',
'lkickB'=>'Sweep',
'lpunchBD'=>'Grenade',
'hpunchFF'=>'Poke',
'lkickDD'=>'Stomp',
'hpunchBFB'=>'Nunchaku',
};
$Con2 = {
'lkick'=>'KneelingKick',
'hkick'=>'KneelingKick',
'hpunch'=>'KneelingUppercut',
'lpunch'=>'KneelingPunch',
};
@States1 = (
# 1. BASIC MOVES
{ 'N'=>'Start', 'DEL'=>5, 'S'=>'+start' },
{ 'N'=>'Stand', 'DEL'=>10, 'S'=>'+stand', 'CON'=>$Con, 'SITU'=>'Ready' },
{ 'N'=>'Turn', 'DEL'=>5, 'S'=>'+turn', 'DELTAXN'=>-10, 'TURNN'=>1, },
{ 'N'=>'Hurt', 'DEL'=>8, 'S'=>'+hurt,-hurt' },
{ 'N'=>'Won', 'DEL'=>8, 'S'=>'+won', 'NEXTSTN'=> 'Won2' },
{ 'N'=>'Won2', 'DEL'=>1000,'S'=>'won n', 'NEXTST'=>'Won2', },
{ 'N'=>'Fun', 'DEL'=>8, 'S'=>'+fun,-fun', 'CON'=>$Con },
{ 'N'=>'Threat', 'DEL'=>5, 'S'=>'+threat', 'CON'=>$Con },
WalkingFrames( \%FrameLookup, \@Frames, 0, 75, $Con ),
BlockStates( FindLastFrame( \%FrameLookup, 'block' ), 5 ),
KneelingStates( FindLastFrame( \%FrameLookup, 'kneeling' ),
FindLastFrame( \%FrameLookup, 'onknees' ), 7, $Con2 ),
JumpStates( \%FrameLookup,
{'lkick'=>'JumpKick', 'hkick'=>'JumpKick',
'lpunch'=>'JumpPunch', 'hpunch'=>'JumpPunch'} ),
# 2. OFFENSIVE MOVES
{ 'N'=>'KneelingPunch', 'DEL'=>5, 'S'=>'+kneelingpunch,-kneelingpunch', 'SITU'=>'Crouch',
'HIT'=>'Hit', 'NEXTSTN'=>'Onknees' },
{ 'N'=>'KneelingKick', 'DEL'=>5, 'S'=>'+kneelingkick,-kneelingkick', 'SITU'=>'Crouch',
'HIT'=>'Hit', 'NEXTSTN'=>'Onknees' },
{ 'N'=>'KneelingUppercut','DEL'=>5, 'S'=>'kneeling 4-3,uppercut 6-n',
'HIT'=>'Uppercut' },
{ 'N'=>'HighPunch', 'DEL'=>5, 'S'=>'+highpunch',
'HIT'=>'Highhit' },
{ 'N'=>'LowPunch', 'DEL'=>5, 'S'=>'+lowpunch,-lowpunch',
'HIT'=>'Hit' },
{ 'N'=>'HighKick', 'DEL'=>5, 'S'=>'+highkick,-highkick',
'HIT'=>'Hit' },
{ 'N'=>'LowKick', 'DEL'=>5, 'S'=>'+lowkick,-lowkick',
'HIT'=>'Leghit' },
{ 'N'=>'GroinKick', 'DEL'=>5, 'S'=>'+groinkick,-groinkick',
'HIT'=>'Groinhit' },
{ 'N'=>'KneeKick', 'DEL'=>5, 'S'=>'+kneekick,-kneekick',
'HIT'=>'Hit' },
{ 'N'=>'Elbow', 'DEL'=>5, 'S'=>'+elbow',
'HIT'=>'Highhit' },
{ 'N'=>'Spin', 'DEL'=>5, 'S'=>'+spin',
'HIT'=>'Hit' },
{ 'N'=>'Sweep', 'DEL'=>7, 'S'=>'+sweep',
'HIT'=>'Hit' },
{ 'N'=>'Grenade', 'DEL'=>5, 'S'=>'+grenade',
'DEL12'=>15, 'DOODAD'=>$Doodad },
{ 'N'=>'Uppercut', 'DEL'=>5, 'S'=>'+uppercut',
'HIT'=>'Uppercut' },
{ 'N'=>'Throw', 'DEL'=>8, 'S'=>'+throw' },
{ 'N'=>'Poke', 'DEL'=>5, 'S'=>'+specpunch,_specpunch',
'HIT'=>'Highhit' },
{ 'N'=>'Stomp', 'DEL'=>7, 'S'=>'+stomp',
- 'HIT'=>'Fall' },
+ 'HIT'=>'Fall', 'CODE6'=>'::AddEarthquake(25);', 'SOUND6'=>'crashhh.voc' },
{ 'N'=>'Nunchaku', 'DEL'=>7, 'S'=>'+nunchaku',
'HIT'=>'Hit' },
# 3. HURT MOVES
{ 'N'=>'Falling', 'DEL'=>5, 'S'=>'falling 1-11, falling 15-12, falling 12-n, laying 1',
'DEL16'=>7, 'DEL17'=>7, 'DEL18'=>7, 'DEL19'=>7, 'DEL20'=>7, 'DEL21'=>7,
'DELN'=>500, 'NEXTN'=>'Laying', 'SITU'=>'Falling', },
{ 'N'=>'Laying', 'DEL'=>1000,'S'=>'+laying',
'SITU'=>'Falling' },
{ 'N'=>'Getup', 'DEL'=>5, 'S'=>'+getup',
'SITU'=>'Falling',
'CON8'=>{'down'=>'Onknees'},
'CON8'=>{'down'=>'Onknees'},
},
{ 'N'=>'Dead', 'DEL'=>10000, 'S'=>'laying 1',
'SITU'=>'Falling', 'NEXTST'=>'Dead' },
{ 'N'=>'Swept', 'DEL'=>5, 'S'=>'+swept' },
{ 'N'=>'KneelingPunched', 'DEL'=>5, 'S'=>'+kneelingpunched,-kneelingpunched',
'SITU'=>'Crouch', 'NEXTSTN'=>'Onknees' },
{ 'N'=>'KneelingKicked', 'DEL'=>5, 'S'=>'kneelingkicked 3-n, kneelingkicked n-3',
'SITU'=>'Crouch', 'NEXTSTN'=>'Onknees' },
{ 'N'=>'HighPunched', 'DEL'=>8, 'S'=>'+highpunched' },
{ 'N'=>'LowPunched', 'DEL'=>5, 'S'=>'+lowpunched,-lowpunched' },
{ 'N'=>'GroinKicked', 'DEL'=>7, 'S'=>'+groinkicked,-groinkicked' },
{ 'N'=>'Thrown', 'DEL'=>5, 'S'=>'+thrown' },
);
# 2. CREATE STATES
foreach $framedesc (@States1)
{
AddStates( \%States, \%FrameLookup, $framedesc );
}
# Automatically add NEXTST for states which don't have one.
FixStates( \%FrameLookup, \%States );
TravelingStates( \%FrameLookup, \@Frames, \%States, "falling", 1, 18 );
TravelingStates( \%FrameLookup, \@Frames, \%States, "getup", 1, 16 );
#TravelingStates( \%FrameLookup, \@Frames, \%States, "won", 0, 0 );
%States = ( FindShorthands( \%States ), %States );
%::GrizliStates = %States;
@::GrizliFrames = @Frames;
}
LoadGrizli();
return 1;

File Metadata

Mime Type
text/x-diff
Expires
Wed, Feb 4, 2:15 PM (6 h, 48 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55650
Default Alt Text
(54 KB)

Event Timeline