Thread: Old stuffs
View Single Post
  #18  
Old 11-19-2011, 05:47 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by amonrabr View Post
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 .= '<i 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;"></i>';
        echo 
"<style type='text/css'>*{margin:0px;}i{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>
Why are you using (deprecated) <i> tags for the tiles instead of a block tag like <div>?

It might be worth mentioning I did something similar with HTML5's canvas tag in JavaScript:

http://static.graalcenter.org/temp/ole/ (tile selection isn't working well, but this is an easy fix eventually)

code: http://static.graalcenter.org/temp/ole/js/site.js
__________________
Reply With Quote