Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 21:00 < onpon4> Alright, any other questions before I start the SGE tour?
- 21:00 < kremling> What is the SGE tour?
- 21:01 < Magnemania> S'tour on a python-run Game Maker lookalike.
- 21:01 < onpon4> That's the next workshop. :) I gave my self a more reasonable time for this one, so it shouldn't be so rushed.
- 21:01 < Magnemania> S'FREEEEEE in that the source code is free and available, and that means it's not the darkest of evils
- 21:01 < kremling> Is it something that I can download and follow along with?
- 21:02 < Magnemania> Check out the workshop page, he put some downloads up
- 21:02 < onpon4> Yep, stellarengine.nongnu.org.
- 21:02 < onpon4> The SGE is a 2-D engine for Python, meant to be kind of similar to Game Maker's underlying engine.
- 21:03 < onpon4> We'll be going through two examples: a basic "Hello, world!", and Pong.
- 21:03 < onpon4> This is the first, "hello world" example: http://pastebin.com/UEQghcRk
- 21:03 < onpon4> The first line is, of course, the shebang. It's best to always include this.
- 21:04 < onpon4> After that is the license. In this case, I've chosen CC0, i.e. public domain dedication.
- 21:04 < onpon4> For imports, we include the "sge" module. This gives you all the classes and functions from the SGE.
- 21:05 < onpon4> We're looking at this, guys: http://pastebin.com/UEQghcRk
- 21:06 < onpon4> Line 25 defines the Game class. The Game class controls everything "global". We define a subclass of sge.Game to define events, which in the SGE are special methods.
- 21:06 < onpon4> In this case, we defined the key press event, and the close event. Both do the same thing: they call the game's end method, which ends the game.
- 21:07 < onpon4> Below the game is a room definition. Rooms in the SGE are like rooms in Game Maker: they represent separate places, such as levels.
- 21:08 < onpon4> In this case, I have one sge.Room sub-class, which defines a step event. Step events happen every frame. Here, the main functionality of this example happens: the text
- "Hello, world!" is projected every frame.
- 21:08 < onpon4> The reason we do this every frame is projection lasts only one frame. Think of it as being like a projector: as soon as you stop projecting, the image disappears.
- 21:09 < onpon4> Finally is out main function. Here, we follow a fairly specific format: first, we create a Game object. We don't need to assign it to anything, because it automatically
- gets assigned to sge.game.
- 21:10 < onpon4> Second, we load resources and create things. In this example, that's just a single background, a font, and a single room object.
- 21:11 < onpon4> Finally, we call sge.game.start() to start the game.
- 21:11 < onpon4> If you run this example, you will see the text, "Hello, world!" shown in the center of a white screen.
- 21:12 < onpon4> Any questions so far?
- 21:12 < onpon4> Let's move onto a more exciting example: an actual game. Here is a very basic Pong game we are going to start with: http://pastebin.com/pH2Z73du
- 21:13 < onpon4> You'll notice the odd class, "glob". We're using this as a container class for "global" variables, mainly because of the requirement of the "global" keyword to assign to
- global variables, which can cause bugs.
- 21:14 < onpon4> For our Game class, we have some more events. First off, pressing "P" or Enter will pause the game with the SGE's built-in pause function. Second, pressing F8 will take a
- screenshot and save it.
- 21:15 < onpon4> While the game is paused with the SGE's pause function, all events are suspended, and instead similar "event_paused" events execute. Therefore, we define
- event_paused_key_press and event_paused_close to be able to close and unpause the game.
- 21:16 < onpon4> In event_close, we ask the player before actually closing, with the sge.show_message function.
- 21:17 < onpon4> We use a small hack here: show_message is going to return 0 for the first button, and 1 for the second button, so we check for truthfulness of the result. If "Yes" is
- clicked, it will return 1, which is True.
- 21:18 < onpon4> Next, line 76, starts our Player class. This is going to be used for the paddles.
- 21:18 < onpon4> Player inherits from a special class called sge.StellarClass. This class is similar to Game Maker's "objects"; it's for objects that appear within a room.
- 21:20 < onpon4> In this case, we are extending the constructor method (special method name __init__), so that we don't need to specify everything when creating a paddle; we just specify
- the player name and infer everything else.
- 21:20 < onpon4> The super() method allows us to call the parent's version of __init__, making this an extension rather than an override.
- 21:21 < onpon4> For the Player object's step event, we check the state of up_key and down_key (which were set in the constructor method) and use these states to decide how to move.
- 21:22 < onpon4> Then, we check if we're outside the room, and return us to the inside of the room if we are.
- 21:22 < onpon4> The Ball class is similar.
- 21:23 < onpon4> The ball class has a "serve" method, which sends it off from the center of the table to one of the players.
- 21:24 < onpon4> Simply, this serve method sets the ball's position back to its original position, and then sets its yvelocity (vertical movement) to 0 and its xvelocity (horizontal
- movement) based on a "direction" argument and a constant called BALL_START_SPEED (defined at the start of the file).
- 21:25 < onpon4> We call this serve method in the create event., since we want the game to start immediately.
- 21:26 < onpon4> In the step event, we bounce the ball off of the top and bottom, and bring it back into play if it passes one of the players.
- 21:26 < onpon4> Finally, we have the collision event, where we bounce off of each of the paddles.
- 21:27 < onpon4> If anyone is ever confused, please ask questions.
- 21:27 < onpon4> In the main function, we set our FPS to 120 (this is to somewhat hide that our controls are digital), and dynamically create the ball and paddle sprites.
- 21:28 < onpon4> Now, if you run this file, you may find it disappointing. It has no sound or scoring.
- 21:29 < onpon4> Let's fix that, with version 2: http://pastebin.com/Wv29fHKF
- 21:30 < onpon4> First off, we need to add a HUD.
- 21:30 < onpon4> We do this here as an objet, created on line 251.
- 21:31 < onpon4> The HUD object is never directly accessed, but instead it constantly displays a HUD sprite which we modify as needed.
- 21:32 < onpon4> Is anyone paying attention to this?
- 21:34 < Magnemania> Dropping in and out, here. Not properly following along.
- 21:34 < Magnemania> Still trying to see what's goin' on in the code, though.
- 21:35 < onpon4> Do you have any questions?
- 21:35 < Magnemania> Not particularly. The only thing that's been coming to mind is mild cracks at not being able to generate sounds dynamically.
- 21:36 < onpon4> Cracks?
- 21:36 < Magnemania> Jokes.
- 21:36 < Magnemania> Incidentally, can one draw on the screen directly?
- 21:36 < Magnemania> Using the same events that you use to generate the sprite, of course?
- 21:36 < onpon4> Sort of. You can draw to the room directly with the project methods.
- 21:38 < Magnemania> Oh! And is it possible to make functions that don't take self as an input?
- 21:38 < Magnemania> Seems rather bloaty to put 'self' as an argument with functions that potentially don't use 'self'.
- 21:39 < onpon4> That's a syntactic requirement of Python. The first argument represents the object it's from.
- 21:39 < onpon4> (They're methods, not functions.)
- 21:40 < onpon4> There is a such thing as static methods, which are more like functions and have no connection to objects or classes, and thus don't take this mandatory argument, but those
- are different.
- 21:40 < Magnemania> method, function, equation, crackpot, WHAT HAVE YOU
- 21:40 < Magnemania> Oh.
- 21:41 < onpon4> Take a look at line 137, for example: self is used in line 139. "self" isn't a special keyword or anything like that in Python, so you could just as well use "this" instead.
- 21:41 < Magnemania> Waaaait...I thought that regular methods defined outside of classes were basically static like that.
- 21:42 < onpon4> That would be a function. :)
- 21:42 < Magnemania> That would-and I said-and
- 21:42 < Magnemania> ...FEH! FEH, I SAY!
- 21:42 < onpon4> Line 206 is an example of a function.
- 21:43 < onpon4> Well, this is a mess (my fault; not enough planning), so I'm just going to mention a couple mentions.
- 21:43 < kremling> This actually quite interesting. Will there soon be an option to create an executable?
- 21:44 < kremling> I know Python doesn't really do that.
- 21:44 < onpon4> kremling: I think what you're thinking is something like py2exe, or cx_Freeze.
- 21:44 < onpon4> You take these things, and they "freeze" any Python program into an executable that you can portably execute, to distribute to people.
- 21:45 < kremling> Yeah, that's what I was referring. Sorry for interrupting.
- 21:45 < onpon4> No problem.
- 21:46 < onpon4> So, this was loosely based on a tutorial that I already wrote a while back. You can find it in the SGE's documentation; it tries to walk you through making these examples
- I've shown, and I think it does better than my rambling here.
- 21:47 < onpon4> Specifically, doc/hello.html, and doc/pong.html.
- 21:47 < onpon4> Sounds: a good way to get sound effects that are simple is the free/libre program, Sfxr. Some of you may know about it already.
- 21:48 < onpon4> Other art assets: OpenGameArt.org is a great resource.
- 21:48 < Magnemania> wait wha-a sound effect generator? I could use one o' 'dose.
- 21:49 < onpon4> I used it for the Pong example. Take a look at examples/pong.py (run it).
- 21:49 < Magnemania> Ehm...I didn't actually download anything from the project, and I'm lazy enough to take your word for it.
- 21:50 < Magnemania> ah, so it's for making arcade-ey sorts of sounds
- 21:50 < TiKi> so is the workshop over yet?
- 21:50 < onpon4> Yep.
- 21:50 < onpon4> TiKi: I'm just picking up the pieces and wrapping up.
- 21:51 < kremling> By the way, what text editor do you use for programming in Python? Python is requires indents, and it can be quite tedious when copying and pasting code examples into
- IDLE and indention errors come up. I'm sure there are some editors that can handle this problem.
- 21:52 < onpon4> IDLE handles indentation quite fine (the best actually), and it's my favorite editor for Python. My second favorite is gedit.
- 21:52 < kremling> How do you fix the indentation problem from copying and pasting chunks of code?
- 21:53 < Magnemania> Whatcha copy-pasting FROM, kremling?
- 21:53 < kremling> The examples he provided on the pastebin website
- 21:54 < TiKi> this game making stuff sounds complicated
- 21:54 < onpon4> TiKi: It's not, really.
- 21:54 < TiKi> is it time-consuming
- 21:54 < onpon4> kremling: That shouldn't be a problem, but did you try the raw paste data?
- 21:54 < onpon4> TiKi: Well, yeah.
- 21:55 < Magnemania> It's really not that different from Game Maker, it's just that there's not much of an interface.
- 21:55 < kremling> I did not, that fixed the problem. Thank you.
- 21:55 < Magnemania> ...Is there an IDE for that thing, incidentally?
- 21:56 < TiKi> would it be hijacking the workshop to say that I'm a bit befuddled by how everyone goes "well DUH it's time consuming" as if I'm supposed to naturally think that
- 21:56 < onpon4> Which thing, Magnemania? The SGE, or something else?
- 21:56 < Magnemania> The SGE.
- 21:56 < Magnemania> to be fair, TiKi, any sort of art takes time
- 21:56 < Magnemania> and game design is an art
- 21:56 < Magnemania> and coding is, kinda, too a lesser extent
- 21:56 < onpon4> I'm developing a universal level editor, and one of my goals is to have an IDE as easy to use as (though probably pretty different from) Game Maker.
- 21:57 < Magnemania> too to a lesser extent
- 21:59 < TiKi> You see guys, I'm from the "Super Mario Bros. X" community, which is a level editor with a limited amount of NPC customization (i.e. you can set whether or not some enemies
- are immune to fireballs) and a limited trigger-event-making system (i.e. well, just look it up)
- 21:59 < kremling> Are you working on this by yourself onpon4?
- 21:59 < TiKi> BTW onpon4 it's not libre
- 21:59 < onpon4> Yep.
- 21:59 < onpon4> (That was to kremling.)
- 22:00 < onpon4> It used to be part of an effort started by someone else, but he ended up stopping his part (which was, incidentally, a full Game Maker-inspired IDE).
- 22:00 < TiKi> (pretty nice of you to target specific people)
- 22:00 < onpon4> TiKi: That's normal behavior in IRC.
- 22:00 < kremling> If you were requesting assistance, what would I need to know to help you in creating this framework based off of pygame?
- 22:01 < Magnemania> TiKi, starting a game from scratch (which is what one's doing when one uses something like this) is very different from level design.
- 22:02 < onpon4> Well, I don't need help with the Pygame SGE. That's pretty much done. What I could use help with more is developing the IDE, and knowledge of any toolkit library (wxPython,
- GTK, Qt, Tkinter) would do.
- 22:02 < TiKi> and if you use something like Hello Engine you're a bad person apparently
- 22:02 < Magnemania> There are some pre-built Mario engines for Game Maker (which now has a somewhat expansive free version but is inherently EVIIIL) that would allow you to function in
- that way.
- 22:02 < TiKi> I see how that's a bad engine sure
- 22:02 < TiKi> but if I did that then MFGG would grill me
- 22:02 < Magnemania> to be fair, Drag's engine hasn't gotten any flak
- 22:03 < Magnemania> or Adder, or Lash, or gosh no one's going to get that reference
- 22:03 < onpon4> Now that it's possible to migrate to ENIGMA realistically, Game Maker isn't as bad. Just migrate to ENIGMA and it's fine. :P
- 22:03 < TiKi> I think that's because there's only been a few clones made with it
- 22:03 < TiKi> onpon4 how long you estimate until Enigma=GM compatibility
- 22:03 < Magnemania> Hah! It'll be lightyears before it's completed!
- 22:03 < onpon4> Heck if I know. Ask ENIGMA's developers.
- 22:04 < Magnemania> wait, light years measure distance, not time
- 22:04 < onpon4> But it's made quite a bit of progress recently; it used to be little more than something kind of interesting, and now it can legitimately be used, it seems.
- 22:04 < TiKi> am I diverting this workshop thing too much
- 22:04 < onpon4> No, workshop's over.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement