1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
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
#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
else:
self._frame = 0
self.image = self._images[self._frame]
def update(self, t): # just updates the frame / object
##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]:
self._frame = self.animations.get(self._current_anim)[0]
self._frame += timePassed/self._delay
##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]
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): # push to the next frame of curr animation
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.image = self._images[self._frame]
# cnt = len(anmiations) <-- why was this here?
|