Dateien hochladen nach „“
parent
5a68ac9d9b
commit
19fd20431b
|
@ -4,13 +4,8 @@ class game():
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import os
|
|
||||||
print("initializing hashengine and installing dependencies if missing")
|
print("initializing hashengine and installing dependencies if missing")
|
||||||
self.linecount = 0
|
required = {'keyboard', 'sounddevice', 'soundfile'}
|
||||||
if os.name == 'nt':
|
|
||||||
required = {'sounddevice', 'soundfile', 'windows-curses'}
|
|
||||||
else:
|
|
||||||
required = {'sounddevice', 'soundfile'}
|
|
||||||
installed = {pkg.key for pkg in pkg_resources.working_set}
|
installed = {pkg.key for pkg in pkg_resources.working_set}
|
||||||
missing = required - installed
|
missing = required - installed
|
||||||
|
|
||||||
|
@ -21,14 +16,21 @@ class game():
|
||||||
print(i)
|
print(i)
|
||||||
subprocess.check_call([python, '-m', 'pip', 'install', i], stdout=sys.stdout)
|
subprocess.check_call([python, '-m', 'pip', 'install', i], stdout=sys.stdout)
|
||||||
print("done")
|
print("done")
|
||||||
|
import os
|
||||||
|
import ctypes
|
||||||
import string
|
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.osmodule = __import__("os")
|
||||||
import curses
|
self.keyboard = __import__("keyboard")
|
||||||
self.screen = curses.initscr()
|
|
||||||
self.screen.nodelay(1)
|
|
||||||
self.screen.keypad(True)
|
|
||||||
curses.noecho()
|
|
||||||
curses.endwin()
|
|
||||||
try:
|
try:
|
||||||
self.sounddevice = __import__("sounddevice")
|
self.sounddevice = __import__("sounddevice")
|
||||||
except OSError:
|
except OSError:
|
||||||
|
@ -52,52 +54,19 @@ class game():
|
||||||
self.map["{}:{}".format(i, f)] = " "
|
self.map["{}:{}".format(i, f)] = " "
|
||||||
|
|
||||||
self.objects = []
|
self.objects = []
|
||||||
|
|
||||||
def round2(self, target):
|
def round2(self, target):
|
||||||
from decimal import localcontext, Decimal, ROUND_HALF_UP
|
from decimal import localcontext, Decimal, ROUND_HALF_UP
|
||||||
with localcontext() as ctx:
|
with localcontext() as ctx:
|
||||||
ctx.rounding = ROUND_HALF_UP
|
ctx.rounding = ROUND_HALF_UP
|
||||||
return Decimal(target).to_integral_value()
|
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):
|
def update(self):
|
||||||
import curses
|
|
||||||
curses.noecho()
|
|
||||||
curses.endwin()
|
|
||||||
temp = self.screen.getch()
|
|
||||||
for i in self.pressedkeys:
|
for i in self.pressedkeys:
|
||||||
if temp == ord(i):
|
if self.keyboard.is_pressed(i):
|
||||||
self.pressedkeys[i] = True
|
self.pressedkeys[i] = True
|
||||||
else:
|
else:
|
||||||
self.pressedkeys[i] = False
|
self.pressedkeys[i] = False
|
||||||
curses.flushinp()
|
|
||||||
|
|
||||||
self.futuremap = self.map.copy()
|
self.futuremap = self.map.copy()
|
||||||
for i in self.objects:
|
for i in self.objects:
|
||||||
|
@ -118,10 +87,8 @@ class game():
|
||||||
if "{}:{}".format(self.round2(i.y-i.yvelocity), self.round2(i.x)) in self.map:
|
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))] == " ":
|
if self.map["{}:{}".format(self.round2(i.y-i.yvelocity), self.round2(i.x))] == " ":
|
||||||
i.y -= i.yvelocity
|
i.y -= i.yvelocity
|
||||||
self.calculateupobj(i.y+(-abs(i.yvelocity))-1, i.x, i.yvelocity)
|
|
||||||
else:
|
else:
|
||||||
i.y -= i.yvelocity
|
i.y -= i.yvelocity
|
||||||
self.calculateupobj(i.y+(-abs(i.yvelocity))-1, i.x, i.yvelocity)
|
|
||||||
else:
|
else:
|
||||||
i.y = i.targety
|
i.y = i.targety
|
||||||
i.targety = None
|
i.targety = None
|
||||||
|
@ -191,6 +158,33 @@ class game():
|
||||||
self.sounddevice.wait()
|
self.sounddevice.wait()
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def getattributes(self, target):
|
||||||
|
import inspect
|
||||||
|
temp = []
|
||||||
|
for i in inspect.getmembers(target):
|
||||||
|
if not i[0].startswith('_'):
|
||||||
|
if not inspect.ismethod(i[1]):
|
||||||
|
temp.append(i)
|
||||||
|
return temp
|
||||||
|
|
||||||
|
def convertgametostring(self):
|
||||||
|
temp = []
|
||||||
|
for i in self.objects:
|
||||||
|
temp.append(self.getattributes(i))
|
||||||
|
return str(temp)
|
||||||
|
|
||||||
|
def loadgamestring(self, target, clearexisting=True):
|
||||||
|
import ast
|
||||||
|
target = ast.literal_eval(target)
|
||||||
|
if clearexisting:
|
||||||
|
self.objects = []
|
||||||
|
for i in target:
|
||||||
|
temp = object("#")
|
||||||
|
for f in i:
|
||||||
|
temp.__setattr__(f[0], f[1])
|
||||||
|
self.addobj(temp)
|
||||||
|
|
||||||
|
|
||||||
class object():
|
class object():
|
||||||
def __init__(self, character, gravity=0.1, x=0, y=0, antixforce=0.1):
|
def __init__(self, character, gravity=0.1, x=0, y=0, antixforce=0.1):
|
||||||
|
@ -234,5 +228,4 @@ if __name__ == "__main__":
|
||||||
box.xvelocity = -1
|
box.xvelocity = -1
|
||||||
elif "q" in keys and keys["q"] == True:
|
elif "q" in keys and keys["q"] == True:
|
||||||
exit()
|
exit()
|
||||||
time.sleep(0.01)
|
time.sleep(0.05)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
file = open("targetplugin.py", 'r')
|
||||||
|
file = file.readlines()
|
||||||
|
name = input("name: ")
|
||||||
|
plugin = {}
|
||||||
|
plugin["name"] = name
|
||||||
|
tempbefore = ""
|
||||||
|
tempafter = ""
|
||||||
|
set = ""
|
||||||
|
for i in file:
|
||||||
|
if i == "#before\n":
|
||||||
|
set = "before"
|
||||||
|
elif i == "#after\n":
|
||||||
|
set = "after"
|
||||||
|
else:
|
||||||
|
if set == "before":
|
||||||
|
i = i.replace('"', "'")
|
||||||
|
tempbefore = tempbefore + i
|
||||||
|
if set == "after":
|
||||||
|
i = i.replace('"', "'")
|
||||||
|
tempafter = tempafter + i
|
||||||
|
plugin["main"] = {}
|
||||||
|
plugin["main"]["onupdatebefore"] = tempbefore
|
||||||
|
plugin["main"]["onupdateafter"] = tempafter
|
||||||
|
file = open("outplugin.plugin", 'w')
|
||||||
|
file.write(str(plugin))
|
||||||
|
file.close()
|
|
@ -0,0 +1,2 @@
|
||||||
|
#before
|
||||||
|
#after
|
Loading…
Reference in New Issue