Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Utility: RPGenerator v0.7.23 - Build your own RPG in Codea

edited August 2013 in Code Sharing Posts: 391

RPGenerator is a utility project created to help you make fully functional classic style RPGs. This project will cover all the basic aspects of making an RPG including, but not limited to, the following: maps, characters, dialogue, items, shops, menus, monsters, battles, skills/spells and their effects, weather, cutscenes, and more.



This project does not auto-generate any of the aspects listed above. It does, however, come with a few samples and provides an outline for you to create the aspects listed above. The project will not write a storyline for you. Since an RPG is mostly story, even while utilizing this project there is still a lot of work to be done to create an RPG.



And now for the code you have been waiting for:


RPGenerator Auto Installer: https://gist.github.com/Slashin8r/5962435


RPGenerator Full Project: https://gist.github.com/Slashin8r/5962430



RPG Auto Installer: https://gist.github.com/Slashin8r/5992239


RPG Full Project: https://gist.github.com/Slashin8r/5992265



CiderControls Auto Installer: https://gist.github.com/Slashin8r/6048817


CiderControls Full Project: https://gist.github.com/Slashin8r/6048814



Screenshots:


I'm A Ghost, Can It Get Any Worse?: https://www.dropbox.com/s/aw7rxu84mtip988/2013-07-22 22.24.57.jpg


Brrrrrrrrrr, Ghostly Chills: https://www.dropbox.com/s/da0jyhxi5h5yp4k/2013-07-22 22.25.52.jpg


Hello Mr. Dwarf: https://www.dropbox.com/s/dac51yb5svxnc9o/2013-07-22 22.27.13.jpg


Where Did I Go?: https://www.dropbox.com/s/7vedb3e1g91puqu/2013-07-22 22.26.47.jpg


Inventory Menu: https://www.dropbox.com/s/a1wgeswxncr85ia/2013-07-22 22.24.16.jpg



Installation:


1) Create 3 blank projects: RPGenerator, RPG, and CiderControls


2) Paste corresponding Auto Installer code into each of the 3 projects


3) Run each project


4) Open RPG and set RPGenerator and CiderControls as dependencies


5) Create Dropbox account if you don't already have one and sync it to Codea


6) Run RPG and give it a few minutes to download all the images (There will be a message printed when completed)


7) If the game doesn't start, close Codea completely and restart.



Known Issues:


-On first run, you will receive an error. This is related to the newly downloaded images. After the error, close and restart Codea, then the project will run correctly.



Roadmap:


0.8.0: Map Chunks


0.9.0: Bad guys and monsters


0.10.0: Menu GUI, NPC Shops, Items (weapons, armor, potions, etc.)


0.11.0: Attacks, spells, and the effects to go with them


0.12.0: Battle System


0.13.0: Cutscenes


0.14.0: Mounts and Vehicles


1.0.0: Debug and Refine everything

«13456

Comments

  • edited July 2013 Posts: 391

    Edit: post no longer relevant.

  • Posts: 2,043

    @Slashin8r, could you please provide links to the tile sheets, the way they are right now I can't save them

  • edited July 2013 Posts: 391

    Edit: post no longer relevant.

  • edited July 2013 Posts: 2,043

    @Slashin8r, I get an error when I try to run
    http://i.imgur.com/9D4mTrX.

    image

  • Posts: 391

    Did you copy the images into your documents folder with the same name I used in the code? If you saved the images with different names you will need to change it in the tables for each instance of readImage().

  • Posts: 2,043

    @Slashin8r I restarted Codea and the error went away.

  • Posts: 391

    Nice, I hope that code gives you a decent jump start in all your world editing endeavors. I am currently working on the auto-tiling algorithm for roofs/walls and then onto the animated tiles such as water and waterfalls. For the animated tiles I'm thinking I may need to make a separate table for them so that each tile could contain multiple tile sheets.

  • Posts: 105

    @Slashin8r I have not tried your map yet but I am just wondering. Lets say you have a tree in a big field and your player are there too. If you draw the player after that you draw the tree, the player will be shown over the tree. Thats good if your player is in front of the tree, but what do you do if the player is behind the tree? How did you do?

  • IgnatzIgnatz Mod
    Posts: 5,396

    @MMGames- what you do then is sort your objects by distance and draw the furthest first

  • edited July 2013 Posts: 105

    @Ignatz Something like this maybe:

    function setup()
        tree:setup()
        player:setup()
    end
    
    function draw()
        if player.y<400 then --The tree position in y is 400
            tree:draw() --Player will be drawn after the tree
    end
        player:draw()
        if player.y>425 then --Height of the tree is 25
            tree:draw() --Tree is drawn after the player
    end
    end
    
  • IgnatzIgnatz Mod
    Posts: 5,396

    Rather - If all your objects are in meshes, including the player, sort them by distance

  • edited July 2013 Posts: 391

    @MMGames, I simply did a check on the tile below the players position. If the tile below the player is passable (my variable for able to walk on) then the player sprite would be redrawn after the objects are drawn onto the floor tiles. If the tile below is not passable, then the player sprite was only drawn before the objects.



    Drawing order:


    Floor Tiles


    Player Sprite


    Objects


    Player Sprite (only if tile below is passable)



    You can see in the 2nd screenshot above that this is working as expected. My character is rendered behind the tree, however if I were to walk on the forest tiles, my character would render on top.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Slashin8r - I've looked at part of the code and have a few suggestions.

    You are reading in the floor tile spritesheet about 16 times when once would be enough. Also, there seems to be no need to break up the tilesheet at all, since you could do this:
    1. have one mesh for the entire floor (the part that uses this spritesheet, anyway)
    2. then you can use the spritesheet as the texture for the whole mesh
    3. when you add tiles to your mesh, you can set the texture mappings for each tile so it clips out the right part of the spritesheet. If these mappings are in an array, then it will be very compact code

    I'm also wondering why your FPS is so low. My inclination would be, if your floor is going to stay the same for each level, to draw it just once onto an internal image with setContext, then sprite that image on each draw. Then your FPS should be back up to 60.

    wrt objects, I might do the same, ie create a single image with all the objects, and overlay it on the floor. If objects are added, moved or removed, you can either redraw the image or else just adjust the affected part of the image. Whether using a predrawn image is worth it, depends on how much it is likely to change, and the complexity of drawing it.

    wrt moving in front and behind, you could handle this very easily with predrawn images as above. If your char is behind an object, draw your objects image, then your char, then redraw just the object that is in front of your char. This minimises the drawing work.

  • edited July 2013 Posts: 391

    @ignatz, I'm a bit confused on what you are suggesting. The reason I read from the tilesheet so much is because the tilesheet is really a tilesheet set, it is comprised of many tile sheets which I then break up into the tiles and objects tables. Then to accomplish the auto-tiling I need to take those individual tile sheets and break them up into 24 pieces in order to utilize the 20 pieces necessary for auto-tiling.



    As for FPS, I am currently getting 60 on average, but I am using the 4th gen iPad. Not sure what the frame rate is on other devices. You can see my frame rate in the screens above, getting anywhere from 59 to 61.



    To get my character behind an object I just went about it the opposite way you suggested. Since all the objects are drawn together, I figured it'd be much simpler to just redraw the player when he encounters an object he can walk on. Your way accomplishes the same thing by redrawing the object that the player can not walk on.



    I do have a question I'm sure you could answer. I am trying to set up the auto-tiling for roof/wall tiles. I need to be able to rotate the tile image and then store it into the mesh. I have tried using the rotate command but that seems to only work in the draw() function. I could probably have it rotate there, but it would be much easier to fit into my current code if I could simply rotate the image before it is put into the mesh and then drawn. I could also read the image pixel by pixel and redraw it, but I fear that will cause some lag. Any suggestions?

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Slashin8r - the current code seems to read in the same tilesheet over and over (see JakAttak's extract further up), that's why I made the suggestion.

  • edited July 2013 Posts: 391

    @ignatz, yeah that's the only way I could go about it since it is one huge image of many tile sheets. Notice how I copy that same image from every different location using the same height and width. I'm not sure if I can do it any different except to split the large image into 32 separate tile sheets, but then I still have to read all 32 images to accomplish the same thing.



    Would it go faster if I saved the large tile sheet sets into an array and then break them up so it doesn't call the readImage() function so much?

  • edited July 2013 Posts: 391

    @ignatz, after re-reading your comments above I now understand what you were suggesting. I set the large tile sheet set as a mesh texture. Now if I want just the bottom left corner 32x48 tile sheet, how do I go about grabbing only that part of the mesh? I am also assuming that if I do it this way I will then need to do the same thing in my autoTile() function for the 20 pieces of the individual tile sheets.

  • edited July 2013 Posts: 391

    So after some more testing I do notice a frame rate drop when I switch maps, since it needs to regenerate the map every time. I have now solved this by storing generated maps into a table with its corresponding map index. So now I can check if the generated map already exists before generating it again and again.



    After both my maps are generated for the first time, my frame rate low is 50 and frame rate high is 70.

  • edited July 2013 Posts: 391

    Link at the top has been updated and now is provided through Dropbox so the formatting is not lost. Sprites have also been given new names and I now use them through Dropbox so the image sizes have changed. No need to upload them with retina checked anymore. Toss them into your own Dropbox and all should work.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Slashin8r - suppose you set the large tileset as a texture for the whole floor mesh.

    If (to keep the math simple) you have a tileset texture 1000 x 500, and you want the tile at x=150,y=200 with width w=100, h=height 100, then your texture mapping is x,y,w,h as a fraction of total width and height, so it is 0.15, 0.2, 0.1, 0.1

  • edited July 2013 Posts: 391

    @ignatz, ok I think I understand. So I just have to use fractions to get to each location. I got 8 tile sheets on the x axis and 4 on the y axis so something like (0/8, 0/4, 1/8, 1/4) up to (7/8, 3/4, 1/8, 1/4) would grab all 32 of them, correct?



    Then I just store the fractions instead of the images. And then breaking it down more I would just simply divide the fraction yet again. 4 pieces along the x axis and 6 pieces along the y axis and save the 20 locations needed instead of 20 individual images. Using the top right tile sheet to test my math, the pieces would start at (28/32, 18/24, 1/32, 1/24) up to (31/32, 23/24, 1/32, 1/24).

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Slashin8r - you got it!

    Try it and see - just remember 0,0 is the bottom left corner, 1,1 is top right...

  • edited July 2013 Posts: 391

    @ignatz, I actually just finished updating the code to work that way. It runs much smoother now, I have yet to see frame rate drop below 58 on my device now. The code has been updated in my Dropbox as well. Now to do the same thing with the character sprites and I will also have to add a tileset variable to the generateMap() function as I am currently calling my tile sheet set globally.

  • Posts: 391

    Got rid of the AutoTile tab and function now that I am using just meshes. Also added project version at the top of the main tab so you all can easily keep up with the updates.

  • IgnatzIgnatz Mod
    edited July 2013 Posts: 5,396

    @slashin8r - The code here will automatically download your tile set images when the program runs, so you don't need to post links to them.

    http://coolcodea.wordpress.com/2013/05/23/62-3d-downloading-images-on-demand/

    If you dont use something like this, and people still have to manually download the images, I suggest moving them from Documents to Dropbox because it is a pain to have to do this manually.

  • Posts: 391

    @ignatz, thanks for the code, I will definitely add it in right away.

  • edited July 2013 Posts: 391

    I have now implemented the code @ignatz provided. The images necessary for the project to run will now be automatically downloaded and stored into your own personal Dropbox. Make sure you have a Dropbox account and have it synced with Codea before attempting to run the project. If you do not have a Dropbox account synced, then you will have to change the image names from Dropbox: to Documents: in the Images tab. You may have to run the project twice, once to download the images, then again for it to run with the images you downloaded.

  • BriarfoxBriarfox Mod
    edited July 2013 Posts: 1,542

    The photo download seems to be a tad buggy. It keeps looping. Then crashed codea. A restart had the files.

    Edit: deleted the files and tried again. Worked without the looping but it still required a restart.

  • edited July 2013 Posts: 391

    Yeah I'm not sure exactly what it is doing to cause that. For some reason it is executing setup2() before the images actually finish downloading and saving. I'll add some alerts along the path to see where it jumps to setup2(). It also seems like there is a problem with the recursive call.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Slashin8r - there should be nothing in setup except the call to load the images

  • Posts: 391

    @ignatz, that's all I got in there right now. For some reason the variable i is always nil and so it keeps looping trying to save the images over and over, then for some reason it continues to the draw function. The code looks solid and I am unable to figure out where it is going wrong.

  • BriarfoxBriarfox Mod
    Posts: 1,542

    After setup1 is ran it will go to the draw. It does not wait for the image callback to finish. You will need to check for the images in draw before you start the draw loop. It's a little early here and I just woke up but it appears you keep calling a nill loadImages() in line 38.

  • edited July 2013 Posts: 391

    @Briarfox, I added an imageStatus check in the draw function and now it does not draw early, however we still do have the image check returning nil. Even if the images are downloaded correctly, it still isn't returning an image when we try to read the newly downloaded images, which then causes the recursive function to run an infinite loop.

  • Posts: 391

    Added more imageStatus checks before each loadImage() since every once in a while I ran into an issue where the image will save but use the name of the other image I'm trying to download as well. Still getting nil image even after it successfully downloads, however.

  • edited July 2013 Posts: 391

    Ok, I finally got the automatic image downloading working correctly. I had to add a table that just tracked the status of each image download and use that table to skip redownloading instead of just checking if the image exists (since this always returned nil for some reason). It will still check if the image exists so it can skip all when you already have all the images.



    Next update will convert the character sprites to a single mesh just like the tiles have been converted.

  • Posts: 391

    Just finished converting the player images to use a mesh.



    Next update will cover auto-tiling of roof/wall tiles. This one may take some time.

  • Posts: 391

    Updated the link to the code. It is now on GitHub and thanks to @Briarfox I was able to create an auto installer for it. Direct link to the project and link to the auto installer are available in the 1st post.

  • BriarfoxBriarfox Mod
    edited July 2013 Posts: 1,542

    @Slashin8r you dont want to gist the AutoGist variables.

    use this to exclude from gist.

    --/*
    autoGist = AutoGist(PROJECTNAME,"Codea RPG Maker by Slashin8r",VERSION)
        --autoGist:setKey("5945833")
        autoGist:backup(true)
    --*/
    
  • BriarfoxBriarfox Mod
    edited July 2013 Posts: 1,542

    Something else is wonky with your gist. Did you manual create a gist then assign the key? If so this is not correct. Comment out where you called autoGist:setKey(). It is not needed. It's a function to set a key if your key gets corrupted. AutoGist will grab its own key. Then try updating the version number. The gist description Is created by autogist and should be left as is. It needs to contain the version number for the updater to work.

    Also if you add a tab called ChangeLog it will be displayed with an update to let your users know whats new.

    ChangLog.lua

    --[[
    Version 1.5.6
    -Allow the user to create games purely by thought!
    
    --]]
    

    I checked your revisions. There is no need to save your version number as local data. Simply use what i posted in the above post. Also there is no need to create a gist first. AutoGist will detect if a gist needs to be created, then create it and finally save the key

  • Posts: 391

    @Briarfox, ok I made those changes. Can you check it out for me to make sure it's correct? Also, do I need to delete my current gist and then let it do it automatically since I initially did it manually then went on to add the updater part?

  • Posts: 391

    Ok so it looks like it is working correctly now, I changed the version and it auto updated the gist. Thank you so much @Briarfox, this is one sweet app you created. :D

  • BriarfoxBriarfox Mod
    Posts: 1,542

    Worked like a charm! :) I'm really looking forward to seeing where you take this rpg maker!

  • IgnatzIgnatz Mod
    Posts: 5,396

    where is the latest code?

  • BriarfoxBriarfox Mod
    Posts: 1,542

    Links in the first post, I believe.

  • IgnatzIgnatz Mod
    Posts: 5,396

    I'm getting this error after installing

    error: [string "-- table of available characters..."]:23: attempt to index field 'sheet' (a nil value)

  • Posts: 391

    Just made it home from a long journey and thought I'd check here before passing out, hehe.



    @ignatz, did the images download correctly for you? That error sounds like it is missing the Character-001.png file in your Dropbox. I changed some of the code you originally posted for the automatic downloads, something might have gone wrong there.

  • edited July 2013 Posts: 391

    Made some minor changes. Updated documentation and the dialogue event. Dialogue event is still currently being called as a map event for testing purposes. Dialogue text is now pulled from the NPCs table and a random dialogue is chosen to be displayed. Dialogues can be one page or multiple pages, the amount of text each page can hold is limited, but the number of pages is unlimited.



    Still working on roof/wall algorithm. When it is finished it will be released in version 0.4

  • Posts: 60

    I am getting a error with the auto installer.

    Error: [string " ..."]:60: Invalid buffer name

    Anyone else see this?

  • Posts: 391

    Just finished the algorithms for roof and wall tiles. Added in the images necessary for them as well.



    @Aalok, did you name your project RPG Maker? If you named it something else, then change the PROJECTNAME in the auto installer. I will try the auto installer myself to verify.

  • BriarfoxBriarfox Mod
    Posts: 1,542

    Its the error thats thrown when the project name doesn't exist. I'll add some better checking to let the user know.

Sign In or Register to comment.