Re: [pygame] roguelike question
On Mon, Oct 04, 2010 at 01:05:36PM -0500, Michael Schultz wrote: > Hi, new to the list, but not the language. I'm completely at home with > Python :) Have you read PEP 8? Your Common.Common class, which has two unrelated methods and no instance state, and is instantiated everywhere for a single use and then discarded, is not how we do things in Python land. What's wrong with a simple global function? > Right now, I'm coding a roguelike game, and am having > trouble getting the map to update changes. I've got movement and > collision detection, but for whatever reason, the changes to the map > are not being updated. > > When the player is up against a "d" tile, and presses the key "d", the > "d" should be replaced with a "." tile, but nothing's happening. Because the code: for tile in tiles: if tile.rect.bottom == new_tile.rect.top: tile = new_tile is not doing what you think it is doing (and also, the comparison looks wrong). You need something like: for index, tile in enumerate(tiles): if tile.rect == new_tile.rect: tiles[index] = new_tile (Incidentally, a plain list of tiles is not the best data structure for a roguelike.) > Here's the files: > > ===move_test.py > http://pastebin.com/fmz491K9 > > ===Actions.py > http://pastebin.com/TUm3mv3b > > ===Terrain.py > http://pastebin.com/SXR8LqyL > > ===Common.py > http://pastebin.com/YhN2Cszu > > ===Imp.py > http://pastebin.com/2g4Yz469 Why not use Mercurial and put the code on bitbucket.org? Or git and github.com? Or Bazaar and launchpad.net? Marius Gedminas -- The primary purpose of the DATA statement is to give names to constants; instead of referring to PI as 3.141592653589797, at every appearance, the variable PI can be given that value with a DATA statement, and used instead of the longer form of the constant. This also simplifies modifying the program, should the value of PI change. -- Fortran manual for Xerox computers signature.asc Description: Digital signature
Re: [pygame] pygame.mixer.init(frequency=?)
On Thu, Feb 25, 2010 at 10:37:36AM -0800, James Paige wrote: > On Thu, Feb 25, 2010 at 10:31:12AM -0800, B W wrote: > >I have two songs. One has a bitrate of 48000, the other 44100. If I allow > >Pygame (SDL mixer) to use the default frequency, the playback speed of > > the > >songs is distorted. If I explicitly set the mixer frequency to match a > >song so it sounds good, the other sounds distorted. > > > >Reinitializing the mixer is not a good option. There are other sounds > > that > >need to play, and would be interrupted by a reinit. Resampling the songs > >is not ideal, either, as Vorbis is a lossy format and sound quality is > >obviously lost in re-sampling. Is that a theoretical observation, or can you actually hear the difference? > >Does anyone have a recommendation? Are all sounds in an implementation > >expected to have the same bitrate? > > Even if SDL_mixer was capable of handling this situation, it would still > have to handle it by resampling. Unless I am greatly mistaken, there is > no way to avoid resambling in this situation, so it will be better to > resample in advance, rather than to expect the library to do it at > runtime. If SDL resampled the sound on load, you'd end up with: decode vorbis -> resample (mostly lossless) -> play. If you resample it in advance, you end up with decode vorbis -> resample (mostly lossless) -> reencode vorbis (lossy!) => decode vorbis -> play It's not the resampling that B W is trying to avoid, it's the lossy reencoding. Marius Gedminas -- (mental note: stop installing red hat. everytime i do so, it takes ages to fix my system again.) -- from the sig of Martin H�gman signature.asc Description: Digital signature
Re: [pygame] Requiring pygame in setup.py
On Sun, Oct 04, 2009 at 09:33:47PM -0300, Henrique Nakashima wrote: > Hello, I'm working on my setup.py for a Pygame library > (http://www.pygame.org/project-LibRPG-1293-2260.html) and trying to > declare Pygame 1.9.1 as a dependency. I wrote: > > setup(... > provides=['librpg'], > requires=['pygame(>=1.9.1)'], If you use setuptools, it's spelled install_requires. If you use distutils, it doesn't enforce dependencies. >... >) > > It worked, but when I replaced 1.9.1 with 1.9.2, to check if it > actually depended on pygame, it worked as well. What is the right way > to ask easy_install to get pygame as a dep when my lib is installed? Marius Gedminas -- To stay awake all night adds a day to your life. -- Stilgar (Frank Herbert _Children_of_Dune_) signature.asc Description: Digital signature
Re: [pygame] Re: Hexagonal collision detection?
On Wed, Sep 16, 2009 at 05:14:11AM -0700, rygoody wrote: > Alright NEVERMIND about explaining it. I spent like the past hour > studying this and figured it out. > > I gotta say, this is like the most brilliant function ever for this. I > would have never thought of this. That's why we have textbooks :-) Although they're called "blog posts" these days. I only wish I had a link handy -- perhaps Ian will supply one? Analytical geometry is fun! Marius Gedminas -- We'll show a small example here with one user calling another. (Under international treaties describing technical papers these users must be called "Alice" and "Bob".) -- Anthony Baxter signature.asc Description: Digital signature
Re: [pygame] file mods and svn props for executables
On Tue, May 12, 2009 at 09:46:29PM +0200, Marcus von Appen wrote: > On, Tue May 12, 2009, James Paige wrote: > > > On Tue, May 12, 2009 at 08:58:02PM +0200, Marcus von Appen wrote: > > > #!/... > > > > > > line is usually dealt with correctly by env(), which in turn is executed > > > correctly by bourne-compatible shells. > > > > Not unless the executable bit is set. > > sh myfoo.py > > works just great, even without the executable bit (as supposed by bourne > shells). No it does not. Please do not spread disinformation. m...@platonas:~ $ cat example.py #!/usr/bin/env python if 2 * 2 == 4: print "hello" m...@platonas:~ $ sh example.py example.py: 4: Syntax error: end of file unexpected (expecting "then") m...@platonas:~ $ python example.py hello Marius Gedminas -- Programs that write programs are the happiest programs in the world. -- Andrew Hume signature.asc Description: Digital signature
Re: [pygame] file mods and svn props for executables
On Tue, May 12, 2009 at 11:49:36AM -0700, Lenard Lindstrom wrote: > I was looking at the Pygame examples in linux and noted that many have > the '#!/usr/bin/env python' tag line but are not marked as executable > either by SVN or linux. Is there a convention for this? If it has a #! line, and works when executed, it should be marked as executable in svn/file system permissions. Marius Gedminas -- Suppose you went back to Ada Lovelace and asked her the difference between a script and a program. She'd probably look at you funny, then say something like: Well, a script is what you give the actors, but a program is what you give the audience. -- Larry Wall signature.asc Description: Digital signature
Re: [pygame] [Pygame] Key Configuration
On Mon, May 11, 2009 at 05:31:06PM -0700, Fawkes wrote: > I was wondering what would be the best way to do a key configuration > for my game? One of the comments from our recent release ( > http://pygame.org/project/1106/ ) was that we ought to have the > controls configurable by the player for instance if they have a non > QWERTY keyboard. Right now all the controls are hard coded (e.g. the > game looks to see if Z is pressed, do something). I was thinking of > using a dictionary like the following. > > controls{ > "confirm":K_z, > "cancel":K_x > "prev_ally":K_a, > "next_ally":K_s, > "prev_enemy":K_q, > "next_enemy":"K_w} > > The values within the dictionary would be changeable by the player > within the game. Is this a good way to go about doing this? Sometimes it's useful to allow more than one key for the same action. Like claudio already said, for the purposes of the main game loop it's more convenient to have a dictionary from key to action (it also allows you to detect conflicts). However for the purposes of the user interface, it may be more convenient to have a dictionary like you have. It's pretty simple to translate between the two forms, so you could have both. Marius Gedminas -- Never, ever expect hackers to be able to read closed proprietary document formats like Microsoft Word. Most hackers react to these about as well as you would to having a pile of steaming pig manure dumped on your doorstep. -- ESR (http://www.tuxedo.org/~esr/faqs/smart-questions.html) signature.asc Description: Digital signature
Re: [pygame] Cairo + SDL
On Sun, 5/3/09, Marius Gedminas wrote: > On Sun, May 03, 2009 at 07:32:39AM -0700, Yanom Mobis wrote: > > Is cairo used for game programming? > > There are a few games using Cairo: > http://lists.cairographics.org/archives/cairo/2006-May/007032.html > > It was not designed specifically for games, though, unlike SDL. On Mon, May 04, 2009 at 03:47:04PM -0700, Yanom Mobis replied: > so does it have support for collision detection, load images onto the > screen, mouse input, etc? No, yes, no, and why don't you go over to http://cairographics.org/ and read a little, if you're interested? Marius Gedminas -- A: Because it destroys the flow of the conversation Q: Why is it bad? A: No, it's bad. Q: Should I top post in replies to mailing lists? signature.asc Description: Digital signature
Re: [pygame] Cairo + SDL
On Sun, May 03, 2009 at 07:32:39AM -0700, Yanom Mobis wrote: > Is cairo used for game programming? There are a few games using Cairo: http://lists.cairographics.org/archives/cairo/2006-May/007032.html It was not designed specifically for games, though, unlike SDL. Marius Gedminas -- We don't care. We don't have to. We're the Phone Company. signature.asc Description: Digital signature
Re: [pygame] API draft for vector type
On Wed, Apr 29, 2009 at 11:02:58PM +0200, Lorenz Quack wrote: > Marius Gedminas wrote: >> On Tue, Apr 28, 2009 at 06:32:12PM +0200, Lorenz Quack wrote: >>>>> 1.5.4.1 v.isNormalized() -> bool >>>>> 1.5.4.2 v.normalize() -> None# normalizes inplace >>>>> 1.5.4.3 v1.normalized() -> v2# returns normalized vector >>>> In my opinion normalize() and normalized() are far too ambiguous. We >>>> might should use something like ip_XXX() for inplace operations: >>>> >>>> v.ip_normalize () -> None >>>> v.normalize () -> v2 >>>> >>>> We do that naming already for Rect objects and should take care of doing >>>> that anywhere where inplace operations happen. The same then applies to >>>> the rest of your inplace methods. >>> hm. ok. but the ip is after the name: v.normalize_ip() >> >> When I see 'ip', I cannot stop thinking about IP addresses. >> >> I think .normalize() vs .normalized() is clear enough, and also follows >> the convention set by Python builtins (list.sort() vs sorted()). > > I personally also prefer .normalize() and .normalized() but if there is > also a precedence like with rect in this case I prefer consistency over > my personal taste. Consistency within pygame trumps consistency with the stdlib. I'd forgotten about Rect's _up convention, and was evidently not paying attention to the original quoted text ("We do that naming already for Rect objects"). Marius Gedminas -- Some of the more environmentally aware dinosaurs were worried about the consequences of an accident with the new Iridium enriched fusion reactor. "If it goes off only the cockroaches and mammals will survive..." they said. signature.asc Description: Digital signature
Re: [pygame] API draft for vector type
On Wed, Apr 29, 2009 at 12:40:24PM -0700, Patrick Mullen wrote: > On Tue, Apr 28, 2009 at 3:39 PM, Marius Gedminas wrote > > >>> 1.8 misc > > >>> == > > >>> 1.8.1 support iter protocol > > >>> 1.8.2 str(v) -> "[x, y, z]" > > >>> 1.8.3 repr(v) -> "Vec" > > >> > > >> Most objects have the same output for str() and repr(). Why do you > > >> differ here? > > > > > > with repr I wanted to make explicitly clear that this is not a list but I > > > thought that the normal str() would look nicer that way. what would you > > > suggest? "[x, y, z]" for both (or "(x, y, z)" if we choose to make > > > vectors immutable) or "Vector3d"? > > > > I'm +0.95 for distinct __str__ and __repr__. str is what you show your > > users and should be short and clear, while repr is what you give the > > programmers who're debugging and therefore exact types matter. > > > > As far as I understand it, __repr__ is supposed to give you a representation > that can reproduce an equivalent object. "Supposed to" is too strong, but yes, if that's not too cumbersome, it's a good idea. > In other words, eval(repr(ob)) == > ob. I'm not sure if this property is true in all cases where __repr__ has > been used, Definitely not. > but it holds for python standard types. Not all of them. > I think it's more of a > consideration than a full on standard. Yep. > Still, I would prefer then to have > the __repr__ be "Vector3d(x, y, z)" if that is in fact the constructor of a > vector3d. Of course this doesn't matter much. Yes and yes. Marius Gedminas -- Bumper sticker: Alcohol and calculus don't mix. Never drink and derive. signature.asc Description: Digital signature
Re: [pygame] API draft for vector type
On Tue, Apr 28, 2009 at 06:32:12PM +0200, Lorenz Quack wrote: >>> 1.5.4.1 v.isNormalized() -> bool >>> 1.5.4.2 v.normalize() -> None# normalizes inplace >>> 1.5.4.3 v1.normalized() -> v2# returns normalized vector >> >> In my opinion normalize() and normalized() are far too ambiguous. We >> might should use something like ip_XXX() for inplace operations: >> >> v.ip_normalize () -> None >> v.normalize () -> v2 >> >> We do that naming already for Rect objects and should take care of doing >> that anywhere where inplace operations happen. The same then applies to >> the rest of your inplace methods. > > hm. ok. but the ip is after the name: v.normalize_ip() When I see 'ip', I cannot stop thinking about IP addresses. I think .normalize() vs .normalized() is clear enough, and also follows the convention set by Python builtins (list.sort() vs sorted()). And if vectors are immutable, this question becomes moot. >>> 1.6 properties >>> == >>> 1.6.1.1 v.length -> a # gets the magnitude/length of the vector >>> 1.6.1.2 v.length = a >>> # sets the length of the vector while preserving its direction >> >> The setter might be risky due to rounding issues. > > true, but I think this can be very usefull. and I can live with the fact that > v.length = 1. > v.length == 1. # -> false > when dealing with floating point variables you have to expect weird > behavior like this. I used to think that way. Then I read _What Every Computer Scientist Should Know About Floating Point Arithmetic_ and understood that floats are very predictable if you understand them. (I still don't understand them. *wink*) >>> 1.7 comparison operations >>> = >>> 1.7.0the "==" and "!=" and "bool" operater compare the differences >>> against >>> the attribute v._epsilon. this way the user can adjust the >>> accuracy. >>> 1.7.1.1 v == s -> bool >>> # true if all component differ at most by v._epsilon >> >> How am I as user supposed to manipulate _epsilon? It should be made public. > > well. I thought you rarely want to twiddle with this so I marked it > private. I thought the normal user doesn't want to be bothered with this > and the pro can access it. I'm kind of expecting some expert to pop in and explain how this breaks mathematical properties of equality (v1 == v2 and v2 == v3 no longer implies v1 == v3) and how this could result in bugs and pain in real life code. >>> 1.8 misc >>> == >>> 1.8.1 support iter protocol >>> 1.8.2 str(v) -> "[x, y, z]" >>> 1.8.3 repr(v) -> "Vec" >> >> Most objects have the same output for str() and repr(). Why do you >> differ here? > > with repr I wanted to make explicitly clear that this is not a list but I > thought that the normal str() would look nicer that way. what would you > suggest? "[x, y, z]" for both (or "(x, y, z)" if we choose to make > vectors immutable) or "Vector3d"? I'm +0.95 for distinct __str__ and __repr__. str is what you show your users and should be short and clear, while repr is what you give the programmers who're debugging and therefore exact types matter. >>> 1.10 open questions (in no particular order) >>> >>> 1.10.1 a) use radians for all angles >>> b) use degrees for all angles >> >> Degrees, I'd say. The api should be easy to use and letting users >> calculate the rad values before is not that intuitive. math.radians(180) is not intuitive? Well, maybe. You have to know it's there. (Can I mention math.hypot? Nobody knows about math.hypot. It's a modest little function that deserves more fame than it gets.) > I just checked: unfortunately pygame seems to be inconsistent: > transform.rotate use degrees and draw.arc uses radians. Does transform.rotate rotate clockwise or counter-clockwise? Pydoc doesn't say. >>> * __abs__ >>> pyeuclid returns the magnitude. >>> 3DVectorType returns vec3d(abs(x), abs(y), abs(z)) >>> vectypes and this proposal don't implement __abs__ to avoid confusion >> >> I'd expect abs() to get the magnitude/length, too. > > I don't so to avoid confusion I wouldn't implement it at all. how do > other people feel about this? I'd expect len(v) to return its length, but (1) that would be a horrible abuse of the sequence protocol, and (2) Python doesn't allow __len__ to return a non-integer value, thankfully. I didn't even know/had forgotten all about __abs__. > thanks again for the quite thorough feedback. Thanks for the comprehensive proposal. Marius Gedminas -- User n.: A programmer who will believe anything you tell him. signature.asc Description: Digital signature
Re: [pygame] Never seen this before
On Sat, Apr 25, 2009 at 08:17:11AM -0700, Tyler Laing wrote: > Happens to everyone. It takes time(10 years or 10,000 hours) to get > good at something. I'm at about year 6-7 and I find while I still make > silly mistakes, I've become much better at catching them before or > during testing. :) Silly mistakes never go away. With experience you begin to expect them and check your assumptions more often. There have been countless times I've written unit tests for tiny functions that I couldn't possibly have written wrong, only to discover that I have in fact made a silly mistake. Marius Gedminas -- I'm unaware of anyone having implemented even a fraction of H.323 in Python. Doing so would require a special kind of dedication, and quite possibly a large amount of whiskey and prescription medication. -- Anthony Baxter signature.asc Description: Digital signature
Re: [pygame] Never seen this before
On Sat, Apr 25, 2009 at 06:33:00AM -0700, Yanom Mobis wrote: > what does the super() function do? It's a way to call the superclass version of the method you're overriding. (Technically, it's a built-in type, and not a function, but that's an irrelevant implementation detail). Read more about it: * http://www.python.org/download/releases/2.2/descrintro/#cooperation * http://fuhm.net/super-harmful/ Marius Gedminas -- Microsoft's entry in this cavalcade of horrors is Universal Plug and Play (UPnP). This is a protocol that allows [...] an end-user system to request a dynamic port-forwarding from the firewall to the box. Many network administrators will probably (rightly) recoil at letting applications on a Windows box dictate firewall policy. -- Anthony Baxter signature.asc Description: Digital signature
Re: [pygame] multi-width aalines and aacircles
On Tue, Mar 24, 2009 at 08:56:16AM -0600, John Krukoff wrote: > > -Original Message- > > From: owner-pygame-us...@seul.org [mailto:owner-pygame-us...@seul.org] On > > Behalf Of Lenard Lindstrom > > Sent: Monday, March 23, 2009 6:07 PM > > To: pygame-users@seul.org > > Subject: Re: [pygame] multi-width aalines and aacircles > > > > None of the SDL_gfx functions has a line width argument that I could see. > > Sure, but at least SDL_gfx gives you the tools you need to get there for AA > lines. A filled polygon, redraw the edges with an AA line, use some AA > circles to draw caps, and viola! > > AA donuts would still be a pain, and require an offscreen buffer, which is > unfortunate. > > And, likely you'd ask for variable width AA bezier curves next, which also > isn't supported. That one may be because it's hard, though. How about full Cairo support while we're at it? ;-) Marius Gedminas -- Programs that write programs are the happiest programs in the world. -- Andrew Hume signature.asc Description: Digital signature
Re: [pygame] Redraw under mouse cursor in HWSURFACE mode
On Sun, Mar 01, 2009 at 03:19:53PM -0800, Lin Parkh wrote: > I'm noticing a weird little artifact namely that I get left over > fragments of a surface i redraw on to screen where the mouse cursor > moves. It appears as if my code is interacting with whatever controls > cursor redraw. I'm afraid I'm not familiar with this problem. > I notice that this only happens when i go to fullscreen > mode and enable hardware draw (HWSURFACE (not using double buffer right > now since not 'flipping display' but rather controling exactly what > rectangles get redrawn). You will get flicker that way, unless you're very careful about how you're redrawing those rectangles. > I need HWSURFACE to be on for performance. It's not always an improvement and could in fact lower performance. Again, it's a matter of what exactly you're drawing. > So > seems like in HWSURFACE mode the mouse cursor is run differently and is > interacting with my redraws (i.e. fails to let them complete well under > it). Anyone familiar with this kind of mouse cursor issue in HWSURFACE > mode? Thanks Marius Gedminas -- Cool. Does it also recode ISO10646-1 pcf files into the funny permutations and subsets used a long time ago in a galaxy far far away on the planets Isolatinus XV and Koiruski VIII ... -- Markus Kuhn inquires about libXft signature.asc Description: Digital signature
Re: [pygame] surfarray on 64-bit machines
On Mon, Mar 02, 2009 at 02:06:35PM +1100, René Dudfield wrote: > hehe, double typo... > > 'use_arraytype' > > http://www.pygame.org/docs/ref/surfarray.html#pygame.surfarray.use_arraytype That works better, thanks! I've refactored PySpaceWar's fading title code into three classes now, one that uses plain PyGame, one that uses Numeric, and one that uses NumPy. The last one will be preferred if available. Marius Gedminas -- main(k){float i,j,r,x,y=-16;while(puts(""),y++<15)for(x =0;x++<84;putchar(" .:-;!/>)|&IH%*#"[k&15]))for(i=k=r=0; j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111;r=j);} /* Mandelbrot in ASCII. */ signature.asc Description: Digital signature
Re: [pygame] surfarray on 64-bit machines
On Sat, Feb 28, 2009 at 10:53:56AM -0800, Lenard Lindstrom wrote: > Marius Gedminas wrote: >> On Fri, Feb 27, 2009 at 08:04:30PM -0800, Lenard Lindstrom wrote: >>> But arithmetic operations have ufunc equivalents which take an >>> optional output array. This means the astype(), along with its >>> intermediate array, can be removed. It probably also means the >>> intermediate array float array goes away as well. So it is likely >>> this alternative uses no intermediate arrays. >>> >>> ## array = pygame.surfarray.pixels_alpha(image) >>> alpha = 42.5 >>> ## array[...] = (mask * alpha / 255).astype('b') >>> numpy.multiply(mask, alpha / 255, pygame.surfarray.pixels_alpha(image)) >> >> Unfortunately this gives me a TypeError: return arrays must be of ArrayType >> > I'm guessing you have both Numeric and NumPy installed. Yes; and since I'm not writing for myself only, I'd like the code to work with all possible combinations of Numeric/NumPy/PyGame versions. (I have fallbacks in place when numpy or Numeric cannot be important.) > Try > > pygame.surfarray.user_arraytype('numpy') > > at the start. NumPy became the default only recently with 1.9. Unfortunately, this gives me AttributeError: 'module' object has no attribute 'user_arraytype' I've got pygame 1.8.1 here (Ubuntu's 1.8.1release-0ubuntu1 to be precise) Marius Gedminas -- Q: A good ninja is hard to find. A: Well, yes, actually, being hard to find is the whole point with them. -- http://tinyurl.com/5tnrwr signature.asc Description: Digital signature
Re: [pygame] surfarray on 64-bit machines
On Fri, Feb 27, 2009 at 08:04:30PM -0800, Lenard Lindstrom wrote: > Marius Gedminas wrote: >> Since I'm really clueless about >> Numeric/numarray/numpy, please tell me if this code has any obvious >> shortcomings: >> >> # initialization, done once >> import pygame >> import numpy >> image = pygame.image.load('title.png') # has an alpha channel >> mask = pygame.surfarray.array_alpha(image) >> >> # this is done once every frame >> array = pygame.surfarray.pixels_alpha(image) >> alpha = 42.5 # a float varying between 1 and 255 >> array[...] = (mask * alpha / 255).astype('b') >> > Well, alpha and 255 are both scalars, so (mask * (alpha / 255)) saves > one intermediate array. Also the preferred NumPy convention is to use > dtypes (data-types) rather than type characters: .astype(numpy.uint8). I was using Numeric.UnsignedInt8 before, and couldn't find the NumPy version of that in a hurry. dir(array) showed me a typecode() method which returned things like 'b', and so I tried those. > But arithmetic operations have ufunc equivalents which take an optional > output array. This means the astype(), along with its intermediate > array, can be removed. It probably also means the intermediate array > float array goes away as well. So it is likely this alternative uses no > intermediate arrays. > > ## array = pygame.surfarray.pixels_alpha(image) > alpha = 42.5 > ## array[...] = (mask * alpha / 255).astype('b') > numpy.multiply(mask, alpha / 255, pygame.surfarray.pixels_alpha(image)) Unfortunately this gives me a TypeError: return arrays must be of ArrayType Marius Gedminas -- ... Another nationwide organization's computer system crashed twice in less than a year. The cause of each crash was a computer virus -- Paul Mungo, Bryan Glough _Approaching_Zero_ (in 1986 computer crashes were something out of the ordinary. Win95 anyone?) signature.asc Description: Digital signature
Re: [pygame] surfarray on 64-bit machines
On Fri, Feb 27, 2009 at 11:16:28AM +1100, René Dudfield wrote: > hey, > > is it possible to use numpy instead of Numeric? Numeric really is > dying now... even we are going to stop trying to keep it working. I suppose I should. Since I'm really clueless about Numeric/numarray/numpy, please tell me if this code has any obvious shortcomings: # initialization, done once import pygame import numpy image = pygame.image.load('title.png') # has an alpha channel mask = pygame.surfarray.array_alpha(image) # this is done once every frame array = pygame.surfarray.pixels_alpha(image) alpha = 42.5 # a float varying between 1 and 255 array[...] = (mask * alpha / 255).astype('b') Cheers! Marius Gedminas -- Never trust a computer you can't repair yourself. signature.asc Description: Digital signature
Re: [pygame] surfarray on 64-bit machines
This was a long time ago (shame on me for not finding the time to investigate this further): > On Wed, Oct 22, 2008 at 7:23 PM, Marius Gedminas wrote: > > A user reported that PySpaceWar fails on 64-bit Linux machines if I try > > to scale the alpha channel. Here's the code (simplified): > > > >import pygame > >import Numeric > >image = pygame.image.load('title.png') # has an alpha channel > >mask = pygame.surfarray.array_alpha(image).astype(Numeric.Int) > >array = pygame.surfarray.pixels_alpha(self.image) > >alpha = 42.5 # a float between 1 and 255 > >array[:] = (mask * alpha / 255).astype(Numeric.UnsignedInt8) > > > > The error happens on the last line, and it says > > > >ValueError: matrices are not aligned for copy > > > > Any ideas? The code works fine on 32-bit systems. On Wed, Oct 22, 2008 at 09:28:46PM -0500, Charlie Nolan wrote: > I may be having this same error. I've got a bug report with that same > error message at one point (and on a 64-bit machine), even though it > works fine on my (32-bit) machine. Could you try printing out > "array[:].shape"? In my case, I do a sensible slice and somehow end > up with a 0x600 array. On a 32-bit machine: array[:].shape == array.shape == (333, 83) On a 64-bit machine: array[:].shape == (0, 83) On Wed, Oct 22, 2008 at 07:46:53PM -0700, Lenard Lindstrom wrote: > I am curious, but what happens if array[:] is replaced with array[...]. The code starts working! Thank you! > It is a two dimension array, so I am surprised the single index slice > [:] even works. (on 32-bit only, for some reason). > The alternate form [..] is indifferent to array > dimension. It's a thinko on my part. I want an in-place assignment, I tend to write container[:] = new_value, without considering dimensionality at all. Cheers! Marius Gedminas -- A programmer started to cuss Because getting to sleep was a fuss As he lay there in bed Looping 'round in his head was: while(!asleep()) sheep++; signature.asc Description: Digital signature
Re: [pygame] Name self not defined
On Tue, Jan 27, 2009 at 07:24:13PM -0800, James Paige wrote: > You can't use "self" in the "def" line. Here is how I usually accomplish > what you are trying to do: > > class Car(Basicsprite): #car class > def __init__(self, speedarg=(0,0)): > self.speed = speedarg > Basicsprite.__init__(self) > def move(self, speedv=None): > if speedv==None: speedv = self.speedv > self.rect = self.rect.move(speedv) > > > But maybe somebody else can suggest a nicer way to do that. The idiomatic way to express that is 'if speedv is None:'. See http://www.python.org/dev/peps/pep-0008/ Marius Gedminas -- lg_PC.gigacharset (lg = little green men language, PC = proxima centauri) -- Markus Kuhn provides an example of a locale signature.asc Description: Digital signature
Re: [pygame] Pathfinding
On Sun, Jan 25, 2009 at 07:16:38PM -0800, Yanom Mobis wrote: > 1) How is pathfinding done? There are algorithms for it. Breadth-first search is the simplest one and works well for grids where the distance between nearby cells is the same. Dijkstra is a generalization that works for arbitrary maps. A* is essentially Dijkstra with an extra heuristic that makes it work faster, which is important for large maps. All of them find the shortest possible path. Wikipedia describes them all. > 2) How do you prevent a moving sprite from being caught in a v-shaped > rut made of obstacles? You use a pathfinding algorithm. On Sun, Jan 25, 2009 at 07:20:36PM -0800, Noah Kantrowitz wrote: > 2) Alter the chain length score computation to reduce exploitation. Could you please translate that to something mere mortals without PhDs could understand? On Sun, Jan 25, 2009 at 09:13:28PM -0800, Bill Coderre wrote: > There are still ways that this can get confused or beaten, of course. > Until someone comes out with a low-cost traveling-salesman solver, > however, whatever algorithm you find will have some snags. I don't see how traveling salesman applies here. Could you elaborate? My personal snag with A* is that the NPCs seem to know too much about the map and directly walk the most optimal path without exploration. Marius Gedminas -- philiKON: I'm changing ZCML to parse files twice as fast.. niemeyer, weee ooh, I like it! how do you do that? Lying i knew it * benji cries fowl! -- #zope3-dev signature.asc Description: Digital signature
Re: [pygame] fast sqrt? and profiling
On Wed, Jan 21, 2009 at 01:43:37PM -0500, Michael George wrote: > Marius Gedminas wrote: >> On Wed, Jan 21, 2009 at 07:45:08AM -0800, Ian Mallett wrote: >> >>> math.hypot() is good for distance calculation. >> >> I did some microbenchmarks a while ago, and math.hypot() was faster than >> x**2 + y**2. I was surprised. >> > Out of curiousity, did you also try x*x + y*y? Yes. Actually, since I was using a vector class, it was self.x * self.x, and I think the speedup of using math.hypot(self.x, self.y) over self.x*self.x + self.y*self.y could be explained by reducing by half the overhead of getattr. > If it's using general > purpose exponentiation routines I could see that being slower than a > square root. Or it could be dynamic dispatch/type checks for using multiple operations (two multiplications/exponentiations, and one addition) over using a single primitive implemented in C. Anyway, it all depends heavily on the actual implementation. The timeit module is your friend. I just wanted to chime in with praise for math.hypot which is often overlooked. Marius Gedminas -- Lisp-style macros [...] are to C-style macros what Emacs is to cat. -- Jacek Generowicz signature.asc Description: Digital signature
Re: [pygame] fast sqrt? and profiling
On Wed, Jan 21, 2009 at 07:45:08AM -0800, Ian Mallett wrote: > math.hypot() is good for distance calculation. I did some microbenchmarks a while ago, and math.hypot() was faster than x**2 + y**2. I was surprised. Still, avoiding O(n**2) algorithms would be best. Marius Gedminas -- Anything can be made to work if you fiddle with it long enough. signature.asc Description: Digital signature
Re: [pygame] unit and doc testing questions
On Thu, Jan 15, 2009 at 07:44:00AM +1100, René Dudfield wrote: > it can be good to mark your slow tests somehow, so you can run them > separately. > > With pygame we extend the python unittest module to allow specifying > tags(categories) for tests. This allows us to also use interactive > tests, and other tests you may not want to run every time. > > However you could just move them into a different directory, and > change your test runner to look in a different directory given a cmd > line option... you don't need any fancy testing framework. I prefer phrasing it as "Python lets you trivially create your own fancy testing framework in 15 minutes". ;-) > doctests can be a quick way to do testing. You can create your code > in the interactive interpreter, then paste the output into the doc > strings. You can use doc tests, and unittests together too... so the > doc tests can be run in a unittest test runner. This is, in fact, my preferred mode of testing. Example: http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/tests/test_world.py (I dislike long doctests in the docstrings of real functions, they obscure the code too much and make it hard to read. Short doctests there are fine. Long doctests belong in a separate test module.) > On Thu, Jan 15, 2009 at 5:57 AM, Jake b wrote: > > I say 'compiling', because I found a method in the python cookbook that says > > "you want to ensure your modules tests are run each time your module is > > compiled." > > > > It pretty much does "if module is imported, but not main script, and needs > > recompile(because was changed): then run tests" This sounds very interesting. Do you have a URL? I tried searching on http://code.activestate.com/recipes/langs/python/, but didn't find anything. Marius Gedminas -- Writing setattr hooks properly is a black art. Writing persistent setattr hooks is more like hearding bees blindfolded... -- Casey Duncan signature.asc Description: Digital signature
Re: [pygame] unit and doc testing questions
On Tue, Jan 13, 2009 at 06:44:10AM -0600, Jake b wrote: > I'm learning about doctest, and unittests. Now if I create a file, like > pygame/test/rect_test.py , is there and easy way to import the project in > its parent directory? Make sure it's in sys.path, then import using the absolute package name. (Hint: 'pygame' is a bad name for a project, it will clash with the pygame library.) > I thought "import ../mymodule" might work, ( but at least not in 2.5 ). > Then I got it to work appending sys.path. > 1) What is your advice on imports from test files? ( Do you append your > sys.path, or something else? ) The test runner makes sure your project is importable by adding it to sys.path, if necessary. > 2) Do you have two seperate unittests ? (A) One is ran every time source > files are compiled, and a second, (B) slower one is ran at a longer interval > for slow tests ? Such separation is rarely necessary. I generally have a separate test module for every code module (with separate tests for each function/method), and then a top-level script that imports all test module, collects all the tests into a single unittest.TestSuite, and runs them. http://pypi.python.org/pypi/nose can be used instead of a custom script, but I got used to writing those before nose was available and so far hadn't gotten to try it out. "Compiling" is a very nebulous, automatic and invisible step in Python. I run the tests whenever I want to get some feedback on my code, and also before committing my changes to the source control system (you have one, right?) > 3) Other advice relating to testing ? Keep them short and fast. Marius Gedminas -- Microsoft has performed an illegal operation and will be shut down. -- Judge Jackson signature.asc Description: Digital signature
[pygame] surfarray on 64-bit machines
A user reported that PySpaceWar fails on 64-bit Linux machines if I try to scale the alpha channel. Here's the code (simplified): import pygame import Numeric image = pygame.image.load('title.png') # has an alpha channel mask = pygame.surfarray.array_alpha(image).astype(Numeric.Int) array = pygame.surfarray.pixels_alpha(self.image) alpha = 42.5 # a float between 1 and 255 array[:] = (mask * alpha / 255).astype(Numeric.UnsignedInt8) The error happens on the last line, and it says ValueError: matrices are not aligned for copy Any ideas? The code works fine on 32-bit systems. Marius Gedminas -- If C gives you enough rope to hang yourself, C++ gives you enough rope to bind and gag your neighborhood, rig the sails on a small ship, and still have enough rope left over to hang yourself from the yardarm. signature.asc Description: Digital signature
Re: [pygame] Good code for text wrapping?
On Mon, Sep 22, 2008 at 02:41:28PM +1000, René Dudfield wrote: > oops, I also forgot... > - CSS3 and CSS4 support. > - a pony. I'm sure the last one could be implemented easily, if you had SVG support and Javascript. Marius Gedminas -- In short, at least give the penguin a fair viewing. If you still don't like it, that's ok: that's why I'm boss. I simply know better than you do. -- Linus "what, me arrogant?" Torvalds, on c.o.l.advocacy signature.asc Description: Digital signature
Re: [pygame] Good code for text wrapping?
On Tue, Sep 16, 2008 at 12:11:45PM +1000, René Dudfield wrote: > The cookbook has this entry, but it doesn't work with new lines. > http://www.pygame.org/wiki/TextWrapping > > Anyone have any code like this that supports new lines? http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/ui.py#L466 Output example: http://mg.pov.lt/pyspacewar/pyspacewar-help-screen.png It's GPL-ed, feel free to use or ask me for a licence change if that's not suitable. Marius Gedminas -- If you are smart enough to know that you're not smart enough to be an Engineer, then you're in Business. signature.asc Description: Digital signature
Re: [pygame] my 3d planet game
On Thu, Jun 12, 2008 at 06:20:25PM +1000, Astan Chee wrote: > I've been working on my 3d planet game and now it is finally done. For > those of you interested the source can be found at: > http://code.google.com/p/planetgame/ > Also, this is kinda like a post-prototype, so any feedback is much > appreciated. The main window doesn't fit on my 1280x800 screen. If I blindly tab down there and press Enter, without changing any of the default settings, I get this exception: Traceback (most recent call last): File "wxSol.py", line 1925, in OnAddObj orbit = int(self.txt_orb_time.GetValue()) ValueError: invalid literal for int() with base 10: '0.6' Cheers! Marius Gedminas -- Special bonus feature: absolutely nowhere in RetchMail's code is there an arbitrary 3-second sleep(). Wow! What other mail retriever can say that? (Hint: not fetchmail.) -- http://open.nit.ca/wiki/index.php?page=RetchMail signature.asc Description: Digital signature
Re: [pygame] Battery Life
On Mon, Jun 02, 2008 at 09:31:34PM -0700, The dob wrote: > I'm running pygame on Maemo (linux on a mobile device). In my main > game loop I am using pygame.event.wait() and sleeping all other > running threads. To me this means that until there is an event, the > process should not consume very much processor time. Unfortunately, > the battery on the device still drains very quickly (about 4 hours > when idle, as compared to 2 days while other applications are idle). > > Running 'top' does not indicate that the idle process is consuming > very much processing power either. What does strace show your process doing? Marius Gedminas -- It's not illegal to disagree with my opinions (*). [...] (*) Although it obviously _should_ be. Mwhaahahahahaaa... You unbelievers will all be shot when the revolution comes! -- Linus Torvalds signature.asc Description: Digital signature
Re: [pygame] your opinion: singleton-pattern vs. modules vs. classes
Hi, On Mon, Mar 03, 2008 at 05:09:12PM +0100, Olaf Nowacki wrote: > probably most of you use an mvc aproach for writing games with pygame. > i would like to know how you implement these (mvc-) objects: > > - as classes > - as modules or > - as singleton-pattern classes? Classes. I see no point to add a restriction of at most one game in a Python process. Regards, Marius Gedminas -- Computers are not intelligent. They only think they are. signature.asc Description: Digital signature
Re: [pygame] LAN vs Internet
On Thu, Jan 31, 2008 at 12:43:45PM -0500, David wrote: > I have been making gentle progress towards a networking module for my > game, but have doubts about the value of my approach. > > I have been working toward the goal of having a module that will find > peers on a LAN, via a UDP discovery process, or on an internet server. > The game is basically a one-on-one contest, so the player-finding > process is just to setup matches, and not as a many-playered universe. > > The UDP discovery process makes the whole module much more complex, > and I am wondering whether it has any real value. Perhaps you could make it simpler by reusing an existing implementation of Zeroconf, e.g. Avahi: http://en.wikipedia.org/wiki/Avahi_(software) It's LGPL, so no licence taint. It's also cross-platform. And it has Python bindings. OTOH it might make the distribution of the game somewhat more complicated (another library to install). > Do any of you play network games on a LAN that is *not* internet > connected? How common is that usage case? I don't play multiplayer games much. > I ask, because if LANs are generally internet connected, the game can > just use an internet server to find competitors, including those > within that LAN. That would require the server to proxy all communications between players, to work with NATed LANs. Is the latency decrease worth maintaining complex code? You decide. Marius Gedminas -- Never assume the reader has read the subject line. signature.asc Description: Digital signature
Re: [pygame] Good code
On Thu, Dec 06, 2007 at 05:52:59PM +0100, Mundial 82 wrote: > Thanks to all your help, my little newbie project is shaping up. So now I > have a different question: being a non-programmer, I like to learn by > reading other people's code when it is available. I find it difficult, > though, to understand what are the good practices and structures that are > present in good coding. Hint: it's whatever makes reading and understanding the code easier. Usually the best way to do that is to split the code into separate chunks (such as modules, classes and functions) that can be reasoned about and used without having to remember what's inside them. > So, for the code reading newbies: what are your examples of nice, clean, > elegant code for games that I could take a look at (beyond the pygame.org > tutorials, that is)? I've tried to make pyspacewar code nice and clean: http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/ Regards, Marius Gedminas -- lg_PC.gigacharset (lg = little green men language, PC = proxima centauri) -- Markus Kuhn provides an example of a locale signature.asc Description: Digital signature
Re: [pygame] Fullscreen Display
Hi, On Tue, Dec 04, 2007 at 08:50:53PM +, Matt Smith wrote: > I have seen the following line used to initialise a full screen display in > a number of books and tutorials: > > screen = pygame.display.set_mode((xsize, ysize), FULLSCREEN, 32) > > When I use it in my program then I get the following error: > > Traceback (most recent call last): > File "bouncing_ball_OOP.py", line 63, in > screen = pygame.display.set_mode((xsize, ysize), FULLSCREEN, 32) > NameError: name 'FULLSCREEN' is not defined You need to import it, usually with from pygame.locals import * near the top of your program. > I expected the set_mode method to treat the FULLSCREEN as an argument and > not as a variable/ object. That's not how Python works. Cheers! Marius Gedminas -- If the code and the comments disagree, then both are probably wrong. -- Norm Schryer signature.asc Description: Digital signature
Re: [pygame] This showed up in pygame-users@seul.org
On Wed, Nov 21, 2007 at 04:48:20PM +0100, Laura Creighton wrote: > Anybody want to come explain twisted to somebody who just wants > to network his game? Alas pygame-users is not a mailman mailing > list, and Activestate seems to have stopped archiving it in August, > so there is no way I know of to read the whole thread. I've seen a couple of blog posts about integrating PyGame with twisted's main loop. Here's one: http://bob.pythonmac.org/archives/2005/04/17/twisted-and-foreign-event-loops/ And here's some source code for a VNC viewer that's built with twisted and pygame: http://homepage.hispeed.ch/py430/python/ Marius Gedminas -- A real friend isn't someone you use once and then throw away. A real friend is someone you can use over and over again. signature.asc Description: Digital signature
Re: [pygame] Reverse Compiling
On Tue, Aug 07, 2007 at 03:52:51PM -0700, Ian Mallett wrote: > I was backing up my files onto a CD when I ironically deleted an original > .py file for a module leaving the .pyc version. My question here, is can > you reverse compile it? I want to make some changes. http://www.crazy-compilers.com/decompyle/ Marius Gedminas -- If it weren't for the last minute, nothing would get done. signature.asc Description: Digital signature
Re: [pygame] What is wrong with this
On Sat, Jul 14, 2007 at 02:31:20PM -0400, Jason Coggins wrote: > I am trying to create a very simple program that makes a list of the > music files in a folder, sorts the files into alphabetical order and > then plays each file in the folder. The program below plays the first > file in the folder and then freezes without playing any of the > remaining songs. I'm glad you found the problem, but I cannot refuse the opportunity to offer some generic Python style suggestions. > > > import pygame, os > > def findFiles(location): > files = [] > for item in os.listdir(location): > files.append(item) This is a bit pointless. You're taking a list of files and converting it to another list, one item at a time. files = os.listdir(location) would work perfectly well. > files.sort() > return files (And if you don't care about older Python versions, you could do def findFiles(location): return sorted(os.listdir(location) ) > def playMusic(music) > clock=pygame.time.Clock() I cringe when I see an assignment statement squished together without any spaces around the '='. > pygame.mixer.music.load(music) > pygame.mixer.music.play(0, 0.0) > while pygame.mixer.music.get_busy(): > clock.tick(300) > return Empty returns at the end of a function are a bit pointless. > def main(): > pygame.init() > pygame.mixer.init() > destinationPath = "/home/owner/Desktop/playList" > os.chdir(destinationPath) > playList = [] This assignment is pointless. You're reassigning a different value to playList on the very next line. > playList = findFiles(destinationPath) > for item in playList: > playMusic(item) > > Cheers! Marius Gedminas -- C, n: A programming language that is sort of like Pascal except more like assembly except that it isn't very much like either one, or anything else. It is either the best language available to the art today, or it isn't. -- Ray Simard signature.asc Description: Digital signature
Re: [pygame] Rendering Text By Line
On Tue, Jul 10, 2007 at 10:34:45PM -, [EMAIL PROTECTED] wrote: > > It's pretty simple to split your string on carriage returns (and/or line > > feeds), create surfaces for each line of text, and blit those surfaces to > > the destination surface. > > I'm doing something like that. I haven't yet gotten word-wrapping to work, > but the following out-of-context code does wrapping by line. PySpaceWar has word-wrapping for the help screen: http://mg.pov.lt/pyspacewar/pyspacewar-help-screen.png (For some reason the pygame window is translucent by default, so you can see a terminal underneath. Yes, I'm playing with Compiz Fusion.). The code is here: http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/ui.py#L466 (class HUDFormatted Text). (It's under the GNU GPL, in case you're considering copying it.) Cheers from EuroPython, Marius Gedminas -- I need a word processor on my laptop like I need a Selectric typewriter in my laptop bag. -- Don Marti signature.asc Description: Digital signature
Re: [pygame] I have a quick question... again...
On Tue, Jun 19, 2007 at 04:34:15PM -0400, Charles Joseph Christie II wrote: > On Sunday 17 June 2007 08:30:04 pm Greg Ewing wrote: > > I once did a true 3D tetris for the Mac. It was > > quite an interesting experience, both to implement > > and to play. Some day I'll dig it out and make a > > pygame version... > > How do you do 3D tetris? o.O http://en.wikipedia.org/wiki/Blockout Marius Gedminas -- Perl is hard for most people to write. They write PERL or Pearl. -- Abigail signature.asc Description: Digital signature
Re: [pygame] Text-Based RPG
On Tue, Jun 19, 2007 at 10:22:13AM -0400, Jonah Fishel wrote: > Thank you very much. I was very helpful. > Trogdor... that's great. I gotta use that word in the game =) http://en.wikipedia.org/wiki/Trogdor Marius Gedminas -- Added mysterious, undocumented --scanflags and --fuzzy options. -- nmap 3.0 announcement signature.asc Description: Digital signature
Re: [pygame] I have a quick question... again...
On Sat, Jun 16, 2007 at 01:27:37PM -0400, Charles Joseph Christie II wrote: > > I don't know about canonical, but PySpaceWar uses pure MVC. I think; I > > never fully understood the "controller" part of it; my views are often > > also controllers. > > > > http://mg.pov.lt/pyspacewar/http://mg.pov.lt/pyspacewar/ Gaah, obviously it should have been just http://mg.pov.lt/pyspacewar/ Copying and pasting URLs from Firefox to GNOME Terminal sometimes has this strange delay that makes me thing I didn't press the middle mouse button, so I do it again. > > There were two reasons for making the model independent of views: > > > > * I wanted beautiful and understandable code > > * I want to add network play at some undetermined point in the future > > I'll take a look at that. But when you say making the model independant of > views, what exactly do you mean? Model objects have no references to view objects. You can take the Python modules that implement the game model of PySpaceWar (world.py, game.py, ai.py) and build a different user interface without changing those modules. Or build a network server that doesn't have any drawing code. In theory. I haven't attempted either, so it's possible that some flaw in the design may require modifications to the model classes to support alternative views. > What's unit testing? I wouldn't be surprised if I knew what it was, but > didn't > know what it was called. I also wouldn't be surprised if I never had the > slightest idea what it was, either. It's the programming equivalent of putting your answers into the original math equation to make sure you haven't made any silly mistakes while solving the problem. Dive Into Python has two chapters devoted to unit testing (and test-first programming, which is a somewhat separate thing): http://www.diveintopython.org/unit_testing/index.html http://www.diveintopython.org/unit_testing/stage_1.html Marius Gedminas -- 1 + 1 = 3 -- from a Microsoft advertisement signature.asc Description: Digital signature
Re: [pygame] Game Objects 0.0.2
On Fri, Jun 15, 2007 at 08:21:15PM +0100, Will McGugan wrote: > I've just uploaded version 0.0.2 of Game Objects. It has an updated > Color class and GameClock class. This release also fixes the problem > with installing from source. Let me know if you find any bugs, or have > feature suggestions! I liked the blog entry and started looking around in the svn repository browser (no syntax highlight, *sigh*). I think there's a bug in ColorRGBA.grey: the 'a' argument (alpha?) is required, but never used. I'm somewhat surprised that your r/g/b/a setters perform an isinstance check and explicitly require a float. What's wrong with accepting ints (0 or 1)? The __setitem__ has an obvious error ('value' is misspelt as 'vale'), which makes me think you don't have unit tests. Why is __rmul__ doing division instead of multiplication? Marius Gedminas -- C++ is a loaded machine gun helpfully pointed at your feet with the safety off. -- ChaosDiscord on Slashdot signature.asc Description: Digital signature
Re: [pygame] I have a quick question... again...
On Sat, Jun 16, 2007 at 09:32:09AM -0700, Casey Duncan wrote: > On Jun 16, 2007, at 8:56 AM, Laura Creighton wrote: > [..] > > > >If you use Model-View-Controller like separation of your code, > >None. All your changes will be in the drawing. > > I'm curious how many of you actually employ MVC using pygame, since > the library encourages mixing the model and view via sprites. I'd be > interested to see a "canonical" example of a pygame that uses MVC. I don't know about canonical, but PySpaceWar uses pure MVC. I think; I never fully understood the "controller" part of it; my views are often also controllers. http://mg.pov.lt/pyspacewar/http://mg.pov.lt/pyspacewar/ There were two reasons for making the model independent of views: * I wanted beautiful and understandable code * I want to add network play at some undetermined point in the future > MVC has strong advantages when you need to present and interact with > the same data in multiple ways, but often in simple games data is > only presented a single way. Using MVC has advantages for unit > testing as well, but how many pygames actually employ unit tests in a > meaningful way? For some low-level functions (e.g. vector math) unit tests were rather useful. Also, I couldn't have refactored the AI code that Ignas Mikalajūnas wrote for me without writing a set of unit tests for it. Other than that, my initial resolution to have everything covered by unit tests evaporated pretty rapidly when I got caught in the frenzy of prototyping the fun stuff. > Also, is unit testing something that the gaming > industry at large embraces? (I'm completely clueless about the gaming industry.) > I'm curious how widespread these practices really are in the pygame > community, not to make a point for or against them, but to better > understand theory vs. practice. Marius Gedminas -- Never trust an operating system you don't have sources for. signature.asc Description: Digital signature
Re: [pygame] Smooth Scaling for Terrain Generation
On Sat, Jun 16, 2007 at 12:33:10AM -, [EMAIL PROTECTED] wrote: > I fiddled with a different terrain generation algorithm, this one based on > using Pygame to do something like Conway's Game of Life. That is, I draw > some random shapes of "grass" on "water" on a 100x100 image, then iterate > each pixel through a Life-like process to build a grass/sand/water map. > The results look OK, and I was thinking it was reasonably simple and > fast... but it assumes a 100x100 image. My program uses 1000x1000 zones. ... > I'd also be open to different ways to generate terrain entirely. Check out http://freespace.virgin.net/hugo.elias/models/m_perlin.htm Marius Gedminas -- Si fractum non sit, noli id reficere. signature.asc Description: Digital signature
Re: [pygame] Transparent PNGs
On Wed, Jun 06, 2007 at 02:38:18PM -0400, Kris Schnee wrote: > Brian Fisher wrote: > >This isn't really enough for other people to test what is failing for > >you... > > > >Can you post the "Game Logo.png" that fails for you with this code? > > Here's the image I'm testing it with. > http://kschnee.xepher.net/pics/Game%20Logo.png ... > I get a logo with a white background, on black. It's not a transparent image. It's an 8-bit/color RGB image with a white background. If anti-aliasing is not important to you, you can drop the convert_alpha() and use i.set_colorkey((255, 255, 255)), but for best results open an image editor and make the image properly transparent. Marius Gedminas -- I've been in the sun for a week. I took the bold step of leaving my laptop at home. I found only 4K messages pending when I returned. -- Keith Packard signature.asc Description: Digital signature
Re: [pygame] 'Shining Sea' source code
On Wed, May 30, 2007 at 10:02:34PM -, [EMAIL PROTECTED] wrote: > > The game starts, but I cannot control anything. I believe you > > mentioned W, A, S, D keys? Nothing happens. When I kill the game, > > I get this traceback: if pygame.mixer.music.get_busy(): > > KeyboardInterrupt (BTW there's no sound or music.) ... > I made the ZIP file directly from a working set of code and just zipped up > the whole directory, with all the music etc.. Is there some reason the > code wouldn't be portable? Hmm... the music is in MIDI; does Ubuntu's > Pygame support that? That could be it. I'm pretty sure this dinky laptop soundcard doesn't have any MIDI capability of its own, and today's Linux systems don't provide a software synthesizer out of the box (you can get one, but only if you run it manually). *tests* Yes, that was it. I renamed the 'music' directory so the game wouldn't find it, and I had no problems after that. Marius Gedminas -- The death rate on Earth is: (computing) One per person. signature.asc Description: Digital signature
Re: [pygame] "Shining Sea" source code
On Wed, May 30, 2007 at 07:01:07PM -, [EMAIL PROTECTED] wrote: > A version with source code: > http://kschnee.xepher.net/code/070530ShiningSeaSource.zip Thanks! I had to change all font.render() calls to enable anti-aliasing, to sidestep a bug in Ubuntu's pygame (segmentation faults when rendering non-anti-aliased spaces). The game starts, but I cannot control anything. I believe you mentioned W, A, S, D keys? Nothing happens. When I kill the game, I get this traceback: Traceback (most recent call last): File "Shining Sea.py", line 687, in game.Go() File "Shining Sea.py", line 634, in Go function_to_call() File "Shining Sea.py", line 608, in WanderingScreen Conch.j.PlaySong("island") File "/tmp/shining-sea/Conch/conch.py", line 128, in PlaySong if pygame.mixer.music.get_busy(): KeyboardInterrupt (BTW there's no sound or music.) Marius Gedminas -- Voodoo Programming: Things programmers do that they know shouldn't work but they try anyway, and which sometimes actually work, such as recompiling everything. -- Karl Lehenbauer signature.asc Description: Digital signature
Re: [pygame] Need help testing Slingshot rc2
On Fri, May 25, 2007 at 07:46:32AM -0400, Charles Joseph Christie II wrote: > On Friday 25 May 2007 04:23:24 am Rikard Bosnjakovic wrote: > > On 5/24/07, Charles Joseph Christie II <[EMAIL PROTECTED]> wrote: > > > It segfaulted when trying to find some timidity configs. > > > > Sounds very unlikely, and OTOH: strace is not a good tool for finding > > segmentation violations. But you can try adding the -f option to > > strace (follow forks) and see what happens. > > Same thing, it shows a bunch of sound related things and the timidity config > file is the last thing on the list before "segmentation fault". Because it > doesn't dump a core, gdb was no help either <_< If you run 'ulimit -c unlimited' before you run python Slingshot.py, then you ought to get a core file. Marius Gedminas -- To stay awake all night adds a day to your life. -- Stilgar (Frank Herbert _Children_of_Dune_) signature.asc Description: Digital signature
Re: [pygame] Need help testing Slingshot rc2
On Thu, May 24, 2007 at 09:04:48PM +0200, John Eriksson wrote: > Please, help me test Slingshot once more and tell me what you think. There's a typo in Tutorial 2: "nuclear wast pods". And another one in 3: "cant". Tutorial 4 also misspels waste as "wast". A pair of keys for controlling the torpedo speed would be nice -- not all mice have wheels. Marius Gedminas -- IBM motto: "If you can't read our assembly language, you must be borderline dyslexic, and we don't want you to mess with it anyway" -- Linus Torvalds signature.asc Description: Digital signature
Re: [pygame] Need feed back on new game!
On Wed, May 23, 2007 at 06:54:51AM +0200, John Eriksson wrote: > Since PyGame.org still seems to be dead I'll post the direct link to > Slingshot should anyone liek to try it and drop some comments. > > http://arainyday.se/projects/python/Slingshot/Slingshot_rc1.tar.gz Thanks! That's a fun game! Marius Gedminas -- Linux became only possible because 20 years of OS research was carefully studied, analyzed, discussed and thrown away. -- Ingo Molnar signature.asc Description: Digital signature
Re: [pygame] Need feed back on new game!
On Tue, May 22, 2007 at 09:11:01PM +0200, Rikard Bosnjakovic wrote: > On 5/22/07, John Eriksson <[EMAIL PROTECTED]> wrote: > > >Could you try downloading it again? (I can't for some reason start my > >vmware windows right now.) > > pygame.org seems to be dead at the moment. Still spewing SQL errors all over the place here. Marius Gedminas -- Unix for stability; Macs for productivity; Palm for mobility; Windows for Solitaire signature.asc Description: Digital signature
Re: [pygame] Fixed width font
On Sun, May 20, 2007 at 12:54:13AM +1000, Alex Holkner wrote: > Will McGugan wrote: > >Is there any way I can get a fixed width font accross all platforms, > >without bundling the script with a ttf? > > > >I'm using 'courier new' on Windows, but the exact look of the font is > >not too important. > Courier New is installed on all platforms: Um, not precisely. For example, on many Linux systems you will not find Courier New. There will probably be an alias of that name, to some other fixed-width font. There will also be a generic alias 'Monospace'. > it is one of Microsoft's > "core web" fonts, Yes. > and is required by PDF applications. The PDF 1.4 spec (the last one I read) requires the availability of some 14 fonts, but Courier New was not one of them (plain Courier was, though). That doesn't mean these fonts must be present on all platforms, the PDF viewer may have those fonts bundled with it. Heck, a PDF viewer is not necessarily installed on all platforms. I agree that 'Courier New' ought to be a pretty safe bet. Marius Gedminas -- Any sufficiently advanced technology is indistinguishable from a rigged demo. - Andy Finkel, computer guy signature.asc Description: Digital signature
[pygame] Re: Missing fonts on Ubuntu Edgy
On Thu, Mar 01, 2007 at 04:46:01PM +0200, Marius Gedminas wrote: > Suggested fix: have pygame/sysfont.py parse ~/.fonts.cache-1. (There's > a slight complication: most fonts.cache-1 files have three fields per > line (font name, some number, font properties), while ~/.fonts.cache-1 > has four (font name, some number, some other number, font properties). > > Actually, as I recall from a discussion about a different bug[1] (that > still plagues me in 1.7.1), the CVS version of PyGame uses fc-list to > find fonts on Unix systems, so this bug should be already fixed in CVS. > > [1] http://aspn.activestate.com/ASPN/Mail/Message/pygame-users/2970161 For those who do not want to wait for 1.8, here's a patch that fixes this problem (and the other one too) in 1.7.1: attached. Marius Gedminas -- I code in vi because I don't want to learn another OS. :) -- Robert Love Patch for pygame 1.7.1: * Also parse ~/.fonts.conf-1 on Unix systems to find more fonts (needed to find many TTF fonts on Ubuntu Edgy). * Fix font style parsing in fonts.conf-1 files (bug described in http://aspn.activestate.com/ASPN/Mail/Message/pygame-users/2970161). --- sysfont.py.orig 2007-03-01 16:25:04.0 +0200 +++ sysfont.py 2007-03-01 16:46:51.0 +0200 @@ -128,21 +128,25 @@ #read the fonts from a unix 'fonts.cache-1' file -def read_unix_fontscache(dir, file, fonts): +def read_unix_fontscache(dir, file, fonts, nfields=3): file = open(os.path.join(dir, file)) for line in file.readlines(): try: -font, num, vals = line.split(' ', 2) +fields = line.split(' ', nfields-1) except ValueError: continue -font = font.replace('"', '') +font = fields[0].replace('"', '') if font[-4:].lower() not in [".ttf", ".ttc"]: continue font = os.path.join(dir, font) -vals = vals.split(':') + +vals = fields[-1].split(':') name = _simplename(vals[0][1:]) -bold = vals[1].find('Bold') >= 0 -italic = vals[1].find('Italic') >= 0 +bold = italic = 0 +for prop in vals[1:]: +if prop.startswith('style='): +bold = prop.find('Bold') >= 0 +italic = prop.find('Italic') >= 0 _addfont(name, bold, italic, font, fonts) @@ -182,6 +186,13 @@ for p in paths: if os.path.isdir(p): os.path.walk(p, _fontwalk, fonts) +filename = os.path.expanduser('~/.fonts.cache-1') +try: +# Unlike other fonts.cache-1 files, this one has four fields per line +# rather than three +read_unix_fontscache('', filename, fonts, nfields=4) +except IOError: +pass return fonts signature.asc Description: Digital signature
[pygame] Missing fonts on Ubuntu Edgy
This is on Ubuntu Edgy: >>> import pygame >>> pygame.init() open /dev/sequencer: No such file or directory (6, 0) >>> pygame.version.ver '1.7.1release' >>> pygame.font.match_font('Verdana') '/usr/share/fonts/truetype/freefont/FreeSansOblique.ttf' I do have Verdana: $ fc-match -v Verdana|grep file file: "/usr/share/fonts/truetype/msttcorefonts/verdana.ttf"(s) however /usr/share/fonts/truetype/msttcorefonts/ does not have a fonts.dir, nor fonts.scale, nor fonts.cache-1. Only fonts.cache-1 in my home directory knows about Verdana. I imagine I would have the same problem with any fonts installed into ~/.fonts/ Suggested fix: have pygame/sysfont.py parse ~/.fonts.cache-1. (There's a slight complication: most fonts.cache-1 files have three fields per line (font name, some number, font properties), while ~/.fonts.cache-1 has four (font name, some number, some other number, font properties). Actually, as I recall from a discussion about a different bug[1] (that still plagues me in 1.7.1), the CVS version of PyGame uses fc-list to find fonts on Unix systems, so this bug should be already fixed in CVS. [1] http://aspn.activestate.com/ASPN/Mail/Message/pygame-users/2970161 Marius Gedminas -- If Linux doesn't have the solution, you have the wrong problem. signature.asc Description: Digital signature
Re: [pygame] Problem with pygame.image.load() and a gzip.open() stream
On Thu, Feb 15, 2007 at 09:54:36PM +, Paul Broadhead wrote: > I have a bmp image file that loads fine with: > > fid = open('test.bmp','rb') > theimg = pygame.image.load(fid) > fid.close() > > but if I gzip the image using "gzip test.bmp" then try > > fid = gzip.open('test.bmp.gz','rb') > theimg = pygame.image.load(fid) > fid.close() > > I get an error: > theimg = pygame.image.load(fid) > pygame.error: File is not a Windows BMP file My guess would be that pygame tries to seek around the file, but cannot do so. (It may be a completely wrong guess, because I would expect an exception rather than this sort of error.) Why do you want a gzipped bmp file rather than a png? Marius Gedminas -- He who sacrifices functionality for ease of use Loses both and deserves neither signature.asc Description: Digital signature
Re: [pygame] alpha channel in font-rendered Surfaces
On Thu, Feb 15, 2007 at 07:40:13AM -0600, Brendan Speer wrote: > On 2/15/07, Goran <[EMAIL PROTECTED]> wrote: > >I have a problem when trying to fade-in a text. > > > >Using the alpha-channel when blitting in an image works fine, but not a > >surface generated by Font.render(). > > Surface.convert_alpha creates per-pixel alpha values. > > >From the Surface.set_alpha help: 'This value is different than the per > >pixel > Surface alpha. If the Surface format contains per pixel alphas, then this > alpha value will be ignored. If the Surface contains per pixel alphas, > setting the alpha value to None will disable the per pixel transparency.' > > In order to do what you're asking, you need to look at Sufarray. and > manipulate each per-pixel alpha individually, I do that in PySpaceWar with Numeric: http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/ui.py?rev=260#L817 (The code is GPLed.) > or you can use convert() > instead of convert_alpha() (I think...) There's a fallback in PySpaceWar that does this when Numeric is not installed. Marius Gedminas -- 11. Are you at least tracking the number of users of retchmail? As far as I know, retchmail has exactly three users. -- http://open.nit.ca/wiki/index.php?page=RetchMail signature.asc Description: Digital signature
Re: [pygame] sdl_ttf font render failed
On Wed, Jan 31, 2007 at 03:42:37PM +0100, Simon Oberhammer wrote: > hi pygamers, > whenever I use font.render() with the antialias param set to False I > get this error: > > File "pysssi_dist.py", line 258, in printf >s = self.print_font.render( str,False,self.color1) > pygame.error: SDL_ttf render failed Actually, you only get this if you call font.render with a string that contains a space character, and with antialias set to False. Seems to be a known bug in the SDL_ttf version that is in Ubuntu. Marius Gedminas -- Always proofread carefully to see if you any words out. signature.asc Description: Digital signature
Re: [pygame] Masking Test: Simulated Lighting
On Sun, Jan 21, 2007 at 10:17:32PM +0100, Nicola Larosa wrote: > > Kris Schnee wrote: > >> I was thinking about how to simulate a lighting effect in Pygame: a > >> character with a portable light source in a dark room. > > Marius Gedminas wrote: > > This reminds me of something... > > > > Here it is: Escape from Anathema Mines from the second Ludum Dare > > http://www.imitationpickles.org/ld48 > > URL changed, no redirect, bad Phil Hassey broke da interweb. ;-) > > http://www.imitationpickles.org/ld486/ More likely that was me botching the copy and paste. > You've obviously never tried to reverse engineer a chip using an electron > microscope. [...] That's like looking at the grains of sand on a beach > and trying to map out the coastline of Hawaii. -- Cutie Pi, July 2006 Nice one. Mind if I steal it? Marius Gedminas -- Press any key to continue, or any other key to cancel. signature.asc Description: Digital signature
Re: [pygame] Masking Test: Simulated Lighting
On Sun, Jan 21, 2007 at 06:47:35AM -0500, Kris Schnee wrote: > I was thinking about how to simulate a lighting effect in Pygame: a > character with a portable light source in a dark room. This reminds me of something... Here it is: Escape from Anathema Mines from the second Ludum Dare http://www.imitationpickles.org/ld48 Impressive lighting. Marius Gedminas -- Microsoft's entry in this cavalcade of horrors is Universal Plug and Play (UPnP). This is a protocol that allows [...] an end-user system to request a dynamic port-forwarding from the firewall to the box. Many network administrators will probably (rightly) recoil at letting applications on a Windows box dictate firewall policy. -- Anthony Baxter signature.asc Description: Digital signature
Re: [pygame] PySpaceWar 0.9.3
On Sat, Jan 06, 2007 at 03:00:31PM +0100, Kai Kuehne wrote: > Hi Marius, > there is no explosion sound when destroying the enemy ship. That's intentional: sound doesn't travel through vacuum. On the other hand that's surprising and strange in a game. I've now added an option to toggle this, set to "fun" by default. BTW it's fun to play pyspacewars with the imperial march from Star Wars playing in the background. Cheers, Marius Gedminas -- [...] the basic "your gun, your foot, your choice" memory model. -- jtv on lkml signature.asc Description: Digital signature
Re: [pygame] PySpaceWar 0.9.3
On Thu, Jan 04, 2007 at 05:25:55PM +0100, Kai Kuehne wrote: > On 1/4/07, Marius Gedminas <[EMAIL PROTECTED]> wrote: > >On Tue, Jan 02, 2007 at 06:23:32PM +0100, Kai Kuehne wrote: > >> [Feedback] > >Done in Subversion. You're right, this makes the game considerably more > >fun. > > Great, much better. :) And now the svn version has sound effects and support for music. No actual music, though. Any ideas where I might get freely redistributable soundtracks? Marius Gedminas -- For vi emulation of emacs, just type ":sh emacs" (without the quotes). signature.asc Description: Digital signature
Re: [pygame] PySpaceWar 0.9.3
On Tue, Jan 02, 2007 at 06:23:32PM +0100, Kai Kuehne wrote: > Oh, and it would be nice if you would highlight the ship after it was shot > by the other ship. E.g., a red ring around the ship or something. I needed > too long to find it in the space, especially if there was a far distance > between > the two ships. Done in Subversion. You're right, this makes the game considerably more fun. Marius Gedminas -- I've been in the sun for a week. I took the bold step of leaving my laptop at home. I found only 4K messages pending when I returned. -- Keith Packard signature.asc Description: Digital signature
[pygame] PySpaceWar 0.9.3
Merry Christmas, everyone! Here's my gift to you all: PySpaceWar 0.9.3. Biggest new feature is customizable keyboard controls. Well, you could say it's the only new feature, as a configuration file is pretty much required once you have this kind of customization. Get it at http://mg.pov.lt/pyspacewar/ Testing, feedback of any kind, or return gifts (such as pretty artwork or sound effects) would be appreciated. Cheers! Marius Gedminas -- You can't have megalomania. *I* have megalomania. -- Joe Bednorz signature.asc Description: Digital signature
Re: [pygame] map format
On Tue, Dec 19, 2006 at 06:59:21PM +0100, Farai Aschwanden wrote: > I wanted to use such a system too, but 2 points stopped me using it: > 1. Its restricted to the charset (well 256 chars is quite a lot) You could use pairs of characters. Or triplets, or whatever. > 2. Interprete char signs that way can be expensive: > if "$" then print image x > if "*" then print image y > if Don't do that. Use a dictionary to map from characters to whatever you want (images, integers, tile objects) on load time. That's what Jasper did: > >symbolToTerrain = { > > '_' : Plains, > > '@' : Fertile, > > '+' : Desert, > > '^' : Mountains, > > '*' : Hills, > > '$' : Forest, > > '%' : Water, > > '~' : River, > > '&' : WideRiver, > > '=' : Roads, > > '#' : Bridge, > > '!' : Cliff, > >} Besides, you should measure the actual code before assuming it will be too expensive. Marius Gedminas -- I would suggest re-naming "rmbdd()". I _assume_ that "dd" stands for "data dependent", but quite frankly, "rmbdd" looks like the standard IBM "we lost every vowel ever invented" kind of assembly lanaguage to me. -- Linus Torvalds signature.asc Description: Digital signature
Re: [pygame] Scripting language
On Tue, Dec 19, 2006 at 12:27:02AM +0100, Jakub Piotr Cłapa wrote: > The problem is that disk access is a built-in in Python. And if you want > to expose anything than you leave a way to go through your function to > your module and than to anything you want. That's the reason why > restricted execution was withdrawn from the stdlib. Nobody seems to care > about security enught to handle this (rather difficult) problem. Brett Cannon is working on this problem. http://sayspy.blogspot.com/2006/05/researching-programming-language.html http://sayspy.blogspot.com/2006/07/security-design-doc-using-object.html and several subsequent posts Marius Gedminas -- The last good thing written in C was Franz Schubert's Symphony #9. -- Erwin Dietrich signature.asc Description: Digital signature
[pygame] Font.render barfs on spaces
Hi, Pygame 1.7.1 on my Ubuntu Linux system is unable to render a space in the default font, when anti-aliasing is disabled: >>> import pygame >>> pygame.version.ver '1.7.1release' >>> pygame.font.init() >>> f = pygame.font.Font(None, 10) >>> f.render(" ", 0, (255, 255, 255)) Traceback (most recent call last): File "", line 1, in ? pygame.error: SDL_ttf render failed Other characters work fine: >>> f.render("a", 0, (255, 255, 255)) Space also works if I enable anti-aliasing: >>> f.render(" ", 1, (255, 255, 255)) Is this a bug? Marius Gedminas -- The IQ of the group is the lowest IQ of a member of the group divided by the number of people in the group. signature.asc Description: Digital signature
Re: [pygame] Galcon linux version
On Wed, Dec 13, 2006 at 12:28:45PM +, Adam Bark wrote: > Yay linux! Is it actually possible to play a net game in the demo? When I > ran the win version on cedega I typed a name in then got an error about it > not exiting properly (can't remember exactly but I can reproduce it if you > want to see it). In linux however I get this error. > > Traceback (most recent call last): > File "main.py", line 540, in ? > File "pgu/engine.py", line 113, in run > File "pgu/engine.py", line 178, in loop > File "pgu/engine.py", line 82, in fnc > File "mygui.py", line 122, in event > File "pgu/gui/app.py", line 147, in event > File "pgu/gui/container.py", line 185, in event > File "pgu/gui/widget.py", line 300, in _event > File "pgu/gui/theme.py", line 321, in func > File "pgu/gui/container.py", line 185, in event > File "pgu/gui/widget.py", line 300, in _event > File "pgu/gui/theme.py", line 321, in func > File "pgu/gui/container.py", line 185, in event > File "pgu/gui/widget.py", line 300, in _event > File "pgu/gui/theme.py", line 321, in func > File "pgu/gui/container.py", line 185, in event > File "pgu/gui/widget.py", line 300, in _event > File "pgu/gui/theme.py", line 321, in func > File "pgu/gui/container.py", line 185, in event > File "pgu/gui/widget.py", line 300, in _event > File "pgu/gui/theme.py", line 321, in func > File "pgu/gui/input.py", line 92, in event > LookupError: unknown encoding: latin-1 IIRC py2exe doesn't bundle the 'codecs' module by default, and you have to edit some .ini file and explicitly ask for it to be included. My memory of everything is a bit hazy, since I haven't used py2exe for ages, but this sounds like the problem I've seen. I'm sure there's a FAQ somewhere. Marius Gedminas -- Woe unto them that rise up early in the morning -- Isaiah 5:11 signature.asc Description: Digital signature
Re: [pygame] Galcon released
On Tue, Dec 12, 2006 at 11:27:04AM -0800, Bob the Hamster wrote: > On 12/9/06, Phil Hassey <[EMAIL PROTECTED]> wrote: > >Richard, > > > >I think it might work in wine, but I don't know for sure ... > > > >Is there a "py2exe" out there for linux stuff? If there was, I might be > >able to put together a linux package of it. > > > >Phil > > There is a common misconception among developers who come from a > Windows background that you cannot distribute commerial programs for > linux because there is no way to "bind them into an exe" > > You can easily make a tarball containing your .pyd files and not your > .py source code, and sell that to Linux users. I think you mean .pyc (or .pyo) rather than .pyd (which is used for DLLs used as Python extension modules on Windows). I've heard that it is pretty easy to decompile them back into .py files. Marius Gedminas who is currently unable to see what everyone is talking about, since there is no Linux version of Galcon yet -- Everyone has a photographic memory. Some don't have film. signature.asc Description: Digital signature
Re: [pygame] I can handle more of a one monitor?
On Mon, Oct 09, 2006 at 05:21:38PM -0700, Jasper wrote: > I had a friend try my game on a dual monitor system once, and it > wouldn't work. I recall at the time someone here said SDL just didn't > support dual monitors, so there was no way to make it work short of > extending SDL. My experience was that pygame.display.list_modes() returned the dual-head desktop as the largest mode (2048x768), which then caused an SDL crash if I tried to pass it to pygame.display.set_mode with the FULLSCREEN flag. Single-head modes (1024x768 or lower) work just fine, but you get the same picture on both monitors. Marius Gedminas -- Anybody who doesn't cut his speed at the sight of a police car is probably parked. signature.asc Description: Digital signature
Re: [pygame] PyGame on Palm?
On Wed, 30 Aug 2006 20:06:57 +1000 "Jonathan McLean" <[EMAIL PROTECTED]> wrote: > I believe the short, practical answer would be no. I do not believe > there is currently any python that is capable of being run on Palm OS. > A port named Pippy was attempted for Python 1.5.2, but I believe all > work has been canned on that. Any one elses' clarification would be > greatly appreciated. I've seen a port of Python 2.3 compiled for PalmOS 5, but I've never tried it. IIRC it didn't have any GUI stuff and was therefore basically useless. Google finds Pippy (not maintained since 2002) and this message about Python 2.3 port with a broken link: http://itconnection.ru/pipermail/zopyrus/2005-April/078617.html Marius Gedminas -- He who sacrifices functionality for ease of use Loses both and deserves neither pgpLSSRTgetQ7.pgp Description: PGP signature
Re: [pygame] 2D vector class
On Mon, Aug 14, 2006 at 11:49:00AM -0700, Brian Fisher wrote: > On 8/14/06, Alex Holkner <[EMAIL PROTECTED]> wrote: > >Thanks Brian for writing the very useful benchmark script, I'll be > >keeping an eye on it during development. I expect you'll get the same > >performance I am if you use __slots__, a minor change. > > > Hmmm.. I had tried using __slots__ on the class early on, thinking it > would potentially be the best python thing you could do because then > your attributes are allocated in your object... when I tested it on > python 2.3 on WinXP it seemed to be about the same performance as > using a list member... it disappointed me at the time because I really > thought it was the best way to go... __slots__ is for optimizing memory usage, not speed. Marius Gedminas -- HOST SYSTEM NOT RESPONDING, PROBABLY DOWN. DO YOU WANT TO WAIT? (Y/N) signature.asc Description: Digital signature
Re: [pygame] BUG: display.init() confuses key mods
On Sun, Aug 13, 2006 at 09:32:02AM +1000, René Dudfield wrote: > weirdness... > > This is from my full screen code... > >mods = event.mod > ># right alt modifier doesn't work it seems. ># So I use 512 as a constant... seems to work. >if (mods & K_LALT) or (mods & K_RALT) or (mods & 512): These should be KMOD_LALT and KMOD_RALT, not K_LALT/K_RALT. KMOD_xxx are bit masks used in event.mod, K_xxx are key codes used in event.key. (mods & KMOD_ALT) is the same as (mods & KMOD_LALT) or (mods & KMOD_RALT). Marius Gedminas -- H.323 has much in common with other ITU-T standards - it features a complex binary wire protocol, a nightmarish implementation, and a bulk that can be used to fell medium-to-large predatory animals. -- Anthony Baxter signature.asc Description: Digital signature
Re: [pygame] 2D vector class
On Fri, Aug 11, 2006 at 01:38:06PM -0500, Nelson, Scott wrote: > I've got 2 simple games roughed out (about 600 lines each) with about > 2000 lines worth of shared modules I've written. I have a somewhat full > featured 2D vector class (supports adding, subtracting, scaling, > rotation, normalizing, angle between, etc. that I use in both heavily to > represent points, velocities, etc. After using it for awhile, I've > wondered how others have approached creating a 2D vector class. Here's > my "philosophical" questions, as the class I have works well, but I want > to know how to make it better. My main goals are to keep it simple, let > it interface cleanly with Pygame's use of tuples of 2 ints for 2D > points, not be specifically tied to Pygame, and have it not be a > performance hog. > > So, here's the issues that I'd love to hear feedback on: > > #1 - Do you store the vector components internally as self.x and self.y > or as a tuple? Or subclass the vector class from a tuple? If you use > self.x and self.y, what is an efficient way to pass this as a tuple to > pygame functions? I chose to subclass tuple in pyspacewar, but I forgot why. > #2 - Do you store the values as ints (making it easier to pass to > Pygame) or floats (more accurate vector math, but need to cast to int > before passing to pygame functions that require a tuple of ints?). Or > do you not even care and just let duck-typing do it stuff? I needed floats, because I wanted the world to be scaled arbitrarily for display, and besides that I needed the accuracy for gravity calculations. You can find my Vector class here: http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/world.py It has unit tests, and is somewhat optimized (only those bits that showed up when profiling). Marius Gedminas -- C is for Cookies. Perl is even better for Cookies. signature.asc Description: Digital signature
Re: [pygame] GP2X Game Comp
On Tue, Jun 13, 2006 at 05:36:19PM +1000, Richard Jones wrote: > Hrm, I recently acquired a Nokia 770. It has a *slightly* higher resolution > (800x480) but otherwise has very similar specs. Eerily similar, in fact. Hrm. I have one. Yummy. > I've not had a chance to do much except "import pygame" and test opening a > window: > >http://jafo.ca/getentry.html?stamp=20060526_0237 > > Anyway, stand by for a completely different announcement... PySpaceWar (http://mg.pov.lt/pyspacewar) runs on my Nokia 770 without any changes. At about 1 frame per second. ;-) Marius Gedminas -- The only way to learn a new programming language is by writing programs in it. -- Brian Kernighan signature.asc Description: Digital signature
Re: [pygame] Re: [Tutor] An Introduction and a question
On Fri, Jun 09, 2006 at 05:00:48PM -0300, Andre Roberge wrote: > On 6/9/06, Michael Sullivan <[EMAIL PROTECTED]> wrote: > >Here is my code: > > > >#!/usr/bin/env python > > > >import random > >import time > >import math > > > >class LinePuzzlePiece: > > """This class defines a single playing piece for LinePuzzle""" > > def __init__(self): > > seed(time) The 'import' statement does not work this way. You want to say random.seed(time.time()) Also note that to call a function you always have to add (). Also, it is not necessary to manually set the random seed -- it is done automatically. > > index = int(math.floor(uniform(1, 10))) colorlist = ["red", > >"blue", "green" "yellow", "purple"] self.color = colorlist[index] (Someone's mail client wrapped the lines unnecessarily.) The random module has a very handy little function called 'choice': colorlist = ["red", "blue", "green", "yello", "purple"] self.color = random.choice(colorlist) If you want a random integer from a certain range (1 <= x < 10), you can say index = random.randrange(1, 10) without having to go through the whole rigamarole of converting floating point numbers to integers. int() by the way floors the number (at least if it is positive), so math.floor would be superfluous. > > def printcolor(): > > print self.color Others have already pointed out that printcolor should take one argument, self. > >mypiece = LinePuzzlePiece You need to add () at the end to actually create an object of your class. > >mypiece.printcolor And here, to call the function. (I know that I'm repeating what other have said, but I want to be complete.) Here's the complete fixed program. I've also fixed the indentation to be 4 spaces, as is customary for Python: #!/usr/bin/env python import random class LinePuzzlePiece: """This class defines a single playing piece for LinePuzzle""" def __init__(self): colorlist = ["red", "blue", "green", "yello", "purple"] self.color = random.choice(colorlist) def printcolor(self): print self.color mypiece = LinePuzzlePiece() mypiece.printcolor() > 2. I'm cc-ing the pygame user group. I suggest that future questions > related to pygame be sent over to that group instead. They are just > as friendly as the folks on the tutor list. /me waves in a friendly manner Cheers! Marius Gedminas -- Microsoft does have a Year 2000 problem. We're it. signature.asc Description: Digital signature
Re: [pygame] Transparent PNGs / Flipped Images
On Fri, Jun 02, 2006 at 06:03:28PM -0400, Kris Schnee wrote: > Marcus von Appen wrote: > >On, Thu Jun 01, 2006, Kris Schnee wrote: > >>I noticed that my PNG image files aren't displaying with transparency. > >>Is there a way to fix that? > > > >Did you try pygame.Surface.convert_alpha() after loading the image? > > I did: > > foo = pygame.image.load( filename ).convert() Use convert_alpha(), not convert(). Trust me, it works. ;) Marius Gedminas -- Of course I use Microsoft. Setting up a stable unix network is no challenge ;p signature.asc Description: Digital signature