Commits

Anonymous committed a4fcd6c

cleaned up for win32 and py1.5.2

Comments (0)

Files changed (9)

examples/aliens.py

     return surface.convert()
 
 def load_images(*files):
-    return [load_image(file) for file in files]
+    imgs = []
+    for file in files:
+        imgs.append(load_image(file))
+    return imgs
 
 
 class dummysound:
 
         # Create new alien
         if alienreload:
-            alienreload -= 1
+            alienreload = alienreload - 1
         elif not int(random.random() * ALIEN_ODDS):
             Alien()
             alienreload = ALIEN_RELOAD

examples/chimp.py

     def _spin(self):
         "spin the monkey image"
         center = self.rect.center
-        self.dizzy += 12
+        self.dizzy = self.dizzy + 12
         if self.dizzy >= 360:
             self.dizzy = 0
             self.image = self.original
 #Main Loop
     while 1:
         clock.tick(60)
-	
+
     #Handle Input Events
         for event in pygame.event.get():
             if event.type is QUIT:

examples/uberball.py

 	def __init__(self):
 		self.menuMode = 0
 		self.score = 0
-		self.lives = 3
 		self.level = 1
 		self.effectCurrent = 0
 		self.effectDuration = 0
 	def NewGame(self):
 		self.menuMode = 2 # Game
 		self.score = 0
-		self.lives = 3
 		self.level = 1
 		self.effectCurrent = 0
 		self.effectDuration = 0
 		
 		# Load level
-		
-	def Death(self):
-		self.lives -= 1
-		
-		if self.lives < 0:
-			self.GameOver ()			
-
-	def GameOver(self):
-		self.menuMode = 0
 
 	def ScoreAdd(self, scoreAdd):
-		self.score += scoreAdd
+		self.score = self.score + scoreAdd
 
 #classes for our game objects
 class Paddle(pygame.sprite.Sprite):
 
 	def update(self):
 		# Fall
-		self.rect.centery += self.speed
+		self.rect.top = self.rect.top + self.speed
 
 	def collide (self, test):
 		if self.rect.colliderect (test.rect):
 		self.image, self.rect = render_ball(Ball.radii[size], (50, 200, 200))
 		screen = pygame.display.get_surface()
 		self.area = screen.get_rect()
-		self.area.right += 5
-		self.area.left -= 10
+		self.area.left = self.area.left - 5
 		
 		self.rect.centerx = x
 		self.rect.centery = y
 		self.moveY = 4 + (2 * size)
 		self.lastRect = self.rect
 
-	def setType(self, size):
+	def changeType(self):
+		size = not self.size
 		self.size = size
 		x = self.rect.centerx
 		y = self.rect.centery
 		self.rect.centery = y
 		
 		# Set the speed based on the size, and keep its direction
-		if self.moveX >= 0:
-			self.moveX = 4 + (2 * size)
+		if size:
+			self.moveX = self.moveX * 2
+			self.moveY = self.moveY * 2
 		else:
-			self.moveX = -4 + (2 * size)
-		if self.moveY >= 0:
-			self.moveY = 4 + (2 * size)
-		else:
-			self.moveY = -4 + (2 * size)
+			self.moveX = self.moveX / 2
+			self.moveY = self.moveY / 2
 
 	def update(self):
 		self.lastRect = self.rect
 				self.gameState.ScoreAdd (10)
 				# Randomly create a power up
 				if not randint(0, self.powerchance):
-					self.powerchance = 20
+					self.powerchance = len(self.allballs) * 2
 					center = brick.rect.center
 					powerUp = PowerUp(randint(0,1), randint(3,7), center[0], center[1])
 					powerUp.add((self.allpowerups, self.allsprites))
 		for ball in pygame.sprite.spritecollide(self.paddle, self.allballs, 0):
 			ball.collidePaddle(self.paddle)
 			self.bong_sound.play()
-			self.gameState.ScoreAdd (10)
+			self.gameState.ScoreAdd(10)
 
 		# Check powerups against paddle
 		for powerUp in pygame.sprite.spritecollide(self.paddle, self.allpowerups, 1):
 					newBall.moveX = -ball.moveX
 					newBall.moveY = -ball.moveY
 					newBall.add((self.allballs, self.allsprites))
-			elif powerUp.type == 2: # Convert the balls
+			else: # Convert the balls
 				for ball in self.allballs.sprites():
-					ball.setType (randint(0,1))
+					ball.changeType()
 
 		# If all the balls are gone
 		if not self.allballs:
-			self.gameState.Death ()
-			
-			if self.gameState.lives > 0:
-				# Create a ball
-				newBall = Ball (randint(0,1))
-				newBall.add((self.allsprites, self.allballs))
-			else:
-				self.gameControl.setMode (0)	# Back to the main menu
+			self.gameControl.setMode(0)	# Back to the main menu
 
 	def draw(self, background, screen):
 		#Draw Everything
 		textposScore.left = background.get_rect().left + 10
 		screen.blit(textScore, textposScore)
 
-		# Draw lives
-		textLives = self.fontLives.render(str(self.gameState.lives), 1, (255, 255, 255))
+		# Draw balls
+		textLives = self.fontLives.render(str(len(self.allballs)), 1, (255, 255, 255))
 		textposLives = textLives.get_rect()
 		textposLives.bottom = background.get_rect().bottom - 5
 		textposLives.right = background.get_rect().right - 10
 		if self.gameControl.gameEvent.keystate[K_ESCAPE]:
 			self.gameControl.setMode (-1)	# -1 is exit the game
 	
-		# Move selection up nad down
-		if self.gameControl.gameEvent.keystate[K_DOWN] and self.menuSelect < self.menuMax-1:
-			self.menuSelect += 1
+		# Move selection up and down
+		if self.gameControl.gameEvent.newkeys[K_DOWN] and self.menuSelect < self.menuMax-1:
+			self.menuSelect = self.menuSelect + 1
 			
-		if self.gameControl.gameEvent.keystate[K_UP] and self.menuSelect > 0:
-			self.menuSelect -= 1
+		if self.gameControl.gameEvent.newkeys[K_UP] and self.menuSelect > 0:
+			self.menuSelect = self.menuSelect - 1
 		
 		# Process current selection
-		if self.gameControl.gameEvent.keystate[K_RETURN]:
+		if self.gameControl.gameEvent.newkeys[K_RETURN]:
 			if self.menuSelect == 0:
 				self.gameControl.setMode (2)
 			if self.menuSelect == 1:
 
 	def eventHandle(self):
 		# Quit on any keys
-		if self.gameControl.gameEvent.keystateTime[K_RETURN] == self.gameControl.gameEvent.ticks:
+		if self.gameControl.gameEvent.keystate[K_RETURN]:
 			self.gameControl.setMode (0)
-		if self.gameControl.gameEvent.keystateTime[K_SPACE] == self.gameControl.gameEvent.ticks:
+		if self.gameControl.gameEvent.keystate[K_SPACE]:
 			self.gameControl.setMode (0)
 		
 	def update(self):
 		Otherwise repeats occur that we dont desire."""
 		
 	def __init__(self):
-	        # Setup the keystate and keystateTime initial values
-	        self.keystate = pygame.key.get_pressed()
-
 		# Run update to init all the variables
+		self.keystate = None
 		self.update()
 
 	def update(self):
 		pygame.event.pump() #keep messages alive
 
 		# Get the key state
-		self.keystate = pygame.key.get_pressed()
-	        
+		if self.keystate:
+			oldstate = self.keystate
+			self.keystate = pygame.key.get_pressed()
+			self.newkeys = map(lambda o,c: c and not o, oldstate, self.keystate)
+		else:
+			self.keystate = pygame.key.get_pressed()
+			self.newkeys = self.keystate
+
 		# Get the mouse data
 		self.mousePos = pygame.mouse.get_pos()
 		self.mouseButtons = pygame.mouse.get_pressed()
-	        
+
 	        # Get the time
 	        self.ticks = pygame.time.get_ticks()
 
 Windows, MacOS, OSX, BeOS, FreeBSD, IRIX, and Linux.
 """
 
-import sys, os
+import sys, os, string
 if sys.platform=='darwin':
     # this may change someday, but we want to chdir to where our file is if we're in / for no
     # good reason..
         self.name = name
         self.info = str(info)
         self.urgent = urgent
-        self.ver = sys.version_info
+        self.ver = map(int, string.split(sys.version, '.')[:2])
         if urgent:
             self.warn()
 
     def __getattr__(self, var):
         if not self.urgent:
             self.warn()
-        MissingModule = "%s module not available"%self.name
-        raise NotImplementedError, MissingModule
+            self.urgent = 1
+        MissingPygameModule = "%s module not available" % self.name
+        raise NotImplementedError, MissingPygameModule
 
     def __nonzero__(self):
         return 0
         else:
             print message
 
-    
+
 
 #we need to import like this, each at a time. the cleanest way to import
 #our modules is with the import command (not the __import__ function)
 static void alphablit_solid(SDL_BlitInfo *info);
 static int SoftBlitAlpha(SDL_Surface *src, SDL_Rect *srcrect,
                         SDL_Surface *dst, SDL_Rect *dstrect);
+extern int SDL_RLESurface(SDL_Surface *surface);
+extern void SDL_UnRLESurface(SDL_Surface *surface, int recode);
 
 
 
                         src_locked = 1;
         }
 
-        /* Unencode the destination if it's RLE encoded */
-        if ( dst->flags & SDL_RLEACCEL ) {
-                SDL_UnRLESurface(dst, 1);
-                dst->flags |= SDL_RLEACCEL;        /* save accel'd state */
-        }
-
         /* Set up source and destination buffer pointers, and BLIT! */
         if ( okay  && srcrect->w && srcrect->h ) {
                 SDL_BlitInfo info;
                 info.src = src->format;
                 info.dst = dst->format;
 
-printf("branching to appropiate blitter\n" );
                 if(src->flags&SDL_SRCALPHA && src->format->Amask)
                     alphablit_alpha(&info);
                 else if(src->flags & SDL_SRCCOLORKEY)
                     alphablit_solid(&info);
         }
 
-        /* Re-encode the destination if it's RLE encoded */
-        if ( dst->flags & SDL_RLEACCEL ) {
-                dst->flags &= ~SDL_RLEACCEL; /* stop lying */
-                SDL_RLESurface(dst);
-        }
-
         /* We need to unlock the surfaces if they're locked */
         if ( dst_locked )
                 SDL_UnlockSurface(dst);
 	if(cdrom->track[track].type != SDL_AUDIO_TRACK)
 		return RAISE(PyExc_SDLError, "CD track type is not audio");
 
-        /*validate times*/
-        startframe = (int)(start * CD_FPS);
+	/*validate times*/
+	startframe = (int)(start * CD_FPS);
+	endframe = 0;
 	if(startframe < 0)
 		startframe = 0;
-	if(endframe < startframe || startframe > cdrom->track[track].length * CD_FPS)
-                RETURN_NONE;
-        if(end)
-                endframe = (int)((end-start) * CD_FPS);
-        else
-                endframe = cdrom->track[track].length - startframe;
+	if(end)
+		endframe = (int)((end-start) * CD_FPS);
+	else
+		endframe = cdrom->track[track].length - startframe;
+	if(endframe < startframe || startframe > (int)(cdrom->track[track].length * CD_FPS))
+		RETURN_NONE;
 
-        result = SDL_CDPlayTracks(cdrom, track, startframe, 0, endframe);
+	result = SDL_CDPlayTracks(cdrom, track, startframe, 0, endframe);
 	if(result == -1)
 		return RAISE(PyExc_SDLError, SDL_GetError());
 
 		    RAISE(PyExc_ValueError, "gamma ramp must contain integer elements");
                     return 0;
                 }
-		c_uint16_array[i] = PyInt_AsLong(item);
+		c_uint16_array[i] = (Uint16)PyInt_AsLong(item);
         }
 	return 1;
 }
 	Mix_QuerySpec(&music_frequency, &music_format, &music_channels);
 	music_pos = 0;
 	music_pos_time = SDL_GetTicks();
+	volume = Mix_VolumeMusic(-1);
 
 #if MIX_MAJOR_VERSION>=1 && MIX_MINOR_VERSION>=2 && MIX_PATCHLEVEL>=3
-        volume = Mix_VolumeMusic(-1);
-        val = Mix_FadeInMusicPos(current_music, loops, 0, startpos);
-        Mix_VolumeMusic(volume);
+	val = Mix_FadeInMusicPos(current_music, loops, 0, startpos);
+	Mix_VolumeMusic(volume);
 #else
-        if(startpos)
-            return RAISE(PyExc_NotImplementedError, "music start position requires SDL_mixer-1.2.4");
+	if(startpos)
+		return RAISE(PyExc_NotImplementedError, "music start position requires SDL_mixer-1.2.4");
 	val = Mix_PlayMusic(current_music, loops);
 #endif
-     	if(val == -1)
+	if(val == -1)
 		return RAISE(PyExc_SDLError, SDL_GetError());
 
 	RETURN_NONE
 
 #define NO_PYGAME_C_API
 #include "pygame.h"
-
+#include "math.h"
 
 typedef struct tColorRGBA {
 	Uint8 r; Uint8 g; Uint8 b; Uint8 a;