Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Multi-Sprite Loader
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
GreenTiger




PostPosted: Sat May 01, 2004 7:15 pm   Post subject: Multi-Sprite Loader

Okay dudes, this is another kinda obscure question for you dudes. Despite my computer's sorry state, I decided I could at least spend time programming. I was working on my isometric manager, specifically the sprite loader, I've attached the neccessary files in a zip file. <Note how it's coded in STILL 3.11...the only version I had on my C drive before this bad crash...>

Anyways, I want to load somewhere in the order of magnitude of under 35*35 tiles of of around 16 differant types. I'll go through this slowly. The three main types of landscape I'll have a blocks, toppings and liquids. Blocks are normal ground that you stand on, liquids you float on and toppings you just walk through. The values for these blocks will be stored in an 35*35 array where the first dimension represents the tileset (ground, ice, water, ect) and the second dimension represents the tiletype (square block, slope, ect)

Because there's so many blocks, each block tileset (there's 8) will need to take up two rows, so ground will get both 1 and 2, ect.
Although I hope to get liquids to animate, both them and toppings should only take up one tileset...I'll explain that MUCH later because right now, my program isn't even working up to there.

Okay, now my isometrics was working just FINE with just ground, or just one tileset, but now I've got to load them all in.
Now a step back for a second, why a 35*35 array?
The map format I made, perhaps it was a mistake to make it so complex, but it's too late now because I've made some major maps with it already (a sample map has been included, but it's not one of the ones to be used in the game)

In the maps, two characters represent a block 001100 would be a square ground block surrounded by air. These characters can go to 1-9 (0 always means nothing) and A-Z, almost like Hexadecimal, but expanded.

I've called it OmegaNumerics...but the name really isn't that important.

Anyways, so the isometric map reader reads the blocks in the map and draws a sprite in the isometric position of that block with the picture of that block. That all works fine; except sprites get loaded into the wrong position.

This is where I need help. The sprite loader, I want to load around 1000 sprites or so with as little coding as possible. So I did loops, and now I've gone loopy over it all and I'm as confused. Something isn't working right. I need a second opinon on what I'm doing wrong. I isolated the SpriteLoad procedure into a seperate file for easier access because getting the finalworldformer to run the isometric.tu (which contains the spriteload proc) takes WAY too long.

so yeah, I could use some help. Right now, I'm just interested in getting those two differant landscapes loaded, ground and desert, (which will take up four rows, two each, but neither one take up the entire row either...and they take up differant amounts. It sounds confusing now (any maybe it's just how I wrote it) but it SHOULD (hopefully) make sense when you look through.

Thanks in advance.
I'll credit you guys for your help.
And feel free to use the sprites included or the code as long as you credit me.

<EDIT: The attachment thingie wasn't working so I uploaded it to my site (a pain in the butt with my comp as it is...no ftp clients) so it is now available at: www.ccc.horizonhouse.ca/compsci/early_v.zip
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sun May 02, 2004 8:01 am   Post subject: (No subject)

Actually, your .zip is not available!

Well, let's see anyway...I'm no expert in isometrics, but I've had my share of time with pictures.

If you are using straight .bmps or .jpgs you can always do the whole pic#.bmp trick to speed up the naming and loading of the pictures.
You could setscreen ("offscreenonly") and load pictures to a hidden canvas...

From what you've said it seems as though you are having problems loading a large number of pictures/data files? Well, my guess is that you could use types and records to unify each sprite...but I'm sure you're already doing that.

You mentioned that you were getting looped out of your mind...if all the loops are doing is to load pictures you shouldn't need more than one or two nested - at most (save for cases of multiple directory levels).

And you're in 3.11? Correct? And you are using Turing Sprites? Well...you may not get as much help as wanted as, as you must know, Sprites don't work in 4.0+. So in that respect you may be a bit on your own, but I'm sure some of the more senior ppl around here could give you a hint or two with regards to 3.11.

Or just switch to DanSprites.

Or make your own.

Get your zip up and running and I'll check it out.
GreenTiger




PostPosted: Sun May 02, 2004 8:51 am   Post subject: (No subject)

Ooops...sorry about that...misspell

http://www.ccc.horizonhouse.ca/CompSci/early_v.zip

keep forgetting the capitals in my websites' folders...

Anyways, yeah, my problem isn't with displaying the sprites, they work just perfect.

My problem is loading the pictures, because I have a total of three loops around there because the differant tilesets are in differant directories.

The zip should give you a pretty good idea now that it's location is spelled properly.
Delos




PostPosted: Sun May 02, 2004 11:22 am   Post subject: (No subject)

Ok...I have the programmes now...(without .t endings, just to make my life difficult!)

And I looked at them...and didn't understand much of what I saw...

So:

code:

% Spriter

type fileData :
    record
        name : string
        str : int
    end record
% Record type for each file...the file name and a stream for it.

var sets1 : flexible array 1 .. 0 of fileData
var sets2 : flexible array 1 .. 0 of fileData
var sets3 : flexible array 1 .. 0 of fileData
% This will hold all picture files.

var rootPath : string := Dir.Current
var path : string := Dir.Current
% A path for this directory - will be used to scroll through dirs.
var dirStr : int
% Directory stream.
var tempName : string
% Temporary file name.

% Some necassary procs.

procedure newSets1
    new sets1, upper (sets1) + 1
    % Add another element.
    sets1 (upper (sets1)).name := ""
    sets1 (upper (sets1)).str := -1
    % This instantiates the added line, to nothing in particular.
    % Useful as it will avoid crashes later.
    % Note the '% "xx"'.  This could be incorporated to use as
    % check to see whether anything exists in the particular element
    % in sets.
end newSets1
procedure newSets2
    new sets2, upper (sets2) + 1
    % Add another element.
    sets2 (upper (sets2)).name := ""
    sets2 (upper (sets2)).str := -1
end newSets2
procedure newSets3
    new sets3, upper (sets3) + 1
    % Add another element.
    sets3 (upper (sets3)).name := ""
    sets3 (upper (sets3)).str := -1
end newSets3

procedure getPicturesFrom (var picPath : string)
    % This procedure gets pictures from a directory (picPath).
    dirStr := Dir.Open (picPath)

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Very important loop         %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    for i : 1 .. 2
        tempName := Dir.Get (dirStr)
    end for
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % This loop gets rid of the 2 initial files
    % present in pretty much any directory (perhaps not the root).
    % These are "." and ".." (used for directory scrolling).
    % By getting rid of them, the only remaining files are the picture ones.

    % Of course, you could always add an index for .bmp to your loading
    % so as to eliminate the need for these lines anyway :D!

    loop
        tempName := Dir.Get (dirStr)
        exit when tempName = ""
        % Exit when no file found.  Otherwise, load file.

        /*
         %%%%%%%%%%%%%%%%%%%%
         NOTE!!!!!
         Around here you can add an if statement that will allow you to choose which
         of the sets to assign the next file to.  Since you will know which type of
         picture goes where...just do a check on it and then assign it accordingly.

         This demonstrates adding a pic to set1...whatever type of picture that may
         represent:
         %%%%%%%%%%%%%%%%%%%%
         */
        newSets1
        sets1 (upper (sets1)).name := tempName
        % Allocate the file name to the specified element...could be useful.
        sets1 (upper (sets1)).str := Pic.FileNew (tempName)
        % Create a new picture.
    end loop
    Dir.Close (dirStr)
end getPicturesFrom


Dir.Change ("simple")
path := Dir.Current

Dir.Change ("b_desert")
% The names of these directories will need to be stored somewhere...in an array probably.
path := Dir.Current

getPicturesFrom (path)

path := rootPath
% Reset the path, so as to move to the next directory easily.

for i : 1 .. upper (sets1)
    Pic.Draw (sets1 (i).str, 10 * i, 100, picCopy)
    locate (1, 1)
    put sets1 (i).name
    delay (100)
    % Delay for fun.
end for



This shouldn't be too difficult to follow. I've commented it to death...so...yeah.

Hope that helps...tell me if it does...I've set it up so that you can play around with it quite a bit...I don't think any important parts are hardcoded.

Note: I used 3 flexible arrays here as opposed to one 2dim array because I figured that you won't always have equal numbers of each type of pic...thusways you won't have to precheck the contents of every element before use.
GreenTiger




PostPosted: Sun May 02, 2004 12:26 pm   Post subject: (No subject)

Yeah, thanks for that, I"ll try it out. Sorry about the lack of commenting, I usually have really good commenting, but I put it in after my proggy's working PERFECTLY...which is not nearly the case yet...

Flexible arrays...why didn't I think of that. Genius, you guys, thanks.

<EDIT: Just BTW, I think I figured out another method to do it, kinda halfway between yours and my original one (except it works, unlike my original one!)

Thanks again!>
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: