Latest / Talk Python To Me / #223: Fun and Easy 2D Games with Python
Transcript
- 0:00Have you tried to teach programming to beginners?
- 0:01Python is becoming a top choice for the language,
- 0:05but you still have to teach them how to work with the language
- 0:08and understand core concepts like loops, variables, classes, and more.
- 0:11It turns out video game programming, when kept simple, can be great for this.
- 0:16Do you need to repeat items in a scene?
- 0:18Well, there's a natural situation to introduce loops.
- 0:21How about move an item around?
- 0:23Maybe make a function to redraw it at a location.
- 0:25On this episode, you'll meet Paul Craven, who created a new 2D game engine for Python
- 0:31just for this purpose called Arcade.
- 0:33And even if you don't teach or you're not learning Python, it's great to play with.
- 0:37It's really easy to make 2D platformer and side-scroller games.
- 0:41This is Talk Python To Me, episode 223, recorded July 25th, 2019.
- 0:47Welcome to Talk Python To Me, a weekly podcast on Python,
- 1:04the language, the libraries, the ecosystem, and the personalities.
- 1:07This is your host, Michael Kennedy.
- 1:09Follow me on Twitter, where I'm @mkennedy.
- 1:11Keep up with the show and listen to past episodes at talkpython.fm.
- 1:14and follow the show on Twitter via at talkpython.
- 1:17This episode is sponsored by Indeed and Rollbar.
- 1:20Please check out what they're offering during their segments.
- 1:23It really helps support the show.
- 1:24Paul, welcome to Talk Python.
- 1:26Hey, great to be here.
- 1:27Thanks for having me, Michael.
- 1:28Yeah, it's great to talk to you again.
- 1:30We got a chance to meet each other at the creator's booth part of the PyCharm booth at PyCon.
- 1:37That was fun.
- 1:37Yeah, I enjoy PyCon a lot.
- 1:39Yeah, so did I.
- 1:40I call it my geek holiday.
- 1:41In August, I'm going to go on holiday with my family, but in May, I went on the holiday with my friends and my geek friends.
- 1:49It was great.
- 1:49Thankfully, it's the only conference I go to, and I look forward to it every year.
- 1:53Yeah, yeah, absolutely.
- 1:54And while we were there, you were presenting your project that ties in both to your teaching side of what you're doing at the university,
- 2:04but also just making gaming and Python more fun, this thing called Python Arcade.
- 2:09So I'm really looking forward to talking to you about that.
- 2:11Yeah, it's a project I'm really passionate about.
- 2:14Yeah, I can tell.
- 2:14So before we get to that, though, let's start with your story.
- 2:17How did you get into programming and then Python?
- 2:19Video games, actually.
- 2:20Long ago, I worked with an Apple IIe.
- 2:24My dad had gotten one of those, and being the evil father that he was, he wasn't going to just pay for video games for me to play.
- 2:30So he said if I wanted to play games, I'd have to program them myself.
- 2:36And there's a few books out there by David All, more basic computer games and basic computer games.
- 2:43And they basically just had computer games in basic that you could type in.
- 2:48And I got started programming doing that.
- 2:51And once you had the game in there, you could start modifying it and customizing it the way you wanted.
- 2:55I just absolutely love that as a way of learning to program.
- 2:59And that's how I introduce my college students, many of which haven't programmed at all, to try to get them hooked into programming.
- 3:08Because it's not just me teaching them programming.
- 3:11If they only take one semester, it's only a limited use.
- 3:13But what I really want them to do is realize that programming can be fun and entertaining and a creative process that they can get into just because they plain like programming.
- 3:24Yeah, absolutely.
- 3:25I definitely think that that's an interesting angle to help people get more engaged.
- 3:29So that's basic was the sort of entry point.
- 3:32But where do you learn about Python?
- 3:34I had a student actually present it.
- 3:36We were teaching programming in Java, which is a terrible language to teach programming in.
- 3:42It was the main way to do it for most schools for a long time.
- 3:45Oh, it was a step backwards from like Pascal.
- 3:47And that's how we were teaching it.
- 3:50And he gave a presentation on Python.
- 3:52Wasn't too interested in it at first because the last thing I needed to do was learn another computer programming language.
- 3:57But his presentation was actually really good.
- 4:00And it got me thinking about how simple and incredibly straightforward you could get somebody started with programming.
- 4:06And then that just got the bug in my head that maybe this would actually not be a bad way of teaching programming.
- 4:13So we started now it's pretty common to start teaching in Python.
- 4:16But when we started teaching in Python, it was not the common first language by any means.
- 4:20Yeah, absolutely.
- 4:21It was all about Java.
- 4:22When was this?
- 4:22What time?
- 4:23What year?
- 4:24About?
- 4:24I would guess it'd be about 11, 12 years ago now.
- 4:26Yeah.
- 4:27Okay.
- 4:27Interesting.
- 4:28So Python was not nearly as popular and clearly the right choice as it is today, I guess.
- 4:33Yeah.
- 4:33No, not at all.
- 4:34And it took a little bit of convincing for me with the other people at the college in order to be able to do that.
- 4:40And we started introducing it, you know, just a few weeks at first and then, you know, eventually moved on to the entire semester.
- 4:46So our first semester is Python.
- 4:48And then once they get hooked into programming, then we hit them with Java after it's too late and they've already signed up for second semester.
- 4:54There you go.
- 4:55They're already committed.
- 4:57Well, I think that that's an interesting way to think about it because I think that a lot of the ways that programming is taught, and I don't just mean like self-taught, I mean like even in like universities and stuff, I think it's kind of broken.
- 5:09I think it's taught with an expectation of extreme delayed gratification.
- 5:13I've talked about this before, but basically like we're going to teach you loops.
- 5:18We're going to teach you variables.
- 5:19We're going to teach you memory.
- 5:20We're going to teach you the heap.
- 5:21We're going to teach you pointers.
- 5:22We're going to teach you all these things.
- 5:24So maybe at the end of the semester, you can do something sort of interesting, maybe.
- 5:29But you might have to wait a couple of courses after that before you actually build something that you care about.
- 5:33And that's just, it's crazy.
- 5:36It's not just delayed gratification.
- 5:37It's delayed explanation.
- 5:38Public, static, void, main, string, args.
- 5:41I mean, you can't explain all of that in their first lesson just to print something to the screen, right?
- 5:46Just type this in and we'll explain maybe sometime later in the semester how it works.
- 5:50That's not how I want to do it.
- 5:51I want them to understand exactly what they're doing.
- 5:54Yeah, exactly.
- 5:55So I definitely like that you're starting with something that gets them to like these short little wins quicker.
- 6:00Then you can move on to stuff where you're talking about static languages like Java or whatever.
- 6:04When they're already understanding like, okay, if I go through this, the payoff is really big or here's how I'll use it or whatever.
- 6:11Right.
- 6:11That's exactly it.
- 6:12It does assume that they'll like arcade games.
- 6:16But a lot of my students aren't as interested in spreadsheets and are a lot more interested in arcade games.
- 6:23So I can hook a fair percentage of them.
- 6:25When we were talking, one of the things you said that I thought was pretty interesting is much of what you have to teach for programming, there's some kind of visual aspect to it, right?
- 6:34Like lists or data structures or loops or whatever, right?
- 6:41And it's one thing to just do that in like a terminal app or something like that.
- 6:45But you can actually visualize it better potentially if you have this simple game platform to test to sort of teach these more abstract concepts in.
- 6:54Right.
- 6:54A student can get really frustrated if they're supposed to get a 10 as an output and instead they get a 12 as an output.
- 7:00They don't really care.
- 7:01But if they're like drawing a football field or they're drawing a unicorn or something like that on their screen, then they'll spend a fair bit of time trying to get things lined up or just right.
- 7:12Right, right.
- 7:12If the horn points down, that's not okay.
- 7:15That's not okay.
- 7:16For the occasional student, they do want to just sort of give up at that point.
- 7:20But most students really will spend a lot more time if they see that visual image and try to get it just the way they want it.
- 7:28Maybe give us some examples of the types of things that you're teaching them there with games.
- 7:33Well, to start off with, one of the first things we do is just create an image.
- 7:37And the thing I like about using Arcade for that is that you can do it without defining a function before you get to that point.
- 7:45So you learn about how to call a function.
- 7:47And even just by calling a function, I don't have to have them create classes.
- 7:51I don't have to have them create functions.
- 7:53All they have to do are simple calls.
- 7:56And then they can actually build on that to create an image.
- 8:01And then that introduces them to the coordinate system.
- 8:03And you can go off of that so that if they want something like a fence and they don't want to create a drawing command for each individual post in a fence, then that just naturally leads itself to, oh, hey, wow, there's a solution for that.
- 8:18Let's introduce loops.
- 8:19Exactly.
- 8:19Yeah, because it's really painful to write 50 little fence objects and move them around.
- 8:23Exactly.
- 8:24And it's very iterative.
- 8:26And they can see the value in picking up that, hey, I need to learn about loops.
- 8:32Hey, oh, if I create a function, then I can create a function that'll draw a snowman.
- 8:37I can create a function then and call that function to draw a snowman here, here, and here, rather than just repeating the code over and over again.
- 8:44Yeah, sure.
- 8:44I do like that you can start in this really simple mode, kind of like the print of the world side of things.
- 8:50You don't have to have all the extra stuff, but you do have a pretty rich API, which do you want to talk about and get into.
- 8:55But maybe before we really dig into even to arcade, let's just kind of set the landscape for everybody.
- 9:01You know, not everybody is creating games or maybe more like me.
- 9:06They've messed with like creating games, but it was like 15 years ago and they haven't really done much since then.
- 9:10Right.
- 9:10So what are some of the options for building games?
- 9:13You know, what's the spectrum of what we could do?
- 9:15Well, at the low level, you've got the ability to just individually manipulate the dots, what I would call raster graphics.
- 9:23It's a very slow way of doing graphics, but it's the original way a lot of people have done graphics.
- 9:28Then there are a lot of libraries out there or APIs for like OpenGL, which is really big.
- 9:33DirectX, which is OpenGL is cross-platform.
- 9:36DirectX is very much Windows.
- 9:39And Mac now has sort of gone away from OpenGL and they're pushing their own metal as a way of doing graphics.
- 9:46So they have all these different APIs.
- 9:48And then basically to make it easier to program those, there are a lot of game engines that sit on top of those.
- 9:56You got the Unreal, Unity, Godot.
- 9:59There's several game engines that do that and take care of some of the underlying work for you in those OpenGL DirectX metal.
- 10:08Yeah.
- 10:08And a lot of times that means working like in C++, right?
- 10:11Like with Unreal or some of those other real game engines or Unity is C# or things like that, right?
- 10:16Right.
- 10:17Unity can do like C# or JavaScript.
- 10:18Godot's fairly popular.
- 10:20It's a lot more of a friendly type of language, but it's not Python.
- 10:24So there's different options out there, but all of them take a fair bit to get up and going.
- 10:32And I wanted something that was really easy for a beginning programmer to get working, but still allow a hobbyist or a more advanced user to create some cool games in their, you know, off time.
- 10:45Right. Well, so that makes certainly makes sense for Python and then like even maybe a simple API on top of that.
- 10:52Right. So, you know, you're not going to drop into like native OpenGL and C++ and say, we're going to teach you about data structures because like that's a deep world.
- 11:00I spent a lot of time writing simulators and doing programming there and it's fun, but it's not a simple place.
- 11:05Not necessarily friendly either.
- 11:06No, no, no, not so much.
- 11:08So in the Python world, I had heard of Pygame.
- 11:10That's been around for quite a while.
- 11:12I heard of Pygame Zero, which I didn't really know how that was different than Pygame until recently.
- 11:17What else is there?
- 11:18Obviously, there's Arcade as well.
- 11:20Yeah, pyglet, a few other ones, Coco's or 2D, I think.
- 11:25And Pygame by far is the most popular one.
- 11:28And I taught using it.
- 11:29In fact, even wrote a book on developing arcade games in Pygame.
- 11:34And I really like Pygame, but it has been around a very long time.
- 11:41So it kept a lot of backwards compatibility on Python.
- 11:46So it didn't use any of the new Python 3 features.
- 11:49And the maintenance on Pygame at the time had completely fallen off.
- 11:55So where I would try to make improvements and do pull requests, absolutely nobody was doing anything with that.
- 12:02Isn't that super frustrating when you're like working with this project, you love the project, you put a lot of energy into it.
- 12:08You go so far as like actually creating a pull request and submitting it.
- 12:11It's one thing for them to say, you know, it doesn't actually fit with our vision or we can't accept it or whatever.
- 12:16But if it just goes unaddressed, like that is really not the best feeling.
- 12:20Yeah.
- 12:20So there was a lot of back and forth on that trying to resurrect some of the people that were working with it.
- 12:27And I actually just try to do my own development because you could always create your own branch.
- 12:32But Pygame was developed off of an old library called SDL, a C++ library.
- 12:37And that library itself was pretty old.
- 12:42There's an SDL 2 version of the library, which I also tried working with and didn't much care for.
- 12:47The underpinnings on Pygame, just if you wanted to keep the backwards compatibility and update everything,
- 12:55it just didn't seem to me to be a really worthwhile effort, particularly when there weren't maintainers at the time.
- 13:03It's actually started to pick up on maintenance now, which is great.
- 13:06But I wanted something better.
- 13:08And I thought, gosh, since most of the people that I work with are starting from scratch,
- 13:13I could actually just start a game engine from scratch using something more modern like OpenGL and work off of that.
- 13:23Yeah.
- 13:23And you get all the benefits of like high end modern graphics cards, graphics, GPU accelerated stuff and all that.
- 13:29Right.
- 13:30Yeah.
- 13:30And I taught a long time using Pygame.
- 13:32So I found a lot of things.
- 13:34And there's a lot of things about Pygame I really like.
- 13:36So I was able to take those ideas and move it forward, try to clean up the interface, use the new Python 3 features,
- 13:43do the bugs that my students always complained about.
- 13:47Because when I teach, there's always these little warts you have to sort of tell the students about.
- 13:51And every hour you spend telling a student, oh, well, that coordinate system that you learned,
- 13:56well, it's different in computers because zero zero is in the upper left instead of the lower left.
- 14:01Or set mode is in order to open a window, you use a command called set mode.
- 14:07I know it's called set mode, but you really don't want me to get into that.
- 14:10And, oh, you want to make a football and rotating ellipse?
- 14:14Yeah, sorry, you can't do that.
- 14:15You start getting over these and you come up with a list of them over time.
- 14:19And it's just, gosh, I think I could do something better, quite frankly.
- 14:44And when you start a one-on-one conversation with one of their career coaches, you'll get resume reviews and personalized advice to help you get what you deserve.
- 15:04So if filling out countless job applications isn't your thing, let top tech companies apply to you.
- 15:10Join Indeed Prime for free at talkpython.fm/Indeed.
- 15:15That's talkpython.fm/Indeed.
- 15:20So you set out to do that, right?
- 15:22Yeah, basically I set out to do that.
- 15:25A lot of false starts, a lot of attempts on different backends.
- 15:30And so I got a fair bit of time into figuring out exactly how I wanted to do it.
- 15:35So yeah, Arcade is built off of OpenGL.
- 15:38It also uses pyglet for doing the window management.
- 15:42pyglet is also a pretty good game engine.
- 15:45And it is not nearly as friendly as Arcade, but opens a lot more of the internals.
- 15:54So when a programmer is more willing to dive into the internals, pyglet's not a bad option.
- 15:59Is there like an escape hatch in your API to like drop down to those internals?
- 16:03Or is it like take it or leave it?
- 16:05I mean, you could just import the pyglet library and start doing work in the pyglet library.
- 16:09I wouldn't really call it an escape hatch.
- 16:11Yeah, just directly work it.
- 16:13Yeah, just start working with...
- 16:15Yeah, it's not really something separate.
- 16:17Yeah, okay.
- 16:18The pyglet has their own system for managing sprites, which we can talk about in a bit.
- 16:22I really just use them for doing OpenGL calls and Windows event management.
- 16:28Okay, so there's not like a deep integration, like multi-layer thing.
- 16:31It's more just like, just take what they built and go with that.
- 16:34Right.
- 16:34For the few things you need.
- 16:36Right.
- 16:36And some of the, like Pygame Zero and some of the other, there have been a lot of things
- 16:40that have been built on top of Pygame.
- 16:42I kind of wanted to try to avoid some of that because you get too many layers of abstraction
- 16:48and things just get kind of weird after a while.
- 16:51Yeah, there's always that leaky abstraction or...
- 16:53Exactly.
- 16:53That thing that should be easy to do, but it's actually really impossible to do
- 16:56because something in the middle.
- 16:58Yeah.
- 16:59Nice.
- 16:59So it sounds like another one of your focuses on building Arcade
- 17:03was to focus on making it like Python 3 native.
- 17:08Right.
- 17:09Right.
- 17:09The ability to do type hinting, just going ahead and using f-strings.
- 17:16Quite frankly, I really like the type hinting in particular because when I get students that
- 17:22work in PyCharm and they have those little linters that go with it, it helps a lot of students.
- 17:30And it's not something actually I thought that would help students as much as it really has.
- 17:33I've gotten a lot better code once they get those hinting features that are available.
- 17:38Right.
- 17:38We expected a number and you're passing a string.
- 17:40That's probably not okay.
- 17:42Something like this.
- 17:43Yeah.
- 17:43Right.
- 17:43Exactly.
- 17:45And it's just, I kind of started working with Python 3 to begin with just at the beginnings
- 17:50of it.
- 17:51So I just am more used to everything that's Python 3.
- 17:55And thankfully that's not really such the issue that it used to be.
- 17:58Yeah.
- 17:58I saw some articles about Arcade and some commenters saying, oh, I can't believe you're using F
- 18:04strings.
- 18:05This means I have to have Python 3.
- 18:076 and I can't get that.
- 18:08How am I going to get that?
- 18:09You know, it's like, those are kind of going away.
- 18:10I think.
- 18:11It is a pain.
- 18:13I'm not going to make a lot.
- 18:15And well, I mean, until like a year ago, Ubuntu had 3.5 a year and a half.
- 18:20Not super long.
- 18:21Right.
- 18:21Like that's.
- 18:22Right.
- 18:22Even though 3.6 had been out for quite a while.
- 18:24It seems like Ubuntu seems to lag about, I don't know, a point version.
- 18:27Right.
- 18:28Like it's 3.6 now, but 3.7 is out.
- 18:31Yeah.
- 18:31I don't know their exact release schedule, but you know, that time is fixing this.
- 18:35Right.
- 18:36So I definitely think Python 3 is the right place to be for this and type hinting.
- 18:40It's super interesting.
- 18:41Do you do anything with it in terms of like changing behaviors or anything?
- 18:45Like that?
- 18:45Or is it just there to help students be more accurate?
- 18:48Really just help students be more accurate.
- 18:50One of the other things I've really liked is being in the classroom, customizing the exception
- 18:56messages.
- 18:56So as I get students that run into problems, having the exception and certain areas, I'll
- 19:04actually do a little bit of checking to make sure that they're actually passing in the right
- 19:08type of data.
- 19:09It slows things down if I do that too much.
- 19:12But where the most common mistakes are when you run a batch of 20 to 40 kids every single
- 19:17semester through using this, you really get a good idea of how to make the code library
- 19:25better.
- 19:26Yeah.
- 19:26Because you have a bunch of people that have no expectations of what to do correctly.
- 19:30So how do you help them fall into the pit of success and like make the most, the right
- 19:35thing, the most obvious thing and whatnot.
- 19:36Right.
- 19:37Right.
- 19:37It's one of the things I really like about in creating a library to iteratively be able
- 19:42to take people through the library and look over their shoulders while they're working
- 19:45on it is really valuable and improving that library.
- 19:49And the also having it out on the internet where people that you can't see give you feedback,
- 19:55having both of those different types of feedback is really quite nice.
- 19:59Yeah.
- 19:59That's super interesting.
- 20:00I mean, some companies, they have like usability labs for their developers and they bring people
- 20:05in and then like watch through mirrors and other ways of what they're doing.
- 20:08And in a sense, like that's, that's very, very rare for open source libraries, I would
- 20:13suspect.
- 20:13But in a sense, that's kind of what you're doing, right?
- 20:15Just because you're teaching and walking around in the classroom, right?
- 20:18Exactly.
- 20:19And one of the big features of this particular library is a large set of examples.
- 20:24And over the last 12, 13 years, I've been teaching with video games.
- 20:29I got this library of different things that students have asked for.
- 20:33And so I create all these different code samples and make sure.
- 20:36And that's one of the things that helped also in creating the arcade libraries.
- 20:39I had, I knew all these different types of things that people wanted to do and they wanted
- 20:43to create 2D arcade games.
- 20:45And I created the library.
- 20:47I needed to make sure that I supported all of those different items.
- 20:51And I had all that set of example code in Pygame.
- 20:54And then I basically had to make sure that I could do all of those same features in the
- 20:58arcade library.
- 20:59That is really handy to have all those examples.
- 21:01So I guess, you know, we probably haven't done a great job of just like defining exactly
- 21:07what arcade is and its point, right?
- 21:09So it's arcade is for building 2D platform-like or side-scroller-like games with Python, right?
- 21:16Yeah, or top-down.
- 21:18But basically any type of 2D graphics.
- 21:21And that's what arcade is really made to do.
- 21:24And it's made to do it so that people can get up and going simply and easily.
- 21:28It's not supposed to be a huge overhead or mentally taxing library to use.
- 21:34Yeah.
- 21:34Could you create like a tower defense game?
- 21:36Yes.
- 21:36The best game that we've got actually that I am aware of that's been built in it is a
- 21:40tower defense game, which is a pretty crazy game actually.
- 21:43I've wasted way more hours of playing that than I would admit to my student that wrote it.
- 21:48Is it online?
- 21:49Is it something people can check out?
- 21:51Yeah, actually, it's called Great Skeleton War.
- 21:53And there's a link to the GitHub repository on the Arcade Academy website that hosts the
- 22:02Arcade library.
- 22:02Yeah, nice.
- 22:04Yeah.
- 22:04So no, it creates great top-down, side-scroller, animated.
- 22:10It is really oriented towards doing that type of work.
- 22:14And it works on cross-platform, obviously, with OpenGL and Python on Mac, OS, Windows, and Linux.
- 22:21Is there any option for mobile or it's just a three at the moment?
- 22:23No option for mobile.
- 22:25Basically, those are the three main platforms that are in use.
- 22:28Yeah.
- 22:28Okay, cool.
- 22:29I mean, that's a totally reasonable thing, given what you're building, but I just want to check.
- 22:33So maybe give us a quick example of what the API feels like to write like a super simple
- 22:40game.
- 22:41You've got like a nice little example.
- 22:43And you even talked about how it doesn't even have to have functions or classes or anything
- 22:48like that.
- 22:49Right.
- 22:49If you wanted to do something really straightforward and just draw something to the screen,
- 22:54it's pretty darn straightforward.
- 22:56First off, you import the Arcade library, obviously.
- 22:59And then in the Arcade library is an open window command.
- 23:03You just give it the dimensions of the window and a screen title.
- 23:06Then the next command you do is you set a background color.
- 23:10It has a set of colors you can choose from or you can specify in a red, green, blue format.
- 23:18And the next, basically as an outline, you've got a start render and a finish render command.
- 23:22All your drawing commands have to happen between start render and finish render.
- 23:27Does that map over to like GL swap buffer down below or something like that?
- 23:30Yeah.
- 23:31Start render basically clears the screen and then the finish render will actually swap the
- 23:35buffer in front.
- 23:36Okay, cool.
- 23:37Then you've got commands such as draw a circle, draw a circle, fill, draw a circle outline,
- 23:42draw in a rectangle, drawing an arc.
- 23:44You can put bitmaps on the screen.
- 23:46All of these commands are actually slow to run.
- 23:50If you really wanted something high performance, you need to actually batch up these commands
- 23:55and then run a draw command.
- 23:56But to get started, you don't have to do that or really worry about that.
- 24:00When you get to more advanced programs, you can fill in with the batch type of program.
- 24:06Right, right, right.
- 24:07Basically, yeah, you just import arcade, open a window, set a background, start render,
- 24:11finish render, pop a whole bunch of straightforward drawing commands in the middle of that.
- 24:16And that would be pretty darn close to a finished program, except the program would immediately
- 24:22end right after you did that.
- 24:24So the window would come up, flash on the screen and then go away.
- 24:27So you do need to do an arcade.run, which will basically hold the window open on the screen
- 24:32until you hit the close button.
- 24:33Yeah, okay, cool.
- 24:34And yeah, you can draw a happy face or some sort of simple type of item in like 20 lines,
- 24:4250 lines if you want to add a bunch of comments in appropriate blank space.
- 24:45Yeah, super nice.
- 24:46That sounds very straightforward.
- 24:47And like I had said, you could just put those commands straight into a .py file and then run
- 24:53it, right?
- 24:53You don't even need a function or a class or decorators or inheritance or any of that.
- 24:57So it's pretty approachable for people to get started with.
- 25:01Exactly.
- 25:01I usually have them create drawings like this and then move on to functions so that they learn
- 25:08to create functions that draw horses or pigs or whatever the heck that is they want to draw.
- 25:14And then they can put that into a function.
- 25:16And then that starts making more sense to them why they need functions.
- 25:20And then eventually we can start getting into classes and how to handle events.
- 25:26Yeah.
- 25:26I mean, this just sounds like a really fun way to get into programming.
- 25:29You know, when I was taught, I was like learning just basically data structures in Lisp.
- 25:34Yeah.
- 25:35And that was not as much fun.
- 25:38I got to tell you, it wasn't as much fun.
- 25:39Even if you're an experienced programmer, I prefer starting with really small, simple,
- 25:44straightforward programs.
- 25:46If I have to start with some new framework and it's going to be 50 files that are in
- 25:54XML and some other type of format, it's just a headache to get started and really figure out
- 26:00where to even begin.
- 26:01But if I can get started in a 20 line program, I can start iterating off of that and learn
- 26:07a framework a lot easier.
- 26:09I'm starting to use this term that Python is a full spectrum language.
- 26:13And what I mean by that is like, it's really appropriate for super beginner folks.
- 26:18Cause like this example, you don't even need functions.
- 26:20Like you don't even need to know what a function is.
- 26:22You just need to like write these commands and you're good.
- 26:24But it also has really rich concepts like classes and decorators and generators and whatnot.
- 26:31And it kind of grows all the way from like simple programs to Instagram or whatever.
- 26:36Right.
- 26:36I feel like your API kind of mirrors that a little bit, right?
- 26:40Like it has this super simple way where you can be productive with a very partial understanding
- 26:45of what's going on.
- 26:46But then you have richer types like windows classes and decorators and events that you can
- 26:51hook into and stuff.
- 26:52Exactly.
- 26:53Really what I was trying very hard with this particular package to be able to do for somebody
- 26:59to get up and going easily with it and not a lot of effort, but still have a lot of power
- 27:04if they want to take the time to do it.
- 27:06Yeah.
- 27:06It sounds like it's pretty good for teaching programming to people who are learning programming,
- 27:11but maybe even for like kids.
- 27:12I mean, a lot of times people teach them kids.
- 27:14I saw some nice articles on using Pygame Zero to teach kids programming and stuff like that.
- 27:19What are your thoughts on that?
- 27:20Yeah, I think they're all good options.
- 27:22Quite frankly, I like actually seeing a little bit of competition out in the landscape.
- 27:27So when I create items, I like to look at what other people are doing, pyglet, Pygame, Pygame Zero,
- 27:35and particularly in the whole open source type of movement, figure out, oh, is there a better
- 27:42way of doing this?
- 27:43And if there's only one solution, I think things can get kind of stagnant.
- 27:49So I think Pygame Zero and Pygame are still completely viable options.
- 27:53I mean, obviously, I'm biased towards my library because like, who wouldn't be?
- 27:58But I like seeing the competition out there.
- 28:02And I do speed performance comparisons with my library and the other libraries and also how
- 28:08clean the code looks.
- 28:09And that's a nice way for me to make sure that this library is good, right?
- 28:14Yeah.
- 28:14Frame rates?
- 28:16Like, what does it look like for a game on arcade?
- 28:19Most of the games that people put together are usually 60 frames per second.
- 28:24Basically, if you program it poorly, specifically, if you draw items individually, as opposed to
- 28:31lists, that's where people usually end up getting into problems having the frame rates drop below
- 28:3760.
- 28:38Arcade uses OpenGL.
- 28:40So basically, as long as you load your sprites, your shapes, the items that you want into a list,
- 28:46I've had it be able to manage 400,000 sprites on the screen that aren't moving at the same time and
- 28:55still keep 60 frames per second.
- 28:57And I can get about 1,500 to 2,000 moving sprites on the screen at the same time.
- 29:05Yeah, that's pretty awesome.
- 29:06Yeah.
- 29:07If you include collision, it takes a little bit more time.
- 29:10So going really into the deep on which one's faster, which one's not, is really starting to
- 29:15get into the weeds, which I would absolutely love to do, but might not be what everybody wants to do
- 29:20right now.
- 29:21Yeah, yeah, for sure.
- 29:22But it's maybe the main takeaway is it's pretty quick, right?
- 29:26You definitely get like smooth frame rates and smooth behaviors and whatnot out of it these days
- 29:31using OpenGL.
- 29:32Yeah, I've got some speed comparisons comparing arcade to Pi game.
- 29:38And basically, when you keep adding sprites in the same list, particularly if they're not moving
- 29:44with OpenGL and arcade, you can keep doing that.
- 29:48And it's like an order one operation to draw it.
- 29:50You load them to the graphics card.
- 29:52Once they're on the graphics card, you just tell the graphics card to draw them and pow,
- 29:55they're back on screen.
- 29:56Yeah, that's super interesting.
- 29:57And I think that's one of the aspects of Python performance.
- 30:01that's really interesting to think about here, because you're not actually every time you
- 30:07say, here's a sprite and here are the things I want you to draw it.
- 30:09It's not like Python is doing all this computation to make it happen.
- 30:12It's kind of just like we've already loaded that stuff into the GPU memory.
- 30:17And we're just saying, hey, GPU, apply this transform to this thing over here or the set of
- 30:23transforms to those things or the whole viewport or whatever, right?
- 30:26Like it's sort of orchestrating what's happening with the scene, right?
- 30:30Rather than it's actually like drawing every little bit.
- 30:32Right.
- 30:33The graphics operations themselves are actually really quite fast and they're pretty well offloaded
- 30:39for Python.
- 30:39So the Python does the high level work and then offloads it onto the graphics card.
- 30:44And if you've done that right, then it doesn't matter quite so much what language you're working
- 30:48with.
- 30:49One of the items that I am working on right now is in actually moving the sprites and managing
- 30:58a large number of sprites, having them change where they are or detecting collisions between
- 31:06sprites.
- 31:07That is where you can see a bit of a speed difference.
- 31:11Pygame actually does pretty good with this because it is not pure Python.
- 31:15Python, it compiles a fair bit down to the C level and the different objects, the sprites
- 31:21that you've got on your screen are actually backed in the C program so they can do native
- 31:26manipulation that way pretty quick.
- 31:27And the arcade library doesn't do that, but I don't know if we'll end up doing that in the
- 31:35future.
- 31:36I've done a lot of experiments and there's a fair speed improvement if you offload some of
- 31:41that stuff to the C level.
- 31:42Yeah, I can imagine that there's like a handful of things that would really benefit from that.
- 31:47Have you considered or experimented with Cython or something like that?
- 31:50I've thought about it.
- 31:51I've not had a chance to experiment with it.
- 31:53Goes back to the whole limited amount of time in a day, unfortunately.
- 31:56Yeah, well, it could be a cool project for one of your more advanced students to tell them
- 32:02like, okay, in this course, you're going to optimize this.
- 32:05I'd be really interested to know what it would do.
- 32:07I've never tried running it under Cython.
- 32:09Yeah, I mean, not the whole thing necessarily, but just take like, you know, do some profiling
- 32:12and grab like the three slowest spots or whatever and just hit those functions with Cython, you
- 32:17know, for example.
- 32:17Right.
- 32:18This portion of Talk Python To Me is brought to you by Rollbar.
- 32:23Got a question for you.
- 32:25Have you been outsourcing your bug discovery to your users?
- 32:27Have you been making them send you bug reports?
- 32:30You know, there's two problems with that.
- 32:32You can't discover all the bugs this way.
- 32:34And some users don't bother reporting bugs at all.
- 32:36They just leave, sometimes forever.
- 32:38The best software teams practice proactive error monitoring.
- 32:42They detect all the errors in their production apps and services in real time and debug important
- 32:47errors in minutes or hours, sometimes before users even notice.
- 32:50Teams from companies like Twilio, Instacart, and CircleCI use Rollbar to do this.
- 32:55With Rollbar, you get a real-time feed of all the errors so you know exactly what's broken
- 33:01in production. And Rollbar automatically collects all the relevant data and metadata you need
- 33:06to debug the errors so you don't have to sift through logs. If you aren't using Rollbar yet,
- 33:10they have a special offer for you and it's really awesome. Sign up and install Rollbar at
- 33:15talkpython.fm/Rollbar and Rollbar will send you a $100 gift card to use at the Open Collective
- 33:22where you can donate to any of the 900 plus projects listed under the Open Source Collective
- 33:27or to the Women Who Code organization. Get notified of errors in real time and make a difference in
- 33:32open source. Visit talkpython.fm/Rollbar today.
- 33:38Let's talk a little bit about the API just a little bit more before we move off of that.
- 33:42So on one end of the spectrum, we have like open window, set background color, render, render,
- 33:47render, done. Sort of not even a function. We talked about adding functions and classes,
- 33:53but maybe a more real application might create a class that derives from the arcade.window.
- 33:58And then it has all these events, right? Like an on draw, on key press, on mouse motion,
- 34:04viewport, all those kinds of things. You want to take us through like how that might look?
- 34:07Precisely. A little more advanced, not a lot more advanced, but a little more advanced
- 34:11game will end up using classes. And one of the main ones is the window class, which works like a lot
- 34:18of classic window classes in other APIs where you've got certain methods that you can override if you want
- 34:27to respond to keystrokes or button presses or window resizing. Any of that type of work can be done
- 34:37in your own custom window class.
- 34:40Yeah. One thing I like about that is it lets you avoid like writing the event loop and dealing with
- 34:46all of that funkiness that maybe some of the libraries have to deal with.
- 34:51Yeah. That's one of the things that Pygame does that I really don't like is that you basically have
- 34:55to create your own event loop, which is pretty, I don't know, 80s or 90s style anymore.
- 35:02And a lot of the libraries that build on top of Pygame or Pygame based try to hide that or they create
- 35:10their own event loop on top of it, which for obvious reasons, it's not the best way of doing it.
- 35:15And there's a lot that happens in a good event loop for processing, for queuing up the events. And it's not really something that should probably be left to everyday users that don't need to dive into that.
- 35:33Yeah.
- 35:34So you still basically plug into the event loop, like the keyboard events and the draw events and whatnot.
- 35:39Exactly.
- 35:39Nice. So one of the things that I think is super tricky. So, you know, I used to work on 3D simulators at the OpenGL a little bit and C++ and whatnot.
- 35:48And it was fun. I did that, I don't know, for a year or two, but not for a long time. But the actual job of creating the 3D thing and rendering it and doing all that is not super hard.
- 36:02But what is, at least to me, was super hard is like, how do I get a realistic looking thing on the screen? And in this context, this probably comes down mostly to sprites. How do I get little graphics that then represent the characters and the elements, you know, an asteroid in an asteroid game, a little missile in like a missile command or, you know, whatever, right?
- 36:22Having really good ones of those without a team of designers, like that's like a big difference between a good game and not so much a good game.
- 36:28Yeah. It just kind of shows you the value of good graphic artists, quite frankly.
- 36:33Yeah.
- 36:33When I teach programming, though, a lot of students coming in, I'm not teaching graphic art. And I don't want them to spend a lot of time creating great graphic art either. I typically will give, point students towards artwork. A guy called Kenny, he's got a Kenny.nl website, K-E-N-N-E-Y.nl.
- 36:55And he creates a lot of open art that's freely available for use in games. And while it doesn't have a particular style to it, it's a nice spot to start with. He's got thousands of different tiles and images that are 2D and a nice spot for students to start with for doing graphics.
- 37:19And then, yeah, I kind of show them how to look up other graphics using like Google images or some other search engine and download and use.
- 37:30One of the things I really liked about Arcade, Pi Game, it was a hassle because they would often download images and the images would have a transparent background.
- 37:39But Pi Game, by default, didn't support a transparent background. So you had to figure out a color that that mapped to and then tell it that this color is transparent. And there were so many headaches around that.
- 37:50Yeah.
- 37:51The art was often different sized than they wanted. So maybe they wanted a 50 by 50 sprite, but the art that they downloaded was 200 by 200.
- 38:01And not all of them really knew how to use graphics programs to resize the art very well. And Pi Game didn't do that resizing very easily. And that was such a hassle.
- 38:12That's also built into Arcade to basically allow them to resize that on the fly. The transparency is built in.
- 38:21And it's just the aspect of getting the art, downloading and using it is a little bit easier for students doing that.
- 38:29Yeah, this is really cool. So like the Kenny and Elf stuff is really nice.
- 38:35Like I'm checking out the Pixel Vehicle Pack. And if you wanted to create like a like a Frogger type game, it's even got little like characters with jumping different jump stage animations on them and whatnot.
- 38:47Yeah, it's quite cool. So these come in as like a big block, like one giant pixel picture of all of them.
- 38:55Is there a way to say like, I want the third fire truck in this big picture full of fire trucks? Or do you cut them out?
- 39:03Typically, he also makes them available as individual images. And I found with people, it's been a lot easier for me to rather than having them deal with a sprite sheet and try to figure out the coordinates of the sprite sheet to pull individual sprites out of that.
- 39:17To use the individual files.
- 39:47Draw the sprites in one batch command. So you say draw a wall and pow, the walls are drawn. Basically, once they're on the graphics card, it's an order one operation.
- 39:55And then you can see, does the player collide with any wall? Does a player collide with any lava? Does a player collide with an enemy? Those types of things. So the sprite list is pretty integral to the whole thing.
- 40:06Yeah, it definitely seems like it's pretty powerful. Super cool. Let's see. So all the stuff we talked about is really good for putting pictures on a screen, right?
- 40:16But there's the other part. I told you one of the things that I thought was hard about creating this type of stuff like simulators and games and whatnot is the pictures and the graphics and in 3D world, like the actual models, right? And understanding those.
- 40:32But there's also more to it. There's physics, there's collisions, there's sounds, there's like editors and levels. Like, let's talk about some of those things. What comes in it? I know that there's some cool options for physics engines.
- 40:44Yeah, basically, there's several levels. And as you progress, you can get more advanced. First off, there's a command just to see if one sprite collides with another sprite. That's the simplest. The second is I've got what's called a simple physics engine. And you can have one sprite. And it can have a velocity. And then you can have another list of sprites, which basically act as walls that you can't move through.
- 41:10So it'll keep the player from moving through a wall, which is great for any sort of top down game where you've got a player or the enemies moving around as you don't want them moving through walls. There's a platformer one where it adds gravity to the mix. And it works reasonably well for side scrolling platformers. And it gives you the ability to jump.
- 41:33The last PyCon, I had somebody add in the ability to support double jumps and triple jumps or however many you want to select.
- 41:40Yeah.
- 41:41And if you really want to go nuts, I've got example code. There's another library package called PyMonk, which adds full 2D physics to the whole thing.
- 41:52I'm looking at it. It's pretty cool. Like the example has a little bike rolling into like a stack of bricks and the bricks all like, you know, obviously come apart and fall down like, well, like bricks would if you hit them.
- 42:03Yeah, it's cool.
- 42:04You can add springs and all sorts of things. And it is a really neat library to work with. It is not easy to get started with, particularly if you want to try to make a platformer out of 2D physics.
- 42:17It's I spent a fair bit of time on that. I've got an example on the website, but it is not particularly easy.
- 42:23Yeah. Yeah. But I guess that's like the pro version if you want to like really make a super legit realistic game.
- 42:29Yes, precisely.
- 42:30Yeah. So we talked about sprites and that sounds like that's basically built in. Arcade is 2D only, right? There's no 3D aspect.
- 42:37Correct.
- 42:37Any 3D you want to have, like you kind of have to simulate with like your sprites or scaling or something, right?
- 42:44Yeah, you'd have to do like a 2.5 or isometric even is really kind of complex to do. And there's not really built. There's some built in support for drawing an isometric map, but figuring out where the walls are and movement.
- 42:58Is a non-trivial problem that's not in the library right now.
- 43:02Yeah, yeah, of course. So another type of game that seems like would be pretty appropriate. So you talked about the platformers. What about like side scrollers? Like I don't really care about it, but Flappy Bird or Angry Birds or something like that.
- 43:16Yeah, I've had people do Angry Birds. I have people do Flappy Bird with my head. That was really weird when I got that program to grade.
- 43:26I can imagine. Hold still, I got to take a picture of you. Why? Never mind.
- 43:29They took it off the website. So yeah, I love my job in that basically for finals, I just sit here and go through and grade students video games. So it's pretty cool job to get. And yeah, sometimes you're kind of surprised with what they end up coming up with.
- 43:48And Flappy Bird with my head was definitely one of them. But I've also had people do Minesweeper, Word Search Games, Sudoku.
- 43:56Yeah, Minesweeper sounds fun. A Mastermind would be another simple and fun one.
- 44:00Yeah, so they don't have to be necessarily what I consider sprite type games, but they could be more board games or puzzle games, that type of thing.
- 44:08Yeah, sure. Okay, that sounds cool. Yeah, you probably don't need physics in Minesweeper, but still.
- 44:14No, but it is an interesting aspect because it's a nice spot to show students recursion because a lot of students don't see where recursion is useful. And it is useful in the sweep feature of Minesweeper.
- 44:26Right, of course. Yeah, it's like a tree sort of thing.
- 44:29Yeah, you basically just recursively click around where they clicked and it works pretty well.
- 44:34Okay, nice. So you run out of spots that are empty or whatever.
- 44:38You can go.
- 44:38Yeah, okay. So one thing that would be really nice, and I guess let's talk about the examples first and then I'll talk about this.
- 44:45So something that surprised me a little bit, I saw some of the articles you had written, like I think the one about Asteroid Smasher, right?
- 44:54Mm-hmm.
- 44:55And on there, I saw that you can basically, once you pip install Arcade, it comes with a bunch of examples already.
- 45:02And I can say like python-m arcade.examples.pick something like Asteroid Smasher.
- 45:08And actually, if I go to the REPL and I import arcade.examples and say help arcade.examples, there's like 30 examples in there.
- 45:15Actually, I think there's about 100 examples total on the example site on the documentation.
- 45:23I need to sort of recount those.
- 45:25But anyway, to me, the example, having examples to base learning off of was really important because a lot of the feedback I get from students that are out in the workforce are saying,
- 45:39hey, I haven't had a chance to ever work with other and read other code.
- 45:45That's a skill.
- 45:46I've written my own code.
- 45:47But when I get on the workforce, most of what my job is, is reading other people's code and making modifications to it.
- 45:53Right.
- 45:53And it's usually super complicated because it's been polished for three years.
- 45:57Yeah, exactly.
- 45:58And it's hard to read, right?
- 45:59Yeah.
- 45:59And this gives students a way of learning to read code.
- 46:05Plus, I myself, quite frankly, just learn things better by seeing examples.
- 46:09And there are certain people that learn better that way rather than having things presented to them in sort of a linear format.
- 46:17And the examples, I've tried to come up with so many different examples so that all of the requests that I've gotten over time,
- 46:25when people want to learn something, know how to do something, I create an example for it.
- 46:31And a lot of my answers to emails anymore on like, how do you do this?
- 46:35Are just, oh, look, here's an example on exactly how to do it.
- 46:38Yeah.
- 46:39Yeah.
- 46:40That's a nice way to do it.
- 46:41Yeah.
- 46:41If there's not an example, then bang, now I got a new idea for an example.
- 46:45Yeah.
- 46:45So I'll just read through some of what you got when you do that help statement.
- 46:49So you've got like Asteroid Smasher, which is basically asteroids.
- 46:52It's pretty nice.
- 46:53A limited version of that.
- 46:55You've got drawing text.
- 46:56You've got full screen example, which is pretty nice.
- 46:59You've got some loops.
- 47:00You've got like a particle stress.
- 47:02Fireworks.
- 47:03The fireworks one is kind of cute.
- 47:04Bunch of stuff with Sprite.
- 47:06Moving them around.
- 47:07Sprite CSV map, which is cool.
- 47:10And then rooms.
- 47:11And yeah, there's a lot of stuff in there.
- 47:13There's a Tetris.
- 47:14Yeah.
- 47:14The Tetris is actually one of the newer ones that I've got in there.
- 47:18Also have some procedural generation showing how to generate mazes a couple different ways,
- 47:23different rooms.
- 47:25Some of the other items that I've really been working on is to also support basically using
- 47:32a program called the Tiled Map Editor so that you can actually just design a level or a layout
- 47:39in a different program visually and then load it up really easily in your own program.
- 47:43Yeah, that's nice.
- 47:44Is that that's working?
- 47:45And is that like, is that all?
- 47:47What is that other program people use?
- 47:48The Tiled Map Editor.
- 47:50It is a really nice program that is used actually by a lot of different languages, but it creates
- 47:58a TMX file and tile sets so that you can take regularly sized tiles.
- 48:03You can visually lay them out as a lot of different options that way.
- 48:06You can even animate tiles.
- 48:08And then I've got an older version of loading those tiles function that does that.
- 48:16And we're actually creating a new, more powerful version of that.
- 48:21You can basically animate the tiles.
- 48:24It'll automatically do the animations.
- 48:26You can draw hit boxes around tiles.
- 48:29So not every tile you just assume is a rectangle that you hit, but you might have a ramp or like
- 48:36a coin.
- 48:36You're going to have a circle for a hit box.
- 48:40And you can just draw that in the Tiled Map Editor.
- 48:43And then you can import it with just a few commands in the arcade library.
- 48:49That is cool.
- 48:50Yeah, I found it at mapeditor.org.
- 48:52And it's a cute C++ app on open source on GitHub.
- 48:56And yeah, it looks really nice, actually.
- 48:59Yeah, it's a nice alternative to if you want to do 2D games, you could pair that with a, you
- 49:09know, with Python and arcade and run through quite a few different levels and code that way.
- 49:15Yeah, that's interesting.
- 49:16And there's an example of loading the output from this thing.
- 49:19Which is that example?
- 49:20Example of loading what?
- 49:22Of loading the output from the Tiled Map Editor.
- 49:25Oh, right.
- 49:25So basically, I've got one example for that for loading for the Tiled Map Editor.
- 49:29And then I also did a whole presentation on basically doing that.
- 49:35Basically, if you go to arcade.academy at the front of that website, it's got a tutorial that
- 49:41leads you from just the beginning.
- 49:43It's a platformer tutorial.
- 49:45It leads you just from the beginning of opening the window, adding sprites, and then eventually
- 49:49using the map editor to lay out the sprites.
- 49:52And in the next version of arcade, it'll actually have an updated version that'll support animation,
- 50:00have a better support for hitboxes, and other, some of the more advanced features of the Tiled
- 50:05Map Editor.
- 50:06That's super cool.
- 50:07Yeah, the one that I found was Sprite Tiled Maps.
- 50:10Yes, that map, singular.
- 50:12That's it.
- 50:13That's really nice.
- 50:14Because like I was saying, like, that's one of the parts of like, hey, I built this thing
- 50:18that shows stuff on the screen, and it draws these sprites.
- 50:21Wait, how do I create levels?
- 50:24How do I create graphics?
- 50:24Like, all that stuff is just, you know, it seems like it's not going to be a problem maybe
- 50:29at first, but it really is.
- 50:30Yeah.
- 50:30And if you want to do the visual layout and not program exactly where every block goes,
- 50:35having some sort of graphical editor, and the Tiled Map Editor is just beautiful for it.
- 50:39It really is.
- 50:40The guys put a ton of work into it.
- 50:42And you do not have to do a whole lot of work to load that using the arcade library.
- 50:48Yeah, that's really great.
- 50:49Definitely think that's super valuable to have.
- 50:51You know, one thing that I was thinking while you're talking, it probably doesn't exist.
- 50:56It might be cool if it were to exist.
- 50:58Maybe somebody out there could create it if they wanted.
- 51:00So we talked about the sprites over on kinney.nl.
- 51:04We talked about the Tiled Map Editor.
- 51:05It would be fun if there was, like, some starter, sort of getting started, like, a little library.
- 51:13So you can just pip install it, and you've got, you know, like, 500 sprites that you can work with
- 51:20and, like, 10 levels that are already built that you can just, like, okay, I'm going to just start from this
- 51:25and go, you know, like, import this level and run with it.
- 51:28And you hear some sounds or, like, these little building blocks for people to, like, sort of quick start up with them.
- 51:35Does anything like that exist?
- 51:36Not that I am aware of, but that would actually be a really great idea.
- 51:40Yeah.
- 51:41So instead of having to, like, start from scratch, you know, you're kind of like, well, these are, like, the 500 sprites.
- 51:46If you pip install this thing, you just have it, you know, and you could go from there.
- 51:50That'd be cool.
- 51:51Yeah, it would.
- 51:52And then eventually, if you're into creating the art yourself, once you've got your placeholder art in there,
- 51:57you can get the mechanics of the game going and then just start replacing the art, like, piece by piece.
- 52:03Yeah, because it seems like the art is, like, the last thing that you want to put your energy into, you know?
- 52:07Right, because until you get the basic mechanics down, you don't really know what art you need or if the art is going to match what you actually need for mechanics.
- 52:18Exactly.
- 52:18Or even if the game idea, the way you first thought of it makes any sense.
- 52:22Like, if you could play around with, like, some little sample data and they go, oh, actually, really, that's close.
- 52:26But this is really what I wanted.
- 52:27Like, you don't want to spend a ton of time on art for that, right, to get it up and running.
- 52:31Exactly.
- 52:31Anyway, that would be cool.
- 52:33Maybe somebody out there is inspired to create that.
- 52:37That'd be great.
- 52:37I'd love to see something like that.
- 52:39Yeah, cool.
- 52:39So I guess we can maybe round out our conversation here by, like, assuming we've built this beautiful game.
- 52:45It's like a cool side-scroller, whatever, Angry Birds, who knows what it is.
- 52:51We want to send it out to the world, put it in the Mac App Store, put it in the Windows Store, who knows?
- 52:56Something like this.
- 52:57One of the challenges of Python is shipping your program to other people who maybe don't have Python installed or the right dependencies or things like that, right?
- 53:07Yeah, it is difficult, and I don't have a perfect answer for that, quite frankly.
- 53:14The aspect of the sound libraries and the little libraries that go with the arcade library, it's difficult to package and get that packaging to work well.
- 53:27Python itself doesn't have a whole lot of great options.
- 53:30There's the whole PyB project.
- 53:33There's PyInstaller.
- 53:34You've got, like, PyOxidizer and some other packages.
- 53:37I would love to see something good and straightforward for being able to package games that you've put together using Arcade.
- 53:45I'm not there yet.
- 53:47Or I can recommend a specific option.
- 53:50That's been one of the spots that I'd love to see Python as a language have some improvements on.
- 53:55I definitely see it as one of the shortcomings.
- 53:58It's great to see the PyOxidizer is coming along, right?
- 54:01This is the newest of the packaging tools.
- 54:04And I think it does take other libraries along with it.
- 54:08I'm not entirely sure.
- 54:09It certainly takes, like, the other Python libraries.
- 54:10But, like, FFmpeg, for example.
- 54:12Does it take, you know, that, right?
- 54:14That I'm not sure about.
- 54:15But I think if you could package your Python code and its dependencies as a binary, you could use the other packaging mechanisms to solve the other dependencies, right?
- 54:26Like, in Windows, you have MSI installers that take along the other dependencies and will put them in the same directory.
- 54:32Or you could have, like, your .app file on Mac.
- 54:34You know, you just put it into a disk image and, like, drag it over, right?
- 54:37Like, that's basically a directory.
- 54:39I suspect you could make it work like that.
- 54:41I'd love to get to a spot where somebody who's learning to program or is more on the hobbyist side doesn't have to spend so much time trying to figure out all these different packagers.
- 54:52And there can just be one simple option for them to create an installer and have that run on a particular platform.
- 55:00Because it's pretty cool to learn how to program and then you get done with learning how to program in college or high school or whatnot.
- 55:08And you want to take your game and show it off to your friends.
- 55:10But then you can only run it on one computer.
- 55:15Yeah, exactly.
- 55:16It's super frustrating.
- 55:17I mean, my dream of the future would be something like I go to the command line.
- 55:23I type Python 3-m package or bundle or something in a directory.
- 55:31And then I get three outputs.
- 55:33Linux, Windows, Mac.
- 55:35Yes.
- 55:36And there's a .exe.
- 55:38There's a .app.
- 55:39And there's a Linux binary.
- 55:40And that's it.
- 55:42It just runs.
- 55:43Yes.
- 55:43Yes.
- 55:44I would love to see something like that.
- 55:45We're not in that world.
- 55:46Maybe that's 2022.
- 55:48I don't know when that world exists, but I would love for it to exist.
- 55:51And then, you know, I think that would really make a big difference, especially on things like this.
- 55:56Yeah.
- 55:56For me on the Arcade Library, this is a big hang up.
- 55:59The sound support is another one that I get a lot of headaches on and trying to make sure I do support.
- 56:07Yeah.
- 56:07We haven't talked about sound yet.
- 56:08So can we have sound?
- 56:10How does that work?
- 56:10Yeah, you can have sound.
- 56:12It's basically, it's one that I keep trying to change.
- 56:16And I always end up finding somebody that has some different configuration that it doesn't work well with.
- 56:21Right now, I'm using FFmpeg.
- 56:24Pygame uses AVbin, which is like a really old binary library that hasn't been updated in, I don't know, since like 2008 or something.
- 56:34I can't remember, but nobody supports it anymore.
- 56:36And so I tried to work with FFmpeg.
- 56:39But then with Windows, you need it installed somewhere.
- 56:42So you have to have the binary installed and downloaded.
- 56:46And Mac's a little bit different.
- 56:49With Linux, it should already be installed.
- 56:51So somehow you need to find it on Linux and then create a link to it.
- 56:56But you can't really directly create a link because then you get permissioning errors.
- 57:00You have to remember where the heck that is.
- 57:01At any rate, sound is a headache.
- 57:04And it's very, it's very kludgy right now.
- 57:08And I'm constantly trying to fine tune or find little exceptions where it's breaking down.
- 57:13But you can play MP3s and OGGs and WAV files.
- 57:18I generally push people to do WAV files for shorter sound effects.
- 57:22I would love better sound to port.
- 57:24So you could easily create a backing track of music to your game.
- 57:28And then when the song is done, you could get a callback and queue up the next song.
- 57:34Stuff like that really should be a lot easier than it is.
- 57:37But that's one of my top headaches, that and distribution.
- 57:41Okay.
- 57:42Well, people have ideas.
- 57:44I guess they can send them along.
- 57:45I don't, for sound, I have no ideas.
- 57:46I don't know anything about sound other than I agree that it's kind of tricky.
- 57:50Yeah, I've had, I've looked into so many different libraries with that where people have suggested, oh, well, you should do this.
- 57:56And, you know, I take a look at it and there's always some rhyme or reason where it doesn't work particularly well.
- 58:00But I would love a solution for that by any means.
- 58:03If anybody knows one, let me know, please.
- 58:07Well, it sounds like you have at least basic support for sound, which is pretty critical.
- 58:11Yes.
- 58:11It makes it a lot more immersive.
- 58:13Yeah, absolutely.
- 58:14Maybe even more so than graphics, right?
- 58:16Like there was a really interesting game on the iPad that was like this retro 8-bit game.
- 58:21But it had brilliant music that was so immersive.
- 58:25And actually, it was quite, quite interesting.
- 58:27I forgot what it's called, but it was, it was fun to play.
- 58:30And it was because of the music.
- 58:31Yeah, I agree.
- 58:32And I told my students the same thing.
- 58:34It's, you got to get some sort of sound effects on there.
- 58:36Yeah, for sure.
- 58:37If you're jumping or you hit an enemy or the game over, it's just a lot better if there's a sound effect with it.
- 58:43Mind you, as soon as I tell students how to do sounds, there is no shortage of flatulence coming out of the speakers in the labs that day.
- 58:51Oh boy.
- 58:53Do you have a good place for sound effects?
- 58:55Like the audio equivalent of Kenny.nl?
- 58:58Kenny.nl actually has some sound effects.
- 59:00So I often ship that.
- 59:02Open Game Art is another website that's pretty good for finding both art and sound effects.
- 59:08A lot of sound effect websites ask you to download bad software to play sounds, however.
- 59:17So I really have to caution students.
- 59:20If they're going out and trying to find sound effects, that's a great way to find malware.
- 59:24Yeah.
- 59:25Sound should never require an install.
- 59:27Exactly.
- 59:28And some sites that I used to like actually have sort of switched over to requiring some sort of install and therefore automatic.
- 59:38Like steer clear of.
- 59:39That is super shady.
- 59:40That's crazy.
- 59:41Yeah.
- 59:41All right.
- 59:42Well, I think we pretty much covered Arcade.
- 59:43That sounds like a really nice project that you built and hopefully people get a chance to check it out.
- 59:48All right.
- 59:49Thank you very much for having me on.
- 59:50Absolutely.
- 59:50Before I let you out of here, though, there's two more questions to ask.
- 59:54So if you're going to write some Python code, what editor do you use?
- 59:56Oh, great question.
- 59:58In order, I will typically do PyCharm first.
- 1:00:02And I really like PyCharm.
- 1:00:04Sublime would be number two for a quick editor to work with.
- 1:00:09And then Vim if I'm on any sort of Linux type of environment.
- 1:00:15Yeah.
- 1:00:16All right.
- 1:00:16Sounds like a good set to me.
- 1:00:18And then notable PyPI package.
- 1:00:20I'll go ahead and throw out there pip install arcade for you.
- 1:00:22But like maybe something people don't necessarily know about, but you're like, well, this is really great.
- 1:00:27People should know about X.
- 1:00:28Oh, good question.
- 1:00:29Other than standard packages, I do like pyglet as far as building stuff off of it for graphics.
- 1:00:38If you want more of the underlying items, Modern GL, if you want to write your own OpenGL code,
- 1:00:44Modern GL is a really pretty good package that's actively supported online as well.
- 1:00:50Oh, that's interesting.
- 1:00:51I've never used that.
- 1:00:52So, yeah.
- 1:00:54Yeah.
- 1:00:54There's like a few different OpenGL packages.
- 1:00:58pyglet's bindings I really like and Modern GL are my two favorites.
- 1:01:03Okay.
- 1:01:04Yeah.
- 1:01:04Cool.
- 1:01:04So, if you know the OpenGL API, like this is it, but in Python rather than C++.
- 1:01:10Right.
- 1:01:11Yeah.
- 1:01:11Cool.
- 1:01:11Okay.
- 1:01:11Nice.
- 1:01:12That's a good one.
- 1:01:12Thanks.
- 1:01:13Thanks.
- 1:01:13See, this is the purpose of this little section because we all learn about these things that
- 1:01:17we don't know.
- 1:01:18All right.
- 1:01:19So, final call to action.
- 1:01:20People are excited with Arcade.
- 1:01:21How do they get started?
- 1:01:22How do they contribute?
- 1:01:23Things like that.
- 1:01:24There's a website, arcade.academy.
- 1:01:27It's got links if you want to download, try it out.
- 1:01:30If you want to contribute to it, which I would absolutely love, there's links on it to GitHub
- 1:01:37and you can do pull requests.
- 1:01:39There's a Discord available too.
- 1:01:41If you want to shoot me an email, I can get you hooked up with the Discord for the development
- 1:01:46on that.
- 1:01:46If you're learning to program, there's also learn.arcade.academy that has a whole curriculum
- 1:01:52that I use for first semester programming.
- 1:01:56And yeah, that's basically how to get started.
- 1:02:00The learn.academy.
- 1:02:00That's great.
- 1:02:01It's got some, basically walks you through all the different things that you do for the
- 1:02:05course, right?
- 1:02:05Yeah.
- 1:02:06Learn.arcade.academy.
- 1:02:08Yep.
- 1:02:09I'll put it in the show notes.
- 1:02:10People can click it.
- 1:02:11There we go.
- 1:02:12All right.
- 1:02:13Well, thank you so much for being here.
- 1:02:14It's great to chat with you.
- 1:02:15Yes.
- 1:02:15Thank you very much.
- 1:02:16You bet.
- 1:02:17Bye.
- 1:02:17This has been another episode of Talk Python To Me.
- 1:02:20Our guest on this episode was Paul Craven, and it's been brought to you by Indeed and Rollbar.
- 1:02:25With Indeed Prime, one application puts you in front of hundreds of companies like PayPal
- 1:02:31and VRBO in over 90 cities.
- 1:02:33Get started at talkpython.fm/Indeed.
- 1:02:36Rollbar takes the pain out of errors.
- 1:02:39They give you the context and insight you need to quickly locate and fix errors that might have
- 1:02:44gone unnoticed until users complain, of course.
- 1:02:47Track a ridiculous number of errors for free as Talk Python To Me listeners at talkpython.fm
- 1:02:52slash rollbar.
- 1:02:53Want to level up your Python?
- 1:02:56If you're just getting started, try my Python Jumpstart by Building 10 Apps course.
- 1:03:00Or if you're looking for something more advanced, check out our new async course that digs into
- 1:03:06all the different types of async programming you can do in Python.
- 1:03:09And of course, if you're interested in more than one of these, be sure to check out our
- 1:03:13Everything Bundle.
- 1:03:13It's like a subscription that never expires.
- 1:03:15Be sure to subscribe to the show.
- 1:03:17Open your favorite podcatcher and search for Python.
- 1:03:20We should be right at the top.
- 1:03:21You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 1:03:26and the direct RSS feed at /rss on talkpython.fm.
- 1:03:30This is your host, Michael Kennedy.
- 1:03:32Thanks so much for listening.
- 1:03:34I really appreciate it.
- 1:03:35Now get out there and write some Python code.
- 1:03:37I'll see you next time.
- 1:03:57Thank you.