From ac9509acac81cd5a2d689c68364ddc20e5391cf7 Mon Sep 17 00:00:00 2001 From: n3tael Date: Wed, 3 Apr 2024 16:06:58 +0300 Subject: [PATCH] feat(ui): cPos, cRot with normal sizes, position, background --- main.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 9207d8d..a5ebb5c 100755 --- a/main.py +++ b/main.py @@ -2,25 +2,24 @@ from time import time_ns, sleep from cmath import exp +import math import pygame import pygame.freetype from gyro import * from lines import * - def deg2rad(rA): return rA/180*PI I = complex(0,1) WHITE = (255,255,255) BLACK = (0,0,0) OFFSET = 0.015625 -PI = 3.14159265358979323846264338327 +PI = math.pi ROT = cNorm(exp(deg2rad(2)*I)) IROT = 1/ROT F = 5 * 10**7 F_ = 10**9 - class Segment: def __init__(self,bA,cA,cB,trColor): self.isFinite = bA @@ -54,14 +53,14 @@ def draw(level,gPlayer,fov,res): cInt = cLineIntersection(tA,tB,complex(0),rot) except ZeroDivisionError: continue - rDist = cDist(0,cInt) + rDist = cDist(0,cInt) if cDot(cInt,rot) > 0: continue if (1 - m.height) > rDist: m = DrawnSegment(1-rDist,j.color) drawn.append(m) return drawn - + def cap(rN): if rN < 0: return 0 @@ -70,7 +69,7 @@ def cap(rN): def mainLoop(): gPlayer = GyroVector(0,1) display = pygame.display.set_mode((1280,720)) - font = pygame.freetype.Font(None,24) + font = pygame.freetype.Font(None,18) while True: framestart = time_ns() @@ -79,7 +78,7 @@ def mainLoop(): return True if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: - gPlayer.cRot *= -1 + gPlayer.cRot *= -1 keys = pygame.key.get_pressed() if keys[pygame.K_d]: gPlayer.rotate(ROT) @@ -96,17 +95,19 @@ def mainLoop(): for i in drawn: pygame.draw.rect(display,i.color, (n,360 - (cap(i.height) * 500),10,cap(i.height) * 1000)) n += 2 - font.render_to(display, (20, 150), str(gPlayer.cPos), (0, 0, 0)) - font.render_to(display, (20, 250), str(gPlayer.cRot), (0, 0, 0)) + + font.render_to(display, (8, 8), "cPos: " + str(gPlayer.cPos), (255, 255, 255), (0, 0, 0)) + font.render_to(display, (8, 26), "cRot: " + str(gPlayer.cRot), (255, 255, 255), (0, 0, 0)) + pygame.display.update() - + frameend = time_ns() sleep((frameend-framestart) / F_) - return True + return True def main(): pygame.init() - pygame.display.set_caption('P3HE') + pygame.display.set_caption('P3HE') if not pygame.get_init(): return False retstatus = mainLoop()