pygame / examples / oldalien.py

Diff from to

examples/oldalien.py

 
 
 #import
-import whrandom, os.path, sys
-import pygame, pygame.image
+import random, os.path, sys
+import pygame
 from pygame.locals import *
 
 if not pygame.image.get_extended():
 
 
 #constants
-FRAMES_PER_SEC = 50
-PLAYER_SPEED   = 5
+FRAMES_PER_SEC = 40
+PLAYER_SPEED   = 12
 MAX_SHOTS      = 2
-SHOT_SPEED     = 6
-ALIEN_SPEED    = 6
+SHOT_SPEED     = 10
+ALIEN_SPEED    = 12
 ALIEN_ODDS     = 45
 EXPLODE_TIME   = 6
 SCREENRECT     = Rect(0, 0, 640, 480)
 
 
 
-def wait_frame():
-    "wait for the correct fps time to expire"
-    global next_tick
-    this_tick = pygame.time.get_ticks()
-    if this_tick < next_tick:
-        pygame.time.delay(next_tick - this_tick)
-    next_tick = this_tick + (1000/FRAMES_PER_SEC)
-
-
-
 # The logic for all the different sprite types
 
 class Actor:
     "Destroy him or suffer"
     def __init__(self):
         Actor.__init__(self, Img.alien)
-        self.facing = whrandom.choice((-1,1)) * ALIEN_SPEED
+        self.facing = random.choice((-1,1)) * ALIEN_SPEED
         if self.facing < 0:
             self.rect.right = SCREENRECT.right
             
     # Initialize SDL components
     pygame.init()
     screen = pygame.display.set_mode(SCREENRECT.size, 0)
+    clock = pygame.time.Clock()
 
     # Load the Resources
     Img.background = load_image('background.gif', 0)
 
     # Main loop
     while player.alive or explosions:
-        wait_frame()
+        clock.tick(FRAMES_PER_SEC)
 
         # Gather Events
         pygame.event.pump()
         player.reloading = keystate[K_SPACE]
 
         # Create new alien
-        if not int(whrandom.random() * ALIEN_ODDS):
+        if not int(random.random() * ALIEN_ODDS):
             aliens.append(Alien())
 
         # Detect collisions
         pygame.display.update(dirtyrects)
         dirtyrects = []
 
-    pygame.time.delay(100)
+    pygame.time.wait(50)
     
 
 #if python says run, let's run!
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.