Dateien hochladen nach „“
parent
87a1de5607
commit
5a68ac9d9b
|
@ -4,8 +4,13 @@ class game():
|
|||
import sys
|
||||
import subprocess
|
||||
import pkg_resources
|
||||
import os
|
||||
print("initializing hashengine and installing dependencies if missing")
|
||||
required = {'keyboard', 'sounddevice', 'soundfile'}
|
||||
self.linecount = 0
|
||||
if os.name == 'nt':
|
||||
required = {'sounddevice', 'soundfile', 'windows-curses'}
|
||||
else:
|
||||
required = {'sounddevice', 'soundfile'}
|
||||
installed = {pkg.key for pkg in pkg_resources.working_set}
|
||||
missing = required - installed
|
||||
|
||||
|
@ -16,21 +21,14 @@ class game():
|
|||
print(i)
|
||||
subprocess.check_call([python, '-m', 'pip', 'install', i], stdout=sys.stdout)
|
||||
print("done")
|
||||
import os
|
||||
import ctypes
|
||||
import string
|
||||
def isAdmin():
|
||||
try:
|
||||
is_admin = (os.getuid() == 0)
|
||||
except AttributeError:
|
||||
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
|
||||
return is_admin
|
||||
if not isAdmin():
|
||||
print("error: hashengine needs to be run as an admin")
|
||||
input("enter to continue...")
|
||||
exit()
|
||||
self.osmodule = __import__("os")
|
||||
self.keyboard = __import__("keyboard")
|
||||
import curses
|
||||
self.screen = curses.initscr()
|
||||
self.screen.nodelay(1)
|
||||
self.screen.keypad(True)
|
||||
curses.noecho()
|
||||
curses.endwin()
|
||||
try:
|
||||
self.sounddevice = __import__("sounddevice")
|
||||
except OSError:
|
||||
|
@ -61,12 +59,45 @@ class game():
|
|||
ctx.rounding = ROUND_HALF_UP
|
||||
return Decimal(target).to_integral_value()
|
||||
|
||||
def getobjbypos(self, x, y):
|
||||
for i in self.objects:
|
||||
if i.x == x and i.y == y:
|
||||
return i
|
||||
return False
|
||||
|
||||
def setobj(self, obj, x, y):
|
||||
for i in range(len(self.objects)):
|
||||
index = i
|
||||
i = self.objects[i]
|
||||
if i.x == x and i.y == y:
|
||||
self.objects[index] = obj
|
||||
|
||||
def calculateupobj(self, y, x, velocity):
|
||||
import curses
|
||||
import time
|
||||
curses.endwin()
|
||||
velocity = abs(velocity)
|
||||
if y >= 2 and y < self.size.lines:
|
||||
if self.getobjbypos(x, y) != False:
|
||||
print("y: {}, x: {}, velocity: {}".format(y, x, velocity))
|
||||
obj = self.getobjbypos(x, y)
|
||||
obj.y += velocity
|
||||
self.calculateupobj(obj.y+(-abs(velocity))-1, obj.x, velocity)
|
||||
return
|
||||
else:
|
||||
return
|
||||
|
||||
def update(self):
|
||||
import curses
|
||||
curses.noecho()
|
||||
curses.endwin()
|
||||
temp = self.screen.getch()
|
||||
for i in self.pressedkeys:
|
||||
if self.keyboard.is_pressed(i):
|
||||
if temp == ord(i):
|
||||
self.pressedkeys[i] = True
|
||||
else:
|
||||
self.pressedkeys[i] = False
|
||||
curses.flushinp()
|
||||
|
||||
self.futuremap = self.map.copy()
|
||||
for i in self.objects:
|
||||
|
@ -87,8 +118,10 @@ class game():
|
|||
if "{}:{}".format(self.round2(i.y-i.yvelocity), self.round2(i.x)) in self.map:
|
||||
if self.map["{}:{}".format(self.round2(i.y-i.yvelocity), self.round2(i.x))] == " ":
|
||||
i.y -= i.yvelocity
|
||||
self.calculateupobj(i.y+(-abs(i.yvelocity))-1, i.x, i.yvelocity)
|
||||
else:
|
||||
i.y -= i.yvelocity
|
||||
self.calculateupobj(i.y+(-abs(i.yvelocity))-1, i.x, i.yvelocity)
|
||||
else:
|
||||
i.y = i.targety
|
||||
i.targety = None
|
||||
|
@ -201,5 +234,5 @@ if __name__ == "__main__":
|
|||
box.xvelocity = -1
|
||||
elif "q" in keys and keys["q"] == True:
|
||||
exit()
|
||||
time.sleep(0.05)
|
||||
time.sleep(0.01)
|
||||
|
||||
|
|
Loading…
Reference in New Issue