Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/devtools
diff options
context:
space:
mode:
authorslm <jtmengel@gmail.com>2010-07-28 21:57:04 (GMT)
committer slm <jtmengel@gmail.com>2010-07-28 21:57:04 (GMT)
commitf552aa367aa18e1ba75d92cabef884fd2503ffcc (patch)
treef3f01fb3cd5612f3f399be0d309d3a1e2123752a /devtools
parent6f1b36ea9a972adb5bf4af03d51d2b8184d363c8 (diff)
Revised the DrawableObject file within devtools/CompleteTestKit/ to optimize speed performance and revisit logic; major changes have been made through comments and the state of DrawableObject is in serious overhaul and, therefore, is not in a functional state.
Diffstat (limited to 'devtools')
-rw-r--r--devtools/CompleteTestKit/DrawableObject.py230
-rw-r--r--devtools/CompleteTestKit/DynamicDrawableObject.py93
-rw-r--r--devtools/CompleteTestKit/DynamicDrawableObject.py~106
-rwxr-xr-x[-rw-r--r--]devtools/CompleteTestKit/FinalDirtyTest.py182
-rw-r--r--devtools/CompleteTestKit/FinalDirtyTest.py~96
-rw-r--r--devtools/CompleteTestKit/text.txt1
-rw-r--r--devtools/CompleteTestKit/to-do/boxes.py35
7 files changed, 295 insertions, 448 deletions
diff --git a/devtools/CompleteTestKit/DrawableObject.py b/devtools/CompleteTestKit/DrawableObject.py
index ce7389f..5fd9f20 100644
--- a/devtools/CompleteTestKit/DrawableObject.py
+++ b/devtools/CompleteTestKit/DrawableObject.py
@@ -1,22 +1,39 @@
import pygame
class DrawableObject(pygame.sprite.Sprite):
+
+# I removed the parameter for FPS, x and y velocities, and the text file reference
+# since this is not a dynamic object
+
+ def __init__(self,images, x = 0, y = 0,):
+ pygame.sprite.Sprite.__init__(self)
+
+ #
+ # My question is why do drawable objects take the form of a List?
+ # it seems that every object takes lists, but then why encapsulate?
+ # I believe that we can collapse these objects
+ # JT Jul 2010
+
+#self._originals = images
+#self._images = images
- def __init__(self,images,textfileName,fps = 10, x = 0, y = 0, xVelocity = 0, yVelocity = 0):
- pygame.sprite.Sprite.__init__(self)
- cnt = 0
-
- #self._originals = images
- #self._images = images
self._images = []
- self._origImages = []
- while cnt < len(images):
- self._images.append(images[cnt].convert())
- self._origImages.append(images[cnt].convert())
- cnt += 1
+ self._origImages = []
+
+#
+# Made the below while loop more efficient and quicker
+# JT Jul 28 2010
+ for i in range(len(images)):
+ self._images.append(images[i].convert())
+ self._origImages.append(images[i].convert())
+
self._start = pygame.time.get_ticks()
self.image = self._images[0]
- self._delay = 1000 / fps
+#
+# This went away since it was relient on FPS which DO's don't have
+""" self._delay = 1000 / fps """
+# JT Jul 28 2010
+
self._last_update = 0
self._frame = 0
self.animations = {}
@@ -27,10 +44,14 @@ class DrawableObject(pygame.sprite.Sprite):
self.xSpeed = xVelocity
self.ySpeed = yVelocity
self.myAngle = 0
- self.xSize = 40
- self.ySize = 40
+ self.xSize = 40 # <--
+ self.ySize = 40 # <--
self.rect.topleft = (x,y)
-
+#
+# Since there will be no animation in a static object I removed the code that
+# read the animFile since it was an unecessary slowdown
+#
+ """
if textfileName != '':
f = open(textfileName, 'r')
@@ -40,84 +61,138 @@ class DrawableObject(pygame.sprite.Sprite):
animValues = currentLine.split(",")
self.animations[animValues[0]] = [int(animValues[1]), int(animValues[2])]
currentLine = f.readline()
-
+ """
def addImages(self, images):
-
self._images.extend(images)
#self._originals.extend(images)
def goToAnim(self, animName):
-
if self.animations.get(animName, 0) != 0:
self._current_anim = animName
self._frame = self.animations[animName][0]
- self.image = self._images[self._frame]
-
- def move(self):
-
- self.xPos += self.xSpeed
- self.yPos += self.ySpeed
-
- self.rect.right += self.xSpeed
- self.rect.top += self.ySpeed
-
- def nudge(self, xNudge = 0, yNudge = 0):
-
- self.xPos += xNudge
- self.yPos += yNudge
-
- self.rect.right += xNudge
- self.rect.top += yNudge
-
- def scale(self, newXSize = None, newYSize = None):
-
- if newXSize != None: self.xSize = newXSize
- if newYSize != None: self.ySize = newYSize
-
- cnt = 0
- while cnt < len(self._images):
- self._origImages[cnt] = pygame.transform.scale(self._origImages[cnt], (self.xSize, self.ySize))
- self._images[cnt] = self._origImages[cnt]
- cnt += 1
+ self.image = self._images[self._frame]
+
+#
+# Again I took out default values because I don't want the primary function
+# of the method to be effectively overridable and have a method that can
+# do nothing without raising flags
+# I also conformed the parameter naming convention so that it conforms with the
+# other methods' naming convention in this object
+# JT Jul 28 2010
+ def nudge(self, x, y):
+ self.xPos += x
+ self.yPos += y
+ self.rect.right += x
+ self.rect.top += y
+
+#
+# reworked the loop for efficiency and the if statement logic
+# JT Jul 28 2010
+ def scale(self, x=None, y=None):
+ if type(x).__name__=='int': self.xSize = x
+ if type(y).__name__=='int': self.ySize = y
+
+ for i in range(len(self._images)):
+ self._origImages[i] = pygame.transform.scale(self._origImages[i], (self.xSize, self.ySize))
+ self._images[i] = self._origImages[i]
def getXSize(self):
-
return self.xSize
def getYSize(self):
-
return self.ySize
-
+
+#
+# I changed rotate to utilize a for instead of a counter/while loop for speed
+# JT - Jul 28 2010
def rotate(self,angle):
-
- cnt = 0
-
self.myAngle += angle
- while cnt < len(self._images):
-
- self._images[cnt] = pygame.transform.rotate(self._origImages[cnt], self.myAngle)
- cnt += 1
+ for i in range(len(self._images)):
+ self._images[i] = pygame.transform.rotate(self._origImages[i], self.myAngle)
def getRotation(self):
-
return self.myAngle
-
+
+#
+# I don't recommend forcing people to keep images within the screen
+# a common trick in bullet hells is to temporarily move image objects off-
+# screen when they die so the game isn't constantly loading a new instance of
+# a common enemy
+# JT - Jul 28 2010
def setPosition(self, x = None, y = None):
-
- if x != None and x >= 0: self.xPos = x
- if y != None and y >= 0: self.yPos = y
-
- self.rect.topleft = (self.xPos, self.yPos)
+ if type(x).__name__=='int': self.xPos = x
+ if type(y).__name__=='int': self.yPos = y
+ self.rect.topleft = (self.xPos, self.yPos)
def getXPos(self):
-
return self.xPos
def getYPos(self):
-
return self.yPos
+
+#
+# Added defaul values in case someone wants their color key to be taken from bot.right corner, eg
+# JT Jul 28 2010
+ def calcColorKey(self, x=0, y=0):
+ myColorKey = images[0].get_at((x,y))
+ setColorKey(myColorKey)
+ def setColorKey(self, aColor):
+ for i in range(len(self._images)):
+ self._images[i].set_colorkey(aColor)
+#
+# Set default value to allow the method to be called empty (since t does nothing atm)
+# JT Jul 28 2010
+ def update(self, t=None):
+ pass
+
+#
+# removed current animation method
+#
+ def nextFrame(self):
+ pass
+
+ def nextCurrentAnimFrame(self):
+ pass
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#
+# Removed this because it took into account the depreciated velocity concept that was
+# contrary to the projected use of the drawable object
+# This would be more useful in a Dynamic Drawable Object
+# JT Jul 28 2010
+"""
+ def move(self):
+ self.xPos += self.xSpeed
+ self.yPos += self.ySpeed
+ self.rect.right += self.xSpeed
+ self.rect.top += self.ySpeed
+"""
+
+#
+# I removed velocity because a static object should not have variables pertaining to movement
+# That is not instructed manually; velocity, being displacement over time, is easily perceived
+# as an exaple of autonomous motion since it's dictated by the passage of time
+# JT Jul 28 2010
+"""
def setSpeed(self, xVelocity = None, yVelocity = None):
if xVelocity != None: self.xSpeed = xVelocity
@@ -130,27 +205,4 @@ class DrawableObject(pygame.sprite.Sprite):
def getYSpeed(self):
return self.ySpeed
-
- def calcColorKey(self):
-
- myColorKey = images[0].get_at((0,0))
- setColorKey(myColorKey)
-
- def setColorKey(self, aColor):
-
- cnt = 0
- while cnt < len(self._images):
- self._images[cnt].set_colorkey(aColor)
- cnt += 1
-
- def update(self, t):
- pass
-
- def updateCurrnetAnimation(self, t):
- pass
-
- def nextFrame(self):
- pass
-
- def nextCurrentAnimFrame(self):
- pass
+"""
diff --git a/devtools/CompleteTestKit/DynamicDrawableObject.py b/devtools/CompleteTestKit/DynamicDrawableObject.py
index e793d38..8d2737d 100644
--- a/devtools/CompleteTestKit/DynamicDrawableObject.py
+++ b/devtools/CompleteTestKit/DynamicDrawableObject.py
@@ -11,7 +11,7 @@ class DynamicDrawableObject(DrawableObject, pygame.sprite.Sprite):
self._images.extend(images)
- # def update(self, t):
+# def update(self, t):
#
# timePassed = t + self._last_update
# if timePassed > self._delay:
@@ -28,77 +28,78 @@ class DynamicDrawableObject(DrawableObject, pygame.sprite.Sprite):
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
- if (self.yPos + self.ySize) >= bottom and self.ySpeed > 0: self.ySpeed = self.ySpeed * -1
- if self.yPos < 0 and self.ySpeed < 0: self.ySpeed = self.ySpeed * -1
-
- # If we're at the right or left of the screen, switch directions.
- if (self.xPos + self.xSize) >= right or self.xPos < 0: self.xSpeed = self.xSpeed * -1
- if (self.xPos + self.xSize) >= right and self.xSpeed > 0: self.xSpeed = self.xSpeed * -1
- if self.xPos < 0 and self.xSpeed < 0: self.xSpeed = self.xSpeed * -1
+# 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
+ if (self.yPos + self.ySize) >= bottom and self.ySpeed > 0:
+ self.ySpeed = self.ySpeed * -1
+ if self.yPos < 0 and self.ySpeed < 0:
+ self.ySpeed = self.ySpeed * -1
+
+#2345678911234567892123456789312345678941234567895123456789612345678971234567898
+
+# If we're at the right or left of the screen, switch directions.
+ if (self.xPos + self.xSize) >= right or self.xPos < 0:
+ self.xSpeed = self.xSpeed * -1
+ if (self.xPos + self.xSize) >= right and self.xSpeed > 0:
+ self.xSpeed = self.xSpeed * -1
+ if self.xPos < 0 and self.xSpeed < 0:
+ self.xSpeed = self.xSpeed * -1
self.move()
if self._frame < len(self._images) - 1:
- self._frame += 1
+ self._frame += 1
else:
- self._frame = 0
+ self._frame = 0
self.image = self._images[self._frame]
def update(self, t): # just updates the frame / object
-
- 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
+ ##print "Last update:", 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
+ timePassed = t + self._last_update
+ ##print " Time since:", timePassed,
+
+#checking if I am in the animation and putting me there if I am not
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]:
+ self._frame = self.animations.get(self._current_anim)[0]
self._frame += timePassed/self._delay
- print "frame ", self._frame
+ ##print " On frame:", self._frame,"\n"
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]
+ 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
- else:
-
- self._last_update = timePassed
+ else:
+ self._last_update = timePassed
def nextFrame(self): # push to next frame
-
self._frame += 1
if self._frame >= len(self._images):
-
framesPast = self._frame - len(self._images)
self._frame = framesPast
self.image = self._images[self._frame]
def nextCurrentAnimFrame(self): # push to the next frame of curr animation
-
- cnt = 0
- while cnt < len(animations):
-
- if animations[cnt] == self._current_anim:
-
- if self._frame < self.animations[self._current_anim][0] or self._frame > self.animations[self._current_anim][1]:
+
+ for cnt in range(len(animations)):
+
+ if animations[cnt] == self._current_anim:
+ if self._frame < self.animations[self._current_anim][0] or self._frame > self.animations[self._current_anim][1]:
+ self._frame = self.animations[self._current_anim][0]
+
+ else: self._frame += 1
+
+ if self._frame > self.animations[self._current_anim][1]:
+ framesPast = self._frame - self.animations[self._current_anim][1]
+ self._frame = framesPast - 1 + self.animations[self._current_anim][0]
- self._frame = self.animations[self._current_anim][0]
- else:
- self._frame += 1
-
- if self._frame > self.animations[self._current_anim][1]:
-
- framesPast = self._frame - self.animations[self._current_anim][1]
- self._frame = framesPast - 1 + self.animations[self._current_anim][0]
-
- self.image = self._images[self._frame]
+ self.image = self._images[self._frame]
- cnt = len(anmiations)
-
- cnt += 1
+# cnt = len(anmiations) <-- why was this here?
diff --git a/devtools/CompleteTestKit/DynamicDrawableObject.py~ b/devtools/CompleteTestKit/DynamicDrawableObject.py~
deleted file mode 100644
index 7ccbc5a..0000000
--- a/devtools/CompleteTestKit/DynamicDrawableObject.py~
+++ /dev/null
@@ -1,106 +0,0 @@
-import pygame
-from DrawableObject import DrawableObject
-
-class DynamicDrawableObject(DrawableObject, pygame.sprite.Sprite):
-
- def __init__(self,images,textfileName,fps = 10, x = 0, y = 0, xVelocity = 0, yVelocity = 0):
-
- DrawableObject.__init__(self, images, textfileName, fps, x, y, xVelocity, yVelocity)
-
- def addImages(self, images):
-
- self._images.extend(images)
-
- # def update(self, t):
-#
-# timePassed = t + self._last_update
-# if timePassed > self._delay:
-#
-# self._frame += timePassed/self._delay
-# while self._frame >= len(self._images):
-#
-# framesPast = self._frame - len(self._images)
-# self._frame = framesPast - 1
-#
-# self.image = self._images[self._frame]
-# self._last_update = timePassed%self._delay
-# self._last_update = timePassed
-
- 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
- if (self.yPos + self.ySize) >= bottom and self.ySpeed > 0: self.ySpeed = self.ySpeed * -1
- if self.yPos < 0 and self.ySpeed < 0: self.ySpeed = self.ySpeed * -1
-
- # If we're at the right or left of the screen, switch directions.
- if (self.xPos + self.xSize) >= right or self.xPos < 0: self.xSpeed = self.xSpeed * -1
- if (self.xPos + self.xSize) >= right and self.xSpeed > 0: self.xSpeed = self.xSpeed * -1
- if self.xPos < 0 and self.xSpeed < 0: self.xSpeed = self.xSpeed * -1
-
- self.move()
-
- if self._frame < len(self._images) - 1:
- self._frame += 1
- else:
- self._frame = 0
-
- self.image = self._images[self._frame]
-
- def update(self, t): # just updates the frame / object
-
- #if self.animations[cnt] == self._current_anim:
-
- 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 += timePassed/self._delay
- print "frame ", self._frame
-
- 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
- else:
-
- self._last_update = timePassed
-
- def nextFrame(self): # push to next frame
-
- self._frame += 1
- if self._frame >= len(self._images):
-
- framesPast = self._frame - len(self._images)
- self._frame = framesPast
-
- self.image = self._images[self._frame]
-
- def nextCurrentAnimFrame(self):
-
- cnt = 0
- while cnt < len(animations):
-
- if animations[cnt] == self._current_anim:
-
- if self._frame < self.animations[self._current_anim][0] or self._frame > self.animations[self._current_anim][1]:
-
- self._frame = self.animations[self._current_anim][0]
- else:
- self._frame += 1
-
- if self._frame > self.animations[self._current_anim][1]:
-
- framesPast = self._frame - self.animations[self._current_anim][1]
- self._frame = framesPast - 1 + self.animations[self._current_anim][0]
-
- self.image = self._images[self._frame]
-
- cnt = len(anmiations)
-
- cnt += 1
diff --git a/devtools/CompleteTestKit/FinalDirtyTest.py b/devtools/CompleteTestKit/FinalDirtyTest.py
index 3921356..5d8421e 100644..100755
--- a/devtools/CompleteTestKit/FinalDirtyTest.py
+++ b/devtools/CompleteTestKit/FinalDirtyTest.py
@@ -7,90 +7,122 @@ from Scene import Scene
from DrawableObject import DrawableObject
from DynamicDrawableObject import DynamicDrawableObject
pygame.init()
-
-FRAME=500
+
+#2345678911234567892123456789312345678941234567895123456789612345678971234567898
+#2345678911234567892123456789312345678941234567895123456789612345678971234567898
+
+#GREEN = 0, 192, 0
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
+maxGroup = 1
+maxTrial = 1 # multiple trials, but hard coded in this test
+maxFrame=500 #temperary
+infoFilePath = 'animInfo.txt'
-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
+screen = pygame.display.set_mode(( screenWidth,screenHeight) )
+pygame.display.set_caption("Testing Custom Objects - FinalDirtyTest.py")
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 = DrawableObject(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")
+for trial in range(maxTrial):
+ print "New trial"
+ screen.blit( background , [0,0] )
+ pygame.display.flip()
+
+ start = time()
+
+ ###NOTE: Convert to an encapsulated LOOP###
+
+ surfaceList = [
+ 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()
+ ]
+
+ """ Object 1 will be a static image that will not be animating NOTE: once
+ you pass the list of frames to the object, they and their encapsulated
+ metadata are no longer only surfaces but are considered instead to be
+ Sprite Objects
+ """
+ drawObject1 = DrawableObject(surfaceList, infoFilePath, None, 0 , 0 , 1 , 1)
+ drawObject1.goToAnim("anim1")
+
+ """ 2-4 are dynamic objects that will refresh at varying rates to illustrate
+ the capabilities of our code to allow users to have varying refresh rate
+ """
+ drawObject2 = DynamicDrawableObject(
+ surfaceList,infoFilePath,24,40,40,1,1)
+ drawObject2.goToAnim("anim1")
+
+ drawObject3 = DynamicDrawableObject(
+ surfaceList,infoFilePath,24,80,80,1,1)
+ drawObject3.goToAnim("anim1")
+
+ drawObject4 = DynamicDrawableObject(
+ surfaceList,infoFilePath,24,120,120,1,1)
+ drawObject4.goToAnim("anim1")
+
+ drawObject5 = DynamicDrawableObject(
+ surfaceList,infoFilePath,24,160,160,1,1)
+ drawObject5.goToAnim("anim1")
- group1=Scene(d)
- group1.addObjects([d2])
- group1.addObjects([d3])
- group1.addObjects([d4])
- group1.addObjects([d5])
- groups=[group1]
+ group1 = Scene( drawObject1 )
+ group1.addObjects( [drawObject2] )
+ group1.addObjects( [drawObject3] )
+ group1.addObjects( [drawObject4] )
+ group1.addObjects( [drawObject5] )
+
+ ### END: Convert to an encapsulated LOOP###
+
+ """ We only need a single group for this example, but this format of an
+ ordered list of our scenes/groups will be echoed in our end
+ implementation.
+
+ Revisit this and possibly simplify: this isn't a tutorial for suggested
+ techniques, but a test to demonstrate that it can be applied and to
+ record the data to imply why it's a viable alternative
+ """
+
+# groupsList=[group1] # < --- What the hell and why
+
print (time()-start) ,
- print " -- Time to load"
-
+ print " -- Time to load and sort animations into groupsListList"
clock = pygame.time.Clock()
- clock.tick()
+ clock.tick() # <--Updates the clock variable in milliseconds
+
start = time()
- for frame in range(FRAME):
- dirtyList=[]
- for image in range(numImages):
- #move / collision detection
- groups[image].update(clock.get_time())
+ for maxFrame in range(maxFrame):
+ dirtyList=[]
+
+ """ Move/collision detection, individually blit each image group, add to
+ dirtyList within the trial, this iterates through a list containing
+ sublists of surfaces that we want to update. This list contains both
+ """
+ for grp in range(maxGroup):
+ groupsList[grp].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()
+ dirtyList.extend( groupsList[grp].draw(screen) )
+ print dirtyList
+ pygame.display.update(dirtyList) # <-- is there a faster way to place?
+
+ for grp in range(maxGroup):
+ groupsList[grp].clear(screen, background)
+
+ print "Trial's average framerate was " , str(1/((time()-start)/maxFrame))
diff --git a/devtools/CompleteTestKit/FinalDirtyTest.py~ b/devtools/CompleteTestKit/FinalDirtyTest.py~
deleted file mode 100644
index 61a1968..0000000
--- a/devtools/CompleteTestKit/FinalDirtyTest.py~
+++ /dev/null
@@ -1,96 +0,0 @@
-#! /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/text.txt b/devtools/CompleteTestKit/text.txt
deleted file mode 100644
index 8c6d6d3..0000000
--- a/devtools/CompleteTestKit/text.txt
+++ /dev/null
@@ -1 +0,0 @@
-anim1,0,8 \ No newline at end of file
diff --git a/devtools/CompleteTestKit/to-do/boxes.py b/devtools/CompleteTestKit/to-do/boxes.py
deleted file mode 100644
index 56b3623..0000000
--- a/devtools/CompleteTestKit/to-do/boxes.py
+++ /dev/null
@@ -1,35 +0,0 @@
-import pygame
-
-class BouncingBox(pygame.sprite.Sprite):
- def __init__(self, imagesList, initial_position):
- pygame.sprite.Sprite.__init__(self)
- self.images = imagesList
- self.listLen = len(imagesList)
- self.listPos = 0
- self.image = imagesList[self.listPos]
- self.rect = self.image.get_rect()
- self.rect.topleft = initial_position
- self.going_down = True # Start going downwards
- self.going_right = True # Start going right
-
- def update(self, right, bottom):
- # If we're at the top or bottom of the screen, switch directions.
- if self.rect.bottom >= bottom: self.going_down = False
- elif self.rect.top <= 0: self.going_down = True
- # If we're at the right or left of the screen, switch directions.
- if self.rect.right >= right: self.going_right = False
- elif self.rect.left <= 0: self.going_right = True
-
- # Move our position up or down by 2 pixels
- if self.going_down: self.rect.top += 2
- else: self.rect.top -= 2
- # Move our position left or right by 2 pixels
- if self.going_right: self.rect.right += 2
- else: self.rect.right -= 2
-
- if self.listPos < self.listLen - 1:
- self.listPos += 1
- else:
- self.listPos = 0
-
- self.image = self.images[self.listPos]