-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
56 lines (38 loc) · 1.08 KB
/
main.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
import pygame as pyg ,random as rand, sys,time
from pygame.locals import *
from objects import Bullet,Tank,Enemy
pyg.init()
win_size = [600,600]
win = pyg.display.set_mode(win_size)
pyg.display.set_caption("tank fire ")
player = Tank(300,300,20,20,'purple')
enemy_list = []
def newEnemy():
colors = ['red','green','yellow','blue','skyblue','pink','navy','orange','Crimson','Coral','SlateGray','Silver']
color=rand.choices(colors)[0]
enemy_list.append(Enemy(rand.randint(0, 600), rand.randint(0, 300), 20, 20,color))
for i in range(3):
newEnemy()
# game variables
fire = True
timer = pyg.time.Clock()
fps = 60
while fire:
win.fill([0,0,0])
timer.tick(fps)
# event handling
for event in pyg.event.get():
if event.type == QUIT:
fire = False
key_pressed = pyg.key.get_pressed()
if key_pressed[K_ESCAPE]:
fire = False
player.update(key_pressed,win)
player.shoot()
for enemy in enemy_list:
enemy.update(win)
enemy.outomove(win)
enemy.shoot(win)
pyg.display.update()
pyg.quit()
print("GAME OVER [+1]")