-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholdfile.py
157 lines (89 loc) · 2.56 KB
/
oldfile.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
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
import pygame
import time
import random
EnemyPositionList=[50,100,150,200,250,300,350,400,450,500,550,600]
orange=(255,153,0)
black = (0,0,0)
red = (255,25,25)
class enemy1():
def __init__(self):
self.esurface=pygame.Surface((50,50))
pygame.draw.circle(self.esurface,orange,(25,25),25)
self.lives=1
self.x = 1225
self.y=EnemyPositionList[random.randint(0,len(EnemyPositionList)-1)]
def draw(self,screen):
screen.blit(self.esurface, (self.x ,self.y))
pygame.init()
screen = pygame.display.set_mode((1200,700))
pygame.display.set_caption("please")
clock = pygame.time.Clock()
class Sprite:
def __init__(self,x,y,width,height):
self.x=x
self.y=y
self.width=width
self.height=height
self.lives=10
def draw(self,screen):
pygame.draw.rect(screen,red,(self.x,self.y,self.width,self.height))
Sprite1=Sprite(100,50,100,100)
moveX,moveY=0,0
EnemyList=[]
vx=-1
x=1225
y=EnemyPositionList[random.randint(0,len(EnemyPositionList)-1)]
vy=0
timer=0
gameLoop=True
while gameLoop:
for event in pygame.event.get():
if event.type==pygame.QUIT:
exit()
if (event.type==pygame.QUIT):
gameLoop=False
if (event.type==pygame.KEYDOWN):
if (event.key==pygame.K_LEFT):
moveX = -4
if (event.key==pygame.K_RIGHT):
moveX = 4
if (event.key==pygame.K_UP):
moveY = -4
if (event.key==pygame.K_DOWN):
moveY = 4
if (event.type==pygame.KEYUP):
if (event.key==pygame.K_LEFT):
moveX=0
if (event.key==pygame.K_RIGHT):
moveX=0
if (event.key==pygame.K_UP):
moveY=0
if (event.key==pygame.K_DOWN):
moveY=0
screen.fill(black)
timer+=1
x += vx
y += vy
if timer % 100 == 0:
e=enemy1()
EnemyList.append(e)
for e in EnemyList:
e.x += vx
e.draw(screen)
if e.x<=-50:
EnemyList.remove(e)
Sprite1.draw(screen)
pygame.display.flip()
pygame.time.wait(5)
Sprite1.x+=moveX
Sprite1.y+=moveY
Sprite1.draw(screen)
pygame.display.flip()
clock.tick(50)
def run():
EnemyList=[]
vx=-1
x=1225
y=EnemyPositionList[random.randint(0,len(EnemyPositionList)-1)]
vy=0
timer=0