-
Notifications
You must be signed in to change notification settings - Fork 0
/
jj.py
156 lines (134 loc) · 4.53 KB
/
jj.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
154
155
156
import os
import sys
import signal
from colorama import init
from input import _Getch as getch
from classes import Board, Din, Coin, Rods, Enemy, Magnet, Speedb
from random import randrange
import time
from defn import *
from particles import Bullet, Snow
if __name__ == "__main__":
os.system('clear')
objboard = Board(23, 400)
din = Din(18, 10)
din.screen(objboard)
boss = Enemy(11, 378)
boss.screen(objboard)
speedfactor = 0
speedtime = 0
prev_speed = -1
tmp = 0
gravity_time = time.time()
snow_time = gravity_time
bosscol = 305
coins = []
rods = []
bullets = []
snowballs = []
magnets = []
speedbs = []
# generate coins,rods and speedboost
for i in range(35):
if i % 2 == 0:
continue
coins.append(Coin(randrange(4, 19), randrange(i * 10, i * 10 + 10)))
coins.append(Coin(randrange(4, 19), randrange(i * 10, i * 10 + 10)))
coins.append(Coin(randrange(4, 19), randrange(i * 10, i * 10 + 10)))
magnets.append(Magnet(randrange(4, 18), randrange(130, 140)))
magnets.append(Magnet(randrange(4, 18), randrange(230, 240)))
magnets.append(Magnet(randrange(4, 18), randrange(330, 340)))
speedbs.append(Speedb(randrange(4, 18), randrange(110, 120)))
speedbs.append(Speedb(randrange(4, 18), randrange(250, 260)))
for i in range(33):
if i % 2 == 1:
continue
rods.append(
Rods(
randrange(4), randrange(
4, 15), randrange(
i * 10, i * 10 + 5)))
# render rods and speedboost
coin_maintainance(coins, objboard, din)
for rod in rods:
rod.screen(objboard)
for i in speedbs:
i.screen(objboard)
# wait for keypress to start
print()
din.printscore()
objboard.screen(tmp, din)
print("\t\t\t\tPRESS ANY KEY TO START")
getch().getget()
start_time = time.time()
while True:
# check for input
char = getch()()
if char == 'q':
din.iskill(objboard, 0)
elif char == 'w':
gravity_time = time.time()
din.clear(objboard)
din.reposition(-1, 0, objboard)
coin_maintainance(coins, objboard, din)
din.reposition(-1, 0, objboard)
coin_maintainance(coins, objboard, din)
din.reposition(-1, 0, objboard)
elif char == 'a':
din.clear(objboard)
din.reposition(0, -1, objboard)
coin_maintainance(coins, objboard, din)
din.reposition(0, -1, objboard)
elif char == 'd':
din.clear(objboard)
din.reposition(0, 1, objboard)
coin_maintainance(coins, objboard, din)
din.reposition(0, 1, objboard)
elif char == 'f':
bullets.append(Bullet(din, objboard))
elif char == ' ':
din.ssheild(1)
"""simulate gravity"""
if time.time() - gravity_time > 0.3:
din.gravity(objboard)
coin_maintainance(coins, objboard, din)
if time.time() - gravity_time > 0.5:
din.gravity(objboard)
coin_maintainance(coins, objboard, din)
if time.time() - gravity_time > 0.8:
din.gravity(objboard)
coin_maintainance(coins, objboard, din)
if tmp == 0:
os.system('clear')
cls()
for rod in rods:
rod.screen(objboard)
for i in speedbs:
i.screen(objboard)
speedfactor, prev_speed = speedb_maintainance(
speedbs, objboard, din, prev_speed)
din.ssheild()
bullets = bullet_maintainance(bullets, objboard, rods, snowballs)
snowball_maintainance(snowballs, din, objboard)
din.clear(objboard)
din.printscore()
if time.time() - speedtime > 0.2:
speedtime = time.time()
tmp = tmp + 1
if tmp < bosscol:
din.stay(1, objboard)
if speedfactor == 1:
tmp = tmp + 2
if tmp < bosscol:
din.stay(2, objboard)
for magnet in magnets:
magnet.attract(din, objboard)
din.screen(objboard)
if tmp > bosscol-20:
enemy_kill(boss, din, objboard, bullets)
if time.time() - snow_time > 1.4:
snowballs.append(Snow(boss, objboard, din))
snow_time = time.time()
objboard.screen(tmp, din)
enemy_maintainance(boss, din, objboard)
din.iskill(objboard)