Tag Archives: Pygame

More refactoring progress.

The work to restore functionality to my game before it was split up continues. I solved the hyperspeed problem, and have avoided properly dealing with object management up to this point.

Like I mentioned before, Wing Pro is super helpful for refactoring. They’ve got a dedicated refactoring tool than is essentially a search and replace tool, except it tries to determine whether or not self.target in one class is the same as the self.target in the other, so it will not change it by default, but you can easily click and set a new one.

I will admit refactoring like this is a pretty boring process. It’s mostly just adding a module name before most variables, but then I start to wonder if that’s the best way to do it, if I should use local objects or not, whether I should create a class that stores all the names as an attribute, but then doesn’t a dictionary do the same thing?

The problem came from decision to split it up into modules. The old code would say something like: if self != player: target player else target allOtherCreatures sort of deal. The issue was that I’d use the actual names of the objects, since everything was created in the global namespace. When I split the project up, it was no longer to available through common means. So the way I solved was add an isPlayer attribute to the player, and added all creatures into a list, which each instance used to create a target list. If self was player, then it would take all the creatures from that list and add them to its own, otherwise the target list would be culled for the instances with isPlayer == True. I suppose that I’ll have to isMob and isItem eventually, but that’s too far into the future for now.

I’ve also been trying to clean up my many print functions used for debugging, because often times I’d just use print self.target and that’s it, but I’m trying my best to change it to something like print ‘This is the target:’, self.target . I also don’t use .format as much as I could simply because I don’t like typing up {0} all the time. Lazy, I know.

No new content though to speak of, maybe I’ll create a new WP tag, just to filter out the posts with content updates or not…

Good news everybody

I guess I got a bit hasty, and instead of doing the responsible thing, I just erased some complicated forward thinking functions I had implemented, and now everything is going to be dealt with as if it was normalized. I had to change a bunch of code, but the entire code base is still less than 1k lines, so it wasn’t too too bad.

Currently trying to integrate a new window/frame with tkinter so I can monitor certain stats, debug or otherwise, without printing ’em. Hopefully I’ll figure it out, otherwise I’m sure pyGame has some sort of window option.

Update Oct 25th 2011

Lines 776, files 1

Alright, so I’m at a point where I’ve begun showing it off to a few friends. It’s cool enough to see for my first project. It’s got just enough to be a minimal app. It’s basically moving and shooting still targets now.

What I’ve got is :

  • Basic movements down with mouse and KB+KP
  • Shooting with hit detection. Plus shrapnel streams off the side in a perpendicular way.
  • Can change sprite, I call frame, on the fly with 0-9 keys, if you hit an enemy, they cycle through the frames I’ve got made.
  • FPS is shown at the stop, but I took that from someone else, but it’s a fairly basic:

frame_count += 1

if frame_count % 15 == 0:
t1 = time.clock()
frame_rate = 15 / (t1-t0)
t0 = t1

  • No walls or boundaries for movement, but there is for bullets, because they need to be limited for memory’s sake.
Here’s an image: Here's my first SS

What I’m looking to do now is add a basic AI, where it moves for a second and aims for another 1/2, then decides to fire if it can see an enemy.

Balls though, my math has never really been that great, but it’s sure as shit challenging using all the sine and cosine and atan2 stuff.

I’m also struggling with using PyGame’s Rects properly.