-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plane_Game2D.py
145 lines (120 loc) · 3.01 KB
/
Plane_Game2D.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
import pgzrun
import pgzero
import random
import pygame
import time
import os
from pynput import mouse
status = 0
counter = 0
time = 0
kills = 0
WIDTH = 500
HEIGHT = 700
# create Player
player = Actor('player_plane')
player.x = 250
player.y = 650
weapons = []
# create three enemy entity
enemy = []
for i in range(3):
e = Actor('en')
e.x = random.randint(0, 500)
enemy.append(e)
def draw():
global counter
global cooldown
global kills
global time
screen.blit('bg', [0, 0])
screen.draw.text(f"Killed: {kills}", (20, 30))
screen.draw.text(f"Time Survivaed: {time}", (20, 10))
player.draw()
# fucked char
if player.image != 'fail1':
for w in weapons:
w.draw()
for e in enemy:
e.draw()
# shoot
def on_key_down(key):
global counter
global cooldown
global kills
global time
# left click for shoot
control = mouse.Controller()
if keyboard.space:
weapon = Actor('aml')
weapon.x = player.x
weapon.y = player.y - 50
weapons.append(weapon)
def on_mouse_down():
global counter
global cooldown
global kills
global time
weapon = Actor('aml')
weapon.x = player.x
weapon.y = player.y - 50
weapons.append(weapon)
status = 1
def update():
global counter, cooldown, kills, time, status
counter += 1
#Player move
if keyboard.left or keyboard.a:
player.x -= 5
if keyboard.right or keyboard.d:
player.x += 5
if keyboard.up or keyboard.w:
player.y -= 5
if keyboard.down or keyboard.s:
player.y += 5
if player.image == 'fail1' and status == 2:
print('You Have Killed',kills)
print('You Got in',time,'secounds')
exit()
# display time & score on screen
#screen.blit()
# timer
for e in enemy:
if counter == 60:
counter = 0
time += 1
# make entity move
if random.randint(1, 2) == 1:
e.x += 2
else:
e.x -= 2
# aim
for w in weapons:
w.y -= 30
for w in weapons:
if w.y <= 0:
weapons.remove(w)
# enemy fix
for e in enemy:
e.y += 5
if e.y > 700:
e.x = random.randint(0, 500)
e.y = 0
#enemy init
for e in enemy:
for w in weapons:
if e.colliderect(w):
e.x = random.randint(0, 500)
e.y = 0
kills += 1
weapons.remove(w)
# faild
if e.colliderect(player) or player.y <= -15 or player.y >= 715 or player.x >= 515 or player.x <= -15:
player.image = 'fail1'
status = 2
# play faild music
music.play('faild')
# background music
music.play('music1')
os.environ['SDL_VIDEO_CENTERED'] = '1'
pgzrun.go()