Dateien hochladen nach „“

master
Justus Jan Nico Wolff 2022-08-10 17:08:39 +02:00
parent b03bad0bb8
commit 8700e761d3
1 changed files with 34 additions and 15 deletions

49
main.py
View File

@ -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