Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-15-2010, 02:27 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Tile functions

A group of functions I've made that can be quite useful when working with tiles. These are mainly for translating level data to tile data to image data(pics1) and back and forth to any degree. For example, if you wish to make your own level editor you will have to parse the .NW format, which uses base64 into tile data. Then you'll have to make that tile data into pixel data, to draw the tile images..

I realize there are already some base64 functions in GS2, but I couldn't seem to get them to work for the .NW tile format, so I made my own.

Anyways, the functions and how to use them:

TilesToImage(tile) - Converts a tile into pixel position on pics1. Should work for all other tileset types as well. This also supports and returns arrays of tiles like so:
TilesToImage({tile1,tile2,tile3,tile4})
So you could use it like so:
temp.pixeldata = TilesToImage(681);
temp.pixeldata = TilesToImage({681,682,697,698});
Which would return the pixel coordinates of the chair tiles.


ImageToTile(pixelX,pixelY) - Converts the pixel position of a tileset image into a tile number. Does NOT support multiple entries. Works like so:
temp.chairtile = ImageToTile(400,160);
Returns 681, which is the upper-left chair tile of the pics1 indoor chair.


Base64ToTile(base64string)
Base64ToTile({base64,base64,base64,base64})
Converts .NW base64 data into tile data. Also supports multiple entries like TilesToImage().
temp.chairtile = Base64ToTile("Kp");
temp.chairtile = Base64ToTile({"Kp","Kq","K5","K6"});
First will return 681, and the second will return {681,682,697,698}.


TileToBase64(tile)
TileToBase64({tile1,tile2,tile3,tile4})
This one will convert tile data into base64 strings, compatible with the .NW format. Examples:
temp.chairtile = Base64ToTile(681); returns "Kp"
temp.chairtile = Base64ToTile({681,682,697,698}); returns {"Kp","Kq","K5","K6"}

PHP Code:
function TilesToImage(t) {
  if (
t.type() == 0) {
    
temp.px = (int(t%16)*16)+(int(t/512)*256);
    
temp.py = (int(t/16)*16)%512;
    return {
px,py};
  } else if (
t.type() == 3) {
    
temp.imgarray = new[0];
    for (
temp.t) {
      
temp.px = (int(i%16)*16)+(int(i/512)*256);
      
temp.py = (int(i/16)*16)%512;
      
imgarray.add({px,py}); 
    }
    return 
imgarray;
  } else return -
1;
}

function 
ImageToTile(tx,ty) {
  return 
this.tile=((int(tx/16)%16)+(int(tx/256)*512))+((int(ty/16)*16)%512);
}

function 
Base64ToTile(t) {
  
temp.base64 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  if (
t.type() == 1) {
    return 
base64.pos(t.substring(0,1))*64 base64.pos(t.substring(1,1));
  } else if (
t.type() == 3) {
    
temp.decodearray = new[0];
    for (
temp.tdecodearray.add(base64.pos(i.substring(0,1))*64 base64.pos(i.substring(1,1))); 
    return 
decodearray;
  } else return -
1;
}

function 
TileToBase64(t) {
  
temp.base64 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  if (
t.type() == 0) {
    return 
base64.substring(int(t/64),1) @ base64.substring(t%64,1);
  } else if (
t.type() == 3) {
    
temp.encodearray = new[0];
    for (
temp.tencodearray.add(base64.substring(int(i/64),1) @ base64.substring(i%64,1));
    return 
encodearray;
  } else return -
1;

Reply With Quote
 


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 11:56 AM.


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