Learn Python with Talk Python's 270 hours of courses

#78: How I built an entire game and toolchain 100% in Python Transcript

Recorded on Saturday, Sep 24, 2016.

00:00 What kind of applications can you build with python? You hear me featuring many people on this show that build websites, web services, or some data science driven application. Of course, all of those are wonderful but I know many of you have dreamed of building a game.

00:00 In this episode I'm interviewing Joseph Cherlin. He created the game Epikos and the entire tool chain entirely in Python. He has a great story about how he came across Python, why he decided to use it in his game, and advice he has for anyone out there taking on a large project like this.

00:00 This is Talk Python To Me, episode 78, recorded September 24th, 2016.

00:00 [music intro]

00:00 Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem and the personalities. This is your host, Michael Kennedy, follow me on Twitter where I am @mkennedy, keep up with the show and listen to past episodes at talkpython.fm and follow the show on Twitter via @talkpython.

00:00 Hey everyone. As always, thank you so much for listening. I think we have an interesting look inside a really cool project by Joseph this week, so I hope you enjoy the episode.

00:00 He talks about the game that he built and the whole tool chain and how he used Python to do it. And he and I talked after the show and decided that it would be really great to give away some copies of his game; as always, if you want to win something from the show, you have to be a friend of the show, it's super easy, just visit talkpython.fm click on 'friends of the show' in the nav bar, enter your email address, boom, we're friends. Well, we are already friends- you are listening the show, right? So thank you so much. But, officially to win, you've got to be a friend of the show so give me your email address so I can hopefully pull it out and send you one of the games. I hope you enjoy the episode, let's hear from Joseph.

02:07 Michael: Joseph, welcome to the show. I'm super excited to talk about how you built your game in Python, and not just your game, but your entire tool chain, and the story of how you did this and your journey is super interesting, and I am looking forward to sharing it with everyone.

02:20 Joseph: Yes, it was really fun and thanks for having me on the show. I think it'll be fun to talk about it.

02:26 Michael: Yeah, it definitely will. And you're welcome. So, before we get into the story of Epikos and your game, and things like that, let's talk about your history, like how did you get into programming?

02:37 Joseph: So strangely, I didn't actually have a computer to program on growing up, like a lot of my friends who are also programmers. But when I started going to college actually my dad bought me a computer. And, as a kind of random thing I took intro to computer programming course in college, it was totally random, I was supposed to be, I was in pre architecture major, so I wasn't doing anything related to programming. And I took this programming course, and I was like, "this is what I want to do to the rest of my life. All I want to do is program, this is it". And I had to switch to computer science, and there were a lot of math prerequisites that were going to be new, I was like I don't care, I'm going to study hard, I'm going to learn everything. I'm not one of these guys who has been programming their whole life or whatever, that's great if you have that, that's awesome, but not me, I learned in college and my express goal was always to program video games, I was in video games had a NES growing up, most of my favorite games are NES games I would say, but that got me into the games and I when was programming in college I always wanted to make games out of my program so I was learning stuff like directx, I was trying to learn stuff for game programming, I was making little games all the time in college.

04:08 Michael: That's really cool.

04:08 Joseph: That's kind of how I got into programming.

04:10 Michael: I think a lot of us can relate to this feeling of like once you discover programming, you're like this is what I want to do. I still remember one of my very first paid outside of university jobs, was working on 3D visualization software doing C++ and OpenGL and I was just thinking, you know my first day and first week at work I'm like, "this is it, like my life is perfect, I doing like OpenGL and programming and oh my gosh, this is so amazing." I was just thrilled. So you've done a lot of C++ programming as directx and probably OpenGL as well, and all the major game engines. That's kind of what you do for your day job, right?

04:53 Joseph: Yeah, I mean I'm not an [00:04:54] dev during the day, I'm a programmer, I do game stuff, so I've been in the games industry about 10 years. I've shipped three or four titles if you count expansion packs, I don't know three or four.

05:09 Michael: Any major ones that we probably played?

05:12 Joseph: I shipped a few console titles, I mean, they weren't bad, I liked them, but probably nothing too big. And then I went and I started working at Arena Net which makes Guild Wars, so Guild Wars 2 I worked on. I would love to take credit for a lot of things to Guild Wars 2 but I can't, I only joined a year before they shipped. I tried to help out before shipping, but I obviously the lion's share of the credit for this game doesn't go to me, there's a lot of programmers here.

05:43 Michael: The major games have an incredible number of developers and artists and team members, it's not a one-person deal to ship games these days, is it?

05:52 Joseph: It's really huge. It isn't super big, like the [00:05:56] or anything, which makes it nice actually, but there's a lot of people you're working with, and the key thing Arena Net actually let me do was, in most games industry jobs you're working like not like nine to five thing, right, you're working 12, 14 hours a day. You can't make a side project right, you have to go home and sleep, right, or go home and drink, so that you can get over working 14 hours and then go to sleep. And that's it, you can't do that, and once I started working at this new job at a more responsible company, basically it is they actually make sure that there's no real overtime there, so I came home and I was like now I should be programming, that's kind of how the game started getting made.

06:42 Michael: That's great. We'll talk about how you're using Python in your game in a moment, but why don't you tell the story of how you got into Python and why you thought it might be interesting for a game in the first place?

06:55 Joseph: I don't know if I'm exactly hundred percent Python programmer, I like Python, I'm really a C programmer, most of my work is in C++ but I prefer C style stuff with a little C++ thrown in. I'm not going off the deep end with all the C++ features, the language I like it a lot, it's my first language was C, so obviously it's like your first language always has a special place in your heart no matter who you are I think. At work I had to fix a bug which happened to be in Python, I think an artist had made a script in Python and it was a good script, it had a bug in it, and I fixed it after learning a little bit of Python, I think about maybe like a couple hours pipeline gave me enough ammo to kind of fix a rudimentary bug, so if you're getting into Python it's not too bad if you are a C programmer already. But then I was looking at this line of code, I was like I wonder what you can do with this thing, so I'm thinking about it as a C programmer really, I'm thinking about Python as a C guy, like oh this looks like it'll save me some time maybe I don't have to declare things, I don't have to put together all the nuts and bolts of the program as much. And I took it home and I wrote a C program you know, I wrote a program in C, I can't remember what it was, I think I'd automated some process I was working on, and then as a challenge I wrote it in Python, so in C it was 300 lines of code, and I'm making up the lines I don't remember exactly how many lines it was. Let's say it was 300 lines of code. In Python it was like 100 lines of code, my first Python program you know, 100 lines of code instead of 300, and I'm thinking wow this is pretty great.

08:52 Michael: That's a nice improvement.

08:54 Joseph: That was the amount of code, that's cool. And then I was looking at it more like okay, let me learn more Python. So this is you know, learning almost no Python, that's great because less code you know, less code means less bugs, right. You don't want to write things as long way as possible, that's it. Less code less bugs, great. And I started learning more Python, I was like wow, I can get this down to fifty lines, and I learned more, so I was like I can get this down to 25 lines, I'll learn more Python learn about how the sorting works, the data structures all the stuff that I just normally manually code or use some library for, which is it tends to be verbose in C or C++. And then, 20 lines of code, 10 lines of code, and I'm sitting here with 10 lines of code instead of 300 lines of code; 10 lines of expressive code instead of 300 lines of nuts and bolts and a little bit of expressive [00:09:51] somewhere in there, and I'm like I could probably write this thing in a couple of lines but it would be really ugly code, I'm going to leave it at whatever it was 25 or 15 lines of code. That experience was the one which convinced me Python, there's something to this language, and I haven't done a lot with scripting languages I'm a C person, so people tell me well you can do this, with this you can do this, ok maybe they're right. But for me, I learned at Python this exact experience was what got me into Python and that totally convinced me there's something to this language.

10:30 Michael: That is a really cool story. I wish you had kept all the versions of code we could put them up as like github gist, or something like that, but still, the story is great, and I think a lot of times you'll hear people say," well I like this language because it's dynamic and it doesn't have types", or "I like this language because it doesn't require compiling like C does" or something. But I think what was really cool about your story is it really highlights what's truly cool about languages like Python and especially Python is that whether or not you compile those 25 lines, it is a much better experience, what you can do and the way you put the standard library together and the packages, and all sorts of stuff, it's great.

11:13 Joseph: Yeah I totally agree with you, I don't want to put words in the mouth of the devs of Python, but I think the point of the language is just to be expressive, so you're right normally you write code and there's a lot of boilerplate code, it is a little bit of code that carries the intent of what you actually wanted to do. And Python it's like the code that expresses what you wanted to do is the code, more or less.

11:37 Michael: Yeah, you had a cool thing where you said you're talking about an algorithm the A* path navigation algorithm in a Reddit post that we'll get to talking about, you said, "here, look Wikipedia is describing the algorithm in words, and then basically pseudo code drop this in the Python, how much work would it be to just make it execute it basically". Which is really nice I think.

11:58 Joseph: It's amazing, like I copy pasted some pseudocode into the pipeline, I changed, I think the equal find right, and the pseudocode is different than the equal signs in Python, and it worked.

12:11 Michael: That is awesome, cool. Let's talk about-

12:15 Joseph: It was like I can't even believe it worked.

12:18 Michael: Yeah that's really cool. So let's talk about your game, what's it called?

12:20 Joseph: Oh sure, Epikos is the game. E-P-I-K-O-S it's a Greek word for epic, and it's a game I wanted to make for a number of years, even in college I wanted to make this game, but once I started working in the games industry, of course I didn't have time, because the hours; but then I eventually had time, I got to a more responsible company. The game is pretty retro, it's hard to say that in a world where pretty much every game claims to be retro these days.

13:03 Michael: Yeah it definitely has a retro feel, I'll vouch for you, it does have a retro feel. It's a visual RPG where I feel kind of like it's a simplified Legend of Zelda type game maybe a little bit, like it has that kind of feel of playing.

13:20 Joseph: It might feel that way. I feel actually it's a combo of Ultima 4 and Final Fantasy 4, so like Ultima you have interesting property that the more the faster you input on your keyboard the faster the game runs. No games even if they claim to be retro, no games have this property anymore, but in the eighties a lot of games had this property; if you type fast, the game went fast, and if you type slowly the game went slowly, and if you left the game didn't do anything at all. And whereas nowadays, even the turn-based games, it doesn't matter how fast you go, they're very slow, because you have to wait for the AI to think, and you have to wait for all these stupid animations you don't even care about to finished playing. And all these sound effects to get over with. And you just want to play the game, but the game is so enamored with its own wonderful effects that it won't you let you play it. And plus the AI is typically not written efficiently, which my it does stuff, but think about it's in Python, I mean that's like 500 times slower than C and the game runs that frame right.

14:30 Michael: Yeah, it's awesome and it's all about designing it in the right way, right. I mean, it's the trade-offs you make, like you said, stay away from the crazy animations and guess what- you can go through the steps faster, that's cool.

14:43 Joseph: Yeah, everything runs really fast.

14:45 Michael: On your website, you have a place where you say, you talk about the outstanding features of the game. Can you maybe highlight some of those?

14:54 Joseph: It has a very original mythology, there's a website called Indie Overlook. I want to plug, they did a review of my game, they got the idea of the feeling of mythology and war is a key part to the game, and also they were critical of some aspects of the game, which I totally agree with, like I agree with what they liked about it and what they didn't like about it, so Indie Overlook, check them out. And the original world and story is one of the main things, so basically everything you see in the game has a lot of backstory and thought behind it, and I'm thinking about Lord of the Rings, because if you're reading Tolkien, he wrote oh and they passed the hill, we'll say well, the hill, you know, once upon a time there was a kingdom on the hill, and before that there was this other Kingdom on the hill, and before that the elves were on the hill, and before that this happened on the hill, he's thinking about not the world in terms of the static thing, but all these layers of history that happened, mythology really. I tried to kind of like put that feeling into everything; everything has ancient roots in my world, ancient roots, and you can find out about it via conversation, but you also can find ancient tablets that you can get translated, you can read more about it. You can also skip this part of the game if you're not a Lord guy, if you just like tactical RPG and story, that's cool. That part is optional, but it's a pretty original world the characters are pretty original, the story is totally new, so that was the idea with the first bullet there. Turn-based combat was another goal of mine, I like turn-based combat, I feel like in the US not many games are made with turn-based combat, definitely not a lot of big games.

16:38 Michael: Would you say it's more like a Japanese style?

16:40 Joseph: I would definitely say Japan has us on this one, right, and I happen to like the turn-based stuff, maybe it's objective I feel like it's a little more thoughtful, but I like real time sometimes too. So I think they're both valid game systems, I just happen to like turn-based better. And it's pretty unrepresented these days, although if you go back to the eighties, real time is pretty on the representatives, because real-time was just harder to do I imagine.

17:10 Michael: Yeah, absolutely I think it started out as a, it was a requirement, right? I mean, in the early games.

17:15 Joseph: Yeah, pretty much.

17:15 Michael: You didn't have the same environment.

17:18 Joseph: Pretty much, and the idea of the turn-basedness of this game is that it will run as fast as you need it to. If you go back and you play Ultima 4, which you should, it's great, if you get good at that game, you and start inputting commands as fast as your fingers can type. The ammo will just go. And that's the idea of my game, like if you can think and you know what all the moves and the strategic combat are, you can just play it and it'll be fast and will be fun because you're doing it so fast, that's a fun feeling, it's kind of a natural high to be doing things fast. I think Starcraft players can tell you, you know it's a lot of fun to move your pieces around fast, or if you want to be more thoughtful just slow down, and the game runs as fast basically as you need it to. And another thing that's fun about the combat is that A* algorithm that we mentioned earlier controls how of course all the monsters and attack and stuff, what I wanted to do was have A* control their decisions but I never got to that done. So you can use A* for not only to pass spatially, but you can pass through decisions like they could say what's my goal to kill the player, ok what different actions can I do, and almost use those as spatial locations in A*.

18:32 Michael: Wow I see, I hadn't really considered applying that algorithm that way, but if you've got like a decision tree that has different outcomes you can use it to sort of put that together. Okay, interesting.

18:42 Joseph: It's super cool called planning I believe, I have a friend told me about it, I didn't come up with it. And, I get to implement that, but hat would be a future work for you guys at home. Each character of course has unique abilities in this game, so I wanted to avoid RPGs like you have to level up and stuff like that, and you have to grind and all that stuff; and then combats impossible to balance because now you got to level 10, well your enemies are down to level three, how did you know that? Maybe you're level 2 and the enemies are too hard, that's not fun. So basically, if you think of the game like Advance Wars- have you played Advance Wars?

19:24 Michael: I haven't played it, no sorry.

19:26 Joseph: How about Fire Emblem?

19:27 Michael: No. I haven't played games for a little while, I used to play turns but I haven't played it for a while.

19:37 Joseph: Oh my god, oh my god this guy works too hard. Ok, this is a great turn based games Fire Emblem and Advance Wars, and they are all Game Boy advanced games I think, they are still making them now, some of them. They are all perfectly balanced because there's no levels and basically they just lay out a scenario and you have to fight through it and they all work, that's kind of the goal with the different characters and their different abilities with me, so there's no there's no XP but I can balance encounters perfectly, or as hard as I wanted to make them at least. Basically I set down the characters and I set down all the monsters and I know they're stacked exactly and all their abilities, and each of the characters have different ways to solve problems, like you got your tank guy who can deal damage and receive damage and you got characters with really different AOE and your character can set traps, a character who has more like utility stuff. So different abilities have to complement each other.

20:36 Michael: Sure, and I like the way that you balanced it because that is one of the hardest parts of creating a game, create it in a way that it's challenging but not frustrating and I think that's really, really cool.

20:47 Joseph: I totally agree.

20:47 [music]

20:47 This portion of Talk Python To Me is brought to you by Hired. Hired is the platform for top Python developer jobs. Create your profile and instantly get access to 3,500 companies who will work to compete with you.

20:47 Take it from one of Hired users who recently got a job and said, "I had my first offer on Thursday, after going live on Monday and I ended up getting eight offers in total. I've worked with recruiters in the past but they've always been pretty hit and miss, I've tried LinkedIn but I found Hired to be the best. I really like knowing the salary upfront, privacy was also a huge seller for me."

20:47 Sounds awesome, doesn't it? Wait until you hear about the signing bonus- everyone who accepts a job from Hired gets a $1,000 signing bonus, and as Talk Python listeners it gets way sweeter. Use the link hired.com/talkpythontome and hired will double the signing bonus to $2,000. Opportunity is knocking, visit hired.com/talkpythontome and answer the door.

20:47 [music]

21:56 Michael: Let's talk about your Reddit post. So you wrote a post on Reddit that was super popular, you wrote and the title was "How I Built An Entire Game And Toolchain 100% In Python Using PyGame" and it got 894 more than that, over 894 upvotes.

22:16 Joseph: I know I was so excited. People love their Python, what can I say.

22:21 Michael: Well, you know what I think is interesting is like if you wrote a post that said how I created an entire game world in C++, or how I did it all in objective C and I put it on the ipad it's like, okay yeah, that's what people do. But I think it's that people love Python and experiences like you're having are just pushing it just a little bit out of its comfort zone of building data-driven web apps and data science tooling and things like that, and I think it really unleashes the creativity and you know the ideas like, oh, I could do that too in Python, how cool.

23:00 Joseph: You're actually right, and you actually can do that. Like Python is as long as you keep the scope of your game down to something simple like I did, it is totally very well equipped to help you write your game and it feels like an act of expression, rather than act of hooking boiler plate you know layers of code together. You're actually, you feel like you're writing a game again.

23:25 Michael: You write less so the joy is more apparent maybe?

23:27 Joseph: Yeah, you write less and you write the stuff that has a logic bits that are gained bits basically and it's quite the experience, I recommend picking up PyGame and even if you [00:23:39] you know just make something, it'll be fun.

23:41 Michael: Ok interesting. So we talked about why you got interested in Python and why you thought it was really cool, but what made you say okay I can actually use Python to write this game before you had the experience of doing it?

23:54 Joseph: Well I didn't know, I didn't know. So I wrote, first I wrote that little program I can't remember what I did, I needed to automate some process and I wrote in Python, it was really impressive, I wrote in so a few lines of code. Next I said well you know, I love 16 color graphics, real eighties style stuff. Most people it's like they're trying to be retro but they kind of push it past what retro actually would have done, which is fine, but I actually wanted true like 16 color stuff, so I wrote a paint program in Python and this paint program it's going paint 16 colors and it would also allow you to animate your stuff and stuff like that, and after I wrote this paint program, it was an experiment I didn't know I was going to write the whole game, I was just like you know I'll start, I'll write a paint program and after I wrote the paint program, I was like you know what, I'm going to write a map editor and I think I'm going to try to write a full game in this. It was kind of a long way of answering your question.

24:50 Michael: Yeah, I know it's like, you just said well maybe it's possible, let's see. And let's get started, yeah?

24:54 Joseph: Yeah, that's what it was.

24:55 Michael: So the first thing that you said, well if I'm going to create this world that we described in the beginning, and it's going to be this retro world with 16 bed and this kind of music and so on, you said alright, the first thing I'm going to need to be able to do is basically issue commands to the game engine or the toolchain and so on, so you built basically a command-line interface or more almost like a repl, like a console for your set of tools in your game right?

25:27 Joseph: Yes and I would recommend doing so for anyone and any hobbyist. Basically, even before the paint program I knew if I was going to write any tools I would need to be able to issue commands for it, and there's UI toolkits out there and you can use whatever you want, but I wanted real fast iteration and there is really nothing as fast typing, mousing around picking stuff up menus aren't really that fast and not really that flexible, and every time you want to add something to your menu you have to deal with all that UI work whereas the old-school style typing you can add a new command to your program pretty easily. I wrote this little console in PyGames, and all that you do was type into the console and you could hit enter or delete, or whatever you want in terms of that. And that was it, it didn't do anything in and out of itself, but every other tool I made, and the game itself if you play it will use it, so if you play the game at the very bottom of the game screen you see things printing out like oh you move north, oh you talked to this guy, and it will print out that's all the console, it's working, it asks you if you want to save, yes or no.

26:36 Michael: Yeah, that's cool.

26:37 Joseph: It's still doing its job, it's a hard worker.

26:40 Michael: That's really cool. That you reuse it, even into the gameplay, that's great. So you have this paint program and because it's really 16-bit there's like 16 choices for color so you click on the color you want and then you've got kind of a square and it's almost like building icons I felt like, I kind of felt like an icon editor because the size and resolution of things. You also had a map editor and I thought the map editor was pretty cool. That was also in PyGame right?

27:08 Joseph: Yeah I have that open right here, so the paint program with 16 colors so more like four bits, even before 16 bits. I think the graphics are about the year 1984 with this game so quite a bit before Super Nes and those things, pretty retro. The map editor was [00:27:31] and of course now that I had the ability to paint tile basically laying out the tiles gets you a map and at the bottom of my map editor our [00:27:41] friend the console and that's the side I made a palette of different tiles you could choose from, of course I ended up writing, painting quite a lot of tiles through the game it ended up being kind of my hobby, I don't know exactly how many but I might open folder of game assets and I'll tell you how many things I've made with this paint program, 826 items were made with this paint program.

28:06 Michael: Like little walls and brick walls and stone walls and water and by the way this is kind of a visual thing that we're doing over audio which is tough but in the Reddit post as well as in the show notes, you can link to all the screenshots for all these tools and so on, so you'll be able to pull them up.

28:25 Joseph: Yeah please go ahead and check out that Reddit post, it has a screenshot of this map editor. Although it's a pretty basic map editor, it's definitely something you can consider writing yourself even if it's just for educational purposes, it's fun to write a map editor.

28:40 Michael: Yeah for sure.

28:41 Joseph: To save load I used pickle so it's just, pickle you know obviously it has five hundred percent secure someone gives you a pickle file and you open it might blow your computer off, but you know, don't do that and and you're ok. I didn't write any saving and loading code at all for this program, I just used pickle I was just like whatever.

29:01 Michael: Yeah just basically take the memory structure of the Python object and just stash them binary to disk and then pull them back up, right, that's more or less the idea.

29:10 Joseph: Yeah, it's fast for a game like this, right, it's perfectly fine and if you write a lot of the games, saving and loading is a thing, I mean you have to deal with it. And I just pickled a bunch of Python dictionaries and the first thing in the dictionary was the version right, this is version 1.0 and the reason versioning is important is because of say I patch to the game, and I did patch the game, you want to up version everyone save files you don't want to have people have to start over because you decided to drop a new version, and even for me when I'm deving it I mean, there's probably like seven or eight versions of the saves, I don't want to have to lose all my saves so it's important that your save loader be able to filter off old versions of saves, even from the very beginning, so I can take that three year old version of Epikus and just load up the characters from it and play the game. And that's just all using Python dictionaries, first thing is dictionaries. The version and then everything else is you know, what characters you talk to, what items you had where you are in the world. And map editor uses the same [00:30:13] the game so pickling and one pickling and I think I did some light compression because the maps got a little too big for pickle and I had to like compress it before I pickled it, but it was all in the realm of Python, no C stuff is going on here at all. And the map editor, basically it lets you choose what category of object you want to like group things, like you can work on natural objects, or things indoors, things in caves or, monsters or whatever you want to work on, you just paint them out with the mouse, this tool does use the mouse, I feel like for painting things the mouse is a great tool, and it lets you using in and out with the wheel.

30:53 Michael: Yeah that makes a lot of sense. Did you, so this world is pretty immense and you can walk around from place to place. Did you like sketch this out on paper, like how did you go to designing the larger world and then connecting it to what you actually do in the tools like in the editor?

31:08 Joseph: For the tool's, first I sort of, I still wasn't totally convinced how can I do this whole game, so I just made a little house in the map editor, a little house with some windows, let's have a little fireplace and some candles, and if you play the game this is where the game starts, so the first scene you'll see is this house, but interestingly, that's the first map I made. And after I made that I was pretty convinced like make a big world, I made some other medium size things, I made some towns which are like bigger than the house, but not really huge; and then I decided to make the game world and as you said, I sketched it out on paper, I planned the whole game out, so you can imagine I wrote a plot so I knew where everything had to be [00:32:07] this is impossible in the game with multiple people programming it or designing it, because you know, different people come up with different things, which is fine, but if you're doing a one-man show like I did, you can plan stuff out and you can stick to your plan if you push yourself hard enough and then it's all planned out, so you can kind of almost catch it on a paper and stick with that sketch and I think I still have the paper around here, but I'm not going to look for it.

32:31 Michael: Yes sure, that's really cool. Nice, so we talked a little bit about some of the things in the game, in terms of the algorithms and what it took to build like how you save and load, the A* algorithm for a path, and AI. But, can we maybe talk about it in general, like what's it like to write a game for PyGame. I looked at PyGame a little bit, I haven't really written to any games, the last time I wrote something it was 3D and then OpenGL and it was more of a simulation than a game for something I was actually working on at a job. But I remember what it's like to write those types of things in say C++ and OpenGL or Directx you know, you've got kind of like an animation loop, you run your AI step, you run a rendering step, you do process input, like what does it look like to write and PyGame? And how does that compare?

33:25 Joseph: It's very simple, actually, it's good or bad depending on how you use it. So, PyGame is simple, it doesn't give you much, so scope your project to playing to PyGames strength and you'll be very happy, if you scope your project, if you are trying to do things PyGame can't do, don't use PyGame. But basically it gives you, you have to use- I want to use PyGames because it was pure Python, what the code looks like is your pretty much normal game loop controls everything, so in most 3d games or other games I've worked at you know at some point in the program there's a loop and the loop does something like take input from the first part of the loop, take input from the keyboard, or from the mouse controller; second part of the loop draws the screen, third part of the loop run all the AIs, all the characters and then you're done, and then it loops again and it draws the next frame of the game, and this is more or less how a lot of games are in, of course you could say what about networking, and all these other features- yeah sure, I mean that could be in the loop or probably not, it's probably interrupt driven or some other messaging system, but for me, it was basically, it's a very simple game loop, take input, draw the screen, run the AI; that's it and drawing the screen of course, not sure if any of those bits you want me to elaborate on, but that's generally what the game loop should look like for PyGame.

34:58 Michael: Okay, yeah I think that's, I mean we don't want to go too deep in code on audio, but at the same time I want to give people a sense for what does it look like, what pieces do you put in there, what pieces does the framework itself, what does a PyGame itself support, you know. So that's really cool. You know you talked about making a plan. So one thing that I thought was interesting, that you talked about and really a powerful message was how long it took you and sort of your process for getting the game done, right, I mean this is a lot of stuff, you're building a lot of apps, you are building a console system, you're building a paint program, a map editor, a file format, AI, there is a lot of things to do just to have the game and then you've got to like build websites and market it, so why don't you tell us about how long it took, and kind of like how you stayed on track?

35:57 Joseph: It took I think about two years to make the game. I was also working a full-time job during this.

36:05 Michael: Yeah, that's a lot of work.

36:06 Joseph: No excuses- I'm working, I can't do it, you can do it, just do it.

36:09 Michael: Yeah, I mean if you come home, on any project, on a project like that if you say look I'm going to take and just dedicate an hour a day and maybe not every single day will that work, but if you're playing is I'm just going to do a little bit every day, you know, you can do it, I think it's maybe one of the messages from that you are you're carrying there.

36:28 Joseph: Yeah absolutely, you can totally do it, do what I did. Say I'm going to program my Python for 15 minutes today, just 15 minutes. Then you can probably do that and then even if you're scared or having creative block, just do that and then, next day you have to say well now I have 20 minutes, and eventually you can see where this is going, pretty soon you're doing for an hour, do it for an hour for a couple weeks, and then two hours. Once you're at two hours you're done, just do it two hours a day, and if you're in that habit of doing two hours a day you'll want to do it more, because you'll be in such a good habit that over the weekend you'll do six or seven hours right, if you have whatever you can do with your friends, go over your friend's house to play D&D, just lock yourself in your room and only program Python. But you'll want to program a lot if you're in a good habit, because it'll just be normal for you, it won't be weird.

37:22 Michael: Yeah, you do have to make a habit out of it, I think that's important, whether it's a game or a website you're trying to launch, or an app or anything, right, but if you're going to create something that is long-term like this, you definitely have to make it a habit, and I also think seeing success encourages you to keep going, because you're excited like look what I did last week I'm going to totally do this thing, look how far I'll be next week, right and you just keep going.

37:47 Joseph: Yeah absolutely, if you don't see any fun stuff coming out of it, it can feel really burdensome, so start with something small, start with your paint program, don't start with the whole game and then at least you can say well I made a paint, you knew if that's all you do and that's as far as you get before giving up, at least you have that.

38:05 Michael: Yeah, that's really cool. You also talked a little bit about running into bottlenecks and helping yourself get over those, like what are some of the bottlenecks that you hit trying to go through this project?

38:14 Joseph: Well, none of it really had to do with Python, luckily, so there's that and the Python code never got complicated, never got boilerplaty, it was always small and the main bottlenecks from Epikos specifically was I never wrote a tool for the cinematics, for the non interactive conversation, so if you've ever played Final Fantasy one of the early ones, like four or five, people talk to each other and it's totally scripted, and it's fun to watch, I wanted a little bit of that experience in my game and I thought it's only going to be a few of these conversations in the game, and then there ended up being like hundreds, and basically like probably like if you imagine that the game took two years, like fourth of that is probably writing these cinematic scripts and they just got more and more and more complicated because I would always try to do better, right, I would say well I did that before I can do better this could pass an earthquake, and it has to have a new font show up magically, I never saw this font before, it's going to look really magical or this one has to start playing sound, and then I have scripts that are playing sound; well now that sounds all my previous ones, they sound dumb you know, they feel dumb... So I basically ended up writing the scripting language that sits on top of Python to do all my cinematics, and it worked, like it shipped but it was just not ideal, and what I should have done was write something like a movie editor, or if you can imagine like a tool where you would scrub through a scene and-

39:58 Michael: Almost a multitrack thing.

39:58 Joseph: Like animating. Exactly, like track editing, and I should have done that, I didn't, so I think the lesson is make sure you have the tools before you dive into deeply, I did that mostly and I didn't do it enough.

40:13 Michael: Yeah, so one thing that I think is interesting shifting gears a little bit, you built your game and you want to get it to people. One thing I think is interesting that is more difficult than it should be in Python and there's interesting projects working on that, you use some that we're talking about and we will, as well as some others, is getting your Python code in your application sent to somebody who can run it like an application, rather than like here's a bunch of scripts, make sure you have these packages installed, right? So how do you go about shipping and packing up the game?

40:50 Joseph: So, I tried everything and the answer was this was pretty technically challenging thing, it wasn't just your typical happy Python coding, it was just like how I'm going do this. I tried kind of everything and what I ended up using was- I couldn't to get [00:41:08] to work which is people with normal route and when they open up my little script

41:11 Michael: Yeah, what are the other projects that comes to mind that I think is interesting, is the Beeware project, and they're working on ways to package up apps that work good for OS 10 for Linux or Windows, things like that and so, but this is a new project coming, I think we'll get there, but it is definitely a place where it's more challenging just to create a thing that you deliver with no assumption of Python or anything.

41:39 Joseph: It's hard, I did something called PyInstalle, so if you grab that I'm telling you right here it would work with PyGame I believe Python2 exe either doesn't work with PyGame or you have to spend days and days to get it to work and it's not really worth your time. So I would say PyInstall, if you read that Reddit post, people made better suggestions than PyInstaller which is some of the beauty of Reddit, right, so there's even better options out there, if you read the post, but if you don't read the post, Py Installer will work for you. And running that basically I was able to make my Python scripts into an exe and then it was simply a matter of packing up the assets with those, so I have a distribution script which I recommend everyone make, and basically when you double-click on the script it takes all your code and builds an exe, and it builds even an installer and basically then you can give that to your friends, rather than giving them a bunch of source code.

42:42 Michael: That's right, I mean, on one hand you've got a package of the Python game so it runs, but then you also have to package up that plus the assets into like an installer so an msi on Windows a PKG on OS10 or something like this, right? It's not just one layer it's several layers. It's frustrating work as well I think because you have a thing you're trying to give the people finished, but you can't give it to them until you go through like this other step of like polishing this delivery.

43:15 Joseph: Exactly that. And it's different on every platform of course, the good news on Linux is you assume people can unzip, but you know a tar file so I just give a tar file, I don't think Linux guys want installer, say I wanted this directory here, ok here you go, whereas I think Windows is a little bit more like different barrier of entry, so you want to so rt of double-click up on it, install somewhere you can see where that is or not, and I recommend not doing any tricks like with the registry, like most programs do you install, like my program if you delete it it's gone, it's off your computer to move it will still work, it doesn't need to know where it was installed, very old school.

43:55 Michael: Yeah, definitely no registry and none of that stuff on Windows which just makes your life hard. So, it runs on Windows and it runs on Linux according to your website but if I recall correctly, I played your game on OS 10, so is it also supported on OS 10, or did I get the Linux version somehow?

44:15 Joseph: Some people have figured out to run it on OS 10, and they've done it like a Linux emulator or Windows emulator [00:44:24] if tried you know different things and this is not officially supported, so one guy sent in a crash report on like I look at it but I don't have a mac I don't know if I can do this for that system, so you might be able to get to run on OS but there's no guarantees.

44:43 Michael: Ok interesting. So, I would say Linux and Windows are most [00:44:48] platforms and if sales pick up and it makes sense for me to do a map, I'll go out and buy Mac, I can't run in virtual box I tried, you know, I don't think it's supported in virtual box, so I can't just emulate a Mac.

45:00 Michael: You know, it's possible that I ran it on windows 10 in parallels on my Mac. Interesting.

45:13 Joseph: And all this support took only a day, so if you think about like Python one of its strength is, it pretty much will run anywhere, so you know Linux support had some capitalizations in some of my file names I had to fix, and of course you have the total [00:45:27] we do the distribution and you know the thing that makes an exe, that doesn't work at all the same way on Linux but besides of that stuff, the game should run really easy and one thing to keep in mind with PyGame is most 3d applications don't work through a virtual box, but PyGame does, so you can even be having your windows system open and open a virtual box with PyGame in it and it'll work fine, so you can dev for Linux and windows at the same time, and it'll be quite nice.

45:57 Michael: Oh that is nice, you don't have to do a boot or anything crazy like that.

45:57 [music]

45:57 We all want to ship our software faster, respond to user request quicker and build an edge on the competition. But the faster you go, the more likely a bug or issue will slip by and cause your users' grief. I have the same trade-offs with my Talk Python websites and infrastructure. That's why I use Snap CI. Every time I check into github, Snap CI springs into action. A clean copy of code at pofan github, a Python 3 virtual environment is created, all the packages and dependencies are installed, the unittests are run, finally, I'm notified in Slack and menubar on my Mac about the outcome. That way I know it's safe to ship a shiny new version of my web app. Ship your software faster with the 30 day free trial at snap.ci/talkpython.

45:57 [music]

47:00 Michael: Could you build a 3D game in PyGame?

47:04 Joseph: Nope it's all about 2D, if you want you're going to have to go into the PyGL stuff which is fine, but don't forget if you know devs at home like ninety-nine percent of the games of games problems arise because they're in 3D, everything is just much more complementary and I love 3D, I do it at work but for side-project, be careful about 3D unless you want something that looks like Minecraft very simple, you know, be very careful about 3D. PyGame avoids a lot of these problems, by being 2D.

47:38 Michael: Yeah, that's great I've done a few major things in 3D and there's so many little catch-ups and hang-ups you can get caught on, like why don't I see this, well I drew it you know, clockwise vs counterclockwise, and I was invisible because that came from the wrong directions, it's just like oh gosh.

47:57 Joseph: It's really complicated and it’s really a career, doing 3D is really a total career and there's specialists to deal with that; it's really all that work.

48:11 Michael: Yeah, to make it look professional, it's really hard. Ok, that's interesting. You know one thing I wanted to give a shout-out about, you've seen the movie Indie game, Indie game the movie?

48:23 Joseph: No, I haven't.

48:23 Michael: People should check out Indie game the movie, it's really interesting, it's not quite the same story as your story because you had a full-time job and you're doing this sort of as a side project which is I think a really cool thing to do; these guys, they spent like two years working on these Indie retro games and it kind of takes you through their journey, but it's also more similar than it is different to this. If you're looking for a good documentary about this kind of stuff, check out Indie game the movie, that one is a good one.

48:52 Joseph: Most Indie games guys still have studios with 5, 6 people in them what's weird about my project is that I did it myself, because my game is just so retro and so unique that I tried for years to convince artists to help me and programmers to help me, and they're like what you want to write a game that's like actually using eighties era technology, you must be nuts. Nobody would help me write this game, so then should I said well I have to write it myself, and at that time Python came along, I thought this is how I'm writing this game. Python is a way to go.

49:26 Michael: That's really cool they lined up that way, great. I think we should probably leave it there, were kind of getting long on time, but before I let you go, let me ask you two questions I always ask my guests: you must have come across some interesting PyPi packages that you could use to make your game work, I mean, PyGame among them probably right? What one is your favorite that you feel like you want to tell people about, they maybe don't know about>

49:48 Joseph: I want to plug PyGame and Pickle, those are super cool. PyGame and Pickle, check them out if you're new to Python they're really cool.

49:56 Michael: Ok, excellent. And when you write Python code what editor do you use?

50:01 Joseph: I use Notepad.

50:03 Michael: Wow okay, awesome. You are being serious?

50:13 Joseph: I'm serious guy Notepad++ by the way, not just Notepad.

50:15 Michael: Yeah, cool, of course it has to understand you know tabs and paces things like that right. Okay awesome, alright well Joseph, this was a really fun story and thank you for giving us a look inside what you built and how you built it. How about a final call to action, what could be, if people are excited about your project how do they check it out, what do they do?

50:36 Joseph: So you can go to epikosrpg.com and there's links to how you can buy it, at itch.io, if you want to buy it through there, you can follow me on twitter I'm JJC_Coder and I would love to hear from everyone whether or not you played the game, even if you didn't like the game, I'd like to hear what you didn't like about the game, and if you liked the game I would like to hear what you liked about the game. Game is moddable so I want to see people's alternative tile sets, I saw quite a few good ones already, so I want you guys to make tiles, make the game look like you want to make, maybe you don't want to be 16 colors maybe you want 128 colors, go for it, I want to see what you make.

51:18 Michael: Awesome. Alright, well thank you so much for being on the show, it was a fun conversation.

51:23 Joseph: Thanks this was really great.

51:23 Michael: Yeah, you bet.

51:24 Joseph: Good luck.

51:24 Michael: Thanks, bye bye.

51:24 This has been another episode of Talk Python To Me.

51:24 Hied wants to help you find your next big thing, visit hied.com/talkpythontome to get five or more offers with salary inequity presented right up front, and a special listeners signing bonus of 2,000 dollars.

51:24 Snap CI is modern continuous integration and delivery. Build, test, and deploy your code directly from github, all in your browser with debugging, docker, and parallelism included. Try them for free at snap.ci/talkpython

51:24 Are you or a colleague trying to learn Python? Have you tried books and videos that left you bored by just covering topics point-by-point? Check out my online course Python Jumpstart by Building 10 Apps at talkpython.fm/course to experience a more engaging way to learn Python. If you're looking for something a little more advanced, try my write pythonic code course at talkpython.fm/pythonic.

51:24 You can find the links from the show at talkpython.fm/episodes/show/78

51:24 Be sure to subscribe to the show. Open your favorite podcatcher and search for Python. We should be right at the top. You can also find the iTunes feed at /itunes, Google Play feed at /play and direct RSS feed at /rss on talkpython.fm.

51:24 Our theme music is Developers Developers Developers by Cory Smith, who goes by Smixx. Cory just recently started selling his music on iTunes so I recommend you check it out at talkpython.fm/music. You can browse his music there and listen to the full-length version of Developers Developers Developers.

51:24 This is your host, Michael Kennedy. Thanks for listening!

51:24 Smixx, take us out of here.

Back to show page
Talk Python's Mastodon Michael Kennedy's Mastodon