Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Writing an RPG engine in Python/Pygame  (Read 11010 times)

TSTwizby

  • Bay Watcher
    • View Profile
Writing an RPG engine in Python/Pygame
« on: November 08, 2012, 04:22:18 am »

Yeah, the title says it all really. There's a game I've been wanting to make for a while, only I haven't managed to get the hang of graphics using C++, which had been my language of choice, so I decided to learn python while I was at it. I've been surprised at how quickly it's moving along; what I've got so far is about three days worth of work. This is the first big thing I've ever done in python, so it probably isn't the best or neatest code, but it works. The point of this thread is to get people's opinions about what I've done so far and get suggestions for what to do next.
So far, my effort has been concentrated on the overworld/map part of the game. In addition to the below, I've got some rudimentary menu setups with buttons and a few nondescript informative display objects.

Implemented features (* is recently implemented features):
Can control player using arrow keys
Collision detection with map edge
Can set player speed
Objects can sit on the map, blocking or allowing player motion, and be moved/removed/added
Objects can be interacted with using spacebar, causing a preset effect
Objects (including player) can have animations set to play on command, which will either loop, pause, or play a different animation once run through. Animations can be paused and added to existing objects, but cannot be removed. Player must have four 'idle' animations (one in each direction) and four 'moving' animations (again, one in each direction) as well as a default animation to handle errors. Maps can be animated as well, though they can only have one constantly looping animation.
Portals between maps can be added to maps. A portal is set to open either from all sides or from a particular side, can be open or shut, and must have four animations corresponding to closed, open, closing, and opening states. (note animations do not need to be more than one frame)
*Map will scroll around the player as they move, keeping the player within a specified rectangle on the actual screen.

Planned features (meaning I know how I'm going to do them and just haven't finished them yet):
Player motion will have the option of being a little more detailed, with running added
Portals will be able to move a player to a different spot on the same map.
Objects on the map will be able to follow simple behaviors (move back and forth, block the player from entering a well, etc)
Sound
Areas on the map will cause effects when moved through, such as random encounters, slowed player movement, etc
Popup menu related to game

Hoped for features (meaning I haven't the slightest idea how to do them, but want to):
Distortion/particle effects to be applied to sprites/maps
Transition effects between maps/scenes (fadeout, wipe, etc)
AI for objects on the map to respond to player motion and actions appropriately, or interact with the player itself
Support for multiple player characters at the same time (one using arrow keys, one using wasd, one using a joystick... however many control schemes I can think up)


And of course, I've still got to build a battle system and character stats and stuff. One nice thing about it though is that it's incredibly easy to render cutscenes using the game engine, so there's one fewer thing to worry about.

Now some questions:
What kinds of NPC interactions are there? Some obvious ones are teleporting the player, starting a cutscene, opening/closing a portal, moving around, adding or removing map objects or bringing up a textbox. Anything important I'm missing?

Second, this being more a programming question: Does it make more sense to handle all the things going on in the main program, or to set up a mapHandler class to deal with all the events related to maps going on? I can see some organizational advantages to the second, but it seems like it would take a fair amount of extra work to pass the relevant data back and forth between the main program and the class. On the other hand, it seems like it might make transitioning between moving around on the map and fighting monsters and whatever else it is you end up doing easier.

For those interested, poorly-commented source code:

Spoiler: mapObjects.py (click to show/hide)

and

Spoiler: Main code (click to show/hide)

The main code here is fairly skeletal and won't work unless you give it some images to pull the map and player sprite from. It's straightforward to add things.
« Last Edit: November 09, 2012, 11:05:55 pm by TSTwizby »
Logged
I got a female and male dragon on my embark. I got cagetraps on the exits but im struggling to find a way to make them path into it.
Live bait.
3 dwarfs out of 7 dead so far

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Writing an RPG engine in Python/Pygame
« Reply #1 on: November 08, 2012, 06:18:12 am »

I'd prefer the character-centered map scrolling. The screen-centered version allows for exploits via the ol' "Edge of the Screen"-trick.

And I suggest making a separate class. That way you have it all neatly packed together without the surrounding code .
Logged

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Writing an RPG engine in Python/Pygame
« Reply #3 on: November 08, 2012, 06:24:01 am »

You know the old Kings Quest games? Some screens had the possibility of containing something hostile, but you could easily evade those things by just staying close to the screen and moving off-screen if they started getting too close.
Logged

mendonca

  • Bay Watcher
  • [CLIVE]
    • View Profile
Re: Writing an RPG engine in Python/Pygame
« Reply #4 on: November 09, 2012, 04:54:40 am »

Posting to watch.
Logged

TSTwizby

  • Bay Watcher
    • View Profile
Re: Writing an RPG engine in Python/Pygame
« Reply #5 on: November 09, 2012, 11:01:08 pm »

Minor update: the map now has a main player around which it is centered, so that the player is always within a designated rectangle on the screen. The default is for the player to always be in the center (rectangle with width/height 1), and it can be modified so that the rectangle is of any size and can be offset from the center (if you want more room on one side of  the map for a display or something). I've also set up some of the framework for adding multiple players, but there's still a few barriers to doing that. Next goal is to make some generic NPC type things, to make sure they all do what they're supposed to. I'll have one change the map, one start a cutscene and one bring up a text box type thing. Other suggestions are welcome.
Logged
I got a female and male dragon on my embark. I got cagetraps on the exits but im struggling to find a way to make them path into it.
Live bait.
3 dwarfs out of 7 dead so far

ductape

  • Bay Watcher
  • MAD BOMBER
    • View Profile
    • Alchemy WebDev
Re: Writing an RPG engine in Python/Pygame
« Reply #6 on: November 17, 2012, 04:12:58 pm »

Lots of good places to start with the engine, see some here: http://www.pygame.org/tags/rpg

I am sure you have seen all of these, but there might be something worthwhile in there.

This one looks to be the best of them: http://www.pygame.org/project-fabula-1746-.html

This is their home page: http://fabula-engine.org/

Loose framework but lots of good stuff. Also has netcode to make it multiplayer if you wanted.
Logged
I got nothing

TSTwizby

  • Bay Watcher
    • View Profile
Re: Writing an RPG engine in Python/Pygame
« Reply #7 on: November 18, 2012, 05:19:29 am »

Thanks. I've glanced briefly through most of those, but didn't find anything too useful that I didn't want to do differently (For example, while there are several very good examples of tiled-map engines/generators, I'm using a non-tiled map). On the other hand, I hadn't seen Fabula before, which indeed seems more complete. I'll take a closer look at it later.

Progress has been very slow the past week or so, partly because school, and partly because I'm having a lot of trouble with text boxes. Pygame text is not very flexible or easy to work with, though it might be just that I haven't been trying the right things. I'd really like to get it so that the text comes in letter by letter rather than all at once, like in most RPG's I see these days. I've played around a bit with how things are rendered, which makes the graphical side of things a bit simpler and easier to change, but I've run into another problem there, and I've got a more fundamental one running around in the background, specifically that it's seemingly impossible to link a function to pygame's clock without setting up a stupidly complex 'on tick' type function in the main program or turning absolutely everything into classes, which seems silly.
Logged
I got a female and male dragon on my embark. I got cagetraps on the exits but im struggling to find a way to make them path into it.
Live bait.
3 dwarfs out of 7 dead so far

rangerplus10

  • Bay Watcher
    • View Profile
Re: Writing an RPG engine in Python/Pygame
« Reply #8 on: November 19, 2012, 10:26:42 am »

Hmm, Python looks kinda like Apple Script, unfortunately, due to my Java exposure, I don't like Apple Script :P Anyway, keep up the good work.
P.S I looked at the code and thought I saw no methods/functions, then I remembered that Python used "def" to define a method. :)
Logged