| 1 | ########################################################################## | ||
| 2 | package Games::PangZero::MachineGun; | ||
| 3 | ########################################################################## | ||
| 4 | |||
| 5 | @ISA = qw(Games::PangZero::Harpoon); | ||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | use vars qw(@SrcRects); | ||
| 9 | |||
| 10 | @SrcRects = ( | ||
| 11 | SDL::Rect->new( 0, 160, 32, 32 ), | ||
| 12 | SDL::Rect->new( 32, 160, 32, 32 ), | ||
| 13 | SDL::Rect->new( 64, 160, 32, 32 ), | ||
| 14 | ); | ||
| 15 | |||
| 16 | sub Create { | ||
| 17 | return ( Games::PangZero::MachineGun->new(@_, 0), Games::PangZero::MachineGun->new(@_, 1), Games::PangZero::MachineGun->new(@_, 2) ); | ||
| 18 | } | ||
| 19 | |||
| 20 | sub new { | ||
| 21 | my ($class, $guy, $index) = @_; | ||
| 22 | my ($self); | ||
| 23 | |||
| 24 | $self = Games::PangZero::Harpoon->new($guy); | ||
| 25 | %{$self} = ( %{$self}, | ||
| 26 | 'x' => $guy->{x} + 16, | ||
| 27 | 'y' => $guy->{y} - 16, | ||
| 28 | 'w' => 32, | ||
| 29 | 'h' => 32, | ||
| 30 | 'index' => $index, | ||
| 31 | 'speedY' => -9, | ||
| 32 | 'speedX' => (-2, 0, 2)[$index], | ||
| 33 | ); | ||
| 34 | bless $self, $class; | ||
| 35 | } | ||
| 36 | |||
| 37 | sub Delete { | ||
| 38 | my $self = shift; | ||
| 39 | |||
| 40 | --$self->{guy}->{harpoons} if $self->{index} == 1; | ||
| 41 | delete $Harpoon::Harpoons{$self->{id}}; | ||
| 42 | $self->GameObject::Delete(); | ||
| 43 | } | ||
| 44 | |||
| 45 | sub Advance { | ||
| 46 | my $self = shift; | ||
| 47 | |||
| 48 | if ($self->{y} < 0 | ||
| 49 | or $self->{x} < 0 | ||
| 50 | or $self->{x} > $Games::PangZero::ScreenWidth - $self->{w}) { | ||
| 51 | $self->Delete(); | ||
| 52 | return; | ||
| 53 | } | ||
| 54 | $self->{y} += $self->{speedY}; | ||
| 55 | $self->{x} += $self->{speedX}; | ||
| 56 | } | ||
| 57 | |||
| 58 | sub Draw { | ||
| 59 | my $self = shift; | ||
| 60 | |||
| 61 | $self->TransferRect(); | ||
| 62 | SDL::Video::blit_surface($self->{surface}, $SrcRects[$self->{index}], $Games::PangZero::App, $self->{rect}); | ||
| 63 | } | ||
| 64 | |||
| 65 | 1; |