Merge pull request 'feat(walls): player can create walls by pressing F3' (#3) from n3tael/p3he:main into main

Reviewed-on: #3
This commit is contained in:
bʰedoh₂ swé 2024-04-04 17:06:21 +00:00
commit 69e8ee5569

20
main.py
View File

@ -2,7 +2,7 @@
try: try:
from numpy import complex256 from numpy import complex256
except ImportError: except ImportError:
from numpy import complex128 as complex256 from numpy import complex128 as complex256
print("Warning! Cannot use full precision!") print("Warning! Cannot use full precision!")
from time import time_ns, sleep from time import time_ns, sleep
@ -87,12 +87,22 @@ def renderDebugInfo(gPlayer, clock, fontSize = 18):
return fps_surf, cPos_surf, cRot_surf return fps_surf, cPos_surf, cRot_surf
def make_wall(wall_buffer):
if (len(wall_buffer) != 2):
print('Warning: wall buffer not contains 2 points.')
return
level.append(
Segment(True, wall_buffer[0], wall_buffer[1], (23,74,183))
)
def mainLoop(): def mainLoop():
gPlayer = GyroVector(0,1) gPlayer = GyroVector(0,1)
display = pygame.display.set_mode((1280,720)) display = pygame.display.set_mode((1280,720))
clock = pygame.time.Clock() clock = pygame.time.Clock()
fontSize = 18 fontSize = 18
debugInfo = True debugInfo = True
wall_buffer = []
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
@ -103,6 +113,14 @@ def mainLoop():
gPlayer.cRot *= -1 gPlayer.cRot *= -1
if event.key == pygame.K_F3: if event.key == pygame.K_F3:
debugInfo = not debugInfo debugInfo = not debugInfo
if event.key == pygame.K_F2:
if (len(wall_buffer) == 1):
wall_buffer.append(gPlayer.cPos)
make_wall(wall_buffer)
wall_buffer.clear()
else:
wall_buffer.append(gPlayer.cPos)
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
if keys[pygame.K_d]: if keys[pygame.K_d]:
gPlayer.rotate(ROT) gPlayer.rotate(ROT)