Graal Forums  

Go Back   Graal Forums > Development Forums > Graphic Design
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #17  
Old 11-19-2011, 05:28 AM
amonrabr amonrabr is offline
Scripter
Join Date: Nov 2001
Location: Brazil
Posts: 374
amonrabr is on a distinguished road
As I said, I will post some codes and things I found...

This is cool, cause I know many people has a website or something..
Just paste the code above in a ".php" file and open it.
Also the code is clean, so its ok to people study it.

PHP Code:
<?Php 
class graalLevel{
    var 
$tile = array();
    var 
$imgFolder 'images/';
    var 
$defaultTileset 'pics1.png';
    function 
prepare(){
        
file_exists($this->imgFolder) or mkdir($this->imgFolder);
        
file_exists($this->imgFolder.$this->defaultTileset) or die("Please, first save pics1.png file in folder '{$this->imgFolder}'.");
    }
    function 
graalLevel($lvl){
        
$this->prepare();
        
preg_match_all('/board \d \d+ \d\d \d (.*)/ei',$lvl,$r);
        function 
convertLine($a,$b,&$o){
            foreach(
str_split($a2) as $c=>$d)$o->tile[$b][$c] = $o->tileSetCoordinates($d);
        }    
        
array_walk($r[1],'convertLine',$this);
    }
    function 
tileSetCoordinates($d){
        
$seq 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
        
$_ strpos($seq,$d[1])+strpos($seq,$d[0])*64;
        return array(
floor((floor($_/512)*16+($_%16))*16)*-1,floor((floor($_/16)%32)*16)*-1);
    }
    function 
render(){
        
$s='';
        for(
$i=0;$i<64;$i++)for($j=0;$j<64;$j++)
            
$s .= '<div class=div style="background-position:'.(count($this->tile)>0?$this->tile[$i][$j][0]:'0').'px '.(count($this->tile)>0?$this->tile[$i][$j][1]:0).'px;"></div>';
        echo 
"<style type='text/css'>*{margin:0px;}.div{background-image:url({$this->imgFolder}{$this->defaultTileset});display:block; width:16px; height: 16px; float:left;}</style><div style='width:1024px;height:1024px;'>$s</div>";
    }
}
if(
array_key_exists('arq',$_FILES) && $_FILES['arq']['size']>&& is_array($t pathinfo($_FILES['arq']['name'])) && $t['extension'] == 'nw'){
    
$level = new graalLevel(    file_get_contents($_FILES['arq']['tmp_name'])    );
    
$level->render();
}
?>

<form method="post" enctype="multipart/form-data">Select nw file:<input type="file" name="arq" /><input type="submit" name="submit" value="enviar"/></form>

Last edited by amonrabr; 11-19-2011 at 09:38 PM.. Reason: now with div
Reply With Quote
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.