Re: [pygame] Line collision detection?
Or if you like spoilers maybe somebuddy has some Python code you can rip, like this guy: http://code.google.com/p/gummworld2/source/browse/branches/tiled2/gamelib/gummworld2/geometry.py Specifically, functions line_intersects_line and point_in_poly. Gumm On Mon, Feb 20, 2012 at 3:33 PM, Miriam English m...@miriam-english.orgwrote: You could use the point of intersection between two lines. One line is the bullet trajectory. The other line is the target trajectory. You have to take into account the time of the intersection too. If the intersection falls inside the target at the right time for both projectile and target then it is a hit. Paul Bourke gives a simple explanation with C code examples at: http://paulbourke.net/**geometry/lineline2d/http://paulbourke.net/geometry/lineline2d/ That's for 2D. The 3D solution would be more complex, but not too much. It could be simplified by making bullets travel instantaneously if distance is negligible. In fact if that's the case there may be an even simpler way of solving whether a line intersects a volume. Cheers, - Miriam Julian Marchant wrote: Hi, I tried searching the internet for an answer, but didn't find anything, so I'll ask here. One problem with normal collision detection I'm sure we're all aware of is the problem that objects moving too fast can pass through other objects without a collision happening. I'm experiencing this problem with a scrolling shooter I'm working on because both bullets and enemies move pretty fast, one enemy is very small, and the frame rate is usually somewhat low (maybe 30 FPS) on the machine I'm targeting. Now, obviously, I intend to make other changes which will help, e.g. making these tiny enemies bigger, but I'd like to tackle the problem directly. There are two ways I can think of: The first way, which I easily could implement and would be most effective, is to move the bullets in steps and do collision detection each step. I have done something like this in a previous game and it worked well, but it seems like overkill in this game (the bullet subrect is only 5x5 pixels) and it isn't perfect anyway. The second way, which I would prefer, is to detect collision with a line from the bullet's new position to the bullet's previous position. I've seen this discussed on the Game Maker Community. The problem with this is I have no idea of how this could be done in a remotely efficient manner. The only method I can think of is to check every individual pixel one at a time, which is obviously not a good idea. Bullets can move diagonally, so just checking the x or y position won't work. So, in a nutshell, my question is: how could I do line collision detection like this in a relatively efficient way? -- If you don't have any failures then you're not trying hard enough. - Dr. Charles Elachi, director of NASA's Jet Propulsion Laboratory - Website: http://miriam-english.org Blogs: http://miriam-e.dreamwidth.org http://miriam-e.livejournal.**comhttp://miriam-e.livejournal.com
Re: [pygame] pygame performance limits
Hi, Armor Nick. Some common bottlenecks I've encountered: rendering many images per frame brute force collision checking computationally intensive logic and AI real-time image transformation heavy usage of images with SRCALPHA 2D and 2.5D layering particles These are easy limits to hit early on especially in scrollers, platformers, and bullet hell type games, or when you start adding environment and GFX. But there are clever techniques that pygamers have developed to deal with them in the form of cookbook recipes, libraries, and modules. Many issues can be easily mitigated by selecting a culling technique or two to reduce the number of things processed each game loop. Some people popping into IRC lately seem easily frustrated by these challenges, wanting an inefficient workload to just perform well. I can understand the sentiment. But I personally get an immense amount of pleasure from conquering these challenges. :) When I started pygame three years ago I was told you can't do a scrolling action-RPG: it's too much work for the CPU. Since then, computers became a significantly faster and several people have produced reasonably impressive action-RPGs, as well as other genre. For some examples one only has to look among the top places at pyweek.org, where pygame competes with the likes of pyglet, cocos2d, and rabbyt, all of which have the proclaimed advantage of 3D acceleration. It's become clear to me that for most hobby games the only real limitation is the resourcefulness of the programmer. I personally haven't yet hit a wall with Python or pygame that forced me to look at another framework or a natively compiled language, and I've done a few relatively ambitious projects. That may seem like a biased representation of Python's and pygame's capabilities, but I assure you it's not. A few times a year my eyes wander to other game development libraries or engines, but I keep coming right back to pygame. Hope that perspective helps. Gumm On Wed, Nov 23, 2011 at 6:08 AM, Chris Smith maximi...@gmail.com wrote: You can use Renpy for graphic novels. SNES RPG's would be no problem. For AI and other things, python might be slow but you will probably be surprised how far you can go with it. It'll certainly be easier than going the C++ route (although I'm not a C++ fan, to be honest... I'd use Lisp if I needed the code to be faster). On 23 November 2011 21:47, Nick Arnoeyts nickarnoe...@gmail.com wrote: I'm actually not quite sure what I'm going to write yet. Either an RPG in the style of SNES-era Final Fantasy, or a visual novel (if you know Higurashi or Clannad). I'm not (yet) interested in 3D and I would certainly do something like that in C++. Pygame is probably fast enough for the graphics, but I was wondering how performance would be for AI and other calculations. yours truly armornick 2011/11/23 Chris Smith maximi...@gmail.com You can't really compare the language C++ with the library Python. You could compare C++ / SDL with Python / Pygame, and probably C++ would be faster (but maybe by not as much as you think)... but it would certainly take a lot more time to write the code. As to what you can do with Pygame, well it is a 2D library that I find fast enough for most things. In some ways I think Pygame is a little 'old-school': Pygame does not do a lot for you, but it gets out of the way, and perhaps most importantly, it's small enough to fit in my mind but big enough to do what I want. Unless you develop as part of a team you need 3D, you are unlikely to choose a project that Pygame cannot handle in some way. Perhaps you could tell us more about what you wanted to write... that would make it easier to tell you if Pygame could do this for you. Chris On 23 November 2011 21:07, Nick Arnoeyts nickarnoe...@gmail.com wrote: Hey everyone I was wondering what the limits of pygame performance are. What is the absolute maximum kind of game that can be written with it, and what kinds of things are better done in pure C++ than python? This is probably a question that's asked periodically on the mailing list, so I apologize in advance. Yours truly Armor Nick
Re: [pygame] Students Interested in Pygames Community
Hi, Elinor. There may be an opportunity to provide answers to the questions frequently asked on IRC channel #pygame. Tutorials do exist, and people use them. More than a few pygame neophytes often come to the channel looking for a fast track to pygame mastery. They don't want to read the API docs, articles, nor look for examples outside the few tutorials available on pygame.org. The questions' typical preamble: I'm looking at Punch the Monkey, but I can't figure out how to... Alas, even the venerable Punch the Monkey tutorial is not simple enough in some circumstances. It is clear that there will always be an influx of people who would appreciate a progressive collection of focus tutorials, each small enough to digest with ease. A very useful feature would be references (URL or module.Class.component) to the key pygame features they demonstrate, linking the practical example to its API documentation. Here are some of the questions I remember. The ones with oo (two o's) are significantly more advanced than Punch the Monkey. o When I render my FPS in a font, it keeps overwriting itself and I can't read it. (simple/proper game loop setup) o How do I manipulate Rect objects? (in all the various ways) oo How do I use sprite.Group, et al? (progression, simple to complex usage) o How do I test collisions? (this seems to be arcane to neophytes, though the sprite.Group and Rect classes seem pretty straightforward) oo How do I handle collisions? (stop, rebound, slide along edges) oo How can I detect collisions between different shapes? (sprite.Group supports custom collided callbacks; and there are other ways that don't involve pygame) oo How can I detect pixel-perfect collision? (various handling involving non-axis aligned math a bonus) oo How can I detect collisions for bullet or line-of-sight scenarios? o After a while my game window says Not Responding. (basic event housekeeping) oo How can I make parts of my game process pygame events differently (contextually)? oo I want an intro, a menu, a game loop, a high score, a credits... How do I connect all these without having one monolithic, spaghetti tangle Game class? oo How can I tint my surfaces, or overlay effects such as patterns? oo My game world is bigger than the screen. How do I manage the world and a camera to update and draw only the visible parts of the world? (many libraries do this, but they are not tutorials; people most often seek entry to this concept so they can learn by writing their own library) #pygame denizens can probably come up with many more. Gumm
Re: Re: [pygame] Students Interested in Pygames Community
On Fri, Oct 21, 2011 at 4:48 AM, René Dudfield ren...@gmail.com wrote: Yeah, and music programming is fun too. As well, text adventures - with natural language processing - can teach a lot about language. Upon René's mention of text it occurs to me that pygame sports an international community, but I don't often see internationalization in our games. I'm sure I could figure it out if I took the time, but if there were an simple, extensible module (a la pygame.org/cookbook) and a tool for managing it we might see more of that. We may not see many translations, but the capabilities would be there if someone wanted to contribute a translation to an existing game. Gumm
Re: [pygame] Fill a Rect object with color?
Lemme borrow Russell's method to show what I think is your missing piece: some way of getting a boom tower's rectangle onto the game's playfield (the main PyGame surface). Run it, and left-click the mouse to change the state of the boom tower. import pygame from pygame.locals import * class BoomTower: def __init__(self, bounds, normal_color, fire_color): self.normal_image = pygame.Surface((bounds.w,bounds.h)) self.normal_image = self.normal_image.convert() self.normal_image.fill(normal_color) ## Set the colour to the default self.fire_image = pygame.Surface((bounds.w,bounds.h)) self.fire_image = self.fire_image.convert() self.fire_image.fill(fire_color) self.current_image = self.normal_image def get_current_image(self): return self.current_image def shoot(self): ## Your other code here if self.current_image is self.normal_image: self.current_image = self.fire_image else: self.current_image = self.normal_image def draw(self, surface, pos): rect = self.current_image.get_rect() rect.center = pos surface.blit(self.current_image, rect) pygame.init() pygame.display.set_mode((800,600)) s = pygame.display.get_surface() r = pygame.Rect(50,50,100,100) boom_tower = BoomTower(r, Color(white), Color(red)) while 1: for event in pygame.event.get(): if event.type == MOUSEBUTTONDOWN: boom_tower.shoot() boom_tower.draw(s, r.center) pygame.display.flip() Gumm Russell Cumins wrote: I'm not 100% sure what you are wanting to change the colour so forgive me if I'm going off on a tangent here. From what you have said thus far I am assuming you want to change the colour of the BoomTower object when it if firing. What I would do is this... class BoomTower: def __init__(self,position,size,colour,fireColour): self.colour = colour self.fireColour = fireColour self.rect = Rect(position,size) self.image = Surface(size) self.image.fill(colour) ## Set the colour to the default def shoot(self,...): ...## Your other code here self.image.fill(self.fireColour) You probably need to add some more code elsewhere to change the colour back for when the BoomTower object is not firing.