Jump to content
  • Advertisement

Captain P

  • Content Count

  • Joined

  • Last visited

Community Reputation

1092 Excellent

About Captain P

  • Rank
  1. There are probably better ways to add support for multiple characters and storylines to your game. Can you give us more information about how you've set up your code so far?
  2. Captain P

    Python + Pygame Problem

    Heh, of course. I forgot to take the sprite's position into account. You'll only want to update the width and height of the rect, not it's position, before clamping it.
  3. Scrolling around a map is no problem, as is accessing individual pixels. Zooming (and rotating) sprites is also possible, but Pygame isn't really geared towards operations like that. You're basically creating a new surface each time you perform one of those operations, so you'll probably have to do some caching for performance reasons. Or you could look at something like Pyglet instead.
  4. Captain P

    [pygame] Local variable referenced by assignment

    Hollower already spotted the problems, but there's something else you should know: 'referenced before assignment' errors are caused by accessing variables before they have been assigned a value. These errors show you a traceback, pointing you at the offending code, and where it was called from. In this case, it points us towards line 66: data = ship.checkkey(data) As Hollower already mentioned, 'data' needs to exist before it can be passed into ship.checkkey() - only after that function has returned will the result be assigned to 'data'.
  5. Captain P

    [pygame] Text not displaying.

    Your code doesn't work again due to indentation problems, so we can't run it for ourselves. Also, when do you get that error? When you try to save an image? When you try to load it? "Current Time Here" doesn't appear anywhere in your code, so is this the actual code you were using when you got that error, or did you accidentally use older code somehow?
  6. Captain P

    [pygame] Text not displaying.

    The code you've shown doesn't run due to indentation problems... with Python, always make sure that indentation is preserved correctly! Anyway, you're only drawing your labels the first run, but you're clearing the screen every run (by blitting bg to the screen). Why not draw those labels every run instead? As for saving multiple images, you could check all files in the current working directory by using os.walk(os.getcwd()). The os.path module also contains useful functions, be sure to have a look at them.
  7. Captain P

    Python + Pygame Problem

    Your code uses the first image's rect as the sprite's dimensions. If other images are smaller or larger, then it's quite obvious why clamping doesn't seem to work. It does work, it's just not using the dimension of the current image. Try replacing: self.rect = self.rect.clamp(SCREENRECT) with: self.rect = self.image.get_rect().clamp(SCREENRECT) However, keep in mind that the sprite's position may now change even though you're standing next to a wall, due to the changing dimension. Personally, I wouldn't use image dimensions directly for things like this - such bounding boxes are often too large to be useful anyway; sprites often have some empty space. See Tuning Canabalt to see why it's useful to tweak bounding-boxes apart from the visualization. Movement is a little jittery in both directions for me, but I suppose having different images could make it look more jittery in one direction than the other. I simply created some equally sized colored rectangles, numbered from 1 to 11. If a sprite's position is it's top-left corner, then having images of different width will make the right side move erratically (unless you've taken this into account when creating your art - it depends a lot on the images you're using). The movement itself isn't any more or less jittery however. Try using equally sized images and see if it's still more jittery.
  8. Captain P

    Python + Pygame Problem

    The clamping seems to work just fine. You may want to change the clamping rectangle to match the screen resolution though: currently there's a 10 pixel difference along the x-axis (SCREEN_RECT is 590 x 400, resolution is 600 x 400). Movement is a bit jittery indeed, both left and right. You're updating at a fixed time interval, but if you would measure the elapsed time, you'd notice that it's not always the same. Sometimes there's a spike or at least a little variation. One way to fix this would be to use the elapsed time to determine the actual movement for that frame. If one update takes longer than expected, the next update will take that into account by moving the sprite a little further. It's not perfect (read Fix your Timestep! to understand why), but at least it runs smoother. Here's a few more tips: try using one list of images per animation sequence. You can use len(sequence) to determine the number of frames. self.sequences = [[R1, R2, R3], [L1, L2, L3]] image = self.sequences[currentSequence][currentFrame] Or perhaps give sequences a name: self.sequences = {'right': [R1, R2, R3], 'left': [L1, L2, L3]} There's no need to use named variables to store the images in. Try using a list comprehension instead: filenames = ['r1', 'r2', 'r3'] images = [pygame.image.load(filename + '.png') for filename in filenames] Did you think about how to handle pausing your game? That's difficult to implement if you're using timestamps (get_tick). Try keeping track of how much time there's left until the next animation frame instead, while passing in a time delta instead of a timestamp. Pausing is then as easy as not updating, or passing a delta of 0.
  9. Captain P

    What tools do you use to design a game?

    Actually, Paint.NET is quite a bit more advanced than MS Paint - it's somewhere in-between Paint and Photoshop (and it's free). Layers, a proper history, effects, plugins... I wouldn't want to miss those anymore. The same goes for Notepad++ - it's much better than plain old Notepad. Syntax coloring, auto-completion, tabbed interface, plugins (function list, explorer, diff tool)... it's more like a generic light-weight IDE than a text editor really. Oh, forgot to mention - I'm using SVN for version control. I haven't put much thought into a backup strategy though so that mostly consists of mailing archives to myself, heh.
  10. That's a creative way to hack your way around the given restrictions, but I wonder if it's worth the effort. Technically, you're still using the console, but likely not in the way your teacher intended, so this sounds rather risky to me. Are you sure this is ok? Perhaps you're forced to use the console because you have to focus on the program itself instead of it's representation... We were once tasked to design a program without starting to implement it. Impatient as we were, we started implementing immediately after we came up with a design... but half-way down the road we were told to implement another groups design. We could've saved ourselves some work if we had just listened (on the other hand, it was fun to build two different programs, heh). So yeah, I'll have to agree with the rest: don't use the console for something like this. But if you do have to use it, then accept that this is not what it's designed for. Having that said, there are many roguelikes that do make good use of console 'graphics'. It's crude, but the emphasis in these games clearly lies on the gameplay, not the visuals. Well, sorry I can't help with the font issue, but I hope my post was still helpful somehow. Good luck with your project.
  11. Captain P

    Any suggestion to easily add rvalue support?

    Why all the const and non-const versions of f? You can pass a non-const object into a function that expects a const reference just fine. So, for each object, check what will be done with it. Will it be modified? Then the function shouldn't promise that it won't - so don't mark that reference as const. Will the object not be modified? Then you can safely mark it as const. Be as strict as possible, but not more strict than that. Also - and maybe that's because I work more with higher-level languages these days - this looks like a lot of scaffolding code. What exactly will it gain you? Is it worth the effort or is your time better spent on other things? Will you actually use all versions of f? Do you need to distinguish rvalues and lvalues, or will your code work just fine without that distinction?
  12. Captain P

    What tools do you use to design a game?

    I see no need to use a heavy-duty language when I can use a nimble one instead, so at home I mostly use Python and Pygame. Notepad++ and Idle for writing code, Paint.NET for creating images and pen and paper to work out (game-)design issues.
  13. Captain P

    debugging ideas

    Did you get any error messages - if so, what did they say? Did you try stepping through your function with the debugger? If so, did you see anything suspicious? Can you load that particular .obj file in a modeling program or with another loader? Did you write the .obj loading code yourself or did you use an existing library? The more information you can get, the easier it will be to pinpoint the source of the problem.
  14. Captain P

    A Hexagon Based Tile Map For Xna

    You can store your data in exactly the same way. Just indent every odd row (or column, depending on the hexagons orientation) when displaying your tiles. Imagine that each [] is a hexagon: [font="Courier New"][][][][] [][][][] [][][][] [][][][] [font="Arial"]Of course, hexagonal tile images will differ from square ones. Hexagonal ones will have some empty space at the corners, so you should reduce the vertical distance between rows somewhat to take that into account. Exactly how much depends on how high these empty corners are, and that's up to you to decide. 2:1 edges usually work well in pixel art, so if a tile is 64x64, then it'll have a 32x16 empty triangle at every corner, so each next row should be draw 48 ( = 64 - 16) pixels below the previous one.[/font] [/font]
  15. Captain P

    Ai Idea

    As far as I know things like this are quite common in roguelikes. You should investigate that genre if you haven't already. Another good example would be L4D's AI Director. Although there's no dynamic map generation going on, mobs are spawned in different places every run, and there's a pacing system that makes sure players don't get tired of combat by creating some rest periods every now and then. I recently found an article on that here (.pdf).
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!