-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.py~
109 lines (102 loc) · 3.08 KB
/
classes.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
102
103
104
105
106
107
108
109
import pygame,sys,math
from random import randint
class BaseClass(pygame.sprite.Sprite):
allsprites = pygame.sprite.Group()
def __init__(self,x,y,image_string):
pygame.sprite.Sprite.__init__(self)
BaseClass.allsprites.add(self)
self.image = pygame.image.load(image_string)
self.rect = self.image.get_rect()
self.rect.x=x
self.rect.y=y
def destroy(self,ClassName):
ClassName.List.remove(self)
BaseClass.allsprites.remove(self)
del self
class Bug(BaseClass):
List = pygame.sprite.Group()
going_right=True
def __init__(self,x,y,image_string):
BaseClass.__init__(self,x,y,image_string)
Bug.List.add(self)
self.velx,self.vely = 0,5
self.jumping,self.go_down =False,False
def motion(self,SCREENWIDTH,SCREENHEIGHT):
predicted_location = self.rect.x +self.velx
if predicted_location<0:
self.velx=0
elif predicted_location + self.rect.width>SCREENWIDTH:
self.velx=0
self.rect.x+=self.velx
self.__jump(SCREENHEIGHT)
def __jump(self,SCREENHEIGHT):
max_jump=20
if self.jumping:
if self.rect.y<max_jump:
self.go_down =True
if self.go_down:
self.rect.y+=self.vely
predicted_location=self.rect.y +self.vely
if predicted_location +self.rect.height>SCREENHEIGHT:
self.jumping =False
self.go_down=False
else:
self.rect.y-=self.vely
class Fly(BaseClass):
List = pygame.sprite.Group()
def __init__(self,x,y,image_string):
BaseClass.__init__(self,x,y,image_string)
Fly.List.add(self)
self.health=100
self.velx ,self.vely= randint(1,4),2
self.amplitude,self.period = randint(20,140),randint(4,5)/100.0
@staticmethod
def update_all(SCREENWIDTH,SCREENHEIGHT):
for fly in Fly.List:
if fly.health<=0:
if fly.rect.y+fly.rect.height<SCREENHEIGHT:
fly.rect.y+=fly.vely
else:
fly.fly(SCREENWIDTH)
def fly(self,SCREENWIDTH):
if self.rect.x + self.rect.width >SCREENWIDTH or self.rect.x <0:
self.image = pygame.transform.flip(self.image,True,False)
self.velx = -self.velx
self.rect.x+=self.velx
# a*sin(bx+c)+y
self.rect.y=self.amplitude* math.sin(self.period*self.rect.x) + 140
#@staticmethod
#def movement(SCREENWIDTH):
# for fly in Fly.List:
# fly.fly(SCREENWIDTH)
class BugProjectile(BaseClass):
List=pygame.sprite.Group()
normal_list=[]
fire= True
def __init__(self,x,y,if_this_variable_is_true_then_fire,image_string):
pygame.sprite.Sprite.__init__(self)
self.image=pygame.image.load(image_string)
self.rect=self.image.get_rect()
self.rect.x=x
self.rect.y=y
self.if_this_variable_is_true_then_fire=if_this_variable_is_true_then_fire
self.rect.width
try:
last_element=BugProjectile.normal_list[-1]
difference=abs(self.rect.x-last_element.rect.x)
if difference <self.width:
return
except Exception:
pass
BugProjectile.normal_list.append(self)
#BaseClass.__init__(self,x,y,width,height,image_string)
BugProjectile.List.add(self)
self.velx= None
@staticmethod
def movement():
for projectile in BugProjectile.List:
projectile.rect.x+=projectile.velx
def destroy(self):
BugProjectile.List.remove(self)
BugProjectile.normal_list.remove(self)
del self