NAME
Game::Floppy - Floppy bird, as an engine
VERSION
Version 0.10
SYNOPSIS
use Game::Floppy;
my $game = Game::Floppy->new(seed => 'anything');
while ($game->status ne 'finished') {
$game->flap if $game->bird->{y} > $game->height / 2;
my $step = $game->tick;
last if $step->{died};
}
print $game->result->stringify, "\n";
Or, from a shell:
floppy
floppy --raylib
DESCRIPTION
A bird falls, a flap lifts it, tubes come from the right with a gap in each, and the bird dies on a tube, on the ground or off the top. This class is the game and nothing else: it prints nothing, reads nothing, sleeps never and calls rand never. Every tube's gap comes from the seed, so the same seed and the same flaps are the same game twice.
The terminal game is Game::Floppy::Terminal and the window is Game::Floppy::Raylib. They are separate modules so that this one can be loaded by anything without pulling either in.
The units are pixels, as release 0.08 drew them, at twenty ticks a second: a field 516 wide and 400 high, the bird's centre at x 80 starting at y 176, falling 3 a tick, lifted 30 by a flap on the tick after it is pressed, a circle of radius 24 against each tube's two rectangles. A tube is 52 wide, appears every 100 ticks at the right edge, moves left 3 a tick, and has a gap 140 high whose top is between 1 and 300; passing one scores 100.
METHODS
new
my $game = Game::Floppy->new(
width => 516, height => 400, seed => 'anything',
bird_x => 80, bird_radius => 24, gravity => 3, lift => 30,
tube_every => 100, tube_speed => 3, tube_width => 52, gap => 140,
tube_score => 100,
);
Every argument has a default, shown. A field is at least 200 high and wide enough for a tube past the bird. The seed is any string; the default seed plays the same game every time, so a program that wants a different game each run makes its own seed.
Arguments are read by name, and a name this class does not know is dropped in silence: new(widthz => 9) builds the default field. Spell them carefully.
flap
$game->flap or warn $game->error->message;
Asks for a flap on the next tick. One flap a tick: a second before the tick is refused as already_flapped, and any flap on a finished game as not_active. Returns 1, or 0 with "error" set.
tick
my $step = $game->tick;
One twentieth of a second. The bird falls by gravity, or rises by lift less gravity when a flap is pending; it dies sky above the field and ground below it. Each tube then moves left, kills the bird if its circle touches either pipe, and is passed and scored once it is wholly left of the bird's centre. A tube appears when the tick count is a multiple of tube_every. Returns a hash with moved, flapped, passed and died, the last undefined or sky, ground or tube. A tick on a finished game moves nothing.
bird
my $bird = $game->bird; # { x, y, radius, tilt }
Where the bird is, as a copy. tilt is the angle a renderer may draw it at: -45 on a flap, rising by one a tick to 45.
tubes
for my $tube (@{ $game->tubes }) { ... }
The tubes on the field, oldest first, each { x, gap_top, gap_bottom, k } as a copy. The top pipe is from the top of the field to gap_top, the bottom pipe from gap_bottom down.
circle_hits_rectangle
Game::Floppy->circle_hits_rectangle($cx, $cy, $r, $x, $y, $w, $h);
Whether a circle touches a rectangle, as raylib's CheckCollisionCircleRec decides it: touching counts.
width, height, seed, bird_x, bird_radius, gravity, lift, tube_every, tube_speed, tube_width, gap, tube_score
The arguments new was given, or their defaults.
score, passed, ticks, status
The score, tubes passed, ticks taken, and ready, active or finished.
error
The Game::Floppy::Error from the last refused flap, or undefined.
result
A Game::Floppy::Result once the game has finished, else undefined.
quit
Finishes the game with the cause quit. Returns 1, or 0 if it had already finished.
reset
Puts the bird back at the start with the same seed, so the same game can be played again.
AUTHOR
LNATION, <email at lnation.org>
BUGS
Please report any bugs or feature requests to bug-game-floppy at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Game-Floppy. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Game::Floppy
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
Search CPAN
LICENSE AND COPYRIGHT
This software is Copyright (c) 2024 by LNATION.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)