From d25afadd0d6cd37e1243471481c583594885e878 Mon Sep 17 00:00:00 2001 From: jonathanm-12 Date: Tue, 2 May 2023 15:11:10 -0400 Subject: [PATCH 1/5] store input into an array --- Virtual Environment/main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Virtual Environment/main.py b/Virtual Environment/main.py index feac424..d7e5afc 100644 --- a/Virtual Environment/main.py +++ b/Virtual Environment/main.py @@ -29,6 +29,8 @@ class MyApp(ShowBase): star_angle = 0 last_message_time = 0 + direction_array = [] + camera_pos = 0 dir_list = ['left', 'right', 'backward', 'forward'] prev_sec = 0 @@ -131,6 +133,7 @@ def cameraSet(self, sph_heading): def ChangeSpherePositionBackwardStart(self): self.isMovingBackward = True + self.direction_array.append('backward') def ChangeSpherePositionBackwardEnd(self): self.isMovingBackward = False @@ -155,6 +158,7 @@ def MoveBackward(self, task): def ChangeSpherePositionForwardStart(self): self.isMovingForward = True + self.direction_array.append('forward') def ChangeSpherePositionForwardEnd(self): @@ -184,6 +188,7 @@ def MoveFoward(self, task): def ChangeSpherePositionRightStart(self): self.isMovingRight = True + self.direction_array.append('right') def ChangeSpherePositionRightEnd(self): self.isMovingRight = False @@ -212,7 +217,8 @@ def MoveRight(self, task): def ChangeSpherePositionLeftStart(self): self.isMovingLeft = True - + self.direction_array.append('left') + def ChangeSpherePositionLeftEnd(self): self.isMovingLeft = False @@ -318,6 +324,8 @@ def ChooseDirection(self, task): break self.index = self.index +1 + + print(self.direction_array) return task.cont @@ -326,3 +334,4 @@ def ChooseDirection(self, task): game.run() + From eae109244738f40a622f0f831bb68f0598f05faa Mon Sep 17 00:00:00 2001 From: jonathanm-12 Date: Tue, 2 May 2023 15:26:28 -0400 Subject: [PATCH 2/5] on close, export --- Virtual Environment/main.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Virtual Environment/main.py b/Virtual Environment/main.py index d7e5afc..6553485 100644 --- a/Virtual Environment/main.py +++ b/Virtual Environment/main.py @@ -6,7 +6,7 @@ import math import generate import simplepbr - +import csv load_prc_file('myConfig.prc') @@ -42,7 +42,6 @@ def __init__(self): simplepbr.init() - self.accept('d', self.ChangeSpherePositionRightStart) self.accept('d-up', self.ChangeSpherePositionRightEnd) self.accept('a', self.ChangeSpherePositionLeftStart) @@ -51,6 +50,7 @@ def __init__(self): self.accept('s-up', self.ChangeSpherePositionBackwardEnd) self.accept('w', self.ChangeSpherePositionForwardStart) self.accept('w-up', self.ChangeSpherePositionForwardEnd) + self.accept('escape', self.onExit) self.taskMgr.add(self.ChooseDirection) self.taskMgr.add(self.MoveFoward) self.taskMgr.add(self.MoveBackward) @@ -325,13 +325,21 @@ def ChooseDirection(self, task): self.index = self.index +1 - print(self.direction_array) return task.cont + + def onExit(self): + with open('dirs.csv', 'w', newline='') as f: + writer = csv.writer(f) + writer.writerow(self.direction_array) + exit(0) game = MyApp() + + game.run() + From e44f46105a3928779e7919713abbb62e6e99fd85 Mon Sep 17 00:00:00 2001 From: jonathanm-12 <81660305+jonathanm-12@users.noreply.github.com> Date: Wed, 3 May 2023 19:58:05 -0400 Subject: [PATCH 3/5] Update main.py --- Virtual Environment/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Virtual Environment/main.py b/Virtual Environment/main.py index 6553485..700c131 100644 --- a/Virtual Environment/main.py +++ b/Virtual Environment/main.py @@ -329,7 +329,7 @@ def ChooseDirection(self, task): return task.cont def onExit(self): - with open('dirs.csv', 'w', newline='') as f: + with open('dirs.csv', 'a', newline='') as f: writer = csv.writer(f) writer.writerow(self.direction_array) exit(0) From 57a8647ac967c2034ff39505a5ff18f43d4c3da4 Mon Sep 17 00:00:00 2001 From: jonathanm-12 <81660305+jonathanm-12@users.noreply.github.com> Date: Thu, 4 May 2023 18:05:24 -0400 Subject: [PATCH 4/5] accept ints as input --- Virtual Environment/main.py | 67 ++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/Virtual Environment/main.py b/Virtual Environment/main.py index 700c131..82235c1 100644 --- a/Virtual Environment/main.py +++ b/Virtual Environment/main.py @@ -7,6 +7,7 @@ import generate import simplepbr import csv +import random load_prc_file('myConfig.prc') @@ -57,6 +58,7 @@ def __init__(self): self.taskMgr.add(self.MoveLeft) self.taskMgr.add(self.MoveRight) self.taskMgr.add(self.rotateStar) + self.taskMgr.add(self.recvInput) blank_node = PandaNode("my_blank_node") self.nodepath1 = NodePath(blank_node) @@ -140,7 +142,13 @@ def ChangeSpherePositionBackwardEnd(self): def MoveBackward(self, task): if self.isMovingBackward == True: - self.sphObject.setPos(self.sphObject.getPos() + Vec3(math.sin(math.radians(self.angle)), math.cos(math.radians(self.angle)), 0) * 0.5 ) + + getNewPos = self.sphObject.getPos() + Vec3(math.sin(math.radians(self.angle)), math.cos(math.radians(self.angle)), 0) * 0.1 + + if getNewPos[0] >= 200 or getNewPos[0] <= -200 or getNewPos[1] >= 200 or getNewPos[1] <= -200: + return Task.cont + + self.sphObject.setPos(self.sphObject.getPos() + Vec3(math.sin(math.radians(self.angle)), math.cos(math.radians(self.angle)), 0) * 0.1 ) self.cameraSet(self.fakeHeading) @@ -168,8 +176,15 @@ def ChangeSpherePositionForwardEnd(self): def MoveFoward(self, task): + if self.isMovingForward == True: - self.sphObject.setPos(self.sphObject.getPos() + Vec3(math.sin(math.radians(self.angle+180)), math.cos(math.radians(self.angle+180)), 0) * 0.5 ) + + getNewPos = self.sphObject.getPos() + Vec3(math.sin(math.radians(self.angle+180)), math.cos(math.radians(self.angle+180)), 0) * 0.1 + + if getNewPos[0] >= 200 or getNewPos[0] <= -200 or getNewPos[1] >= 200 or getNewPos[1] <= -200: + return Task.cont + + self.sphObject.setPos(self.sphObject.getPos() + Vec3(math.sin(math.radians(self.angle+180)), math.cos(math.radians(self.angle+180)), 0) * 0.1 ) self.cameraSet(self.fakeHeading) @@ -195,9 +210,9 @@ def ChangeSpherePositionRightEnd(self): def MoveRight(self, task): if self.isMovingRight == True: - self.angle += 2.5 + self.angle += 0.3 - self.fakeHeading += 2.5 + self.fakeHeading += 0.3 self.cameraSet(self.fakeHeading) @@ -224,10 +239,10 @@ def ChangeSpherePositionLeftEnd(self): def MoveLeft(self, task): if self.isMovingLeft == True: - self.angle -= 2.5 + self.angle -= 0.3 - self.fakeHeading -= 2.5 + self.fakeHeading -= 0.3 self.cameraSet(self.fakeHeading) @@ -254,6 +269,44 @@ def rotateStar(self, task): else: return Task.done + def recvInput(self, task): + + current_sec = int(task.time) + if current_sec != self.prev_sec: + self.prev_sec = current_sec + + direction_index = random.randint(0, 3) + print(direction_index) + + # ['left', 'right', 'backward', 'forward'] + # 0 1 2 3 + + if direction_index == 0: + self.ChangeSpherePositionLeftStart() + self.ChangeSpherePositionRightEnd() + self.ChangeSpherePositionForwardEnd() + self.ChangeSpherePositionBackwardEnd() + + elif direction_index == 1: + self.ChangeSpherePositionLeftEnd() + self.ChangeSpherePositionRightStart() + self.ChangeSpherePositionForwardEnd() + self.ChangeSpherePositionBackwardEnd() + + elif direction_index == 2: + self.ChangeSpherePositionLeftEnd() + self.ChangeSpherePositionRightEnd() + self.ChangeSpherePositionForwardEnd() + self.ChangeSpherePositionBackwardStart() + + elif direction_index == 3: + self.ChangeSpherePositionLeftEnd() + self.ChangeSpherePositionRightEnd() + self.ChangeSpherePositionForwardStart() + self.ChangeSpherePositionBackwardEnd() + + + return Task.cont def ChooseDirection(self, task): @@ -337,8 +390,6 @@ def onExit(self): game = MyApp() - - game.run() From 42e4524d5205628518cb6ed42e2aee34da5431f9 Mon Sep 17 00:00:00 2001 From: jonathanm-12 <81660305+jonathanm-12@users.noreply.github.com> Date: Sun, 7 May 2023 21:32:17 -0400 Subject: [PATCH 5/5] comment out --- Virtual Environment/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Virtual Environment/main.py b/Virtual Environment/main.py index 82235c1..ddea2e1 100644 --- a/Virtual Environment/main.py +++ b/Virtual Environment/main.py @@ -58,7 +58,10 @@ def __init__(self): self.taskMgr.add(self.MoveLeft) self.taskMgr.add(self.MoveRight) self.taskMgr.add(self.rotateStar) - self.taskMgr.add(self.recvInput) + + #Generates random direction once every second, uncomment to enable + + #self.taskMgr.add(self.recvInput) blank_node = PandaNode("my_blank_node") self.nodepath1 = NodePath(blank_node)