Tile Engine Scripting Idea. Suggestions?

This is a discussion on Tile Engine Scripting Idea. Suggestions? within the Game Programming forums, part of the General Programming Boards category; I'm trying to think of a way that I could script in teleports between maps in a tile based RPG ...

  1. #1
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310

    Tile Engine Scripting Idea. Suggestions?

    I'm trying to think of a way that I could script in teleports between maps in a tile based RPG I'm making. I don't want to hard code all the scripts in, I want it all to be able to be done in a map editor I'm going to make. Currently I'm loading the level from a 2D array of ints, with each int representing the type of tile it is. I'm thinking of having each tile in the map array be a class. In the class I would stick:
    -what type of tile it is (grass, tree, dirt, etc)
    -an int for what map number it will warp to (0 if there is no warp)
    -an x/y coordinate to tell it where to warp the player on the map

    Example: The character steps over a tile in map 1 (the world map), which is a cave, and that tile says to load map 2 (the cave), at coordinates (2,5).

    Hmm this idea is starting to make more sense just typing it out. What do you guys think of this technique and do you know of any better ways of doing it?

    Thanks,

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Donít just wait for The Right Thing to strike you Ė try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  2. #2
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    Do you plan on having more than 256 different tiles? If not, use the right byte of the integer for the tile texture and the next three bytes for teleport target map (0 if no teleportation tile), target x and target y within that map. That works unless you plan on using more than 256 maps, more than 256 different tiles or maps with width and/or height greater than than 256.

    Either use bit operators to mask the bytes you don't need and extract the other bytes, or to make it easier, a struct of 4 bytes (if thats a supported datatype).

  3. #3
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Salem: I don't necessarily need the teleports to be invisible, but if type is the only identifier of a tile, how do you know if it is a teleport or not? I want it all to be able to be done in a map editor and then loaded up without having to hard code the teleports (I'm expecting there to be alot).

    Darksaidin: Hmm, I'm not sure about extracting the individual bits from an int (I have little experience with it), but I do know how to use bit fields, and that seems to be the same concept.

    Thanks for the suggestions guys!

    //napKIN

  4. #4
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    I think what Salem was suggesting was something like this

    Type 1: Trees
    Type 2: Grass
    Type 3: Trees w/ teleport
    Type 4: Grass w/ teleport

    For something really simple (but not necessarily as efficient as other suggestions) you could do a class for each tile with an int for the type and a pointer to a struct. In non-teleport tiles, this pointer could be set to NULL. In teleport tiles, it could be set to a struct containing the necessary teleportation information. Then, determining if it is a teleport tile is a simple if statement.
    Away.

  5. #5
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    I've been working on a tile engine myself, and my solution to this problem is to build a class links_t, which holds a dynamically allocated array of structs link_t, which hold x,y,map for where the player is and where the player is going. Then I just made an impact(player_t&) function within the class to interface it with player. This works pretty good but I'm not exactly the most efficient guy around.
    Attached Files Attached Files
    Illusion and reality become impartiality and confidence.

  6. #6
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Thanks! I'll check it out.

    //napKIN

  7. #7
    Registered User MicroFiend's Avatar
    Join Date
    Nov 2002
    Posts
    80
    well my method i used prbly a bit over the top, is i added in an rpg i made my own scripting language (just a simple c-based system) witch was processed during the main game loop (only slowed the frame rate by 1fps) the map editor that i created generated the map and any warps or events were converted into in loop coding stored in an external file it worked like a dream but then again you would have to create a v.efficient embedded enterpreter and this isnt 4 every1 but hey ive taken that 1 step foward and ive now made an rpg maker for idiots to make high quality games in lol, anyway
    Last edited by MicroFiend; 07-27-2003 at 06:52 PM.

  8. #8
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    Originally posted by napkin111
    Darksaidin: Hmm, I'm not sure about extracting the individual bits from an int (I have little experience with it), but I do know how to use bit fields, and that seems to be the same concept.
    It's actually quite simple: Just define a union with enough space for either one integer or 4 bytes:

    Code:
    typedef union {
      int integer;
      struct {
        byte a,b,c,d;
      };
    } UIntBytes;
    Thats it. d is the highbyte, a the lower one. You can write an int into the integer component and read the results from the a..d bytes or do it the other way round.

    The following piece of code is only needed to demonstrate how it works:

    Code:
      UIntBytes uConv;
      uConv.a = 255;
      uConv.b = 255;
      uConv.c = 0;
      uConv.d = 0;
    
      /* only used for sprintf */
      char buffer [50];
      int nonsense;
    
      /* print the integer as a decimal to a string, cout it */
      nonsense = sprintf(buffer, "union as integer: %d", uConv.integer);
      cout << buffer << endl;
    This code uses anonymous structs within a union. I know anonymous unions within structs are standard C, not sure about structs within unions. If it gives you a compiler message, give the struct a name and access a,b,c and d with unionname.structname.a ... d

  9. #9
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Well what I've come to thus far is this:
    Code:
    class Tile
    {
    public:
    	unsigned type : 7;//up to 128 types
    	unsigned mapwarp : 5;//up to 32 maps
    	unsigned x : 7;//up to 128
    	unsigned y : 7;
    };
    This way each tile takes up just over 3 bytes. Each map would then be 55705 bytes, which I don't think is too expensive considering I could warp to any point in any map without having to hard code it all in.

    Darksaidin: Thanks for the lesson, I've just learned something new

    MicroFiend: Dang. I don't think I'll start making my own scripting languages just yet hehehe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In need of critics, suggestions, feeback and ideas.
    By aroticoz in forum C++ Programming
    Replies: 6
    Last Post: 01-07-2006, 11:44 AM
  2. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  3. tile collision detection help needed...
    By werdy666 in forum Game Programming
    Replies: 0
    Last Post: 01-01-2003, 02:57 AM
  4. IDEA: ASCII graphics engine
    By ygfperson in forum Contests Board
    Replies: 5
    Last Post: 09-30-2002, 07:10 PM
  5. Need lots of help with tile engine
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 06-12-2002, 02:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21