Make code worse.
This commit is contained in:
parent
f561ecc076
commit
d28d1d10ed
125
main.py
125
main.py
@ -32,6 +32,66 @@ def nonzerocap(n):
|
|||||||
if n <= 0: return 1
|
if n <= 0: return 1
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
class EngineEvent:
|
||||||
|
def __init__(self, sVariableToModify, fLambda, tsArguments=None):
|
||||||
|
self.sVariableToModify = sVariableToModify
|
||||||
|
self.fLambda = fLambda
|
||||||
|
if tsArguments is not None:
|
||||||
|
self.tsArguments = tsArguments
|
||||||
|
else:
|
||||||
|
self.tsArguments = (sVariableToModify,)
|
||||||
|
|
||||||
|
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_F3:
|
||||||
|
aoEngineEvents.append(EngineEvent("debugInfo", lambda args: not args[0]))
|
||||||
|
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") ))
|
||||||
|
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") ))
|
||||||
|
if event.key == pygame.K_F4:
|
||||||
|
aoEngineEvents.append(EngineEvent(None, lambda args: print(args[0].cPos), tsArguments=("gPlayer",)))
|
||||||
|
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]:
|
||||||
|
aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__iadd__(GyroVector(OFFSET * args[0].cRot*I, 1)), tsArguments=("gPlayer",)))
|
||||||
|
if keys[pygame.K_e]:
|
||||||
|
aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__isub__(GyroVector(OFFSET * args[0].cRot*I, 1)), tsArguments=("gPlayer",)))
|
||||||
|
if keys[pygame.K_w]:
|
||||||
|
aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__isub__(GyroVector(OFFSET * args[0].cRot , 1)), tsArguments=("gPlayer",)))
|
||||||
|
if keys[pygame.K_s]:
|
||||||
|
aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__iadd__(GyroVector(OFFSET * args[0].cRot , 1)), tsArguments=("gPlayer",)))
|
||||||
|
return aoEngineEvents
|
||||||
|
|
||||||
def mainLoop():
|
def mainLoop():
|
||||||
bCap = True
|
bCap = True
|
||||||
bCont = True
|
bCont = True
|
||||||
@ -42,6 +102,8 @@ def mainLoop():
|
|||||||
debugInfo = True
|
debugInfo = True
|
||||||
wall_buffer = []
|
wall_buffer = []
|
||||||
alerts = []
|
alerts = []
|
||||||
|
aoEngineEvents = []
|
||||||
|
fvControl_ao = defaultcontrols
|
||||||
|
|
||||||
def alert_append(alert, delay):
|
def alert_append(alert, delay):
|
||||||
if len(alerts) >= 1:
|
if len(alerts) >= 1:
|
||||||
@ -56,44 +118,31 @@ def mainLoop():
|
|||||||
level = open_level("maps/squareroom.json")
|
level = open_level("maps/squareroom.json")
|
||||||
|
|
||||||
while bCont:
|
while bCont:
|
||||||
for event in pygame.event.get():
|
aoEngineEvents = fvControl_ao()
|
||||||
if event.type == pygame.QUIT:
|
state = {
|
||||||
bCont = False
|
'bCap': bCap,
|
||||||
if event.type == pygame.KEYDOWN:
|
'bCont': bCont,
|
||||||
if event.key == pygame.K_r:
|
'gPlayer': gPlayer,
|
||||||
gPlayer.cRot *= -1
|
'display': display,
|
||||||
if event.key == pygame.K_F3:
|
'fontSize': fontSize,
|
||||||
debugInfo = not debugInfo
|
'debugInfo': debugInfo,
|
||||||
if event.key == pygame.K_F1:
|
'wall_buffer': wall_buffer,
|
||||||
bCap = not bCap
|
'alerts': alerts,
|
||||||
if event.key == pygame.K_F2:
|
'alert_append': alert_append,
|
||||||
if (len(wall_buffer) == 1):
|
'aoEngineEvents': aoEngineEvents,
|
||||||
wall_buffer.append(gPlayer.cPos)
|
'level': level
|
||||||
make_wall(wall_buffer, level)
|
}
|
||||||
wall_buffer.clear()
|
for i in aoEngineEvents:
|
||||||
else:
|
if i.sVariableToModify == "bCont":
|
||||||
wall_buffer.append(gPlayer.cPos)
|
bCont = i.fLambda(list(map(lambda oX: state[oX], i.tsArguments)))
|
||||||
if event.key == pygame.K_F5:
|
if i.sVariableToModify == "debugInfo":
|
||||||
filename = save_level(level)
|
debugInfo = i.fLambda(list(map(lambda oX: state[oX], i.tsArguments)))
|
||||||
alert = Alert(f"File saved as {filename}", display)
|
if i.sVariableToModify == "gPlayer":
|
||||||
|
gPlayer = i.fLambda(list(map(lambda oX: state[oX], i.tsArguments)))
|
||||||
alert_append(alert, 5)
|
if i.sVariableToModify == "bCap":
|
||||||
if event.key == pygame.K_F4:
|
bCap = i.fLambda(list(map(lambda oX: state[oX], i.tsArguments)))
|
||||||
print(gPlayer.cPos)
|
if i.sVariableToModify is None:
|
||||||
|
i.fLambda(list(map(lambda oX: state[oX], i.tsArguments)))
|
||||||
keys = pygame.key.get_pressed()
|
|
||||||
if keys[pygame.K_d]:
|
|
||||||
gPlayer.rotate(ROT)
|
|
||||||
if keys[pygame.K_a]:
|
|
||||||
gPlayer.rotate(IROT)
|
|
||||||
if keys[pygame.K_q]:
|
|
||||||
gPlayer += GyroVector(OFFSET * gPlayer.cRot*I, 1)
|
|
||||||
if keys[pygame.K_e]:
|
|
||||||
gPlayer -= GyroVector(OFFSET * gPlayer.cRot*I, 1)
|
|
||||||
if keys[pygame.K_w]:
|
|
||||||
gPlayer -= GyroVector(OFFSET * gPlayer.cRot, 1)
|
|
||||||
if keys[pygame.K_s]:
|
|
||||||
gPlayer += GyroVector(OFFSET * gPlayer.cRot, 1)
|
|
||||||
|
|
||||||
display.fill(WHITE)
|
display.fill(WHITE)
|
||||||
drawn = draw(level,gPlayer,pi/4,320)
|
drawn = draw(level,gPlayer,pi/4,320)
|
||||||
|
Loading…
Reference in New Issue
Block a user