-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtransition.py
101 lines (95 loc) · 4.58 KB
/
transition.py
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
import pygame #load pygame
from pygame.locals import *
import math
import settings
#fade from transparent to black
class FadeOut:
def __init__(self, speed):
self.speed = speed #store fade speed
self.color = 255 #store current fade color
self.running = True #we're currently running
def update(self, surf):
if not self.running: return True #return and say we're done if we're not running
self.color -= self.speed #fade closer to black
if self.color < 0: self.color = 0 #if we've gone negative, set to zero
surf.fill((self.color,)*4, special_flags=BLEND_RGBA_MULT) #draw the fade
if self.color == 0: #if we've finished fading
self.running = False #we're not running any more
return True #say we're done
#fade from black to transparent
class FadeIn:
def __init__(self, speed):
self.speed = speed #store fade speed
self.color = 0 #store current fade color
self.running = True #we're currently running
def update(self, surf):
if not self.running: return True #return and say we're done if we're not running
self.color += self.speed #fade closer to transparent
if self.color > 255: self.color = 255 #if we've gone past the highest color, limit it
surf.fill((self.color,)*4, special_flags=BLEND_RGBA_MULT) #draw the fade
if self.color == 255: #if we've finished fading
self.running = False #we're not running any more
return True #say we're done
#shift the screen to the left
class ScreenShift:
def __init__(self, speed):
self.speed = speed #store fade speed
self.moved = 0 #store amount moved
self.running = True #we're currently running
def update(self, surf):
if not self.running: return True #return and say we're done if we're not running
self.moved += self.speed #increment amount moved
surf.scroll(-self.moved, 0) #scroll the surface
#clear the area where the screen was
surf.fill((0, 0, 0), (settings.screen_x-self.moved, 0, settings.screen_x, settings.screen_y))
if self.moved > settings.screen_x: #if we're done moving
self.running = False #we're not running
return True #say we're done
#wave the screen out
class WavyScreen:
def __init__(self):
self.running = True #we're currently running
self.amplitude = 1.0 #store initial settings
self.degrees = 0.1
self.frames = 40
self.fade = 255.0
def update(self, surf):
if not self.running: return True #return if we're not running
#loop through all the rows in the screen and shift them individually
for y in xrange(0, settings.screen_y):
surf.set_clip((0, y, settings.screen_x, 1)) #set clipping rect for this row
delta = math.sin(self.degrees)*self.amplitude #calculate scroll value
surf.scroll(int(delta), 0) #scroll surface
self.degrees += 0.1 #increment degrees
if delta < 0: #if the screen was scrolled to the left
surf.fill((0, 0, 0), (settings.screen_x+delta, y, settings.screen_x, 1)) #fill scrolled off area
else: #if screen was scrolled right
surf.fill((0, 0, 0), (0, y, delta, 1)) #fill scrolled off area
surf.set_clip(None) #clear clipping rect
self.amplitude += 0.7 #increment amplitude for next frame
self.frames -= 1 #and decrement frames
if self.frames < 15: #if we're supposed to fade
surf.fill((max(int(self.fade), 0), )*4, special_flags=BLEND_RGBA_MULT) #draw it
self.fade -= 255/15 #decrement fade color
if self.frames <= 0:
surf.fill((0, 0, 0))
if self.frames == -15: #if we've run out of frames
self.running = False #we're not running
return True #say we're done
#transition to a battle
class BattleOpen:
def __init__(self):
self.running = True #transition is currently running
self.pos = settings.screen_y/2 #initial position
def update(self, surf):
if not self.running: return True #return if we're not running
#draw two rectangles clearing out the screen
surf.fill((0, 0, 0), (0, 0, settings.screen_x, self.pos))
surf.fill((0, 0, 0), (0, settings.screen_y-self.pos, settings.screen_x, settings.screen_y))
if self.pos > (settings.screen_y/3):
self.pos -= 2
else:
self.pos -= 5
if self.pos <= 0:
self.running = False
return True