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

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%2022.24.57.jpg


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


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


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


Inventory Menu: https://www.dropbox.com/s/a1wgeswxncr85ia/2013-07-22%2022.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

Edit: post no longer relevant.

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

Edit: post no longer relevant.

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

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().

@Slashin8r I restarted Codea and the error went away.

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.

@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?

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

@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

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

@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.

@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.

@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?

@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.

@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?

@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.

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.

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.