in reply to HollyGame gamekit (almost @ CPAN)
G'day holyghost,
In addition to what ++soonix has written, with which I wholeheartedly agree, I would recommend you put modules in separate files, i.e. HollyGame/Box.pm, HollyGame/Enemy.pm, and so on. Add these two lines to the top of each:
use strict; use warnings;
Then test each module individually with:
perl -c Whatever.pm
That will pick up many of your errors. For instance, in your first subroutine (&Box), you have:
my $self = { $x => shift, $y => shift, $w => shift, $h => shift };
This has many problems. Apart from using four, uninitialised, package variables; $self actually ends up with this value:
{ "" => $_[4] }
Here's a quick one-liner to give you an idea of what's happening:
$ perl -e 'use Data::Dump; sub Box { my $self = { $x => shift, $y => s +hift }; dd $self } Box(qw{a b c})' { "" => "b" }
In the second subroutine (&is_collision) you reference "$self->{x}", "$self->{y}", and so on: those keys don't exist! However, that issue is eclipsed by the syntax errors with the if statements (already pointed out by soonix).
There's lots of other problems. For instance, you create blessed references which then appear to be silently discarded; there appears to be no encapsulation (no accessors or mutators; $self->{KEY} is used throughout); and a number of use MODULE statements appear at the end of a package but seem to be associated with the next package. I pretty much stopped looking at this point: do not consider this to be an exhaustive list.
Perhaps you need to review "perlootut - Object-Oriented Programming in Perl Tutorial"; and consider using one of the "OO Sytems" discussed in that documentation.
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: HollyGame gamekit (almost @ CPAN)
by afoken (Chancellor) on Oct 17, 2017 at 05:10 UTC | |
by kcott (Archbishop) on Oct 17, 2017 at 06:47 UTC |