-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimations.py
More file actions
205 lines (184 loc) · 5.92 KB
/
animations.py
File metadata and controls
205 lines (184 loc) · 5.92 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import pygame
from pygame.locals import *
try:
import android
except ImportError:
android = None
pygame.init()
if android:
android.init()
android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)
try:
import pygame.mixer as mixer
except ImportError:
import android.mixer as mixer
infoObject=pygame.display.Info()
WINDOW_WIDTH=infoObject.current_w
WINDOW_HEIGHT=infoObject.current_h
bgimage=pygame.image.load("images/bg1.png")
bgimage=pygame.transform.scale(bgimage,(WINDOW_WIDTH,WINDOW_HEIGHT))
fpsClock=pygame.time.Clock()
def button_animation(DISPLAYSURF,image_down,image_up,position):
play_button_sound()
static_surf=DISPLAYSURF.copy()
DISPLAYSURF.blit(static_surf,(0,0))
DISPLAYSURF.blit(image_down,position)
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type==MOUSEBUTTONUP:
DISPLAYSURF.blit(image_up,position)
pygame.display.update()
return
def fade_in(DISPLAYSURF):
real_surf=DISPLAYSURF.copy()
fade_speed=20
if android:
fade_speed=50
for a in range(0,255,fade_speed):
static_surf=DISPLAYSURF.convert_alpha()
DISPLAYSURF.blit(real_surf,(0,0))
static_surf.fill((0,0,0,a))
DISPLAYSURF.blit(static_surf,(0,0))
pygame.display.update()
fpsClock.tick(120)
def fade_out(DISPLAYSURF):
real_surf=DISPLAYSURF.copy()
fade_speed=20
if android:
fade_speed=50
for a in range(0,255,fade_speed):
static_surf=DISPLAYSURF.convert_alpha()
DISPLAYSURF.blit(real_surf,(0,0))
static_surf.fill((0,0,0,255-a))
DISPLAYSURF.blit(static_surf,(0,0))
pygame.display.update()
fpsClock.tick(120)
def fade_in_out(DISPLAYSURF):
real_surf=DISPLAYSURF.copy()
fade_speed=20
if android:
fade_speed=50
for a in range(0,255,fade_speed):
static_surf=DISPLAYSURF.convert_alpha()
DISPLAYSURF.blit(real_surf,(0,0))
static_surf.fill((0,0,0,a))
DISPLAYSURF.blit(static_surf,(0,0))
pygame.display.update()
fpsClock.tick(120)
for a in range(0,255,fade_speed):
static_surf=DISPLAYSURF.convert_alpha()
DISPLAYSURF.blit(real_surf,(0,0))
static_surf.fill((0,0,0,255-a))
DISPLAYSURF.blit(static_surf,(0,0))
pygame.display.update()
fpsClock.tick(120)
def put_in(DISPLAYSURF,image,rect):
real_surf=DISPLAYSURF.copy()
put_in_speed=-5
if android:
put_in_speed=-20
for size in range(200,0,put_in_speed):
DISPLAYSURF.blit(real_surf,(0,0))
new_image=pygame.transform.scale(image,(rect.width+size,rect.height+size))
DISPLAYSURF.blit(new_image,rect)
pygame.display.update()
fpsClock.tick()
DISPLAYSURF.blit(real_surf,(0,0))
DISPLAYSURF.blit(image,rect)
pygame.display.update()
fpsClock.tick()
def half_fade_in(DISPLAYSURF):
real_surf=DISPLAYSURF.copy()
fade_speed=20
if android:
fade_speed=50
for a in range(0,220,fade_speed):
static_surf=DISPLAYSURF.convert_alpha()
DISPLAYSURF.blit(real_surf,(0,0))
static_surf.fill((0,0,0,a))
DISPLAYSURF.blit(static_surf,(0,0))
pygame.display.update()
fpsClock.tick(120)
def shake(DISPLAYSURF):
BORDER_COLOR=(0,0,0)
shake_range=20
no_of_shakes=1
time_shake=20
shake_surf=DISPLAYSURF.copy()
for i in range(2):
#DISPLAYSURF.fill(BORDER_COLOR)
DISPLAYSURF.blit(shake_surf,(-shake_range,-shake_range))
pygame.display.update()
pygame.time.wait(time_shake)
#DISPLAYSURF.fill(BORDER_COLOR)
DISPLAYSURF.blit(shake_surf,(shake_range,-shake_range))
pygame.display.update()
pygame.time.wait(time_shake)
#DISPLAYSURF.fill(BORDER_COLOR)
DISPLAYSURF.blit(shake_surf,(shake_range,shake_range))
pygame.display.update()
pygame.time.wait(time_shake)
#DISPLAYSURF.fill(BORDER_COLOR)
DISPLAYSURF.blit(shake_surf,(-shake_range,shake_range))
pygame.display.update()
pygame.time.wait(time_shake)
#DISPLAYSURF.fill(BORDER_COLOR)
DISPLAYSURF.blit(shake_surf,(0,0))
pygame.display.update()
#to delete if lakshay doesnt like the gradual colour bg idea
c=150
g=1
def gradual_bg(DISPLAYSURF):
global c,g
if c>204:
g=-1
elif c<50:
g=1
c+=g
DISPLAYSURF.fill((c,(c+50),c))
#till here to be deleted
BLOCKSOUND=mixer.Sound("sounds/blocked.wav")
def play_block_sound():
BLOCKSOUND.play()
PUTSOUND=mixer.Sound("sounds/put.wav")
def play_put_sound():
PUTSOUND.play()
ENDSOUND=mixer.Sound("sounds/end.wav")
def play_end_sound():
ENDSOUND.play()
BUTTONSOUND=mixer.Sound("sounds/button.wav")
def play_button_sound():
BUTTONSOUND.play()
def read_high_score():
fin=open('score.txt','r')
for line in fin:
print("score is :"+line)
fin.close()
def write_high_score(score):
fin=open('score.txt','r')
for line in fin:
if int(line)<score:
fin.close()
fout=open('score.txt','w')
fout.write(str(score))
fout.close()
return
def set_bgs(DISPLAYSURF):
DISPLAYSURF.blit(bgimage,(0,0))
shadow_color=(180,180,180)
def make_text(text,color,bgcolor,top,left,size=50):
FONT_OBJECT=pygame.font.Font('fonts_and_extras/SourceSansPro-BlackIt.otf',size)
if bgcolor!=None:
text_surf=FONT_OBJECT.render(text,0,color,bgcolor)
else:
text_surf=FONT_OBJECT.render(text,0,color)#if no background color is provided then the background is transparent
text_rect=text_surf.get_rect()
text_rect.topleft=(top,left)
img=pygame.Surface(text_rect.size,16)
img.blit(bgimage,(0,0))
text_surf.set_palette_at(1,shadow_color)
img.blit(text_surf,(0,1))
text_surf.set_palette_at(1,color)
img.blit(text_surf,(0,0))
return (img,text_rect)