/t_backcompat/MoP/lib/SDL/Tutorial/MoP/Models.pm

http://github.com/PerlGameDev/SDL · Perl · 46 lines · 36 code · 9 blank · 1 comment · 3 complexity · cf8a564df513ebfa18bc8cba4bf3a243 MD5 · raw file

  1. package SDL::Tutorial::MoP::Models;
  2. use strict;
  3. use File::ShareDir qw(module_file);
  4. use Cwd qw(abs_path);
  5. use Data::Dumper;
  6. BEGIN {
  7. use Exporter ();
  8. use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
  9. $VERSION = '0.01';
  10. @ISA = qw(Exporter);
  11. #Give a hoot don't pollute, do not export more than needed by default
  12. @EXPORT = qw(map);
  13. @EXPORT_OK = qw(map);
  14. %EXPORT_TAGS = ();
  15. }
  16. my @map = (); # bool values where we can go
  17. my @frame = (); # tile gfx definitions
  18. my $avatar = { x => 0, y => 0, face => 0 }; # player pos
  19. sub new {
  20. my ( $class, %parameters ) = @_;
  21. my $self = bless( {}, ref($class) || $class );
  22. load_map() or die("Can't load map.");
  23. return $self;
  24. }
  25. sub load_map {
  26. my $path = module_file( 'SDL::Tutorial::MoP', 'data/main.map' );
  27. open( FH, $path ) || die "Can not open file $path: $!";
  28. while (<FH>) {
  29. my @row = split( //, $_ );
  30. push( @map, \@row );
  31. }
  32. close(FH);
  33. }
  34. sub map {
  35. return @map;
  36. }
  37. 1;