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


In reply to Re: HollyGame gamekit (almost @ CPAN) by kcott
in thread HollyGame gamekit (almost @ CPAN) by holyghost

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.