Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/MAFH2/fortuneengine/DrawableObject.py
diff options
context:
space:
mode:
Diffstat (limited to 'MAFH2/fortuneengine/DrawableObject.py')
-rw-r--r--MAFH2/fortuneengine/DrawableObject.py217
1 files changed, 122 insertions, 95 deletions
diff --git a/MAFH2/fortuneengine/DrawableObject.py b/MAFH2/fortuneengine/DrawableObject.py
index 6a704a8..d0d17de 100644
--- a/MAFH2/fortuneengine/DrawableObject.py
+++ b/MAFH2/fortuneengine/DrawableObject.py
@@ -1,20 +1,20 @@
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,textfileName,fps = 10, x = 0, y = 0, xVelocity = 0, yVelocity = 0):
+ def __init__(self,images, x = 0, y = 0,):
pygame.sprite.Sprite.__init__(self)
- cnt = 0
-
- self._images = []
+ self._images = []
self._origImages = []
- while cnt < len(images):
- self._images.append(images[cnt].convert_alpha())
- self._origImages.append(images[cnt].convert_alpha())
- cnt += 1
+ 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
+ self.image = self._images[0]
self._last_update = 0
self._frame = 0
self.animations = {}
@@ -22,13 +22,15 @@ class DrawableObject(pygame.sprite.Sprite):
self.rect = self.image.get_rect()
self.xPos = x
self.yPos = y
- 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')
@@ -38,90 +40,138 @@ class DrawableObject(pygame.sprite.Sprite):
animValues = currentLine.split(",")
self.animations[animValues[0]] = [int(animValues[1]), int(animValues[2])]
currentLine = f.readline()
-
- self.goToAnim("anim1")
-
- else:
-
- self.animations["anim1"] = [0, len(self._images) - 1]
- self.goToAnim("anim1")
+ """
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
@@ -134,27 +184,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
+"""