Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/anim/DrawableObjectTests/boxes.py
diff options
context:
space:
mode:
Diffstat (limited to 'anim/DrawableObjectTests/boxes.py')
-rw-r--r--anim/DrawableObjectTests/boxes.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/anim/DrawableObjectTests/boxes.py b/anim/DrawableObjectTests/boxes.py
new file mode 100644
index 0000000..5b444b6
--- /dev/null
+++ b/anim/DrawableObjectTests/boxes.py
@@ -0,0 +1,32 @@
+import pygame
+
+class UpDownBox(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.next_update_time = 0 # update() hasn't been called yet.
+
+ def update(self, current_time, bottom):
+ # Update every 10 milliseconds = 1/100th of a second.
+ if self.next_update_time < current_time:
+
+ # If we're at the top or bottom of the screen, switch directions.
+ if self.rect.bottom == bottom - 1: self.going_down = False
+ elif self.rect.top == 0: self.going_down = True
+
+ # Move our position up or down by one pixel
+ if self.going_down: self.rect.top += 1
+ else: self.rect.top -= 1
+
+ if self.listPos < self.listLen - 1:
+ self.listPos += 1
+ else:
+ self.listPos = 0
+ self.image = self.images[self.listPos]
+ self.next_update_time = current_time