This is preliminary code for game hackers, it is based on the current SDL and includes NPCs, Enemies, a map and a player character. There is also a collision detection system :

unit module PaganVisions; class PaganVisions::AdventurersGuild is PaganVisions::Map { method BUILD() { $!bg_image = SDL_LoadBMP_RW("./pics"/bg-adventurersguild-1.png +"); } } class PaganVisions::Enemy is PaganVisions::Entity { } unit module PaganVisions; class PaganVisions::Entity is PaganVisions::GameObject { has $!direction; has $!moving; has $!dx; ### move x + dx has $!dy; has $!leftstaticimagelib ### StateImagelibrary.pm6 has $!righttstaticimagelib has $!upstaticimagelib has $!downstaticimagelib has $!leftimagelib has $!rightimagelib has $!upimagelib has $!downimagelib method getImage() { if ($direction == "1direction" and $moving) return $leftimagelib.getImage(); if ($direction == "2direction" and $moving) return $rightimagelib.getImage(); if ($direction == "3direction" and $moving) return $upimagelib.getImage(); if ($direction == "4direction" and $moving) return $downimagelib.getImage(); if ($direction == "1direction") return $leftstaticimagelib.getImage(); if ($direction == "2direction") return $rightstaticimagelib.getImage(); if ($direction == "3direction") return $upstaticimagelib.getImage(); if ($direction == "4direction") return $downstaticimagelib.getImage(); return $leftstaticimagelib.getImage(); } method move_left() { $direction = "1direction"; $x -= $dx; } method move_right() { $direction = "2direction"; $x += $dx; } method move_up() { $direction = "3direction"; $y -= $dy; } method move_down() { $direction = "4direction"; $y += $dy; } } class PaganVisions::GameObject { has $!x; has $!y; has $!w; has $!h; method collide($go) { my $r = 0; if ($!x > $go.x) { $r += 1; } elsif ($!x <= $go.x) { $r += 0; } elsif ($!x < $go.x + $go.w) { $r += 1; } elsif ($!x >= $go.x + $go.w) { $r += 0; } if ($!y > $go.y) { $r += 1; } elsif ($!y <= $go.y) { $r += 0; } elsif ($!y < $go.y + $go.h) { $r += 1; } elsif ($!y >= $go.y + $go.h) { $r += 0; } if ($r == 4) { return 1; } else { return 0; } } } class PaganVisions::Map { has $!x; has $!y; has $!dx; ### move x + dx has $!dy; has $!bg_image; method BUILD($filename) { $!bg_image = SDL_LoadBMP_RW($filename); } method move_left() { $!x -= $!dx; } method move_right() { $!x += $!dx; } method move_up() { $!y -= $!dy; } method move_down() { $!y += $!dy; } } class PaganVisions::NPC is PaganVisions::Entity { } class PaganVisions::PlayerEntity is PaganVisions::Entity { } class PaganVisions::Player is PaganVisions::PlayerEntity { submethod BUILD() { //imagelibs addImage($filename) } } class PaganVisions::StateImageLibrary { has @!images; has $index; method addImage($filename) { my $image = SDL_LoadBMP_RW($filename); push($images, $image); } method getImage() { if ($index >= length(@images)) $index = 0; return @images[$index++]; } method getImageWithIndex($ind) { return @images[$ind++]; } } #!perl6 use SDL; SDL::init($SDL_INIT_EVERYTHING) { die "Failed to initialize libSDL with reason: "' ~ SDL::get_error( +) ~ "'"; } my $screen = SDL:SDL_SetVideoMode(640,480,32,undef); my $player = new Player(x => 100, y => 200, dx = 1, dy = 1, direction => "2direction"); my $map = new Map(x => 0, y =>0, dx => 1, dy => 1);


In reply to Perl 6 RPG base code (SDL) 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.