finished core system for now
This commit is contained in:
parent
1b1c170d6b
commit
d48cd8ee91
|
@ -9,6 +9,7 @@ import time
|
||||||
import threading
|
import threading
|
||||||
import pickle
|
import pickle
|
||||||
from pathfinding import pathfinding
|
from pathfinding import pathfinding
|
||||||
|
from keyboard import keyboard
|
||||||
#import itertools
|
#import itertools
|
||||||
#import multiprocessing
|
#import multiprocessing
|
||||||
|
|
||||||
|
@ -56,6 +57,7 @@ class game:
|
||||||
self._threads = []
|
self._threads = []
|
||||||
self._root = obj()
|
self._root = obj()
|
||||||
self._scripts = []
|
self._scripts = []
|
||||||
|
self._keyboard = keyboard(self._canvas)
|
||||||
"""self._workers = []
|
"""self._workers = []
|
||||||
self._processes = 2 # total number of processes.
|
self._processes = 2 # total number of processes.
|
||||||
for i in range(self._processes):
|
for i in range(self._processes):
|
||||||
|
@ -224,6 +226,11 @@ class game:
|
||||||
TLB.current += 1
|
TLB.current += 1
|
||||||
TLB.render()
|
TLB.render()
|
||||||
|
|
||||||
|
def isdown(self, key):
|
||||||
|
temp = self._keyboard.getkeys()
|
||||||
|
if key in temp:
|
||||||
|
return temp[key]
|
||||||
|
|
||||||
def loadgame(self, target):
|
def loadgame(self, target):
|
||||||
print("loading objects...")
|
print("loading objects...")
|
||||||
self._root = pickle.loads(target["obj"])
|
self._root = pickle.loads(target["obj"])
|
||||||
|
@ -249,8 +256,36 @@ class game:
|
||||||
TLB = loadbar(20, 0)
|
TLB = loadbar(20, 0)
|
||||||
self.readdobj(self._root.children, TLB)
|
self.readdobj(self._root.children, TLB)
|
||||||
|
|
||||||
|
def APIGEN(self):
|
||||||
|
API = {}
|
||||||
|
API["HASHGAME"] = self
|
||||||
|
API["vector2"] = vector2
|
||||||
|
API["color3"] = color3
|
||||||
|
API["event"] = event
|
||||||
|
API["NULL"] = NULL
|
||||||
|
API["obj"] = obj
|
||||||
|
API["SOUND"] = self._handler
|
||||||
|
|
||||||
|
return API
|
||||||
|
|
||||||
|
def rungame(self):
|
||||||
|
# yields forever
|
||||||
|
print("preparing scripts")
|
||||||
|
for i in self._scripts:
|
||||||
|
self._threads.append(threading.Thread(target=lambda i: exec(i, self.APIGEN())))
|
||||||
|
print("starting scripts")
|
||||||
|
for i in self._threads:
|
||||||
|
i.start()
|
||||||
|
print("starting loop")
|
||||||
|
while True:
|
||||||
|
took = self.updallobjpositions()
|
||||||
|
self.render()
|
||||||
|
took = 0.1-took
|
||||||
|
if took > 0:
|
||||||
|
time.sleep(took)
|
||||||
|
|
||||||
if not "__CMD__" in globals():
|
if not "__CMD__" in globals():
|
||||||
"""from PIL import Image
|
from PIL import Image
|
||||||
from tkinter import filedialog
|
from tkinter import filedialog
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
canvas = tk.Canvas(root)
|
canvas = tk.Canvas(root)
|
||||||
|
@ -275,8 +310,8 @@ if not "__CMD__" in globals():
|
||||||
temp.render()
|
temp.render()
|
||||||
root.update()
|
root.update()
|
||||||
print()
|
print()
|
||||||
input("press enter to exit.")"""
|
input("press enter to exit.")
|
||||||
root = tk.Tk()
|
"""root = tk.Tk()
|
||||||
canvas = tk.Canvas(root)
|
canvas = tk.Canvas(root)
|
||||||
canvas.grid()
|
canvas.grid()
|
||||||
temp = game(canvas)
|
temp = game(canvas)
|
||||||
|
@ -311,5 +346,5 @@ if not "__CMD__" in globals():
|
||||||
tempobjlist.append(tempobj)
|
tempobjlist.append(tempobj)
|
||||||
temp.render()
|
temp.render()
|
||||||
root.update()
|
root.update()
|
||||||
input("press enter to exit.")
|
input("press enter to exit.")"""
|
||||||
|
|
||||||
|
|
22
keyboard.py
Normal file
22
keyboard.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import string
|
||||||
|
class keyboard:
|
||||||
|
def __init__(self, canvas):
|
||||||
|
tkeys = list(string.ascii_letters)
|
||||||
|
self._keys = {}
|
||||||
|
for i in tkeys:
|
||||||
|
self._keys[i] = False
|
||||||
|
canvas.bind("<KeyPress>", self.keypupd)
|
||||||
|
canvas.bind("<KeyRelease>", self.keydupd)
|
||||||
|
|
||||||
|
def keypupd(self, event):
|
||||||
|
event = event.char
|
||||||
|
if event in self._keys:
|
||||||
|
self._keys[event] = True
|
||||||
|
|
||||||
|
def keydupd(self, event):
|
||||||
|
event = event.char
|
||||||
|
if event in self._keys:
|
||||||
|
self._keys[event] = False
|
||||||
|
|
||||||
|
def getkeys(self):
|
||||||
|
return self._keys
|
Loading…
Reference in a new issue