From e5f0b134290a62f29876efd9e5024e4429b86ed0 Mon Sep 17 00:00:00 2001 From: Jamal Millner II Date: Thu, 19 Dec 2024 08:14:07 -0500 Subject: [PATCH] origin stuff I was late committing --- PlayerScript.gd | 186 +++++++++++++++++++++++++++++++++++++++--------- main.tscn | 1 + 2 files changed, 154 insertions(+), 33 deletions(-) diff --git a/PlayerScript.gd b/PlayerScript.gd index 52c7704..f36d040 100644 --- a/PlayerScript.gd +++ b/PlayerScript.gd @@ -86,15 +86,16 @@ var Keys = [] var RouteCounter = 0 var SendToRobo = [] var RetraveledArray = [] - +var Ori = 0 +var amnt = 0 func _input(event): #if Current_Position != TargetCord: if event.is_action_pressed("ui_left"): - goLeft() + LeftTurn() Been_There() AutoBacktrack = false elif event.is_action_pressed("ui_right"): - goRight() + RightTurn() Been_There() AutoBacktrack = false elif event.is_action_pressed("ui_up"): @@ -106,7 +107,14 @@ func _input(event): Been_There() AutoBacktrack = false elif event.is_action_pressed("ui_accept"): - AutoSolve() + #AutoSolve() + $Sprite2D.rotation_degrees += 180 + $Backv.rotation_degrees += 180 + $Forwardv.rotation_degrees += 180 + $Leftv.rotation_degrees += 180 + $Rightv.rotation_degrees += 180 + Ori += 180 + elif event.is_action_pressed("ui_text_backspace"): print(SendToRobo) print(Current_Position) @@ -115,8 +123,8 @@ func _input(event): CommonsSort(arr1) func _process(delta): - FoundGoal() - AllObjectsFound() + #FoundGoal() + #AllObjectsFound() CallableRaycastData() Mark(Prev_dir) WhatMove() @@ -134,7 +142,10 @@ func _process(delta): IntersectionDumping() CordsDumping() FinishCircling() - + #Orienting() + #print(Current_Position) + #print(Ordered_Commands_Backward) + #print(Individual_Steps) func FoundGoal(): if TargetCord.find(Cords[-1]) != -1 and TargetsArray.find(Cords[-1]) == -1: Goal = true @@ -410,8 +421,13 @@ func BackTracking(): print("The distance from the last intersection is : ", Distance_From_Intersection) print("To get to the last intersection follow these steps : ", TrackBack) if Detail_Dict.Type == "Dead End" and Current_Position != [0,0]: + print("Moving") + FullReverseTurn() + print("Done reverse") + GoBack(TrackBack) GoBack(TrackBack) print(TrackBack) + print("Done") func Circling(): if Been_There_Array.size() > 3: @@ -664,7 +680,15 @@ func MoveAfterIntersection(): else: Invert = false - if Invert == true: + if Invert == true:#print(Direction.find(Dir)) +# if Ori == 0 or Ori == 180: +# print("YYYYYYY") +# if Ori == 0: +# print("Same/Normal Orientation") +# print(Dir) +# if Ori == 180: +# print("Flipped") +# print(Direction[Direction.find(Dir)]) #print(Prev_dir_Opp) IntOptions[-1].erase(Prev_dir_Opp) #print(IntOptions) @@ -717,7 +741,7 @@ func IntersectionWaysAvailable(): func Been_There(): if Been_There_Overide == false: - if Cords.find(Current_Position) == -1: + if Cords.find(Current_Position) == -1 or Prev_dir == "R" or Prev_dir == "L": Cords.push_back(Current_Position) Cords_Copy = Cords.duplicate(true) Cords = Cords_Copy @@ -869,12 +893,14 @@ func goDown(): dir = Vector2.DOWN FullCount += 1 if not D.is_colliding(): - self.global_position.y += 24 - Current_Position[1] -=1 - Prev_dir = "D" - Prev_dir_Opp = "U" + #self.global_position.y += 24 + #Current_Position[1] -=1 + Prev_dir = "F" + Prev_dir_Opp = "F" move += Move_Strength Been_There_Overide = false + #Ori = 0 + Orienting("D") else: Been_There_Overide = true move += Move_Strength @@ -884,12 +910,14 @@ func goUp(): var U = $Backv dir = Vector2.UP if not U.is_colliding(): - self.global_position.y -= 24 - Current_Position[1] +=1 - Prev_dir = "U" - Prev_dir_Opp = "D" + #self.global_position.y -= 24 + #Current_Position[1] +=1 + Prev_dir = "F" + Prev_dir_Opp = "F" move += Move_Strength Been_There_Overide = false + #Ori = 180 + Orienting("U") else: Been_There_Overide = true move += Move_Strength @@ -897,44 +925,124 @@ func goUp(): #BeenTheirFromPrevCord() FullCount += 1 -func goRight(): +func RightTurn(): var R = $Rightv dir = Vector2.RIGHT if not R.is_colliding(): - self.global_position.x += 24.4 - Current_Position[0] +=1 + #self.global_position.x += 24.4 + #Current_Position[0] +=1 + $Sprite2D.rotation_degrees -= 90 + $Backv.rotation_degrees -= 90 + $Forwardv.rotation_degrees -= 90 + $Leftv.rotation_degrees -= 90 + $Rightv.rotation_degrees -=90 Prev_dir = "R" Prev_dir_Opp = "L" move += Move_Strength Been_There_Overide = false + Ori -= 90 + print(Ori) + Orienting("R") else: Been_There_Overide = true move += Move_Strength print("There is something to your right") FullCount += 1 -func goLeft(): +func LeftTurn(): var L = $Leftv dir = Vector2.LEFT if not L.is_colliding(): - self.global_position.x -= 24.4 - Current_Position[0] -=1 + #self.global_position.x -= 24.4 + #Current_Position[0] -=1 + $Sprite2D.rotation_degrees += 90 + $Backv.rotation_degrees += 90 + $Forwardv.rotation_degrees += 90 + $Leftv.rotation_degrees += 90 + $Rightv.rotation_degrees +=90 Prev_dir = "L" Prev_dir_Opp = "R" move += Move_Strength Been_There_Overide = false + Ori += 90 + Orienting("L") + else: Been_There_Overide = true move += Move_Strength print("There is something to your left") FullCount += 1 + +func Orienting(Dir): + var Base = [0,90,180,270] + var Way = "" + var Default = ["U","D","L","R"] + var LOrientation = ["R","L","D","U"] + var ROrientation = ["L","R", "U","D"] + var BOrientation = ["D","U","R","L"] + if Ori < 0: + Ori = 360 + Ori + if Ori >= 360: + Ori = Ori - 360 + + #print(Dir) + #print(Ori) + if Ori == 270: + if Dir == "U": + self.global_position.x -= 24.4 + Current_Position[0] -=1 + if Dir == "D": + self.global_position.x += 24.4 + Current_Position[0] +=1 + if Dir == "F": + self.global_position.x += 24.4 + Current_Position[0] +=1 + + if Ori == 180: + if Dir == "U": + self.global_position.y += 24 + Current_Position[1] -=1 + if Dir == "D": + self.global_position.y -= 24 + Current_Position[1] +=1 + if Dir == "F": + self.global_position.y -= 24 + Current_Position[1] +=1 + + if Ori == 90: + if Dir == "U": + self.global_position.x += 24.4 + Current_Position[0] +=1 + if Dir == "D": + self.global_position.x -= 24.4 + Current_Position[0] -=1 + if Dir == "F": + self.global_position.x -= 24.4 + Current_Position[0] -=1 + + if Ori == 0: + if Dir == "U": + self.global_position.y -= 24 + Current_Position[1] +=1 + if Dir == "D": + self.global_position.y += 24 + Current_Position[1] -=1 + if Dir == "F": + self.global_position.y += 24 + Current_Position[1] -=1 + + #***** Auto Movement ***** func Move(SetDirection): if SetDirection == "R": - self.global_position.x += 24.4 - Current_Position[0] +=1 + $Sprite2D.rotation_degrees -= 90 + $Backv.rotation_degrees -= 90 + $Forwardv.rotation_degrees -= 90 + $Leftv.rotation_degrees -= 90 + $Rightv.rotation_degrees -=90 + Ori -= 90 Prev_dir = "R" Prev_dir_Opp = "L" move += Move_Strength @@ -942,28 +1050,32 @@ func Move(SetDirection): FullCount += 1 if SetDirection == "L": - self.global_position.x -= 24.4 - Current_Position[0] -=1 + $Sprite2D.rotation_degrees += 90 + $Backv.rotation_degrees += 90 + $Forwardv.rotation_degrees += 90 + $Leftv.rotation_degrees += 90 + $Rightv.rotation_degrees +=90 + Ori += 90 Prev_dir = "L" Prev_dir_Opp = "R" move += Move_Strength Been_There() FullCount += 1 - if SetDirection == "D": + if SetDirection == "F": self.global_position.y += 24 Current_Position[1] -=1 - Prev_dir = "D" - Prev_dir_Opp = "U" + Prev_dir = "F" + Prev_dir_Opp = "F" move += Move_Strength Been_There() FullCount += 1 - if SetDirection == "U": + if SetDirection == "F": self.global_position.y -= 24 Current_Position[1] +=1 - Prev_dir = "U" - Prev_dir_Opp = "D" + Prev_dir = "F" + Prev_dir_Opp = "F" move += Move_Strength Been_There() FullCount += 1 @@ -1006,6 +1118,14 @@ func RMove(SetDirection): Been_There() FullCount += 1 +func FullReverseTurn(): + $Sprite2D.rotation_degrees += 180 + $Backv.rotation_degrees += 180 + $Forwardv.rotation_degrees += 180 + $Leftv.rotation_degrees += 180 + $Rightv.rotation_degrees += 180 + Ori += 180 + func AutoSolve(): var DirectionStrengths = [6,6,5,6] var Colliders = RaycastHelper() diff --git a/main.tscn b/main.tscn index a581ab2..29c17b7 100644 --- a/main.tscn +++ b/main.tscn @@ -209,6 +209,7 @@ position = Vector2(26.6667, 26.6667) scale = Vector2(0.9, 0.9) [node name="Rightv" type="RayCast2D" parent="TextureRect/Player"] +visible = false scale = Vector2(1, 0.950617) exclude_parent = false target_position = Vector2(32.8, 0)