From 457f0b9fa08fc46efb3739c548ad7a33ab48c1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Mon, 8 Apr 2024 19:55:18 +0500 Subject: [PATCH] Make speed changable via engine events. --- constants.py | 1 - defaultcontrols.py | 10 +++++----- main.py | 9 +++++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/constants.py b/constants.py index 7e03d7a..f5a8633 100644 --- a/constants.py +++ b/constants.py @@ -3,6 +3,5 @@ from cmath import exp I = complex(0,1) WHITE = (255,255,255) BLACK = (0,0,0) -OFFSET = 0.0078125 ROT = cNorm(exp(deg2rad(2)*I)) IROT = 1/ROT diff --git a/defaultcontrols.py b/defaultcontrols.py index 72f4153..e41cf61 100644 --- a/defaultcontrols.py +++ b/defaultcontrols.py @@ -1,6 +1,6 @@ import pygame from engineevents import EngineEvent -from constants import ROT, IROT, OFFSET, I +from constants import ROT, IROT, I from gyro import GyroVector, MobiusDist from levels import open_level, save_level, make_wall from alert import Alert @@ -69,11 +69,11 @@ def defaultcontrols(): 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",))) + aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__iadd__(GyroVector(args[1] * args[0].cRot*I, 1)), tsArguments=("gPlayer",'offset'))) if keys[pygame.K_e]: - aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__isub__(GyroVector(OFFSET * args[0].cRot*I, 1)), tsArguments=("gPlayer",))) + aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__isub__(GyroVector(args[1] * args[0].cRot*I, 1)), tsArguments=("gPlayer",'offset'))) if keys[pygame.K_w]: - aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__isub__(GyroVector(OFFSET * args[0].cRot , 1)), tsArguments=("gPlayer",))) + aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__isub__(GyroVector(args[1] * args[0].cRot , 1)), tsArguments=("gPlayer",'offset'))) if keys[pygame.K_s]: - aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__iadd__(GyroVector(OFFSET * args[0].cRot , 1)), tsArguments=("gPlayer",))) + aoEngineEvents.append(EngineEvent(None, lambda args: args[0].__iadd__(GyroVector(args[1] * args[0].cRot , 1)), tsArguments=("gPlayer",'offset'))) return aoEngineEvents diff --git a/main.py b/main.py index e1b2a3a..e1a8c22 100755 --- a/main.py +++ b/main.py @@ -9,7 +9,7 @@ import pygame import pygame.freetype from gyro import GyroVector, Poincare2Klein -from constants import I, WHITE, BLACK, IROT, ROT, OFFSET +from constants import I, WHITE, BLACK, IROT, ROT from draw import draw, DrawnSegment from alert import Alert from engineevents import EngineEvent, EngineEventProcessingError @@ -36,6 +36,7 @@ def nonzerocap(n): def mainLoop(): + offset = 0.0078125 sky = (127,127,255) ground = (102, 51, 0) bCap = True @@ -74,6 +75,7 @@ def mainLoop(): nonlocal sky nonlocal ground nonlocal iDistScale + nonlocal offset state = { 'bCap': bCap, 'bCont': bCont, @@ -88,7 +90,8 @@ def mainLoop(): 'level': level, 'sky': sky, 'ground': ground, - 'iDistScale': iDistScale + 'iDistScale': iDistScale, + 'offset': offset } for i in aoEngineEvents: if i.sVariableToModify == "bCap": @@ -113,6 +116,8 @@ def mainLoop(): level = i.fLambda(list(map(lambda oX: state[oX], i.tsArguments))) elif i.sVariableToModify == "iDistScale": iDistScale = i.fLambda(list(map(lambda oX: state[oX], i.tsArguments))) + elif i.sVariableToModify == "offset": + offset = i.fLambda(list(map(lambda oX: state[oX], i.tsArguments))) elif i.sVariableToModify is None: i.fLambda(list(map(lambda oX: state[oX], i.tsArguments))) else: