-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlil_t_endless.py
More file actions
executable file
·178 lines (151 loc) · 4.5 KB
/
Copy pathlil_t_endless.py
File metadata and controls
executable file
·178 lines (151 loc) · 4.5 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python3
import os
import random
import sys
import threading
import time
import scrap_engine as se
class PanelItem(se.Object):
def bump_left(self):
global moving
del moving[moving.index(self)]
self.remove()
def bump(self, ob, x, y):
ob.set(ob.x - 1, ob.y)
self.set(self.x - 1, self.y)
class Panel(se.Square):
def init(self):
for ob in self.obs:
moving.append(ob)
def genpanel():
global panelindex, test
exec("panel_%s=Panel('#', 10, 1, ob_class=PanelItem)" % panelindex)
exec(
"panel_%s.add(map, map.width-11, map.height-%i)"
% (panelindex, random.randint(8, 20))
)
exec("panel_%s.init()" % panelindex)
panelindex += 1
def on_press(key):
global ev
ev = str(key)
if (
sys.platform == "linux"
): # Use another (not on xserver relying) way to read keyboard input, to make this shit work in tty or via ssh, where no xserver is available
def recogniser():
import sys
import termios
import tty
global ev, old_settings, fd, do_exit
do_exit = False
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
tty.setraw(fd)
while True:
char = sys.stdin.read(1)
if ord(char) == 13:
ev = "Key.enter"
elif ord(char) == 32:
ev = "Key.space"
else:
ev = "'" + char.rstrip() + "'"
if ord(char) == 3 or do_exit:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
ev = "exit"
else:
from pynput.keyboard import Listener
def recogniser():
global ev
while True:
with Listener(on_press=on_press) as listener:
listener.join()
def main():
global v, t, ev, g, framenum, genframe
while True:
def nexty(v, g, t):
return round(
player.y
- (v * (v / g) - 1 / 2 * g * (v / g) ** 2)
- v * t
+ 1 / 2 * g * t**2
)
for ob in map.obs[1:]:
if player.y + 1 == ob.y and player.x == ob.x:
t = 0
v = 0
for ob in map.obs[1:]:
if player.y < ob.y < nexty(v, g, t) and ob.x == player.x + 1:
player.set(player.x, ob.y - 1)
t = 0
v = 0
break
elif player.y > ob.y > nexty(v, g, t) and ob.x == player.x + 1:
player.set(player.x, ob.y + 1)
t = 0
v = 0
break
if ev == "Key.space":
v = -0.25
ev = 0
elif ev == "exit":
ev = 0
raise KeyboardInterrupt
if player.set(player.x, nexty(v, g, t)) != 0 and t != 0:
for ob in map.obs[1:]:
if ob.x == player.x and ob.y == nexty(v, g, t):
v = 0
player.set(player.x, player.y + 1)
t += 1
# exec("point_%s=PanelItem('*', 'float')"%panelindex)
# exec("point_%s.add(map, player.x-1, player.y)"%panelindex)
# exec("moving.append(point_%s)"%panelindex)
# panelindex+=1
for mov in moving:
mov.set(mov.x - 1, mov.y)
if player.x < smap.x - 1:
exit()
h.rechar(
(2 - len(str(player.y))) * " "
+ str(player.y)
+ " "
+ str(map.height)
+ " "
+ str(player.y)
+ " "
+ str(nexty(v, g, t))
+ " "
+ str(player.y - nexty(v, g, t))
)
if genframe + 15 == framenum:
genpanel()
genframe += 15
time.sleep(0.05)
smap.remap()
smap.show()
framenum += 1
os.system("")
width, height = os.get_terminal_size()
t = ev = v = 0
g = 0.015
panelindex = 0
framenum = 0
genframe = 0
map = se.Map(height - 1, width + 12, " ")
smap = se.Submap(map, 0, 0)
player = se.Object("t")
block = PanelItem("#")
panel = Panel("#", 10, 1, ob_class=PanelItem)
ground = se.Square("#", map.width, 5)
h = se.Text("00 00")
player.add(map, round(smap.width / 2), round(map.height / 2))
block.add(map, map.width - 11, map.height - 6)
panel.add(map, map.width - 11, map.height - 10)
ground.add(map, 0, map.height - 5)
h.add(smap, 0, 0)
moving = [ob for ob in panel.obs] + [block]
recognising = threading.Thread(target=recogniser)
recognising.daemon = True
recognising.start()
smap.remap()
smap.show(init=True)
main()