Create my own tile and unit engine from scratch, pls help.

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Ryujin8
Newbie
Posts: 4
Joined: Mon Oct 13, 2014 4:54 am
Contact:

Create my own tile and unit engine from scratch, pls help.

#1 Post by Ryujin8 »

I am still very new with Ren'Py and I need some help.
How does one create a tile engine and unit engine from scratch, where do you start?
Are there any tutorials for creating a very basic engine for Ren'Py?

I have seen (http://www.renpy.org/wiki/renpy/doc/coo ... it_Engines) and I went through the tutorials, yet I don't even know in what .rpy file to put the data in. I guess it's script.rpy, I could be wrong.

I would like not to use engines already made apart from what came with Ren'Py itself.

Any help would be super-appreciated :)

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Create my own tile and unit engine from scratch, pls hel

#2 Post by xela »

Are you asking about displaying graphics in renpy while you have knowledge of Python to write underlying logic? TileEngine is fairly difficult to build and close to impossible without prior experience in coding. You could take a look at Jake's BE and software called Tiled but even getting that to work requires some knowhow.
Like what we're doing? Support us at:
Image

Ryujin8
Newbie
Posts: 4
Joined: Mon Oct 13, 2014 4:54 am
Contact:

Re: Create my own tile and unit engine from scratch, pls hel

#3 Post by Ryujin8 »

To answer your question, yes. I had a look at Jake's BE and it got me excited for what is possible. If only Python is needed, then incorporated I could just learn it then.
I also had a look at Tiled, thanx. That'll easy the workflow :)
I have worked quite a bit with Twine before so I'm up for the coding-learning-challenge.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Create my own tile and unit engine from scratch, pls hel

#4 Post by xela »

Good luck. This is how I did a very similar thing (for fun):

- Build a map required in Tiled.
- Load tilessets + loading map from JSON using LiveComposite into Ren'Py and scale it to Jakes BE grid (easier with JSON than with XML but I expect that to be very personal).
*Latest version of tiled comes with auto-tile support that can be easily used to Ren'Py. You can try with RPG-Maker auto-tiles but you can't use them in a game without breaking copy-right laws, still excellent for learning.
- Load a simple battle scenario with move.
- (Very) Simple addition to the BE and you can have units throwing fireballs and arrows at each other (normal built in magic gets old really fast) :)

Jakes BE makes a lot of this stuff easier, especially if you want to learn before creating your own design.
Like what we're doing? Support us at:
Image

Ryujin8
Newbie
Posts: 4
Joined: Mon Oct 13, 2014 4:54 am
Contact:

Re: Create my own tile and unit engine from scratch, pls hel

#5 Post by Ryujin8 »

Thanx for pointing me in the right direction :) I have JSON working in Notepad++ and I've been learning it since yesterday.
What is a loading map?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Create my own tile and unit engine from scratch, pls hel

#6 Post by xela »

"load a map"

Tiled will make a JSON file for you containing logical information about the map you've created. Python has a built-in module to read JSON files and load them into the game. With the info inside of JSON file, you need to tell Ren'Py how to crop tile-sets and construct new map from them. Then you create a normal battle scenario with a grid and moving around in Jakes Battle Engine and tell the grid a size of a single tile and the full size of the map. That way it will know exactly where to place the units and how to move them around.

A MUCH simpler approach is to make a picture of a map in tiled instead of a JSON file. That requires far less coding (or none at all? just follow example of a scenario in BE) and understanding of how this stuff works but that will mean a LOT of images if you want a lot of areas which is quite inconvenient.

*Basically this is what I did when trying to figure this stuff out. First a map from a simple image, then a more complex but convenient loading from JSON and proper tilesets, and finally a port of characters from my game to BE and improving the BE magic a bit (so sprites could shoot arrows and hurl fireballs at one another). At that point my dev team told me to stop messing around and work on more important stuff :)

*I think this is the code I wrote to load the map from JSON but this is very raw and requires to run in init (without a good reason). Maybe it can give you some idea of how to write your own better version (I'll rewrite this completely if we decide to have this type of battle field in the game):

Code: Select all

    class TileMap(_object):
        """
        Prototype to import and build of maps from Tiled.
        For now using a single tileset (can be updated to using infinite amount)
        """
        def __init__(self, path):
            self.data = load_json(path)
           
            # Map:
            self.map = self.data["layers"][0]["data"]
            self.height = self.data["layers"][0]["height"]
            self.width = self.data["layers"][0]["width"]
           
            # Tileset:
            # If this works out, I'll have to account for mupliple tilesets in the future.
            # self.imageheight = self.data["tilesets"]["imageheight"]
            # self.imagewidth = self.data["tilesets"]["imagewidth"]
            self.image = "content/gfx/tilesets/tmw_desert_spacing.png" # + self.data["tilesets"][0]["image"]
            self.ts_name = self.data["tilesets"][0]["name"]
            self.tileproperties = self.data["tilesets"][0]["tileproperties"]
            self.col = [int(key) + 1 for key in self.tileproperties.keys()]
           
        def get_args_for_composite(self):
            """
            Returns a list of arguments to be unpacked for Composite
            """
            args = list()
            for y in xrange(self.height):
                for x in xrange(self.width):
                    args.append((x*96, y*96))
                    args.append(self.ts_name + str(self.map[y*(self.height+(self.width-self.height)) + x]))
            return args
           
        def build_map(self):
            """
            Builds the map and returns it as RenPy Image
            """
            # Register the times as images first:
            t = 1
            # Margins + Spacing
            for y in xrange(6):
                for x in xrange(8):
                    _x = x + 1
                    _y = y + 1
                    renpy.image(self.ts_name + "%d"%t, im.Scale(im.Crop(self.image, (x*32+_x, y*32+_y, 32, 32)), 96, 96))
                    t += 1
                   
            # Build the map into single image and return it:
            args = self.get_args_for_composite()
            return LiveComposite((3840, 2400), *args)
Like what we're doing? Support us at:
Image

User avatar
fluxus
Regular
Posts: 133
Joined: Thu Jun 19, 2014 8:06 am
Projects: Animal Anaesthesia (a teaching game)
Contact:

Re: Create my own tile and unit engine from scratch, pls hel

#7 Post by fluxus »

Uhm.
Do you have regions that is visited one after the other instead of one, big sandbox-style map to wander around in since you're composing all the tiles you need into one larger image which (I presume) is then what is used?

For wandering a large map I'd've thought loading the edges in as they're needed would be less memory-intensive.

...is handling a lot of small tiles harder for Ren'Py than one over-sized map? Somehow?

Very interesting to see tile engine code by the way :)

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Create my own tile and unit engine from scratch, pls hel

#8 Post by xela »

As stated in previous post, this is something I tested as a concept to see how it'll work out. It doesn't matter if large map is loaded or a lot of smaller once, Ren'Py can handle both approaches. Loading resources in as they're needed is also a valid option.

What do you mean by "tile engine code"? I said this was written to be used with Jakes BE.
Like what we're doing? Support us at:
Image

User avatar
fluxus
Regular
Posts: 133
Joined: Thu Jun 19, 2014 8:06 am
Projects: Animal Anaesthesia (a teaching game)
Contact:

Re: Create my own tile and unit engine from scratch, pls hel

#9 Post by fluxus »

xela wrote:It doesn't matter if large map is loaded or a lot of smaller once.
Okay then.

As for calling it 'tile engine code'.. well, yes, I know it's just a part of a larger system. But I wrote a small tile engine myself in python some years back, a game project I never finished.
But I do recognize your way of structuring things - It's nice to see confirmation/inspiration, was what I meant :)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]