Commits

Anonymous committed 653acbd

fixed timing issues

Comments (0)

Files changed (4)

 #This is a list of changes in pygame's history.
 
+Dec 3, 2000
+	fixed timing issues. negative time.delay() will become 0
+
 Nov 30, 2000
 	UserRect module added
 	all objects now have a matching type; SurfaceType, etc
     Aliens. Now it has evolved into something sort of resembling
     fun. This demonstrates a lot of different uses of sprites and
     optimized blitting. Also transparancy, colorkeys, fonts, sound,
-    music, and more. (PS, my high score is 117! goodluck)
+    music, joystick, and more. (PS, my high score is 117! goodluck)
 
 oldalien.py - This more closely resembles a port of the SDL Aliens
     demo. The code is a lot simpler, so it makes a better starting
 try:
     import pygame.mixer
     pygame.mixer.pre_init(11025)
-except ImportError:
+except:
     print 'Warning, sound not initialized'
     pygame.mixer = None
 
 
 #constants
 FRAMES_PER_SEC = 45
-PLAYER_SPEED   = 5
+PLAYER_SPEED   = 6
 MAX_SHOTS      = 2
-SHOT_SPEED     = 6
-BOMB_SPEED     = 6
+SHOT_SPEED     = 9
+BOMB_SPEED     = 9
 MAX_ALIENS     = 30
-ALIEN_SPEED    = 6
-ALIEN_ODDS     = 36
+ALIEN_SPEED    = 9
+ALIEN_ODDS     = 29
 ALIEN_RELOAD   = 12
-EXPLODE_TIME   = 40
+EXPLODE_TIME   = 35
 MAX_EXPLOSIONS = 4
 SCREENRECT     = Rect(0, 0, 640, 480)
-ANIMCYCLE      = 18
+ANIMCYCLE      = 12
 PLODECYCLE     = 7
 BULLET_OFFSET  = 11
 BOUNCEWIDTH    = PLAYER_SPEED * 4
-DIFFICULTY     = 14
-BOMB_ODDS      = 150
+DIFFICULTY     = 16
+BOMB_ODDS      = 130
 DANGER         = 10
 SORRYSCORE     = 20
 GOODSCORE      = 60
 
 #some globals for friendly access
 dirtyrects = [] # list of update_rects
-next_tick = 0   # used for timing
 class Img: pass # container for images
 class Snd: pass # container for sounds
 
     
 
 
-
+last_tick = 0
+ticks_per_frame = int((1.0 / FRAMES_PER_SEC) * 1000.0)
 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)
+    global last_tick, ticks_per_frame
+    now = pygame.time.get_ticks()
+    wait = ticks_per_frame - (now - last_tick)
+    #strange bug i'm hunting...
+    if type(wait) != type(1):
+        print 'attn: pete@shinners.org\n', wait, type(wait), now, type(now)
+    pygame.time.delay(wait)
+    last_tick = pygame.time.get_ticks()
 
 
 
     elif kills >= GOODSCORE: print 'Excellent!'
     elif kills >= GOODSCORE-12: print 'Almost Excellent!'
 
+
+
     
 
 #if python says run, let's run!
     /*DOC*/    "delay for a number of milliseconds\n"
     /*DOC*/    "\n"
     /*DOC*/    "Will pause for a given number of milliseconds.\n"
-    /*DOC*/    "The maximum resolution of this delay is 10 milliseconds. The\n"
-    /*DOC*/    "time you request to delay will be truncated down to the nearest\n"
-    /*DOC*/    "10 milliseconds. This will help delay() return a little before\n"
-    /*DOC*/    "the requested time has passed, instead of a little afterwards.\n"
     /*DOC*/ ;
 
 static PyObject* delay(PyObject* self, PyObject* arg)
 	if(!PyArg_ParseTuple(arg, "i", &ticks))
 		return NULL;
 
+	if(ticks < 0)
+		ticks = 0;
+
 	Py_BEGIN_ALLOW_THREADS
-	SDL_Delay((ticks/10)*10);
+	SDL_Delay(ticks);
 	Py_END_ALLOW_THREADS
 
 	RETURN_NONE