NAME
Game::Snake::Raylib - snake in a window, when raylib is there
VERSION
Version 0.13
SYNOPSIS
use Game::Snake::Raylib;
if (Game::Snake::Raylib->available) {
my $result = Game::Snake::Raylib->new(seed => 'anything')->start;
}
else {
warn Game::Snake::Raylib->why_not;
}
Or, from a shell:
snake --raylib
DESCRIPTION
The game of 0.11, drawn from the same sprite sheet at the same size (a 20 pixel cell under a score line), with the engine and the bot of this release behind it. Raylib::FFI is loaded when the window is asked for, never when this module is, so the module compiles and the distribution's tests run on a machine without raylib. Raylib::FFI itself needs perl 5.38 or later; the rest of this distribution does not.
Loading Raylib::FFI prints a warning that builtin::export_lexically is experimental, and one for each raylib function the installed library lacks. Those are its, not ours, and cannot be silenced from here.
The window runs at fps frames a second and ticks the engine when the engine's speed says so, at most once a frame, so a key is seen on the frame it is pressed whatever the speed. 0.11 ran the window at the snake's speed and sampled the keys once a move.
Arrows, wasd and hjkl steer; p and space pause; Enter plays again after a death; q, Escape or closing the window quits.
CLASS METHODS
available
True when Raylib::FFI and Raylib::Color can be loaded. False with "why_not" set.
why_not
One sentence on why the window cannot open, with no file and line in it.
tile_for
my ($x, $y) = @{ Game::Snake::Raylib->tile_for('head', $segment) };
The top left corner of the 64 pixel tile on the sheet for a segment of "segments" in Game::Snake, or for food. The tail's tile follows its bend when it has one and its dir otherwise; a body segment with a bend gets the corner tile for that pair, or the straight tile for a pair that cannot occur.
tiles
The whole tile table.
key_for
my $name = Game::Snake::Raylib->key_for(265); # up
The name of a key code: a direction, pause, quit, again or undefined.
sheet
The path of the sprite sheet.
METHODS
new
Game::Snake::Raylib->new(cols => 40, rows => 28, seed => '...', level => 2,
watch => 0, cell => 20, top => 24, fps => 60, title => 'Snake', max_ticks => 0);
Every argument has a default, shown. A missing seed is made fresh.
start
Opens the window, plays, closes the window and returns the game's Game::Snake::Result, or undefined when raylib is not available. The high score for the run of the program is kept in high.
cols, rows, seed, level, watch, cell, top, fps, title, max_ticks, game, clock, ticker, frames, refused, high
The arguments, the game, the clock and the ticker, and the counts.
AUTHOR
LNATION, <email at lnation.org>
LICENSE AND COPYRIGHT
This software is Copyright (c) 2024 by LNATION.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)