2024-04-07 11:51:56 +00:00
|
|
|
import pygame
|
|
|
|
from engineevents import EngineEvent
|
2024-04-08 14:55:18 +00:00
|
|
|
from constants import ROT, IROT, I
|
2024-04-07 19:05:00 +00:00
|
|
|
from gyro import GyroVector, MobiusDist
|
2024-04-07 11:51:56 +00:00
|
|
|
from levels import open_level, save_level, make_wall
|
|
|
|
from alert import Alert
|
|
|
|
|
|
|
|
def defaultcontrols():
|
|
|
|
aoEngineEvents = list()
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
aoEngineEvents.append(EngineEvent("bCont", lambda _: False))
|
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
if event.key == pygame.K_r:
|
|
|
|
aoEngineEvents.append(EngineEvent(None, lambda args: args[0].rotate(-1), tsArguments=("gPlayer",)))
|
|
|
|
if event.key == pygame.K_F1:
|
|
|
|
aoEngineEvents.append(EngineEvent("bCap", lambda args: not args[0]))
|
|
|
|
if event.key == pygame.K_F2:
|
|
|
|
def fX(args):
|
|
|
|
#0: wall_buffer
|
|
|
|
#1: gPlayer
|
|
|
|
#2: level
|
|
|
|
if (len(args[0]) == 1):
|
|
|
|
args[0].append(args[1].cPos)
|
|
|
|
make_wall(args[0], args[2])
|
|
|
|
args[0].clear()
|
|
|
|
else:
|
|
|
|
args[0].append(args[1].cPos)
|
|
|
|
aoEngineEvents.append(EngineEvent(None, fX, tsArguments=("wall_buffer", "gPlayer", "level") ))
|
2024-04-07 19:05:00 +00:00
|
|
|
if event.key == pygame.K_F3:
|
|
|
|
aoEngineEvents.append(EngineEvent("debugInfo", lambda args: not args[0]))
|
|
|
|
if event.key == pygame.K_F4:
|
|
|
|
aoEngineEvents.append(EngineEvent(None, lambda args: print(args[0].cPos), tsArguments=("gPlayer",)))
|
2024-04-07 11:51:56 +00:00
|
|
|
if event.key == pygame.K_F5:
|
|
|
|
#0: level
|
|
|
|
#1: alert_append
|
|
|
|
#2: display
|
|
|
|
def fX(args):
|
|
|
|
filename = save_level(args[0])
|
|
|
|
alert = Alert(f"File saved as {filename}", args[2])
|
|
|
|
|
|
|
|
args[1](alert, 5)
|
|
|
|
aoEngineEvents.append(EngineEvent(None, fX, tsArguments=("level", "alert_append", "display") ))
|
2024-04-07 19:05:00 +00:00
|
|
|
if event.key == pygame.K_F6:
|
|
|
|
def fX(aArgs):
|
|
|
|
aLevel = aArgs[0]
|
|
|
|
gPlayer = aArgs[1]
|
|
|
|
fMin = 2
|
|
|
|
cMin = gPlayer.cPos
|
|
|
|
for i in aLevel:
|
|
|
|
fD = MobiusDist(gPlayer.cPos, i.pointA)
|
|
|
|
if fD < fMin:
|
|
|
|
fMin = fD
|
|
|
|
cMin = i.pointA
|
|
|
|
fD = MobiusDist(gPlayer.cPos, i.pointB)
|
|
|
|
if fD < fMin:
|
|
|
|
fMin = fD
|
|
|
|
cMin = i.pointB
|
|
|
|
return GyroVector(cMin,gPlayer.cRot)
|
|
|
|
aoEngineEvents.append(EngineEvent('gPlayer', fX, tsArguments=('level','gPlayer')))
|
2024-04-07 19:10:08 +00:00
|
|
|
if event.key == pygame.K_F7:
|
|
|
|
aoEngineEvents.append(EngineEvent('gPlayer', lambda tgPlayer: GyroVector(0, tgPlayer[0].cRot)))
|
|
|
|
if event.key == pygame.K_F8:
|
|
|
|
aoEngineEvents.append(EngineEvent('gPlayer', lambda tgPlayer: GyroVector(tgPlayer[0].cPos, 1)))
|
2024-04-07 19:05:00 +00:00
|
|
|
|
2024-04-07 11:51:56 +00:00
|
|
|
keys = pygame.key.get_pressed()
|
|
|
|
if keys[pygame.K_d]:
|
|
|
|
aoEngineEvents.append(EngineEvent(None, lambda args: args[0].rotate( ROT), tsArguments=("gPlayer",)))
|
|
|
|
if keys[pygame.K_a]:
|
|
|
|
aoEngineEvents.append(EngineEvent(None, lambda args: args[0].rotate(IROT), tsArguments=("gPlayer",)))
|
|
|
|
if keys[pygame.K_q]:
|
2024-04-08 14:55:18 +00:00
|
|
|
aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__iadd__(GyroVector(args[1] * args[0].cRot*I, 1)), tsArguments=("gPlayer",'offset')))
|
2024-04-07 11:51:56 +00:00
|
|
|
if keys[pygame.K_e]:
|
2024-04-08 14:55:18 +00:00
|
|
|
aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__isub__(GyroVector(args[1] * args[0].cRot*I, 1)), tsArguments=("gPlayer",'offset')))
|
2024-04-07 11:51:56 +00:00
|
|
|
if keys[pygame.K_w]:
|
2024-04-08 14:55:18 +00:00
|
|
|
aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__isub__(GyroVector(args[1] * args[0].cRot , 1)), tsArguments=("gPlayer",'offset')))
|
2024-04-07 11:51:56 +00:00
|
|
|
if keys[pygame.K_s]:
|
2024-04-08 14:55:18 +00:00
|
|
|
aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__iadd__(GyroVector(args[1] * args[0].cRot , 1)), tsArguments=("gPlayer",'offset')))
|
2024-04-07 11:51:56 +00:00
|
|
|
return aoEngineEvents
|