/usr/share/perl5/Games/PangZero/GameObject.pm is in pangzero 1.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | ##########################################################################
package Games::PangZero::GameObject;
##########################################################################
sub new {
my ($class) = @_;
my $self = {
'rect' => SDL::Rect->new( 0, 0, 0, 0 ),
'speedX' => 0,
'speedY' => 0,
'x' => 0,
'y' => 0,
'w' => 10,
'h' => 10,
};
bless $self, $class;
}
sub Delete {
my $self = shift;
for (my $i = 0; $i < scalar @Games::PangZero::GameObjects; ++$i) {
if ($Games::PangZero::GameObjects[$i] eq $self) {
splice @Games::PangZero::GameObjects, $i, 1;
last;
}
}
$self->{deleted} = 1;
$self->Clear();
}
sub Advance {
my $self = shift;
$self->{advance}->($self) if $self->{advance};
}
sub Clear {
my ($self) = @_;
SDL::Video::blit_surface($Games::PangZero::Background, $self->{rect}, $Games::PangZero::App, $self->{rect});
}
sub TransferRect {
my ($self) = @_;
$self->{rect}->x($self->{x} + $Games::PangZero::ScreenMargin);
$self->{rect}->y($self->{y} + $Games::PangZero::ScreenMargin);
$self->{rect}->w($self->{w});
$self->{rect}->h($self->{h});
}
sub Draw {
my ($self) = @_;
$self->TransferRect();
if ($self->{draw}) {
$self->{draw}->($self);
} else {
SDL::Video::fill_rect( $Games::PangZero::App, $self->{rect}, SDL::Color->new(0x80, 0, 0) );
}
}
sub SetupCollisions {
my ($self) = @_;
$self->{collisionw} = ($self->{collisionw} or $self->{w});
$self->{collisionh} = ($self->{collisionh} or $self->{h});
$self->{collisionmarginw1} = ( $self->{w} - $self->{collisionw} ) / 2;
$self->{collisionmarginw2} = $self->{collisionmarginw1} + $self->{collisionw};
$self->{collisionmarginh1} = ( $self->{h} - $self->{collisionh} ) / 2;
$self->{collisionmarginh2} = $self->{collisionmarginh1} + $self->{collisionh};
$self->{centerx} = $self->{w} / 2;
$self->{centery} = $self->{y} / 2;
}
sub Collisions {
my ($self, $other) = @_;
# Bounding box detection
unless ($self->{collisionmarginw1} and $other->{collisionmarginw1}) {
return 0 if $self->{x} >= $other->{x} + $other->{w};
return 0 if $other->{x} >= $self->{x} + $self->{w};
return 0 if $self->{y} >= $other->{y} + $other->{h};
return 0 if $other->{y} >= $self->{y} + $self->{h};
return 1;
}
return 0 if $self->{x} + $self->{collisionmarginw1} >= $other->{x} + $other->{collisionmarginw2};
return 0 if $other->{x} + $other->{collisionmarginw1} >= $self->{x} + $self->{collisionmarginw2};
return 0 if $self->{y} + $self->{collisionmarginh1} >= $other->{y} + $other->{collisionmarginh2};
return 0 if $other->{y} + $other->{collisionmarginh1} >= $self->{y} + $self->{collisionmarginh2};
return 1;
}
1;
|