Compare commits
No commits in common. "2c799fc205bec2785e746b6680c1066532810a32" and "69213f5d8b4f66aa72763383bc4ca21292bb2a35" have entirely different histories.
2c799fc205
...
69213f5d8b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -28,7 +28,7 @@ class vector2:
|
|||
self.y = y
|
||||
|
||||
def __add__(self, v):
|
||||
#if not type(v) != vector2: raise ValueError(f"Must be vector2! got {type(v)}")
|
||||
if not type(v) != vector2: raise ValueError("Must be vector2!")
|
||||
return vector2(self.x+v.x, self.y+v.y)
|
||||
|
||||
def __sub__(self, v):
|
||||
|
@ -100,24 +100,12 @@ class camera(obj):
|
|||
if self.mode == cammode.follow and self.subject:
|
||||
self.position = self.subject.position
|
||||
|
||||
class event:
|
||||
def __init__(self):
|
||||
self._receivers = []
|
||||
|
||||
def connect(self, code):
|
||||
self._receivers.append(code)
|
||||
|
||||
def fire(self):
|
||||
for i in self._receivers:
|
||||
exec(i, globals())
|
||||
|
||||
class game:
|
||||
def __init__(self, size=[20, 20], renderer=stdrend):
|
||||
if renderer == None: raise TypeError("Renderer class needed!")
|
||||
self._size = size
|
||||
self._renderer = renderer(size)
|
||||
self._objects = {}
|
||||
self.camera = camera()
|
||||
|
||||
def addobj(self, obj):
|
||||
id = ""
|
||||
|
@ -126,9 +114,6 @@ class game:
|
|||
obj.ID = id
|
||||
self._objects[id] = obj
|
||||
|
||||
def getobjbyid(self, id):
|
||||
return self._objects[id]
|
||||
|
||||
def removeobj(self, obj):
|
||||
self._objects.pop(obj.ID)
|
||||
obj.ID = NULL()
|
||||
|
@ -136,35 +121,14 @@ class game:
|
|||
def removeobjbyid(self, id):
|
||||
self._objects.pop(id).ID = NULL()
|
||||
|
||||
def between(self, target, minb, maxb):
|
||||
if minb < target < maxb:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def colliding(self, obj):
|
||||
# return list of colliding objects
|
||||
pass
|
||||
|
||||
def render(self):
|
||||
self.camera.update()
|
||||
for i in self._objects.values():
|
||||
pos = i.position + self.camera.position
|
||||
char = i.char
|
||||
bc = i.bcolor
|
||||
fc = i.fcolor
|
||||
if self.between(pos.y, -1, self._size[1]) and self.between(pos.x, -1, self._size[0]):
|
||||
self._renderer.pix(pos.x, pos.y, bc+fc+char+Style.RESET_ALL)
|
||||
|
||||
for i in self._objects:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
testgame = game()
|
||||
object = obj()
|
||||
testgame.addobj(object)
|
||||
object.char = "#"
|
||||
object.fc = forecolors.black
|
||||
testgame.render()
|
||||
print(object.ID)
|
||||
input()
|
||||
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue