the tutor mailing list didn't like the zip I attached, so here's the text of the e-mail I wrote to Joe without the zip included.
----start----- Pygame-specific questions should be posted to the pygame mailing list, not tutor, probably. Joe F wrote: > Hello, I have a code here. and I want to make the > "rockwholescreen.gif" blocked, but still displayed. I want it so > "001.png" can't walk through that gif. any ideas? > > import pygame, os, sys > from pygame.locals import * > > > pygame.init( ) > > def _loadImages_ ( path, name ): > image_obj = os.path.join( path, name ) > image_load = pygame.image.load( image_obj ) > > return image_load why do you have underscores in the name of this function? Usually underscores denote functions that are supposed to be private to a class, I believe, and this function's not in a class at all! also,there's no reason to create an 'image_load' variable. return pygame.image.load( image_obj ) would do just as well. > > images_path = './img/' > images_dict = {} > image_names = { 1:"001.png", 2:"rockwholescreen.gif" } > > for dir, name in image_names.items( ): > images_dict[dir] = _loadImages_( images_path, name ) this strikes me as a very odd way to handle image-loading. if you're using integers as a reference for a dict why not just use list indices? #------- images_path = './img/' image_names = ['001.png','rockwholescreen.gif'] images = [_loadImages_(images_path,name) for name in image_names] #------- It took me a minute to figure out what you were doing, and this way I think your intent is more clear. > > setwinsize = ( 640, 480 ) > windows = pygame.display.set_mode( setwinsize ) I'm guessing you're using a global 'setwinsize' so you don't hard-code in your resolution. If you're going to do this, why not just put your globals at the top, so they're easier to change? If you have to go hunting through your code for a global you want, it's just barely better than hunting through your code to find the place where you need to change the hardcoded value. > > #load First Image > imageload = images_dict[1] > imagerect = imageload.get_rect( 0, 0, * windows.get_size( )) why not just use setwinsize here also instead of getting the size of the display surface? it'll probably be faster. also, I don't understand why you're doing get_rect on (0,0,640,480) does get_rect select a subsurface of the image? > > #load Second Image > imageloads = images_dict[2] > imagerects = pygame.Rect( 0, 448, * windows.get_size( )) if you find yourself appending letters to variable names to distinguish them you're probably at the point where you should be using lists. If someone weren't reading your code very carefully they may get confused here and think these variables are the same as the ones above. Also, later in your code, you might get confused and use the wrong one of these variables without even realizing and give yourself debugging headaches. I don't understand what the * here is doing. it doesn't seem to work for me. > > > > while True: > events = pygame.event.wait( ) I'm pretty sure pygame.event.wait() blocks until if gets an event. Think about this, is this really what you want? If the user sits there not sending any events, the screen won't update, but if they move their mouse, you'll get a lot of mousemovement events and such, and then your program will be rapidly filling the whole screen with the color (25,110,189) and re-blitting everything even though nothing moved. > > if events.type == pygame.QUIT: > break > > if events.type == pygame.KEYDOWN: > if events.key == K_DOWN: > imagerect.move_ip( 0, 10 ); imageload = images_dict[1] > if events.key == K_UP: > imagerect.move_ip( 0, -10 ); imageload = images_dict[1] > if events.key == K_RIGHT: > imagerect.move_ip( 10, 0 ); imageload = images_dict[1] > if events.key == K_LEFT: > imagerect.move_ip( -10, 0 ); imageload = images_dict[1] I don't think the escape key raises a pygame.QUIT so if you want the user to be able to exit with the escape key, you should put also, since you imported everything from pygame.locals you don't need a 'pygame.' here #------ if events.key == K_ESCAPE: break #--------- to get this effect. > > > windows.fill(( 25, 110, 189 )) > windows.blit( imageload, imagerect ) > windows.blit( imageloads, imagerects ) > pygame.display.flip( ) here you're not doing dirty-rect animation. you're just updating the whole screen every time you get an event. This is okay for an example but for a real game you'll need to use some form of dirty-rect updating method if it needs good performance. > > print "Image One Rect: %s \n" % imagerect > print "Image Two Rect: %s \n" % imagerects > > fonts = pygame.font.Font(None, 26) > > _colors_ = { "black" : (0, 0, 0), > "red" : (255, 0, 0) > } again, why the underlines? Are you trying to avoid a namespace collision? > _text_ = fonts.render('Testing', 0, _colors_['red'] ) > _rtext_ = screensize[0] - _text_.get_width( ), 0 > > while True: > events = pygame.event.wait( ) > if events.type == pygame.QUIT: > break > > windows.blit( _text_, _rtext_ ) > pygame.display.flip( ) > so when the '001.png' runs into the 'rockwholescreen.gif' you want it to display 'testing' in red? You don't have any detection in your first 'while' loop that breaks out of the loop if it finds a collision between these two images. Right now all your code does is move an image around. I'm attaching an example zip of what I would do to solve this problem. > pygame.quit( ) > > > thanks.. sure. Just remember, the pygame mailing list specializes in these kinds of questions and can give you lots of good pointers. -Luke _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor