From 8700e761d3324700ae3bb6e3031985612bc1379a Mon Sep 17 00:00:00 2001 From: Justus Jan Nico Wolff Date: Wed, 10 Aug 2022 17:08:39 +0200 Subject: [PATCH] =?UTF-8?q?Dateien=20hochladen=20nach=20=E2=80=9E=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index cda2f69..2f368b2 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ + class game(): def __init__(self): import sys @@ -43,6 +44,12 @@ class game(): self.objects = [] + def round2(self, target): + from decimal import localcontext, Decimal, ROUND_HALF_UP + with localcontext() as ctx: + ctx.rounding = ROUND_HALF_UP + return Decimal(target).to_integral_value() + def update(self): for i in self.pressedkeys: if self.keyboard.is_pressed(i): @@ -52,46 +59,54 @@ class game(): self.futuremap = self.map.copy() for i in self.objects: - self.futuremap["{}:{}".format(round(i.y), round(i.x))] = " " + self.futuremap["{}:{}".format(self.round2(i.y), self.round2(i.x))] = " " for i in self.objects: - if "{}:{}".format(round(i.y), round(i.x-i.xvelocity)) in self.map: - if self.map["{}:{}".format(round(i.y), round(i.x-i.xvelocity))] == " ": + if i.targetx == None: + if "{}:{}".format(self.round2(i.y), self.round2(i.x-i.xvelocity)) in self.map: + if self.map["{}:{}".format(self.round2(i.y), self.round2(i.x-i.xvelocity))] == " ": + i.x -= i.xvelocity + else: i.x -= i.xvelocity else: - i.x -= i.xvelocity + i.x = i.targetx + i.targetx = None - if "{}:{}".format(round(i.y-i.yvelocity), round(i.x)) in self.map: - if self.map["{}:{}".format(round(i.y-i.yvelocity), round(i.x))] == " ": + if i.targety == None: + 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 + else: i.y -= i.yvelocity else: - i.y -= i.yvelocity + i.y = i.targety + i.targety = None self.map = self.futuremap.copy() for i in self.objects: - if round(i.y) == self.size.lines or i.y > self.size.lines: + if self.round2(i.y) == self.size.lines or i.y > self.size.lines: i.y += i.yvelocity i.yvelocity = 0 - elif round(i.y) <= 0: + elif self.round2(i.y) <= 0: i.y += i.yvelocity i.yvelocity = 0 else: - if "{}:{}".format(round(i.y+1), round(i.x)) in self.map: - if self.map["{}:{}".format(round(i.y+1), round(i.x))] != " ": + if "{}:{}".format(self.round2(i.y+1), self.round2(i.x)) in self.map: + if self.map["{}:{}".format(self.round2(i.y+1), self.round2(i.x))] != " ": i.y += i.yvelocity i.yvelocity = 0 else: i.yvelocity -= i.gravity - if round(i.x) == self.size.columns or i.x > self.size.columns: + if self.round2(i.x) == self.size.columns or i.x > self.size.columns: i.x += i.xvelocity i.xvelocity = 0 - elif round(i.x) <= 0: + elif self.round2(i.x) <= 0: i.x += i.xvelocity i.xvelocity = 0 - if i.xvelocity != 0: + if i.xvelocity != 0 and i.antixforce != 0: if i.xvelocity >= i.antixforce: if i.xvelocity > 0: i.xvelocity -= i.antixforce @@ -100,8 +115,10 @@ class game(): else: i.xvelocity = 0 + for i in self.objects: - self.map["{}:{}".format(round(i.y), round(i.x))] = i.character + self.map["{}:{}".format(self.round2(i.y), self.round2(i.x))] = i.character + self.osmodule.system('cls' if self.osmodule.name == 'nt' else 'clear') for i in range(self.size.lines): self.temp = "" @@ -134,6 +151,8 @@ class object(): self.gravity = gravity self.x = x self.y = y + self.targetx = None + self.targety = None self.antixforce = antixforce self.xvelocity = 0 self.yvelocity = 0