in reply to Re: Re: OT: Tile maps
in thread OT: Tile maps
#HEADER FILE # define start and end points for x and y, and assign a # tileset # Note completely off the cuff Ideas following # Area => { name => 'something', tiles => 'forest', world => '50,75->150,175',# anchor it in the world X => 100, Y => 100, }; # CODE # How big do we need to gen? # @mask = gen_area( $area->{X}, $area->{Y}, number_of_tiles_in_selected_set ); # # Make it purty # @output = draw_area(\@mask, $area->{tiles}); $handle = print_it(\@output); # later if ($move) { # # X or Y will be constant here, so we only need width or # or height not both # @mask = gen_area(0, $area->{Y}, forest); @output = draw_area(\@mask); # # here we would append to the appropriate range on our main # output matrix then print it # } sub gen_area { # # This is horribly innefficient the larger your area becomes # but it show the basic Idea # ($x,$y,$num) = @_; for ( 0 .. $x ) { for ( o .. $y ) { $return[$x][$y] = int(rand($num)) + 1; } } return(@return); } # END gen_area sub draw_area { # # Again horribly inefficient, again off the cuff code to # display idea as opposed to how to do it right # ($ref,$set) = @_; @data = @{$ref}; # # @tiles could either be populated with actual filenames, # or simply references to structures in memory who know # where to find the files, or piece together the fabric of # your map # @tiles = get_tiles($set); # # So we build another AoA which takes the values in the # matrix as an offset to pull the approriate tile name, from # the tile array, which is a mapping we can use when # sending it back to the player. # for ($f = 0; $f <= @data; $f++) { @line = @{$data[$f]}; for ($s = 0; $s <= $#line; $s++) { $return[$f][$s] = $tiles[$lines[$s]]; } } return(@return); }
|
|---|