From 431e0666a4561f7c27505d34f083ffbfe2c13457 Mon Sep 17 00:00:00 2001 From: slm Date: Tue, 27 Jul 2010 18:51:49 +0000 Subject: Changed certain file names to indicate depreciated objects that will be temporarily kept for reference purposes. --- (limited to 'devtools/CompleteTestKit') diff --git a/devtools/CompleteTestKit/DynamicDO.py b/devtools/CompleteTestKit/DynamicDrawableObject - depreciated.py index 5375807..0686bc5 100644 --- a/devtools/CompleteTestKit/DynamicDO.py +++ b/devtools/CompleteTestKit/DynamicDrawableObject - depreciated.py @@ -26,7 +26,7 @@ class DynamicDrawableObject(DrawableObject, pygame.sprite.Sprite): # self._last_update = timePassed%self._delay # self._last_update = timePassed - def updateWithMovementself, right, bottom): + def update(self, right, bottom): # If we're at the top or bottom of the screen, switch directions. if (self.yPos + self.ySize) >= bottom or self.yPos < 0: self.ySpeed = self.ySpeed * -1 @@ -47,29 +47,33 @@ class DynamicDrawableObject(DrawableObject, pygame.sprite.Sprite): self.image = self._images[self._frame] - def update(self, t): + def updateCurrentAnimation(self, t): - #if self.animations[cnt] == self._current_anim: + cnt = 0 + while cnt < len(animations): + + if animations[cnt] == self._current_anim: + + timePassed = t + self._last_update + if timePassed > self._delay: - print "last update ", self._last_update - timePassed = t + self._last_update#getting the time since the last time I updated my frame and adding it to the time that I last updated my frame - print "time passed ", timePassed - if (timePassed) > self._delay: - if self._frame < self.animations.get(self._current_anim)[0] or self._frame > self.animations.get(self._current_anim)[1]: #checking if I am in the animation and putting me there if I am not - self._frame = self.animations.get(self._current_anim)[0] + if self._frame < self.animations.get(self._current_anim)[0] or self._frame > self.animations.get(self._current_anim)[1]: #checking if I am in the animation and putting me there if I am not - self._frame += timePassed/self._delay - print "frame ", self._frame + self._frame = self.animations.get(self._current_anim)[0] - while self._frame >= self.animations.get(self._current_anim)[1]: - framesPast = self._frame - self.animations.get(self._current_anim)[1] - self._frame = framesPast - 1 + self.animations.get(self._current_anim)[0] + self._frame += timePassed/self._delay + while self._frame >= self.animations.get(self._current_anim)[1]: + + framesPast = self._frame - self.animations.get(self._current_anim)[1] + self._frame = framesPast - 1 + self.animations.get(self._current_anim)[0] + + self.image = self._images[self._frame] + self._last_update = timePassed%self._delay + self._last_update = timePassed + + cnt = len(animations) - self.image = self._images[self._frame] - self._last_update = timePassed%self._delay - else: - - self._last_update = timePassed + cnt += 1 def nextFrame(self): diff --git a/devtools/CompleteTestKit/DynamicDrawableObject.py b/devtools/CompleteTestKit/DynamicDrawableObject.py index 0686bc5..e46ef04 100644 --- a/devtools/CompleteTestKit/DynamicDrawableObject.py +++ b/devtools/CompleteTestKit/DynamicDrawableObject.py @@ -26,7 +26,7 @@ class DynamicDrawableObject(DrawableObject, pygame.sprite.Sprite): # self._last_update = timePassed%self._delay # self._last_update = timePassed - def update(self, right, bottom): + def updateWithMovement(self, right, bottom): # causes objects to move and collide with walls # If we're at the top or bottom of the screen, switch directions. if (self.yPos + self.ySize) >= bottom or self.yPos < 0: self.ySpeed = self.ySpeed * -1 @@ -47,35 +47,31 @@ class DynamicDrawableObject(DrawableObject, pygame.sprite.Sprite): self.image = self._images[self._frame] - def updateCurrentAnimation(self, t): + def update(self, t): # just updates the frame / object - cnt = 0 - while cnt < len(animations): - - if animations[cnt] == self._current_anim: - - timePassed = t + self._last_update - if timePassed > self._delay: + #if self.animations[cnt] == self._current_anim: - if self._frame < self.animations.get(self._current_anim)[0] or self._frame > self.animations.get(self._current_anim)[1]: #checking if I am in the animation and putting me there if I am not + print "last update ", self._last_update + timePassed = t + self._last_update#getting the time since the last time I updated my frame and adding it to the time that I last updated my frame + print "time passed ", timePassed + if (timePassed) > self._delay: + if self._frame < self.animations.get(self._current_anim)[0] or self._frame > self.animations.get(self._current_anim)[1]: #checking if I am in the animation and putting me there if I am not + self._frame = self.animations.get(self._current_anim)[0] - self._frame = self.animations.get(self._current_anim)[0] + self._frame += timePassed/self._delay + print "frame ", self._frame - self._frame += timePassed/self._delay - while self._frame >= self.animations.get(self._current_anim)[1]: - - framesPast = self._frame - self.animations.get(self._current_anim)[1] - self._frame = framesPast - 1 + self.animations.get(self._current_anim)[0] - - self.image = self._images[self._frame] - self._last_update = timePassed%self._delay - self._last_update = timePassed - - cnt = len(animations) + while self._frame >= self.animations.get(self._current_anim)[1]: + framesPast = self._frame - self.animations.get(self._current_anim)[1] + self._frame = framesPast - 1 + self.animations.get(self._current_anim)[0] - cnt += 1 + self.image = self._images[self._frame] + self._last_update = timePassed%self._delay + else: + + self._last_update = timePassed - def nextFrame(self): + def nextFrame(self): # push to next frame self._frame += 1 if self._frame >= len(self._images): @@ -85,7 +81,7 @@ class DynamicDrawableObject(DrawableObject, pygame.sprite.Sprite): self.image = self._images[self._frame] - def nextCurrentAnimFrame(self): + def nextCurrentAnimFrame(self): # push to the next frame of curr animation cnt = 0 while cnt < len(animations): diff --git a/devtools/CompleteTestKit/DynamicDO.py b/devtools/CompleteTestKit/DynamicDrawableObject.py~ index 5375807..7ccbc5a 100644 --- a/devtools/CompleteTestKit/DynamicDO.py +++ b/devtools/CompleteTestKit/DynamicDrawableObject.py~ @@ -26,7 +26,7 @@ class DynamicDrawableObject(DrawableObject, pygame.sprite.Sprite): # self._last_update = timePassed%self._delay # self._last_update = timePassed - def updateWithMovementself, right, bottom): + def updateWithMovement(self, right, bottom): # causes objects to move and collide with walls # If we're at the top or bottom of the screen, switch directions. if (self.yPos + self.ySize) >= bottom or self.yPos < 0: self.ySpeed = self.ySpeed * -1 @@ -47,7 +47,7 @@ class DynamicDrawableObject(DrawableObject, pygame.sprite.Sprite): self.image = self._images[self._frame] - def update(self, t): + def update(self, t): # just updates the frame / object #if self.animations[cnt] == self._current_anim: @@ -71,7 +71,7 @@ class DynamicDrawableObject(DrawableObject, pygame.sprite.Sprite): self._last_update = timePassed - def nextFrame(self): + def nextFrame(self): # push to next frame self._frame += 1 if self._frame >= len(self._images): diff --git a/devtools/CompleteTestKit/FinalDirtyTest.py b/devtools/CompleteTestKit/FinalDirtyTest.py index 61a1968..b2c86fc 100644 --- a/devtools/CompleteTestKit/FinalDirtyTest.py +++ b/devtools/CompleteTestKit/FinalDirtyTest.py @@ -5,7 +5,7 @@ from boxes import BouncingBox from time import time from Scene import Scene from DrawableObject import DrawableObject -from DynamicDO import DynamicDrawableObject +from DynamicDrawableObject import DynamicDrawableObject pygame.init() FRAME=500 diff --git a/devtools/CompleteTestKit/FinalDirtyTest.py~ b/devtools/CompleteTestKit/FinalDirtyTest.py~ new file mode 100644 index 0000000..61a1968 --- /dev/null +++ b/devtools/CompleteTestKit/FinalDirtyTest.py~ @@ -0,0 +1,96 @@ +#! /usr/bin/env python +import pygame +from pygame.locals import * +from boxes import BouncingBox +from time import time +from Scene import Scene +from DrawableObject import DrawableObject +from DynamicDO import DynamicDrawableObject +pygame.init() + +FRAME=500 +screenWidth = 600 +screenHeight = 400 +numImages = 1 +maxTrial = 5 # multiple trials, but hard coded in this test +dirtyList=[] + +print "width,height", +print screenWidth, +print ",", +print screenHeight + +screen = pygame.display.set_mode( [int(screenWidth), + int(screenHeight)] ) #Screen Set 600x400 +pygame.display.set_caption("Sprite Speed Test Window") +GREEN = 0, 192, 0 # green +background = pygame.image.load("Room.gif") +screen.blit(background,[0,0]) +pygame.display.flip() +start = time() +frameList = [ + pygame.image.load("./art/BMP24/1.bmp").convert(), + pygame.image.load("./art/BMP24/2.bmp").convert(), + pygame.image.load("./art/BMP24/3.bmp").convert(), + pygame.image.load("./art/BMP24/4.bmp").convert(), + pygame.image.load("./art/BMP24/5.bmp").convert(), + pygame.image.load("./art/BMP24/6.bmp").convert(), + pygame.image.load("./art/BMP24/7.bmp").convert(), + pygame.image.load("./art/BMP24/8.bmp").convert(), + pygame.image.load("./art/BMP24/9.bmp").convert(), +] +frameList2 = [ + pygame.image.load("./Animation Styles/IndividualFrames/bmp16/a2/1.bmp").convert(), + pygame.image.load("./Animation Styles/IndividualFrames/bmp16/a2/2.bmp").convert(), + pygame.image.load("./Animation Styles/IndividualFrames/bmp16/a2/3.bmp").convert(), + pygame.image.load("./Animation Styles/IndividualFrames/bmp16/a2/4.bmp").convert(), + pygame.image.load("./Animation Styles/IndividualFrames/bmp16/a2/5.bmp").convert(), + pygame.image.load("./Animation Styles/IndividualFrames/bmp16/a2/6.bmp").convert(), + pygame.image.load("./Animation Styles/IndividualFrames/bmp16/a2/7.bmp").convert(), + pygame.image.load("./Animation Styles/IndividualFrames/bmp16/a2/8.bmp").convert(), + pygame.image.load("./Animation Styles/IndividualFrames/bmp16/a2/9.bmp").convert(), +] + +for aTrial in range(maxTrial): + start = time() + + d = DynamicDrawableObject(frameList2,"text.txt",400,0,0,1,1) + d.goToAnim("anim1") + d2 = DynamicDrawableObject(frameList2,"text.txt",400,40,40,1,1) + d2.goToAnim("anim1") + d3 = DynamicDrawableObject(frameList2,"text.txt",400,80,80,1,1) + d3.goToAnim("anim1") + d4 = DynamicDrawableObject(frameList2,"text.txt",400,120,120,1,1) + d4.goToAnim("anim1") + d5 = DynamicDrawableObject(frameList2,"text.txt",400,160,160,1,1) + d5.goToAnim("anim1") + + group1=Scene(d) + group1.addObjects([d2]) + group1.addObjects([d3]) + group1.addObjects([d4]) + group1.addObjects([d5]) + groups=[group1] + print (time()-start) , + print " -- Time to load" + + + clock = pygame.time.Clock() + clock.tick() + start = time() + for frame in range(FRAME): + dirtyList=[] + for image in range(numImages): + #move / collision detection + groups[image].update(clock.get_time()) + clock.tick() + #individually blit each image group - add to list for update + dirtyList.extend(groups[image].draw(screen)) + + #draw the images flip/update + pygame.display.update(dirtyList) + for image in range(numImages): + groups[image].clear(screen, background) + + #print 1/((time()-start)/FRAME) + pygame.display.flip() diff --git a/devtools/CompleteTestKit/OriginalScene.py b/devtools/CompleteTestKit/OriginalScene - Depreciated.py index 4771f3b..4771f3b 100644 --- a/devtools/CompleteTestKit/OriginalScene.py +++ b/devtools/CompleteTestKit/OriginalScene - Depreciated.py -- cgit v0.9.1