So what's changed since part 0?
Youtube linky, Repliconz gameplay so far
The green things chasing the Guy are instances of the Baddie class. Since Baddies are
Things, many methods have been moved from Guy
to
Game::Repliconz::Thing
which are common to Baddies, including move
,
constrain_velocity_xy
and shoot
. Bullets are also Things, so now technically
bullets can shoot bullets, but we won't be doing that... yet. Anyone
like the idea of cluster bullets?
The movement of baddies is somewhere between a bullet and the guy. A vector is calculated from current baddie position and guy position, so the baddies pursue the guy. Converting this to a unit vector using the bullet's Pythagoras square method would allow the baddies to travel in any arbitrary direction. This results in them converging rather quickly, giving the appearance of a single, super-strong enemy.
It turns out that constrain_velocity_xy
, which was created to limit
the guy's speed, can also be used to limit the baddies' movement to
45 degree angles. They eventually converge using this method too, but
hopefully you'll have shot a good few of them by the time that happens.
Anyway, now Game::Repliconz::Baddie::move
is pretty simple:
sub move {
my ( $self, $target_x, $target_y, $dt, $app ) = @_;
my $v_y = $target_y - $self->{y};
my $v_x = $target_x - $self->{x};
($v_x, $v_y) = $self->constrain_velocity_xy($v_x, $v_y);
$self->{x} += $v_x * $self->{velocity} * $dt;
$self->{y} += $v_y * $self->{velocity} * $dt;
($self->{x} > 0 || $self->{x} < ($app->w - $self->{w})) &&
($self->{y} > 0 || $self->{y} < ($app->h - $self->{h})) &&
($self->{on_screen} = 1);
}
The on_screen
property will be used later in decisions about collision
detection, since bullets continue off screen and enemies spawn there.
Baddies are pushed onto a queue in the main move callback, with more being spawned when the queue goes below a certain size.
Our collision detection is currently very simple, using Collision::Util to check overlapping rectangles. I need to check out how accurate this is, as the framerate / app delay will have an effect... a bullet might be rendered on either side of a target without ever "passing through" it. The video above appears to show some baddies being "hit", yet surviving.
The last change you might have noticed is the cursor is now a sprite, which is achieved simply by hiding the cursor and rendering a png file sprite at the mouse X/Y position.
As always, comments, criticism and contributions welcome.
Code for Repliconz is on Github.
Text only, no HTML, * denotes a required field.