| 1 | ########################################################################## | ||
| 2 | package Games::PangZero::DeadGuy; | ||
| 3 | ########################################################################## | ||
| 4 | |||
| 5 | @ISA = qw(Games::PangZero::GameObject); | ||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | |||
| 9 | sub new { | ||
| 10 | my ($class, $guy, $dir) = @_; | ||
| 11 | my ($self, $player); | ||
| 12 | |||
| 13 | $self = Games::PangZero::GameObject->new(); | ||
| 14 | $player = $guy->{player}; | ||
| 15 | |||
| 16 | %{$self} = ( %{$self}, | ||
| 17 | 'x' => $guy->{x}, | ||
| 18 | 'y' => $guy->{y}, | ||
| 19 | 'w' => 64, | ||
| 20 | 'h' => 64, | ||
| 21 | 'speedY' => -7, | ||
| 22 | 'surface' => $player->{guySurface}, | ||
| 23 | 'anim' => 0, | ||
| 24 | 'bounce' => 0, | ||
| 25 | 'bouncex' => 0, | ||
| 26 | ); | ||
| 27 | $self->{'speedX'} = ($Games::PangZero::Game->Rand(2) + 1.5) * (($self->{x} > $Games::PangZero::ScreenWidth / 2) ? 1 : -1); | ||
| 28 | bless $self, $class; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub Advance { | ||
| 32 | my $self = shift; | ||
| 33 | |||
| 34 | $self->{speedY} += 0.1; | ||
| 35 | $self->{x} += $self->{speedX}; | ||
| 36 | $self->{y} += $self->{speedY}; | ||
| 37 | |||
| 38 | unless ($self->{bouncex}) { | ||
| 39 | if ($self->{x} < -16) { | ||
| 40 | $self->{x} = -16; | ||
| 41 | $self->{speedX} = abs( $self->{speedX} ); | ||
| 42 | $self->{speedY} = -3 if $self->{speedY} > -3; | ||
| 43 | $self->{bouncex} = 1; | ||
| 44 | } | ||
| 45 | if ($self->{x} > $Games::PangZero::ScreenWidth - $self->{w} +16) { | ||
| 46 | $self->{x} = $Games::PangZero::ScreenWidth - $self->{w} + 16; | ||
| 47 | $self->{speedX} = -abs( $self->{speedX} ); | ||
| 48 | $self->{speedY} = -3 if $self->{speedY} > -3; | ||
| 49 | $self->{bouncex} = 1; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | if ($self->{y} > $Games::PangZero::ScreenHeight - 64 and not $self->{bounce}) { | ||
| 53 | $self->{bounce} = 1; | ||
| 54 | $self->{speedY} = -3; | ||
| 55 | } | ||
| 56 | |||
| 57 | if ($self->{y} > $Games::PangZero::PhysicalScreenHeight) { | ||
| 58 | $self->Delete; | ||
| 59 | } | ||
| 60 | $self->{anim} += $self->{speedX} > 0 ? -1 : +1; | ||
| 61 | } | ||
| 62 | |||
| 63 | sub Draw { | ||
| 64 | my $self = shift; | ||
| 65 | my ($srcrect); | ||
| 66 | |||
| 67 | $srcrect = SDL::Rect->new(($self->{speedX} > 0 ? 0 : 64), 128, 64, 64 ); | ||
| 68 | $self->TransferRect(); | ||
| 69 | if(SDL::Config->has('SDL_gfx_rotozoom')) { | ||
| 70 | my $roto = SDL::Surface->new( SDL::Video::SDL_SWSURFACE(), 64, 64, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF); | ||
| 71 | SDL::Video::blit_surface($self->{surface}, $srcrect, $roto, SDL::Rect->new(0, 0, $roto->w, $roto->h) ); | ||
| 72 | $roto = SDL::GFX::Rotozoom::surface($roto, $self->{anim} * 5, 1, SDL::GFX::Rotozoom::SMOOTHING_OFF()); | ||
| 73 | $self->{rect}->x( $self->{rect}->x - ($roto->w - 64) / 2 ); | ||
| 74 | $self->{rect}->y( $self->{rect}->y - ($roto->h - 64) / 2 ); | ||
| 75 | SDL::Video::blit_surface($roto, SDL::Rect->new(0, 0, 64, 64), $Games::PangZero::App, $self->{rect} ); | ||
| 76 | return; | ||
| 77 | } | ||
| 78 | else { | ||
| 79 | SDL::Video::blit_surface($self->{surface}, $srcrect, $Games::PangZero::App, $self->{rect} ); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | 1; |