added basic object system
This commit is contained in:
parent
40a2f32846
commit
077916ae87
104
HEMD.py
Normal file
104
HEMD.py
Normal file
|
@ -0,0 +1,104 @@
|
|||
import threading
|
||||
|
||||
class color3:
|
||||
def __init__(self, r=0, g=0, b=0):
|
||||
self.r = r
|
||||
self.g = g
|
||||
self.b = b
|
||||
|
||||
def _add(self,v):
|
||||
temp = color3(self.r+v.r, self.g+v.g, self.b+v.b)
|
||||
temp.r = temp.r%255
|
||||
temp.g = temp.g%255
|
||||
temp.b = temp.b%255
|
||||
return temp
|
||||
|
||||
def _sub(self,v):
|
||||
temp = color3(self.r-v.r, self.g-v.g, self.b-v.b)
|
||||
temp.r = temp.r%255
|
||||
temp.g = temp.g%255
|
||||
temp.b = temp.b%255
|
||||
return temp
|
||||
|
||||
def _mul(self,v):
|
||||
temp = color3(self.r*v.r, self.g*v.g, self.b*v.b)
|
||||
temp.r = temp.r%255
|
||||
temp.g = temp.g%255
|
||||
temp.b = temp.b%255
|
||||
return temp
|
||||
|
||||
def __add__(self, v):
|
||||
self._add(v)
|
||||
|
||||
def __sub__(self, v):
|
||||
self._sub(v)
|
||||
|
||||
def __mul__(self, v):
|
||||
self._mul(v)
|
||||
|
||||
def __iadd__(self, v):
|
||||
self._add(v)
|
||||
|
||||
def __isub__(self, v):
|
||||
self._sub(v)
|
||||
|
||||
def __imul__(self, v):
|
||||
self._mul(v)
|
||||
|
||||
class vector2:
|
||||
def __init__(self, x=0, y=0):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def __round__(self):
|
||||
return vector2(round(self.x), round(self.y))
|
||||
|
||||
def __add__(self, v):
|
||||
return vector2(self.x+v.x, self.y+v.y)
|
||||
|
||||
def __sub__(self, v):
|
||||
return vector2(self.x-v.x, self.y-v.y)
|
||||
|
||||
def __mul__(self, v):
|
||||
return vector2(self.x*v.x, self.y*v.y)
|
||||
|
||||
def __iadd__(self, v):
|
||||
return vector2(self.x+v.x, self.y+v.y)
|
||||
|
||||
def __isub__(self, v):
|
||||
return vector2(self.x-v.x, self.y-v.y)
|
||||
|
||||
def __imul__(self, v):
|
||||
return vector2(self.x*v.x, self.y*v.y)
|
||||
|
||||
class NULL:
|
||||
def __init__(self):
|
||||
return None
|
||||
|
||||
class enum:
|
||||
def __init__(self, sel):
|
||||
self._sel = dict(sel)
|
||||
for i in self._sel:
|
||||
setattr(self, i, self._sel[i])
|
||||
|
||||
def getposssel(self):
|
||||
return list(self._sel.keys())
|
||||
|
||||
class event:
|
||||
def __init__(self):
|
||||
self._attached = []
|
||||
|
||||
def execute(self):
|
||||
threads = []
|
||||
for i in self._attached:
|
||||
temp = threading.Thread(target=i)
|
||||
temp.start()
|
||||
threads.append(temp)
|
||||
return threads
|
||||
|
||||
def attach(self, target):
|
||||
self._attached.append(target)
|
||||
|
||||
class sprite:
|
||||
def __init__(self):
|
||||
pass
|
161
hashengine.py
161
hashengine.py
|
@ -1,5 +1,8 @@
|
|||
import mtTkinter as tk
|
||||
import threading
|
||||
from HEMD import color3, vector2, event, enum, NULL, sprite
|
||||
import random
|
||||
import string
|
||||
import math
|
||||
#import itertools
|
||||
#import multiprocessing
|
||||
|
||||
|
@ -7,101 +10,19 @@ import threading
|
|||
|
||||
__VERSION__ = "HE2.3-HASHENGINE-2.3"
|
||||
|
||||
class color3:
|
||||
def __init__(self, r=0, g=0, b=0):
|
||||
self.r = r
|
||||
self.g = g
|
||||
self.b = b
|
||||
|
||||
def _add(self,v):
|
||||
temp = color3(self.r+v.r, self.g+v.g, self.b+v.b)
|
||||
temp.r = temp.r%255
|
||||
temp.g = temp.g%255
|
||||
temp.b = temp.b%255
|
||||
return temp
|
||||
|
||||
def _sub(self,v):
|
||||
temp = color3(self.r-v.r, self.g-v.g, self.b-v.b)
|
||||
temp.r = temp.r%255
|
||||
temp.g = temp.g%255
|
||||
temp.b = temp.b%255
|
||||
return temp
|
||||
|
||||
def _mul(self,v):
|
||||
temp = color3(self.r*v.r, self.g*v.g, self.b*v.b)
|
||||
temp.r = temp.r%255
|
||||
temp.g = temp.g%255
|
||||
temp.b = temp.b%255
|
||||
return temp
|
||||
|
||||
def __add__(self, v):
|
||||
self._add(v)
|
||||
|
||||
def __sub__(self, v):
|
||||
self._sub(v)
|
||||
|
||||
def __mul__(self, v):
|
||||
self._mul(v)
|
||||
|
||||
def __iadd__(self, v):
|
||||
self._add(v)
|
||||
|
||||
def __isub__(self, v):
|
||||
self._sub(v)
|
||||
|
||||
def __imul__(self, v):
|
||||
self._mul(v)
|
||||
|
||||
class vector2:
|
||||
def __init__(self, x=0, y=0):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def __add__(self, v):
|
||||
return vector2(self.x+v.x, self.y+v.y)
|
||||
|
||||
def __sub__(self, v):
|
||||
return vector2(self.x-v.x, self.y-v.y)
|
||||
|
||||
def __mul__(self, v):
|
||||
return vector2(self.x*v.x, self.y*v.y)
|
||||
|
||||
def __iadd__(self, v):
|
||||
return vector2(self.x+v.x, self.y+v.y)
|
||||
|
||||
def __isub__(self, v):
|
||||
return vector2(self.x-v.x, self.y-v.y)
|
||||
|
||||
def __imul__(self, v):
|
||||
return vector2(self.x*v.x, self.y*v.y)
|
||||
|
||||
class NULL:
|
||||
class obj:
|
||||
def __init__(self):
|
||||
return None
|
||||
|
||||
class enum:
|
||||
def __init__(self, sel):
|
||||
self._sel = dict(sel)
|
||||
for i in self._sel:
|
||||
setattr(self, i, self._sel[i])
|
||||
|
||||
def getposssel(self):
|
||||
return list(self._sel.keys())
|
||||
|
||||
class event:
|
||||
def __init__(self):
|
||||
self._attached = []
|
||||
|
||||
def execute(self):
|
||||
threads = []
|
||||
for i in self._attached:
|
||||
temp = threading.Thread(target=i)
|
||||
temp.start()
|
||||
threads.append(temp)
|
||||
return threads
|
||||
|
||||
def attach(self, target):
|
||||
self._attached.append(target)
|
||||
self.position = vector2()
|
||||
self.collide = True
|
||||
self.anchored = True
|
||||
self.velocity = vector2()
|
||||
self.acceleration = vector2()
|
||||
self.sprite = sprite()
|
||||
self.id = NULL()
|
||||
self.color = color3()
|
||||
self.colliding = event()
|
||||
self.parent = NULL()
|
||||
self.children = []
|
||||
|
||||
class game:
|
||||
def __init__(self, canvas: tk.Canvas):
|
||||
|
@ -122,3 +43,53 @@ class game:
|
|||
temp.start()
|
||||
self._workers.append({"process": temp, ""})""" # scraped idea im keeping it in incase i ever decide to use it
|
||||
|
||||
def genid(self):
|
||||
out = ""
|
||||
for i in range(255):
|
||||
out = out + random.choice(list(string.ascii_letters))
|
||||
return out
|
||||
|
||||
def addtooap(self, target: obj):
|
||||
if target.position.__round__() in self._OAP:
|
||||
self._OAP[target.position.__round__()].append(target)
|
||||
else:
|
||||
self._OAP[target.position.__round__()] = [target]
|
||||
|
||||
def remfromoap(self, target: obj):
|
||||
self._OAP[target.position.__round__()].remove(target)
|
||||
if len(self._OAP[target.position.__round__()]) == 0:
|
||||
self._OAP.pop(target.position.__round__())
|
||||
|
||||
def getfromoap(self, target: vector2):
|
||||
if target.__round__() in self._OAP:
|
||||
return self._OAP[target.__round__()]
|
||||
else:
|
||||
return []
|
||||
|
||||
def addobj(self, target: obj, physics=True):
|
||||
temp = self.genid()
|
||||
if physics: self._objects[temp] = target
|
||||
self._visobjects[temp] = target
|
||||
self.addtooap(target)
|
||||
|
||||
def removeobj(self, target: obj):
|
||||
if target in self._visobjects: self._visobjects.pop(target)
|
||||
if target in self._objects: self._objects.pop(target)
|
||||
self.remfromoap(target)
|
||||
|
||||
def distance(self, pos1, pos2):
|
||||
return math.dist(((pos1.x, pos1.y), (pos2.x, pos2.y)))
|
||||
|
||||
def getcolliding(self, target):
|
||||
return self.getfromoap(target.position)
|
||||
|
||||
def calcphysobj(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
if not "__CMD__" in globals():
|
||||
root = tk.Tk()
|
||||
canvas = tk.Canvas(root)
|
||||
canvas.create_rectangle(50, 50, 53, 53, fill="#ff0000", width=0)
|
||||
canvas.grid()
|
||||
temp = game(canvas)
|
||||
root.mainloop()
|
||||
|
|
1
main.py
1
main.py
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
print("Hashengine General Purpose CMD.")
|
||||
print("init.")
|
||||
__CMD__ = True
|
||||
def loadfile(target):
|
||||
exec(open(target, 'r').read(), globals())
|
||||
|
||||
|
|
BIN
reference-pixel.PNG
Normal file
BIN
reference-pixel.PNG
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Loading…
Reference in a new issue