From 1a37b2bee00db9490dca21da79b6679575ba62d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=83zvan=20C=2E=20R=C4=83dulescu?= Date: Thu, 16 Jan 2020 10:44:44 +0200 Subject: [PATCH] Update project to follow GDScript guidelines closer Used `var variable := 0.0` as discussed in the Godot issue, instead of `var variable: = 0.0`. Mostly these are minor/cosmetic changes, but I've also reorganized the folder structure (naming of folders) to reflect our guidelines, plus made some minor changes to the demo codes. Still work in progress. --- project/assets/theme/button/disabled.stylebox | Bin 416 -> 421 bytes project/assets/theme/button/focused.stylebox | Bin 426 -> 429 bytes project/assets/theme/button/hover.stylebox | Bin 410 -> 415 bytes project/assets/theme/button/normal.stylebox | Bin 397 -> 401 bytes project/assets/theme/button/pressed.stylebox | Bin 402 -> 411 bytes project/assets/theme/fonts/default_font.tres | 3 - .../assets/theme/fonts/default_font_bold.tres | 3 - .../assets/theme/fonts/default_font_code.tres | 3 - project/assets/theme/panel/panel.stylebox | Bin 403 -> 415 bytes project/assets/theme/separator/line.tres | 2 - .../assets/theme/slider/grabber_area.stylebox | Bin 404 -> 407 bytes project/assets/theme/slider/slider.stylebox | Bin 452 -> 459 bytes project/demos/Arrive/ArriveDemo.gd | 71 ++++++++++++++++++ project/demos/Arrive/ArriveDemo.tscn | 49 ++++++++++++ project/demos/Arrive/Arriver.gd | 37 +++++++++ project/demos/Face/FaceDemo.gd | 63 ++++++++++++++++ project/demos/{face => Face}/FaceDemo.tscn | 31 ++++++-- project/demos/Face/Player.gd | 22 ++++++ project/demos/Face/Turret.gd | 46 ++++++++++++ .../FollowPathDemo.tscn | 0 .../GroupBehaviors/GroupBehaviorsDemo.gd | 68 +++++++++++++++++ .../GroupBehaviors/GroupBehaviorsDemo.tscn | 13 ++++ .../Member.gd | 14 ++-- .../Member.tscn | 3 +- .../Spawner.gd | 6 +- .../BoundaryManager.gd | 10 +-- .../{pursue_vs_seek => PursueSeek}/Player.gd | 28 +++---- project/demos/PursueSeek/PursueVSSeekDemo.gd | 35 +++++++++ .../PursueVSSeekDemo.tscn | 8 +- .../{pursue_vs_seek => PursueSeek}/Pursuer.gd | 14 ++-- .../{pursue_vs_seek => PursueSeek}/Ship.gd | 0 .../{seek_and_flee => SeekFlee}/Boundary.gd | 2 +- .../{seek_and_flee => SeekFlee}/Player.gd | 6 +- .../SeekFleeDemo.gd | 57 +++++++------- .../SeekFleeDemo.tscn | 10 +-- .../{seek_and_flee => SeekFlee}/Seeker.gd | 12 +-- .../{seek_and_flee => SeekFlee}/Seeker.tscn | 3 +- .../{seek_and_flee => SeekFlee}/Spawner.gd | 4 +- project/demos/arrive/ArriveDemo.gd | 39 ---------- project/demos/arrive/ArriveDemo.tscn | 35 --------- project/demos/arrive/Arriver.gd | 40 ---------- project/demos/face/FaceDemo.gd | 44 ----------- project/demos/face/Player.gd | 21 ------ project/demos/face/Turret.gd | 59 --------------- .../group_behaviors/GroupBehaviorsDemo.gd | 58 -------------- .../group_behaviors/GroupBehaviorsDemo.tscn | 13 ---- .../demos/pursue_vs_seek/PursueVSSeekDemo.gd | 31 -------- project/project.godot | 34 ++++----- .../src/{behaviors => Behaviors}/GSTArrive.gd | 10 +-- .../GSTAvoidCollisions.gd | 8 +- .../src/{behaviors => Behaviors}/GSTBlend.gd | 4 +- .../{behaviors => Behaviors}/GSTCohesion.gd | 0 .../src/{behaviors => Behaviors}/GSTEvade.gd | 2 +- .../src/{behaviors => Behaviors}/GSTFace.gd | 4 +- .../src/{behaviors => Behaviors}/GSTFlee.gd | 0 .../{behaviors => Behaviors}/GSTFollowPath.gd | 20 ++--- .../GSTLookWhereYouGo.gd | 2 +- .../GSTMatchOrientation.gd | 8 +- .../{behaviors => Behaviors}/GSTPriority.gd | 8 +- .../src/{behaviors => Behaviors}/GSTPursue.gd | 12 +-- .../src/{behaviors => Behaviors}/GSTSeek.gd | 0 .../{behaviors => Behaviors}/GSTSeparation.gd | 10 +-- project/src/GSTAgentLocation.gd | 4 +- project/src/GSTGroupBehavior.gd | 2 +- project/src/GSTPath.gd | 14 ++-- project/src/GSTSteeringAgent.gd | 18 ++--- project/src/GSTSteeringBehavior.gd | 2 +- project/src/GSTTargetAcceleration.gd | 4 +- project/src/GSTUtils.gd | 4 +- .../GSTInfiniteProximity.gd | 6 +- .../GSTProximity.gd | 2 +- .../GSTRadiusProximity.gd | 18 ++--- 72 files changed, 618 insertions(+), 541 deletions(-) create mode 100644 project/demos/Arrive/ArriveDemo.gd create mode 100644 project/demos/Arrive/ArriveDemo.tscn create mode 100644 project/demos/Arrive/Arriver.gd create mode 100644 project/demos/Face/FaceDemo.gd rename project/demos/{face => Face}/FaceDemo.tscn (56%) create mode 100644 project/demos/Face/Player.gd create mode 100644 project/demos/Face/Turret.gd rename project/demos/{follow_path => FollowPath}/FollowPathDemo.tscn (100%) create mode 100644 project/demos/GroupBehaviors/GroupBehaviorsDemo.gd create mode 100644 project/demos/GroupBehaviors/GroupBehaviorsDemo.tscn rename project/demos/{group_behaviors => GroupBehaviors}/Member.gd (85%) rename project/demos/{group_behaviors => GroupBehaviors}/Member.tscn (83%) rename project/demos/{group_behaviors => GroupBehaviors}/Spawner.gd (95%) rename project/demos/{pursue_vs_seek => PursueSeek}/BoundaryManager.gd (89%) rename project/demos/{pursue_vs_seek => PursueSeek}/Player.gd (78%) create mode 100644 project/demos/PursueSeek/PursueVSSeekDemo.gd rename project/demos/{pursue_vs_seek => PursueSeek}/PursueVSSeekDemo.tscn (84%) rename project/demos/{pursue_vs_seek => PursueSeek}/Pursuer.gd (86%) rename project/demos/{pursue_vs_seek => PursueSeek}/Ship.gd (100%) rename project/demos/{seek_and_flee => SeekFlee}/Boundary.gd (77%) rename project/demos/{seek_and_flee => SeekFlee}/Player.gd (83%) rename project/demos/{seek_and_flee => SeekFlee}/SeekFleeDemo.gd (61%) rename project/demos/{seek_and_flee => SeekFlee}/SeekFleeDemo.tscn (83%) rename project/demos/{seek_and_flee => SeekFlee}/Seeker.gd (77%) rename project/demos/{seek_and_flee => SeekFlee}/Seeker.tscn (86%) rename project/demos/{seek_and_flee => SeekFlee}/Spawner.gd (65%) delete mode 100644 project/demos/arrive/ArriveDemo.gd delete mode 100644 project/demos/arrive/ArriveDemo.tscn delete mode 100644 project/demos/arrive/Arriver.gd delete mode 100644 project/demos/face/FaceDemo.gd delete mode 100644 project/demos/face/Player.gd delete mode 100644 project/demos/face/Turret.gd delete mode 100644 project/demos/group_behaviors/GroupBehaviorsDemo.gd delete mode 100644 project/demos/group_behaviors/GroupBehaviorsDemo.tscn delete mode 100644 project/demos/pursue_vs_seek/PursueVSSeekDemo.gd rename project/src/{behaviors => Behaviors}/GSTArrive.gd (82%) rename project/src/{behaviors => Behaviors}/GSTAvoidCollisions.gd (88%) rename project/src/{behaviors => Behaviors}/GSTBlend.gd (95%) rename project/src/{behaviors => Behaviors}/GSTCohesion.gd (100%) rename project/src/{behaviors => Behaviors}/GSTEvade.gd (85%) rename project/src/{behaviors => Behaviors}/GSTFace.gd (88%) rename project/src/{behaviors => Behaviors}/GSTFlee.gd (100%) rename project/src/{behaviors => Behaviors}/GSTFollowPath.gd (72%) rename project/src/{behaviors => Behaviors}/GSTLookWhereYouGo.gd (88%) rename project/src/{behaviors => Behaviors}/GSTMatchOrientation.gd (85%) rename project/src/{behaviors => Behaviors}/GSTPriority.gd (84%) rename project/src/{behaviors => Behaviors}/GSTPursue.gd (75%) rename project/src/{behaviors => Behaviors}/GSTSeek.gd (100%) rename project/src/{behaviors => Behaviors}/GSTSeparation.gd (80%) rename project/src/{proximities => Proximities}/GSTInfiniteProximity.gd (79%) rename project/src/{proximities => Proximities}/GSTProximity.gd (95%) rename project/src/{proximities => Proximities}/GSTRadiusProximity.gd (73%) diff --git a/project/assets/theme/button/disabled.stylebox b/project/assets/theme/button/disabled.stylebox index 5838b762d953b292bfe91ed1081fee1895223499..252f92461445115f1f5d9f5695587c5dea139a9d 100644 GIT binary patch literal 421 zcmV;W0b2f2Q$s@n000005C8yj0{{Sx0RR9fwJ-f(asnL;0EUu0E>KaF0Pw&0Ux;d- zYq7k|cR+m7fFz~#De>2`WClRYK%MB{#>fD-uS`HyW9$Jd04)G90IQ)kT=qY5tr9w} zP+45t>m}Q_lyPRG^8d+y$~&LLW+C)(`trXa@SpJq2UItwS*(rsan^>)mL|FVH#qNG zwx;NR!K>}w2;rD*$eWrROWu;c1>MA11%Cj>F(a6ui|Jl2*Dy6o(oVRj*_Kq4JQ_^Q zMxV>p=1^Fe#EfgnixqOh8`KvyB9IZ5i>1!)p-CX51;~|<0r|NPV?%0QU@SBOV8LLoXmP7O&TSkx zp^G{Up7Ut1@c$!Vg8J~buTcj44(K>gINdC?=q3(RH0H)GBE>KaF0Pw&0Ux;d- zYq7k|_dxoj0ZAnBDe>2`WClRYK%M=UFc8?K3nfTJQS1RM04@MA0Mu%z4VV3gT&aZ4 z6)KBsd%a})mNLFzHm~A=5hy&7K zRvCRRTbrY>AgQ)jyttOUSRp68L48pp5tIsLvVki8UtqHNApk#QL2>9Jz{5YlaGu#n zpQd9&(-&oQ?Sb2Ui5{hN>PJ~x-17uEAV2~DijF-0(vblo(wJSw=K_1hcLM8I1_Koj znt`IooUw$EYR54HR3AXW{S_WVlR!udoGU>C@^c@uvCk93LTA2%yfW2W-{aPX!3nyk zWAL3vkA>%7gqUjME@i^UfNleZ)5}5!-Gm`9ypkYN=mK#(0y%PN{jJ zxTu?J;nQ9>Szy3S>p7K7Zj=glabYB}R00$kO$N&Np$m=<$UduRy#!uNFxB|u3^_?9Dt_GV=P$4 zfVg%RN&@kRGDgPRl}QBl3|7AY_nR0x&Y^;1=o1LBfO92eK6IQ=X%=q3z-;*|!GMHlen3l5&@ XY0filp34XBEmN*3>j7W^Qd2`iw2Q=+ literal 426 zcmV;b0agA|Q$s@n000005C8yr0{{S$0RR9fwJ-f(dICiZ0ESXNGH}630M7#eYF<@U zRnF{5C0*6-)A{$)*#upSk-P62h UTs@Z$+*`g}W7fmP0#Z{$LspZ#H~;_u diff --git a/project/assets/theme/button/hover.stylebox b/project/assets/theme/button/hover.stylebox index fb464a1a3e3d0d2f746393552a071227236c591e..08fb085da37b7cfff0d15316e0302fd9c700e5cd 100644 GIT binary patch literal 415 zcmV;Q0bu@8Q$s@n000005C8yU0{{Sr0RR9fwJ-f(V*>3909KMbFknFh0RO|{Is807 zkGV<-k~}lQyN-4Dg!hiCQ#=VdWLVWh@^*}f85w$3fM<~10V@D405Slpp*CFhKXR=S zI<8PzT-)m<+qaZ)W~1`|$$y4-K8ejj=;O5Ie?#Cu;|~W^H>X*wjrVcZhRT*Ex&1dd z?_0Je>3_ki?OqAtm~F_LnjA~s7kvx5iL(lS0LC#Rn4pX4UM|-#HC`@T;i6_+Qc?0~ zFfki_E?b*}vM`Am*OC`29f7JOQ06%0gap-~r`~wWiH!JDm zbaY^)Sn7e>osk}`l6~@jJIo( z7uXxDdcp5EHFTasg~t#j5YhtVO2~lJ+=sCtH7^hgt-!HhkXN+3g+1eE{L~v(TWM90H417DNtRK#VUCJk8ULXIwm&pWIu%TyxgL J#R5`OLqkSPx)uNc literal 410 zcmV;L0cHMDQ$s@n000005C8yF0{{Sm0RR9fwJ-f(R072d0EQAhFkn#w0RO|{S@X~Q z(@ZgwDDj+m-gT_Im%Mjeonog-5^V}>@3Vv;N{`B@p^R+X0V@D405AZnp*CFh|G82L zA6KX>uI=@b?OVz?vr+l~X*wjTds(hRT*Ex&1#l z?_0K{=zqbf?cONi)pq1PNsc9NjJ^e(#7PB?S^Q5RK^N1#T&`hWxTx8dQ0G0z<+^;!8aS} z<8*{zwb%)Q+ntFZrF3dYSz;UnMLbjiHXuL(0BWpyzqBxbCR=!IO;Cx(T7zJs_jg=|4#_hR0=ic(=nrA%#EK*ZL ELl+^u*8l(j diff --git a/project/assets/theme/button/normal.stylebox b/project/assets/theme/button/normal.stylebox index 4f8c7da913c0d4a5b6b7228ce8d6b4e29a6242fa..999edcf519aa73039a676a4cc10ced32177ee8cd 100644 GIT binary patch literal 401 zcmV;C0dD?MQ$s@n000005C8y70{{Sd0RR9fwJ-f(Oagri00z=JEl^Pe0Pw&0&)}=)b|I z?OrJ1nQh2hiW*Dam~={8#5k!At02<$usKw%74u;*ThZQT8A?y`V2T+|x`v(1u|SzT zO=HN4Q(56m(?N|01VL&R6PAkw!s4$8_$vS|UI{QD;wNBG&RHm3r=NqviB})pZVmM0 zlu|#h^F4f?hlc+GnZ^M(AYcLjMb-@n$T%8+LP?MG_ vuK^tg2&b2Y9^IrNPfNA@EZK1UO|tfry`A!MJ9hbenz-4kcc7bh|N+ zlTt?QsWugjTUlPzW9&`gm**RkgA=Qp!2B1JZLJu(8b(!$LpbL0p-_t?zMcnbSGNi+hwKr3A1DZs7B_A3A_05Jfop*CFh-?>r=9apF< zuI=@b?OV$DvQhcJ{rnYsrfhGQu0w7d0G65tIsLvVj2nlg$q~KeQM)#NYrwfnwpAjr3_cIy8+@ zxq9GsU!q4To%)HbG3N6;G(0*WPyzr&RXo46FrcWm64*mhR#=z>;u*@AjJIo(7uXxD zdcp5EHFTasg~t#j5YhtVO2~lJ+=sCtH7^hgt-!HhkXN+3g+1eE{L~v(TWM90H417DNtRK#VUCJk8ULXIwm&pWIu%TyxgL#R5`O FLqq00yA}Wd literal 402 zcmV;D0d4+LQ$s@n000005C8yH0{{Se0RR9fwJ-f(Rsw|!0HzWgF(uwedR6+ECfTB)9*I^S)(E zivBB3ZTCh7ueKlWNpcK%Tl6jHB+d(x$}x-o2_)!Zx|ho}%m)`S+j5E!htptI8GSBW zTLU2>Qf;qzaV>eVLOytd`XWXRlnQ0Cfgt|L=7*dgQV1McaKu0GKOn()W+Q!?j*_M^ zDpwEO?o0G2rBgr3(&C;cHXuL(0BWpyzqByGCR=)KjbA3{Up#08in4RY5<;pS#~7e~ z0EPEgcnmFpuogU5LI$MgK44>;Cx(T7zJs_jg=|4#_hR0=ic(=nrA%#EK*ZLLw^ys9smFU diff --git a/project/assets/theme/fonts/default_font.tres b/project/assets/theme/fonts/default_font.tres index 9f845d7..d0e94aa 100644 --- a/project/assets/theme/fonts/default_font.tres +++ b/project/assets/theme/fonts/default_font.tres @@ -2,10 +2,7 @@ [ext_resource path="res://assets/theme/fonts/montserrat/Montserrat-Medium.ttf" type="DynamicFontData" id=1] - [resource] - size = 20 use_filter = true font_data = ExtResource( 1 ) - diff --git a/project/assets/theme/fonts/default_font_bold.tres b/project/assets/theme/fonts/default_font_bold.tres index 238d067..0ab7209 100644 --- a/project/assets/theme/fonts/default_font_bold.tres +++ b/project/assets/theme/fonts/default_font_bold.tres @@ -2,10 +2,7 @@ [ext_resource path="res://assets/theme/fonts/montserrat/Montserrat-Bold.ttf" type="DynamicFontData" id=1] - [resource] - size = 20 use_filter = true font_data = ExtResource( 1 ) - diff --git a/project/assets/theme/fonts/default_font_code.tres b/project/assets/theme/fonts/default_font_code.tres index 4f13506..ea05d17 100644 --- a/project/assets/theme/fonts/default_font_code.tres +++ b/project/assets/theme/fonts/default_font_code.tres @@ -2,10 +2,7 @@ [ext_resource path="res://assets/theme/fonts/source_code_pro/SourceCodePro-Medium.otf" type="DynamicFontData" id=1] - [resource] - size = 20 use_filter = true font_data = ExtResource( 1 ) - diff --git a/project/assets/theme/panel/panel.stylebox b/project/assets/theme/panel/panel.stylebox index 1c623a7bedd81d02d197af0687720376ed3668fd..0c557d022e12b7669a1981e2fcd3c53da6e10a42 100644 GIT binary patch literal 415 zcmV;Q0bu@8Q$s@n000005C8yT0{{Sr0RR9fwJ-f(Vgl_80M=1FFF;`w0QEnZI0dxo zO{*-9bRDMd3(zO+?$Zu-@zVnX8B|^3U27CWEaBG1&9aRLDgY}0F#u2-?)2YswGvLQ zP^ZYY*~@7k(}_D9mH%V@JG}E{eD*>gs5k#50{%5_ma7Wsgc834HrGzvWgcH)vs)X-TD6&^#AKu8OaDM;1v zqrt-UkAMj(!`rwUFi=rM04wG5WBfm` z4FJi6SN0wFo_rwL+n$nsm{L;(6f+R@+zd2IpmjPB1FJ%j2Ppt5051UAaM^$8N+pb3 zp|ZHP*GslMo}w&fHl5~#tfI{I9;wg^K*rP^L` z<681!g}m?v^+gb9k}!31oEI5QX5#bNfG8dS1i(}fD1djffON0heqL?F@}(e#xVm_ zA3)jt6&OQFAcO_am5>4XxsTXb%@fB$Gv7g6nd+_YanJ^U6S}Cw;5m;53;(|eI@R_r x)r8*x9SjgoFAF7flS5$f%7Vy27ck=s1W)rc;~5vvC|h{;-mtZwyPj|jj=gYtsf?1FpAN5qYNdcMA*X&Ctbr%25E4p zu%PICn2qS}NY-00b4&GC~{ zO8syrGd|CR#D9Q1AYcNSG*&wpIdhkB(+yTMGkY-a$sS_TK3FJYWV~IOguwp6$_seE z>7mm(RA>xs0wES~u7nK8pZg#-Qp77rBjB46bMB!z&+N%&k$bh7+nnu~s4k`dE05AaUwB4%zlB<;NadoO5 zZevTe4OKB_pYngoe~5Rs3(Zz&+qC7sBj7*d54~6hSr;$ltnE}`CVBl=IB#2p(DT1> zX}kAf__Q5)M-b!5`=SjUgE%D&@4o@$*h|(DS-S+lUS?NDZvv4lmy<>t%hvU9c%V$% z_%LiGBdgy!@5{| zj!GJ}qbe`VaV8`t#ws`xjg3HQgUsw9sm|nQ$s@yoxSw{ diff --git a/project/assets/theme/slider/slider.stylebox b/project/assets/theme/slider/slider.stylebox index 6fbfe55919efe9c8c652b836acf1a38e393cc024..f89f29b68031a03a4142afc95285636e82f1948f 100644 GIT binary patch delta 450 zcmV;z0X_c21Iq&;Qd2`i0ssI201yBG!~*~TvjG4AD77#BV8jAV4FE=yLXjaAf4+ZG zdJ;)~lG3tYLyyG@sA0SCHU_w5Y}Fuv2ofP5E&wqAH30N!uIKjT>p$kJy;=Fry{hAO z@?9+5UNppY>3_}thWC>cBbHc6YR`X4z<2f8rIO0Bk8Q?&y`sDVi!D4IARf2{}xZ~_=a zMII6$qj1s)3^&RM&fUUl{ojBDNtvU>hj-=s+brRjV0`#_E%0!AQjQb`z|Qxicg&LS z%HH|CI<<>UpgC7zoK(Vc+$Ml>{$WJ<1?nrdyaqd=6=-2@kg3ROFJGh&cMBl|wP@M^ sdi0r&V(X5pW>Q7i(qRe&7>LY*qx3}hI$aW-@48xEIV<<~4^mS@L*sAGaR2}S delta 443 zcmV;s0Yv`G1H=O%Qd2`i0ssI201yBGwF3YEtN{Q3D77#BV6_4j4FIMSLy;jBf4WRb z=}9E{DM`zI4LuespeCfKlvHrb*p^WS7Aa(XF90$CHURRnFLO<~X@&nW=j_qSnKHbt zwwn*u=@{Biy=?z${x`heqzF|Bo}%vjrvUt){tAzjr$xbB5U`FC%c=jL$mD)CLor4rjCdRjIU5kw_ZVXp~_fi4<%O zE-b`EU{mEd<^c5rD7wGG#*h;TVF7X_ zU_fH-!)$Ex#9*PG?;x&B^%i?v+Hi0}7j-ar=h4Q({VxKi+H{vR;d?;Wfx_v|LXB?1 l5LmpjL1fSc@c06Qr+b>~5gAv{ void: + target.position = arriver.global_position + arriver.setup( + max_linear_speed, + max_linear_acceleration, + arrival_tolerance, + deceleration_radius + ) + + +func _unhandled_input(event: InputEvent) -> void: + if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.is_pressed(): + arriver.target.position = Vector3(event.position.x, event.position.y, 0) + target.position = event.position + update() + + +func _draw(): + draw_circle(target.position, deceleration_radius, COLORS.deceleration_radius) + draw_circle(target.position, arrival_tolerance, COLORS.arrival_tolerance) + + +func set_arrival_tolerance(value: float) -> void: + if not is_inside_tree(): + return + + arrival_tolerance = value + arriver.arrive.arrival_tolerance = value + update() + + +func set_deceleration_radius(value: float) -> void: + if not is_inside_tree(): + return + + deceleration_radius = value + arriver.arrive.deceleration_radius = value + update() + + +func set_max_linear_speed(value: float) -> void: + if not is_inside_tree(): + return + + max_linear_speed = value + arriver.agent.max_linear_speed = value + + +func set_max_linear_acceleration(value: float) -> void: + if not is_inside_tree(): + return + + max_linear_acceleration = value + arriver.agent.max_linear_acceleration = value diff --git a/project/demos/Arrive/ArriveDemo.tscn b/project/demos/Arrive/ArriveDemo.tscn new file mode 100644 index 0000000..059dd8e --- /dev/null +++ b/project/demos/Arrive/ArriveDemo.tscn @@ -0,0 +1,49 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://demos/Arrive/Arriver.gd" type="Script" id=1] +[ext_resource path="res://assets/theme/gdquest.theme" type="Theme" id=2] +[ext_resource path="res://demos/Arrive/ArriveDemo.gd" type="Script" id=3] +[ext_resource path="res://assets/sprites/small_circle.png" type="Texture" id=4] + +[sub_resource type="CircleShape2D" id=1] +radius = 16.0 + +[node name="ArriveDemo" type="Node2D"] +script = ExtResource( 3 ) + +[node name="Arriver" type="KinematicBody2D" parent="."] +show_behind_parent = true +position = Vector2( 512, 300 ) +script = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Arriver"] +shape = SubResource( 1 ) + +[node name="Sprite" type="Sprite" parent="Arriver"] +modulate = Color( 0.952941, 0.172549, 0.0431373, 1 ) +texture = ExtResource( 4 ) + +[node name="Target" type="Node2D" parent="."] +position = Vector2( 0, 1 ) + +[node name="GUI" type="PanelContainer" parent="."] +anchor_right = 1.0 +margin_right = 1024.0 +margin_bottom = 87.0 +rect_min_size = Vector2( 1024, 0 ) +theme = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MarginContainer" type="MarginContainer" parent="GUI"] +margin_right = 1024.0 +margin_bottom = 87.0 + +[node name="Label" type="Label" parent="GUI/MarginContainer"] +margin_left = 16.0 +margin_top = 16.0 +margin_right = 1008.0 +margin_bottom = 71.0 +text = "Arrive Demo +Mouse click to make the red \"Player\" move to the yellow target" diff --git a/project/demos/Arrive/Arriver.gd b/project/demos/Arrive/Arriver.gd new file mode 100644 index 0000000..83c522c --- /dev/null +++ b/project/demos/Arrive/Arriver.gd @@ -0,0 +1,37 @@ +extends KinematicBody2D + + +var agent := GSTSteeringAgent.new() +var target := GSTAgentLocation.new() +var arrive := GSTArrive.new(agent, target) +var _accel := GSTTargetAcceleration.new() + +var _velocity := Vector2() +var _drag := 0.1 + + +func _physics_process(delta: float) -> void: + _update_agent() + _accel = arrive.calculate_steering(_accel) + _velocity += Vector2(_accel.linear.x, _accel.linear.y) + _velocity = _velocity.linear_interpolate(Vector2.ZERO, _drag).clamped(agent.max_linear_speed) + _velocity = move_and_slide(_velocity) + + +func setup( + max_linear_speed: float, + max_linear_acceleration: float, + arrival_tolerance: float, + deceleration_radius: float +) -> void: + agent.max_linear_speed = max_linear_speed + agent.max_linear_acceleration = max_linear_acceleration + agent.position = Vector3(global_position.x, global_position.y, 0) + arrive.deceleration_radius = deceleration_radius + arrive.arrival_tolerance = arrival_tolerance + target.position = agent.position + + +func _update_agent() -> void: + agent.position = Vector3(global_position.x, global_position.y, 0) + agent.linear_velocity = Vector3(_velocity.x, _velocity.y, 0) diff --git a/project/demos/Face/FaceDemo.gd b/project/demos/Face/FaceDemo.gd new file mode 100644 index 0000000..28028b0 --- /dev/null +++ b/project/demos/Face/FaceDemo.gd @@ -0,0 +1,63 @@ +extends Node2D + + +onready var player := $Player +onready var gui := $GUI +onready var turret := $Turret + +export(int, 0, 359) var max_angular_speed := 90 setget set_max_angular_speed +export(int, 0, 359) var max_angular_accel := 5 setget set_max_angular_accel +export(int, 0, 180) var align_tolerance := 5 setget set_align_tolerance +export(int, 0, 359) var deceleration_radius := 45 setget set_deceleration_radius +export(float, 0, 1000) var player_speed := 600.0 setget set_player_speed + + +func _ready() -> void: + player.speed = player_speed + turret.setup( + player.agent, + deg2rad(align_tolerance), + deg2rad(deceleration_radius), + deg2rad(max_angular_accel), + deg2rad(max_angular_speed) + ) + + +func set_align_tolerance(value: int) -> void: + if not is_inside_tree(): + return + + align_tolerance = value + turret.face.alignment_tolerance = deg2rad(value) + + +func set_deceleration_radius(value: int) -> void: + if not is_inside_tree(): + return + + deceleration_radius = value + turret.face.deceleration_radius = deg2rad(value) + + +func set_max_angular_accel(value: int) -> void: + if not is_inside_tree(): + return + + max_angular_accel = value + turret.agent.max_angular_acceleration = deg2rad(value) + + +func set_max_angular_speed(value: int) -> void: + if not is_inside_tree(): + return + + max_angular_speed = value + turret.agent.max_angular_speed = deg2rad(value) + + +func set_player_speed(value: float) -> void: + if not is_inside_tree(): + return + + player_speed = value + player.speed = player_speed diff --git a/project/demos/face/FaceDemo.tscn b/project/demos/Face/FaceDemo.tscn similarity index 56% rename from project/demos/face/FaceDemo.tscn rename to project/demos/Face/FaceDemo.tscn index 207981a..5108dd5 100644 --- a/project/demos/face/FaceDemo.tscn +++ b/project/demos/Face/FaceDemo.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] -[ext_resource path="res://demos/face/Turret.gd" type="Script" id=1] -[ext_resource path="res://demos/face/FaceDemo.gd" type="Script" id=2] -[ext_resource path="res://demos/face/Player.gd" type="Script" id=3] +[ext_resource path="res://demos/Face/Turret.gd" type="Script" id=1] +[ext_resource path="res://demos/Face/FaceDemo.gd" type="Script" id=2] +[ext_resource path="res://demos/Face/Player.gd" type="Script" id=3] [ext_resource path="res://assets/sprites/large_circle.png" type="Texture" id=4] [ext_resource path="res://assets/sprites/small_circle.png" type="Texture" id=5] +[ext_resource path="res://assets/theme/gdquest.theme" type="Theme" id=6] [sub_resource type="CircleShape2D" id=1] radius = 16.0 @@ -30,7 +31,7 @@ modulate = Color( 0.945098, 0.215686, 0.0705882, 1 ) texture = ExtResource( 5 ) [node name="Turret" type="KinematicBody2D" parent="."] -position = Vector2( 512, 150 ) +position = Vector2( 512, 286.288 ) script = ExtResource( 1 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="Turret"] @@ -39,3 +40,23 @@ shape = SubResource( 2 ) [node name="Sprite" type="Sprite" parent="Turret"] modulate = Color( 0.137255, 0.866667, 0.647059, 1 ) texture = ExtResource( 4 ) + +[node name="GUI" type="PanelContainer" parent="."] +margin_right = 1024.0 +margin_bottom = 14.0 +theme = ExtResource( 6 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MarginContainer" type="MarginContainer" parent="GUI"] +margin_right = 1024.0 +margin_bottom = 87.0 + +[node name="Label" type="Label" parent="GUI/MarginContainer"] +margin_left = 16.0 +margin_top = 16.0 +margin_right = 1008.0 +margin_bottom = 71.0 +text = "Face Demo +Move the player around with WASD and notice the turret orient itself" diff --git a/project/demos/Face/Player.gd b/project/demos/Face/Player.gd new file mode 100644 index 0000000..44b2d47 --- /dev/null +++ b/project/demos/Face/Player.gd @@ -0,0 +1,22 @@ +extends KinematicBody2D + + +var speed: float + +onready var agent := GSTAgentLocation.new() + + +func _physics_process(delta: float) -> void: + var movement := _get_movement() + move_and_slide(movement * speed) + _update_agent() + + +func _get_movement() -> Vector2: + return Vector2( + Input.get_action_strength("sf_right") - Input.get_action_strength("sf_left"), + Input.get_action_strength("sf_down") - Input.get_action_strength("sf_up")) + + +func _update_agent() -> void: + agent.position = Vector3(global_position.x, global_position.y, 0) diff --git a/project/demos/Face/Turret.gd b/project/demos/Face/Turret.gd new file mode 100644 index 0000000..3e0cdff --- /dev/null +++ b/project/demos/Face/Turret.gd @@ -0,0 +1,46 @@ +extends KinematicBody2D + + +var face: GSTFace +var agent := GSTSteeringAgent.new() + +var _accel := GSTTargetAcceleration.new() +var _angular_drag := 0.01 +var _cannon: Rect2 + +onready var collision_shape := $CollisionShape2D + + +func _ready() -> void: + var radius = collision_shape.shape.radius + _cannon = Rect2(Vector2(-5, 0), Vector2(10, -radius*2)) + + +func _physics_process(delta: float) -> void: + _accel = face.calculate_steering(_accel) + agent.angular_velocity += _accel.angular + agent.angular_velocity = lerp(agent.angular_velocity, 0, _angular_drag) + agent.orientation += agent.angular_velocity * delta + rotation = agent.orientation + + +func _draw() -> void: + draw_rect(_cannon, Color.cadetblue) + + +func setup( + player_agent: GSTAgentLocation, + align_tolerance: float, + deceleration_radius: float, + max_angular_accel: float, + max_angular_speed: float +) -> void: + face = GSTFace.new(agent, player_agent) + + face.alignment_tolerance = align_tolerance + face.deceleration_radius = deceleration_radius + + agent.max_angular_acceleration = max_angular_accel + agent.max_angular_speed = max_angular_speed + agent.position = Vector3(global_position.x, global_position.y, 0) + diff --git a/project/demos/follow_path/FollowPathDemo.tscn b/project/demos/FollowPath/FollowPathDemo.tscn similarity index 100% rename from project/demos/follow_path/FollowPathDemo.tscn rename to project/demos/FollowPath/FollowPathDemo.tscn diff --git a/project/demos/GroupBehaviors/GroupBehaviorsDemo.gd b/project/demos/GroupBehaviors/GroupBehaviorsDemo.gd new file mode 100644 index 0000000..0084405 --- /dev/null +++ b/project/demos/GroupBehaviors/GroupBehaviorsDemo.gd @@ -0,0 +1,68 @@ +extends Node2D + + +onready var spawner := $Spawner + +export var max_linear_speed := 100.0 setget set_max_linear_speed +export var max_linear_accel := 25.0 setget set_max_linear_accel +export var proximity_radius := 140.0 setget set_proximity_radius +export var show_proximity_radius := true setget set_show_proximity_radius +export var separation_decay_coefficient := 2000.0 setget set_separation_decay_coef +export var cohesion_strength := 0.3 setget set_cohesion_strength +export var separation_strength := 1.5 setget set_separation_strength + + +func set_max_linear_speed(value: float) -> void: + if not is_inside_tree(): + return + + max_linear_speed = value + spawner.set_max_linear_speed(value) + + +func set_max_linear_accel(value: float) -> void: + if not is_inside_tree(): + return + + max_linear_accel = value + spawner.set_max_linear_accel(value) + + +func set_proximity_radius(value: float) -> void: + if not is_inside_tree(): + return + + proximity_radius = value + spawner.set_proximity_radius(value) + + +func set_show_proximity_radius(value: bool) -> void: + if not is_inside_tree(): + return + + show_proximity_radius = value + spawner.set_show_proximity_radius(value) + + +func set_separation_decay_coef(value: float) -> void: + if not is_inside_tree(): + return + + separation_decay_coefficient = value + spawner.set_separation_decay_coef(value) + + +func set_cohesion_strength(value: float) -> void: + if not is_inside_tree(): + return + + cohesion_strength = value + spawner.set_cohesion_strength(value) + + +func set_separation_strength(value: float) -> void: + if not is_inside_tree(): + return + + separation_strength = value + spawner.set_separation_strength(value) diff --git a/project/demos/GroupBehaviors/GroupBehaviorsDemo.tscn b/project/demos/GroupBehaviors/GroupBehaviorsDemo.tscn new file mode 100644 index 0000000..536c138 --- /dev/null +++ b/project/demos/GroupBehaviors/GroupBehaviorsDemo.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://demos/GroupBehaviors/Member.tscn" type="PackedScene" id=1] +[ext_resource path="res://demos/GroupBehaviors/Spawner.gd" type="Script" id=2] +[ext_resource path="res://demos/GroupBehaviors/GroupBehaviorsDemo.gd" type="Script" id=3] + +[node name="GroupBehaviorsDemo" type="Node2D"] +script = ExtResource( 3 ) + +[node name="Spawner" type="Node2D" parent="."] +position = Vector2( 512, 300 ) +script = ExtResource( 2 ) +member = ExtResource( 1 ) diff --git a/project/demos/group_behaviors/Member.gd b/project/demos/GroupBehaviors/Member.gd similarity index 85% rename from project/demos/group_behaviors/Member.gd rename to project/demos/GroupBehaviors/Member.gd index 6a891d3..a4b6f8b 100644 --- a/project/demos/group_behaviors/Member.gd +++ b/project/demos/GroupBehaviors/Member.gd @@ -1,16 +1,16 @@ extends KinematicBody2D -var agent: = GSTSteeringAgent.new() +var agent := GSTSteeringAgent.new() var separation: GSTSeparation var cohesion: GSTCohesion var proximity: GSTRadiusProximity -var blend: = GSTBlend.new(agent) -var acceleration: = GSTTargetAcceleration.new() -var draw_proximity: = false +var blend := GSTBlend.new(agent) +var acceleration := GSTTargetAcceleration.new() +var draw_proximity := false -var _color: = Color.red -var _velocity: = Vector2() +var _color := Color.red +var _velocity := Vector2() func setup( @@ -53,6 +53,6 @@ func set_neighbors(neighbor: Array) -> void: func update_agent() -> void: - var current_position: = global_position + var current_position := global_position agent.position.x = current_position.x agent.position.y = current_position.y diff --git a/project/demos/group_behaviors/Member.tscn b/project/demos/GroupBehaviors/Member.tscn similarity index 83% rename from project/demos/group_behaviors/Member.tscn rename to project/demos/GroupBehaviors/Member.tscn index 6b7d2bb..a569388 100644 --- a/project/demos/group_behaviors/Member.tscn +++ b/project/demos/GroupBehaviors/Member.tscn @@ -1,8 +1,9 @@ [gd_scene load_steps=4 format=2] -[ext_resource path="res://demos/group_behaviors/Member.gd" type="Script" id=1] +[ext_resource path="res://demos/GroupBehaviors/Member.gd" type="Script" id=1] [ext_resource path="res://assets/sprites/small_circle.png" type="Texture" id=2] + [sub_resource type="CircleShape2D" id=1] radius = 16.0 diff --git a/project/demos/group_behaviors/Spawner.gd b/project/demos/GroupBehaviors/Spawner.gd similarity index 95% rename from project/demos/group_behaviors/Spawner.gd rename to project/demos/GroupBehaviors/Spawner.gd index e9853fd..63ac60b 100644 --- a/project/demos/group_behaviors/Spawner.gd +++ b/project/demos/GroupBehaviors/Spawner.gd @@ -5,9 +5,9 @@ export var member: PackedScene func _ready() -> void: - var followers: = [] + var followers := [] for i in range(19): - var follower: = member.instance() + var follower := member.instance() add_child(follower) follower.position += Vector2(rand_range(-60, 60), rand_range(-60, 60)) followers.append(follower) @@ -22,7 +22,7 @@ func _ready() -> void: if i == 0 and owner.show_proximity_radius: follower.draw_proximity = true follower.update() - var agents: = [] + var agents := [] for i in followers: agents.append(i.agent) for i in followers: diff --git a/project/demos/pursue_vs_seek/BoundaryManager.gd b/project/demos/PursueSeek/BoundaryManager.gd similarity index 89% rename from project/demos/pursue_vs_seek/BoundaryManager.gd rename to project/demos/PursueSeek/BoundaryManager.gd index a73b32f..8c80687 100644 --- a/project/demos/pursue_vs_seek/BoundaryManager.gd +++ b/project/demos/PursueSeek/BoundaryManager.gd @@ -2,10 +2,10 @@ extends Node2D # Wraps the ships' positions around the world border, and controls their rendering clones. -onready var ShipType: = preload("res://demos/pursue_vs_seek/Ship.gd") -onready var ships: = [$Player, $Pursuer, $Seeker] +onready var ShipType := preload("res://demos/PursueSeek/Ship.gd") +onready var ships := [$Player, $Pursuer, $Seeker] -var _clones: = {} +var _clones := {} var _world_bounds: Vector2 @@ -17,10 +17,10 @@ func _ready() -> void: for i in range(ships.size()): var ship: Node2D = ships[i] - var world_pos: = ship.position + var world_pos := ship.position for i in range(3): - var ship_clone: = ShipType.new() + var ship_clone := ShipType.new() ship_clone.position.x = world_pos.x if i == 1 else (world_pos.x - _world_bounds.x) ship_clone.position.y = world_pos.y if i == 0 else (world_pos.y - _world_bounds.y) diff --git a/project/demos/pursue_vs_seek/Player.gd b/project/demos/PursueSeek/Player.gd similarity index 78% rename from project/demos/pursue_vs_seek/Player.gd rename to project/demos/PursueSeek/Player.gd index 9487f1f..e04dc02 100644 --- a/project/demos/pursue_vs_seek/Player.gd +++ b/project/demos/PursueSeek/Player.gd @@ -1,22 +1,22 @@ -extends "res://demos/pursue_vs_seek/Ship.gd" +extends "res://demos/PursueSeek/Ship.gd" # Controls the player ship's movements based on player input. -onready var agent: = GSTSteeringAgent.new() +onready var agent := GSTSteeringAgent.new() -export var thruster_strength: = 250.0 -export var side_thruster_strength: = 10.0 -export var max_velocity: = 300.0 -export var max_angular_velocity: = 2.0 -export var angular_drag: = 0.025 -export var linear_drag: = 0.025 +export var thruster_strength := 250.0 +export var side_thruster_strength := 10.0 +export var max_velocity := 300.0 +export var max_angular_velocity := 2.0 +export var angular_drag := 0.025 +export var linear_drag := 0.025 -var _linear_velocity: = Vector2() -var _angular_velocity: = 0.0 +var _linear_velocity := Vector2() +var _angular_velocity := 0.0 func _physics_process(delta: float) -> void: - var movement: = _get_movement() + var movement := _get_movement() _angular_velocity = _calculate_angular_velocity( movement.x, _angular_velocity, @@ -50,7 +50,7 @@ func _calculate_angular_velocity( ship_drag: float, delta: float) -> float: - var velocity: = clamp( + var velocity := clamp( current_velocity + thruster_strength * horizontal_movement * delta, -max_velocity, max_velocity @@ -70,13 +70,13 @@ func _calculate_linear_velocity( max_speed: float, delta: float) -> Vector2: - var actual_strength: = 0.0 + var actual_strength := 0.0 if vertical_movement > 0: actual_strength = strength elif vertical_movement < 0: actual_strength = -strength/1.5 - var velocity: = current_velocity + facing_direction * actual_strength * delta + var velocity := current_velocity + facing_direction * actual_strength * delta velocity = velocity.linear_interpolate(Vector2.ZERO, ship_drag_coefficient) return velocity.clamped(max_speed) diff --git a/project/demos/PursueSeek/PursueVSSeekDemo.gd b/project/demos/PursueSeek/PursueVSSeekDemo.gd new file mode 100644 index 0000000..f9cbce5 --- /dev/null +++ b/project/demos/PursueSeek/PursueVSSeekDemo.gd @@ -0,0 +1,35 @@ +extends Node2D + + +onready var pursuer := $BoundaryManager/Pursuer +onready var seeker := $BoundaryManager/Seeker + +export(float, 0, 2000, 40) var max_linear_speed := 200.0 setget set_max_linear_speed +export(float, 0, 200, 1) var max_linear_accel := 10.0 setget set_max_linear_accel +export(float, 0, 5, 0.1) var predict_time := 2.0 setget set_predict_time + + +func set_max_linear_speed(value: float) -> void: + if not is_inside_tree(): + return + + max_linear_speed = value + pursuer.agent.max_linear_speed = value + seeker.agent.max_linear_speed = value + + +func set_max_linear_accel(value: float) -> void: + if not is_inside_tree(): + return + + max_linear_accel = value + pursuer.agent.max_linear_acceleration = value + seeker.agent.max_linear_acceleration = value + + +func set_predict_time(value: float) -> void: + if not is_inside_tree(): + return + + predict_time = value + pursuer._behavior.max_predict_time = value diff --git a/project/demos/pursue_vs_seek/PursueVSSeekDemo.tscn b/project/demos/PursueSeek/PursueVSSeekDemo.tscn similarity index 84% rename from project/demos/pursue_vs_seek/PursueVSSeekDemo.tscn rename to project/demos/PursueSeek/PursueVSSeekDemo.tscn index 0a4e5bc..adb91b1 100644 --- a/project/demos/pursue_vs_seek/PursueVSSeekDemo.tscn +++ b/project/demos/PursueSeek/PursueVSSeekDemo.tscn @@ -1,9 +1,9 @@ [gd_scene load_steps=6 format=2] -[ext_resource path="res://demos/pursue_vs_seek/Pursuer.gd" type="Script" id=1] -[ext_resource path="res://demos/pursue_vs_seek/Player.gd" type="Script" id=2] -[ext_resource path="res://demos/pursue_vs_seek/BoundaryManager.gd" type="Script" id=3] -[ext_resource path="res://demos/pursue_vs_seek/PursueVSSeekDemo.gd" type="Script" id=4] +[ext_resource path="res://demos/PursueSeek/Pursuer.gd" type="Script" id=1] +[ext_resource path="res://demos/PursueSeek/Player.gd" type="Script" id=2] +[ext_resource path="res://demos/PursueSeek/BoundaryManager.gd" type="Script" id=3] +[ext_resource path="res://demos/PursueSeek/PursueVSSeekDemo.gd" type="Script" id=4] [ext_resource path="res://assets/sprites/triangle.png" type="Texture" id=6] [node name="PursueVSSeekDemo" type="Node2D"] diff --git a/project/demos/pursue_vs_seek/Pursuer.gd b/project/demos/PursueSeek/Pursuer.gd similarity index 86% rename from project/demos/pursue_vs_seek/Pursuer.gd rename to project/demos/PursueSeek/Pursuer.gd index b44276e..05c34a0 100644 --- a/project/demos/pursue_vs_seek/Pursuer.gd +++ b/project/demos/PursueSeek/Pursuer.gd @@ -1,9 +1,9 @@ -extends "res://demos/pursue_vs_seek/Ship.gd" +extends "res://demos/PursueSeek/Ship.gd" # Represents a ship that chases after the player. -onready var agent: = GSTSteeringAgent.new() -onready var accel: = GSTTargetAcceleration.new() +onready var agent := GSTSteeringAgent.new() +onready var accel := GSTTargetAcceleration.new() onready var player_agent: GSTSteeringAgent = owner.find_node("Player", true, false).agent export var use_seek: bool = false @@ -11,10 +11,10 @@ export var use_seek: bool = false var _orient_behavior: GSTSteeringBehavior var _behavior: GSTSteeringBehavior -var _linear_velocity: = Vector2() -var _linear_drag_coefficient: = 0.025 -var _angular_velocity: = 0.0 -var _angular_drag: = 1.0 +var _linear_velocity := Vector2() +var _linear_drag_coefficient := 0.025 +var _angular_velocity := 0.0 +var _angular_drag := 1.0 func _ready() -> void: diff --git a/project/demos/pursue_vs_seek/Ship.gd b/project/demos/PursueSeek/Ship.gd similarity index 100% rename from project/demos/pursue_vs_seek/Ship.gd rename to project/demos/PursueSeek/Ship.gd diff --git a/project/demos/seek_and_flee/Boundary.gd b/project/demos/SeekFlee/Boundary.gd similarity index 77% rename from project/demos/seek_and_flee/Boundary.gd rename to project/demos/SeekFlee/Boundary.gd index b5a9c03..cbf2441 100644 --- a/project/demos/seek_and_flee/Boundary.gd +++ b/project/demos/SeekFlee/Boundary.gd @@ -6,7 +6,7 @@ var rect: Rect2 func _ready() -> void: - var extents: = ($CollisionShape2D.shape as RectangleShape2D).extents + var extents := ($CollisionShape2D.shape as RectangleShape2D).extents rect = Rect2(-extents, extents*2) diff --git a/project/demos/seek_and_flee/Player.gd b/project/demos/SeekFlee/Player.gd similarity index 83% rename from project/demos/seek_and_flee/Player.gd rename to project/demos/SeekFlee/Player.gd index 9fba69f..85961a8 100644 --- a/project/demos/seek_and_flee/Player.gd +++ b/project/demos/SeekFlee/Player.gd @@ -2,9 +2,9 @@ extends KinematicBody2D # Class to control the player in basic left/right up/down movement. -onready var agent: = GSTAgentLocation.new() +onready var agent := GSTAgentLocation.new() -export var speed: = 200.0 +export var speed := 200.0 func _get_movement() -> Vector2: @@ -13,7 +13,7 @@ func _get_movement() -> Vector2: func _physics_process(delta: float) -> void: - var movement: = _get_movement() + var movement := _get_movement() if movement.length_squared() < 0.01: return diff --git a/project/demos/seek_and_flee/SeekFleeDemo.gd b/project/demos/SeekFlee/SeekFleeDemo.gd similarity index 61% rename from project/demos/seek_and_flee/SeekFleeDemo.gd rename to project/demos/SeekFlee/SeekFleeDemo.gd index 40a0e24..692c71d 100644 --- a/project/demos/seek_and_flee/SeekFleeDemo.gd +++ b/project/demos/SeekFlee/SeekFleeDemo.gd @@ -4,17 +4,17 @@ extends Node2D enum Mode { FLEE, SEEK } -export(Mode) var behavior_mode: = Mode.SEEK setget set_behavior_mode -export(float, 0, 2000, 40) var max_linear_speed: = 200.0 setget set_max_linear_speed -export(float, 0, 500, 0.5) var max_linear_accel: = 10.0 setget set_max_linear_accel +export(Mode) var behavior_mode := Mode.SEEK setget set_behavior_mode +export(float, 0, 2000, 40) var max_linear_speed := 200.0 setget set_max_linear_speed +export(float, 0, 500, 0.5) var max_linear_accel := 10.0 setget set_max_linear_accel + +var camera_boundaries: Rect2 onready var player: KinematicBody2D = $Player onready var spawner: Node2D = $Spawner -var camera_boundaries: Rect2 - -func _init() -> void: +func _ready() -> void: camera_boundaries = Rect2( Vector2.ZERO, Vector2( @@ -22,14 +22,12 @@ func _init() -> void: ProjectSettings["display/window/size/height"] ) ) - - -func _ready() -> void: - var rng: = RandomNumberGenerator.new() + + var rng := RandomNumberGenerator.new() rng.randomize() for i in range(spawner.entity_count): - var new_pos: = Vector2( + var new_pos := Vector2( rng.randf_range(-camera_boundaries.size.x/2, camera_boundaries.size.x/2), rng.randf_range(-camera_boundaries.size.y/2, camera_boundaries.size.y/2) ) @@ -42,29 +40,32 @@ func _ready() -> void: func set_behavior_mode(mode: int) -> void: - behavior_mode = mode + if not is_inside_tree(): + return - if spawner: - match mode: - Mode.SEEK: - for child in spawner.get_children(): - child.use_seek = true - Mode.FLEE: - for child in spawner.get_children(): - child.use_seek = false + behavior_mode = mode + match mode: + Mode.SEEK: + for child in spawner.get_children(): + child.use_seek = true + Mode.FLEE: + for child in spawner.get_children(): + child.use_seek = false func set_max_linear_speed(value: float) -> void: - max_linear_speed = value + if not is_inside_tree(): + return - if spawner: - for child in spawner.get_children(): - child.agent.max_linear_speed = value + max_linear_speed = value + for child in spawner.get_children(): + child.agent.max_linear_speed = value func set_max_linear_accel(value: float) -> void: - max_linear_accel = value + if not is_inside_tree(): + return - if spawner: - for child in spawner.get_children(): - child.agent.max_linear_acceleration = value + max_linear_accel = value + for child in spawner.get_children(): + child.agent.max_linear_acceleration = value diff --git a/project/demos/seek_and_flee/SeekFleeDemo.tscn b/project/demos/SeekFlee/SeekFleeDemo.tscn similarity index 83% rename from project/demos/seek_and_flee/SeekFleeDemo.tscn rename to project/demos/SeekFlee/SeekFleeDemo.tscn index faf8d07..330a328 100644 --- a/project/demos/seek_and_flee/SeekFleeDemo.tscn +++ b/project/demos/SeekFlee/SeekFleeDemo.tscn @@ -1,10 +1,10 @@ [gd_scene load_steps=10 format=2] -[ext_resource path="res://demos/seek_and_flee/Boundary.gd" type="Script" id=1] -[ext_resource path="res://demos/seek_and_flee/Player.gd" type="Script" id=2] -[ext_resource path="res://demos/seek_and_flee/SeekFleeDemo.gd" type="Script" id=3] -[ext_resource path="res://demos/seek_and_flee/Spawner.gd" type="Script" id=4] -[ext_resource path="res://demos/seek_and_flee/Seeker.tscn" type="PackedScene" id=6] +[ext_resource path="res://demos/SeekFlee/Boundary.gd" type="Script" id=1] +[ext_resource path="res://demos/SeekFlee/Player.gd" type="Script" id=2] +[ext_resource path="res://demos/SeekFlee/SeekFleeDemo.gd" type="Script" id=3] +[ext_resource path="res://demos/SeekFlee/Spawner.gd" type="Script" id=4] +[ext_resource path="res://demos/SeekFlee/Seeker.tscn" type="PackedScene" id=6] [ext_resource path="res://assets/sprites/large_circle.png" type="Texture" id=7] [sub_resource type="CircleShape2D" id=1] diff --git a/project/demos/seek_and_flee/Seeker.gd b/project/demos/SeekFlee/Seeker.gd similarity index 77% rename from project/demos/seek_and_flee/Seeker.gd rename to project/demos/SeekFlee/Seeker.gd index 5795944..4247eb0 100644 --- a/project/demos/seek_and_flee/Seeker.gd +++ b/project/demos/SeekFlee/Seeker.gd @@ -2,16 +2,16 @@ extends KinematicBody2D # AI agent that uses the Seek behavior to hone in on the player's location as directly as possible. -onready var agent: = GSTSteeringAgent.new() -onready var accel: = GSTTargetAcceleration.new() -onready var seek: = GSTSeek.new(agent, player_agent) -onready var flee: = GSTFlee.new(agent, player_agent) +onready var agent := GSTSteeringAgent.new() +onready var accel := GSTTargetAcceleration.new() +onready var seek := GSTSeek.new(agent, player_agent) +onready var flee := GSTFlee.new(agent, player_agent) var player_agent: GSTAgentLocation -var velocity: = Vector2.ZERO +var velocity := Vector2.ZERO var start_speed: float var start_accel: float -var use_seek: = true +var use_seek := true func _ready() -> void: diff --git a/project/demos/seek_and_flee/Seeker.tscn b/project/demos/SeekFlee/Seeker.tscn similarity index 86% rename from project/demos/seek_and_flee/Seeker.tscn rename to project/demos/SeekFlee/Seeker.tscn index 6e5d647..cf2e52d 100644 --- a/project/demos/seek_and_flee/Seeker.tscn +++ b/project/demos/SeekFlee/Seeker.tscn @@ -1,8 +1,9 @@ [gd_scene load_steps=4 format=2] -[ext_resource path="res://demos/seek_and_flee/Seeker.gd" type="Script" id=1] +[ext_resource path="res://demos/SeekFlee/Seeker.gd" type="Script" id=1] [ext_resource path="res://assets/sprites/small_circle.png" type="Texture" id=2] + [sub_resource type="CircleShape2D" id=1] radius = 16.0 diff --git a/project/demos/seek_and_flee/Spawner.gd b/project/demos/SeekFlee/Spawner.gd similarity index 65% rename from project/demos/seek_and_flee/Spawner.gd rename to project/demos/SeekFlee/Spawner.gd index 99de62d..77fa588 100644 --- a/project/demos/seek_and_flee/Spawner.gd +++ b/project/demos/SeekFlee/Spawner.gd @@ -3,5 +3,5 @@ extends Node2D export(PackedScene) var Entity: PackedScene -export var entity_count: = 10 -export var entity_color: = Color.blue +export var entity_count:= 10 +export var entity_color:= Color.blue diff --git a/project/demos/arrive/ArriveDemo.gd b/project/demos/arrive/ArriveDemo.gd deleted file mode 100644 index deaef47..0000000 --- a/project/demos/arrive/ArriveDemo.gd +++ /dev/null @@ -1,39 +0,0 @@ -extends Node2D - - -onready var target: = $Target -onready var arriver: = $Arriver -onready var gui: = $GUI - -export(float, 0, 2000, 40) var max_linear_speed: = 200.0 setget set_max_linear_speed -export(float, 0, 200, 1) var max_linear_accel: = 25.0 setget set_max_linear_accel -export(float, 0, 100, 0.1) var arrival_tolerance: = 20.0 setget set_arrival_tolerance -export(float, 0, 500, 10) var deceleration_radius: = 200.0 setget set_deceleration_radius - - -func _ready() -> void: - target.position = arriver.global_position - - -func set_arrival_tolerance(value: float) -> void: - arrival_tolerance = value - if arriver: - arriver.arrive.arrival_tolerance = value - - -func set_deceleration_radius(value: float) -> void: - deceleration_radius = value - if arriver: - arriver.arrive.deceleration_radius = value - - -func set_max_linear_speed(value: float) -> void: - max_linear_speed = value - if arriver: - arriver.agent.max_linear_speed = value - - -func set_max_linear_accel(value: float) -> void: - max_linear_accel = value - if arriver: - arriver.agent.max_linear_acceleration = value diff --git a/project/demos/arrive/ArriveDemo.tscn b/project/demos/arrive/ArriveDemo.tscn deleted file mode 100644 index b84edba..0000000 --- a/project/demos/arrive/ArriveDemo.tscn +++ /dev/null @@ -1,35 +0,0 @@ -[gd_scene load_steps=6 format=2] - -[ext_resource path="res://demos/arrive/Arriver.gd" type="Script" id=1] -[ext_resource path="res://demos/arrive/ArriveDemo.gd" type="Script" id=2] -[ext_resource path="res://assets/sprites/large_circle.png" type="Texture" id=3] -[ext_resource path="res://assets/sprites/small_circle.png" type="Texture" id=4] - -[sub_resource type="CircleShape2D" id=1] -radius = 16.0 - -[node name="ArriveDemo" type="Node2D"] -script = ExtResource( 2 ) -max_linear_speed = 400.0 -max_linear_accel = 50.0 -arrival_tolerance = 10.0 -deceleration_radius = 80.0 - -[node name="Arriver" type="KinematicBody2D" parent="."] -position = Vector2( 512, 300 ) -script = ExtResource( 1 ) - -[node name="CollisionShape2D" type="CollisionShape2D" parent="Arriver"] -shape = SubResource( 1 ) - -[node name="Sprite" type="Sprite" parent="Arriver"] -modulate = Color( 0.952941, 0.172549, 0.0431373, 1 ) -texture = ExtResource( 4 ) - -[node name="Target" type="Sprite" parent="."] -modulate = Color( 0.827451, 1, 0, 0.501961 ) -texture = ExtResource( 3 ) - -[node name="Sprite" type="Sprite" parent="Target"] -scale = Vector2( 0.5, 0.5 ) -texture = ExtResource( 4 ) diff --git a/project/demos/arrive/Arriver.gd b/project/demos/arrive/Arriver.gd deleted file mode 100644 index 2cfad09..0000000 --- a/project/demos/arrive/Arriver.gd +++ /dev/null @@ -1,40 +0,0 @@ -extends KinematicBody2D - - -onready var agent: = GSTSteeringAgent.new() -onready var target: = GSTAgentLocation.new() -onready var arrive: = GSTArrive.new(agent, target) -var _accel: = GSTTargetAcceleration.new() - -var _velocity: = Vector2() -var _drag: = 0.1 - - -func _ready() -> void: - agent.max_linear_speed = owner.max_linear_speed - agent.max_linear_acceleration = owner.max_linear_accel - agent.position = Vector3(global_position.x, global_position.y, 0) - arrive.deceleration_radius = owner.deceleration_radius - arrive.arrival_tolerance = owner.arrival_tolerance - target.position = agent.position - - -func _unhandled_input(event: InputEvent) -> void: - if event is InputEventMouseButton: - var mb: InputEventMouseButton = event - if mb.button_index == BUTTON_LEFT and mb.pressed: - target.position = Vector3(mb.position.x, mb.position.y, 0) - owner.target.position = mb.position - - -func _physics_process(delta: float) -> void: - _update_agent() - _accel = arrive.calculate_steering(_accel) - _velocity += Vector2(_accel.linear.x, _accel.linear.y) - _velocity = _velocity.linear_interpolate(Vector2.ZERO, _drag).clamped(agent.max_linear_speed) - _velocity = move_and_slide(_velocity) - - -func _update_agent() -> void: - agent.position = Vector3(global_position.x, global_position.y, 0) - agent.linear_velocity = Vector3(_velocity.x, _velocity.y, 0) diff --git a/project/demos/face/FaceDemo.gd b/project/demos/face/FaceDemo.gd deleted file mode 100644 index b754e51..0000000 --- a/project/demos/face/FaceDemo.gd +++ /dev/null @@ -1,44 +0,0 @@ -extends Node2D - - -onready var player: = $Player -onready var gui: = $GUI -onready var turret: = $Turret - -export(int, 0, 359, 1) var max_angular_speed: = 90 setget set_max_angular_speed -export(int, 0, 359, 1) var max_angular_accel: = 5 setget set_max_angular_accel -export(int, 0, 180, 1) var align_tolerance: = 5 setget set_align_tolerance -export(int, 0, 359, 1) var deceleration_radius: = 45 setget set_deceleration_radius - - -func _ready() -> void: - turret.setup( - deg2rad(align_tolerance), - deg2rad(deceleration_radius), - deg2rad(max_angular_accel), - deg2rad(max_angular_speed) - ) - - -func set_align_tolerance(value: int) -> void: - align_tolerance = value - if turret: - turret._face.alignment_tolerance = deg2rad(value) - - -func set_deceleration_radius(value: int) -> void: - deceleration_radius = value - if turret: - turret._face.deceleration_radius = deg2rad(value) - - -func set_max_angular_accel(value: int) -> void: - max_angular_accel = value - if turret: - turret._agent.max_angular_acceleration = deg2rad(value) - - -func set_max_angular_speed(value: int) -> void: - max_angular_speed = value - if turret: - turret._agent.max_angular_speed = deg2rad(value) diff --git a/project/demos/face/Player.gd b/project/demos/face/Player.gd deleted file mode 100644 index 5c7609e..0000000 --- a/project/demos/face/Player.gd +++ /dev/null @@ -1,21 +0,0 @@ -extends KinematicBody2D - - -onready var agent: = GSTAgentLocation.new() - -export var speed: = 125.0 - - -func _physics_process(delta: float) -> void: - var movement: = _get_movement() - move_and_slide(movement * speed) - _update_agent() - - -func _get_movement() -> Vector2: - return Vector2( Input.get_action_strength("sf_right") - Input.get_action_strength("sf_left"), - Input.get_action_strength("sf_down") - Input.get_action_strength("sf_up")) - - -func _update_agent() -> void: - agent.position = Vector3(global_position.x, global_position.y, 0) diff --git a/project/demos/face/Turret.gd b/project/demos/face/Turret.gd deleted file mode 100644 index 7eb6cae..0000000 --- a/project/demos/face/Turret.gd +++ /dev/null @@ -1,59 +0,0 @@ -extends KinematicBody2D - - -onready var collision_shape: = $CollisionShape2D - -var _cannon: Rect2 - -var _agent: = GSTSteeringAgent.new() -var _accel: = GSTTargetAcceleration.new() - -var _angular_velocity: = 0.0 -var _angular_drag: = 0.01 -var _face: GSTFace - - -func _ready() -> void: - var radius = collision_shape.shape.radius - _cannon = Rect2(Vector2(-5, 0), Vector2(10, -radius*2)) - - -func _draw() -> void: - draw_rect(_cannon, Color.blue) - - -func _physics_process(delta: float) -> void: - if not _face: - return - - _accel = _face.calculate_steering(_accel) - _angular_velocity += _accel.angular - - _angular_velocity = lerp(_angular_velocity, 0, _angular_drag) - - rotation += _angular_velocity * delta - - _update_agent() - - -func setup( - align_tolerance: float, - deceleration_radius: float, - max_angular_accel: float, - max_angular_speed: float - ) -> void: - _face = GSTFace.new(_agent, owner.player.agent) - - _face.alignment_tolerance = align_tolerance - _face.deceleration_radius = deceleration_radius - - _agent.max_angular_acceleration = max_angular_accel - _agent.max_angular_speed = max_angular_speed - _agent.position = Vector3(global_position.x, global_position.y, 0) - - _update_agent() - - -func _update_agent() -> void: - _agent.angular_velocity = _angular_velocity - _agent.orientation = rotation diff --git a/project/demos/group_behaviors/GroupBehaviorsDemo.gd b/project/demos/group_behaviors/GroupBehaviorsDemo.gd deleted file mode 100644 index d400c31..0000000 --- a/project/demos/group_behaviors/GroupBehaviorsDemo.gd +++ /dev/null @@ -1,58 +0,0 @@ -extends Node2D - - -onready var spawner: = $Spawner - -export var max_linear_speed: = 100.0 setget set_max_linear_speed -export var max_linear_accel: = 25.0 setget set_max_linear_accel -export var proximity_radius: = 140.0 setget set_proximity_radius -export var show_proximity_radius: = true setget set_show_proximity_radius -export var separation_decay_coefficient: = 2000.0 setget set_separation_decay_coef -export var cohesion_strength: = 0.3 setget set_cohesion_strength -export var separation_strength: = 1.5 setget set_separation_strength - - -func _ready() -> void: - pass - - -func set_max_linear_speed(value: float) -> void: - max_linear_speed = value - if spawner: - spawner.set_max_linear_speed(value) - - -func set_max_linear_accel(value: float) -> void: - max_linear_accel = value - if spawner: - spawner.set_max_linear_accel(value) - - -func set_proximity_radius(value: float) -> void: - proximity_radius = value - if spawner: - spawner.set_proximity_radius(value) - - -func set_show_proximity_radius(value: bool) -> void: - show_proximity_radius = value - if spawner: - spawner.set_show_proximity_radius(value) - - -func set_separation_decay_coef(value: float) -> void: - separation_decay_coefficient = value - if spawner: - spawner.set_separation_decay_coef(value) - - -func set_cohesion_strength(value: float) -> void: - cohesion_strength = value - if spawner: - spawner.set_cohesion_strength(value) - - -func set_separation_strength(value: float) -> void: - separation_strength = value - if spawner: - spawner.set_separation_strength(value) diff --git a/project/demos/group_behaviors/GroupBehaviorsDemo.tscn b/project/demos/group_behaviors/GroupBehaviorsDemo.tscn deleted file mode 100644 index d1338cd..0000000 --- a/project/demos/group_behaviors/GroupBehaviorsDemo.tscn +++ /dev/null @@ -1,13 +0,0 @@ -[gd_scene load_steps=4 format=2] - -[ext_resource path="res://demos/group_behaviors/Member.tscn" type="PackedScene" id=1] -[ext_resource path="res://demos/group_behaviors/Spawner.gd" type="Script" id=2] -[ext_resource path="res://demos/group_behaviors/GroupBehaviorsDemo.gd" type="Script" id=3] - -[node name="GroupBehaviorsDemo" type="Node2D"] -script = ExtResource( 3 ) - -[node name="Spawner" type="Node2D" parent="."] -position = Vector2( 512, 300 ) -script = ExtResource( 2 ) -member = ExtResource( 1 ) diff --git a/project/demos/pursue_vs_seek/PursueVSSeekDemo.gd b/project/demos/pursue_vs_seek/PursueVSSeekDemo.gd deleted file mode 100644 index 5af3c3d..0000000 --- a/project/demos/pursue_vs_seek/PursueVSSeekDemo.gd +++ /dev/null @@ -1,31 +0,0 @@ -extends Node2D - - -onready var pursuer: = $BoundaryManager/Pursuer -onready var seeker: = $BoundaryManager/Seeker - -export(float, 0, 2000, 40) var max_linear_speed: = 200.0 setget set_max_linear_speed -export(float, 0, 200, 1) var max_linear_accel: = 10.0 setget set_max_linear_accel -export(float, 0, 5, 0.1) var predict_time: = 2.0 setget set_predict_time - - -func set_max_linear_speed(value: float) -> void: - max_linear_speed = value - if pursuer: - pursuer.agent.max_linear_speed = value - if seeker: - seeker.agent.max_linear_speed = value - - -func set_max_linear_accel(value: float) -> void: - max_linear_accel = value - if pursuer: - pursuer.agent.max_linear_acceleration = value - if seeker: - seeker.agent.max_linear_acceleration = value - - -func set_predict_time(value: float) -> void: - predict_time = value - if pursuer: - pursuer._behavior.max_predict_time = value diff --git a/project/project.godot b/project/project.godot index 8a29bcd..d615c5b 100644 --- a/project/project.godot +++ b/project/project.godot @@ -17,42 +17,42 @@ _global_script_classes=[ { "base": "GSTSteeringBehavior", "class": "GSTArrive", "language": "GDScript", -"path": "res://src/behaviors/GSTArrive.gd" +"path": "res://src/Behaviors/GSTArrive.gd" }, { "base": "GSTGroupBehavior", "class": "GSTAvoidCollisions", "language": "GDScript", -"path": "res://src/behaviors/GSTAvoidCollisions.gd" +"path": "res://src/Behaviors/GSTAvoidCollisions.gd" }, { "base": "GSTSteeringBehavior", "class": "GSTBlend", "language": "GDScript", -"path": "res://src/behaviors/GSTBlend.gd" +"path": "res://src/Behaviors/GSTBlend.gd" }, { "base": "GSTGroupBehavior", "class": "GSTCohesion", "language": "GDScript", -"path": "res://src/behaviors/GSTCohesion.gd" +"path": "res://src/Behaviors/GSTCohesion.gd" }, { "base": "GSTPursue", "class": "GSTEvade", "language": "GDScript", -"path": "res://src/behaviors/GSTEvade.gd" +"path": "res://src/Behaviors/GSTEvade.gd" }, { "base": "GSTMatchOrientation", "class": "GSTFace", "language": "GDScript", -"path": "res://src/behaviors/GSTFace.gd" +"path": "res://src/Behaviors/GSTFace.gd" }, { "base": "GSTSeek", "class": "GSTFlee", "language": "GDScript", -"path": "res://src/behaviors/GSTFlee.gd" +"path": "res://src/Behaviors/GSTFlee.gd" }, { "base": "GSTArrive", "class": "GSTFollowPath", "language": "GDScript", -"path": "res://src/behaviors/GSTFollowPath.gd" +"path": "res://src/Behaviors/GSTFollowPath.gd" }, { "base": "GSTSteeringBehavior", "class": "GSTGroupBehavior", @@ -62,17 +62,17 @@ _global_script_classes=[ { "base": "GSTProximity", "class": "GSTInfiniteProximity", "language": "GDScript", -"path": "res://src/proximities/GSTInfiniteProximity.gd" +"path": "res://src/Proximities/GSTInfiniteProximity.gd" }, { "base": "GSTMatchOrientation", "class": "GSTLookWhereYouGo", "language": "GDScript", -"path": "res://src/behaviors/GSTLookWhereYouGo.gd" +"path": "res://src/Behaviors/GSTLookWhereYouGo.gd" }, { "base": "GSTSteeringBehavior", "class": "GSTMatchOrientation", "language": "GDScript", -"path": "res://src/behaviors/GSTMatchOrientation.gd" +"path": "res://src/Behaviors/GSTMatchOrientation.gd" }, { "base": "Reference", "class": "GSTPath", @@ -82,32 +82,32 @@ _global_script_classes=[ { "base": "GSTSteeringBehavior", "class": "GSTPriority", "language": "GDScript", -"path": "res://src/behaviors/GSTPriority.gd" +"path": "res://src/Behaviors/GSTPriority.gd" }, { "base": "Reference", "class": "GSTProximity", "language": "GDScript", -"path": "res://src/proximities/GSTProximity.gd" +"path": "res://src/Proximities/GSTProximity.gd" }, { "base": "GSTSteeringBehavior", "class": "GSTPursue", "language": "GDScript", -"path": "res://src/behaviors/GSTPursue.gd" +"path": "res://src/Behaviors/GSTPursue.gd" }, { "base": "GSTProximity", "class": "GSTRadiusProximity", "language": "GDScript", -"path": "res://src/proximities/GSTRadiusProximity.gd" +"path": "res://src/Proximities/GSTRadiusProximity.gd" }, { "base": "GSTSteeringBehavior", "class": "GSTSeek", "language": "GDScript", -"path": "res://src/behaviors/GSTSeek.gd" +"path": "res://src/Behaviors/GSTSeek.gd" }, { "base": "GSTGroupBehavior", "class": "GSTSeparation", "language": "GDScript", -"path": "res://src/behaviors/GSTSeparation.gd" +"path": "res://src/Behaviors/GSTSeparation.gd" }, { "base": "GSTAgentLocation", "class": "GSTSteeringAgent", diff --git a/project/src/behaviors/GSTArrive.gd b/project/src/Behaviors/GSTArrive.gd similarity index 82% rename from project/src/behaviors/GSTArrive.gd rename to project/src/Behaviors/GSTArrive.gd index eeb84c0..a451bd9 100644 --- a/project/src/behaviors/GSTArrive.gd +++ b/project/src/Behaviors/GSTArrive.gd @@ -7,7 +7,7 @@ class_name GSTArrive var target: GSTAgentLocation var arrival_tolerance: float var deceleration_radius: float -var time_to_reach: = 0.1 +var time_to_reach := 0.1 func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void: @@ -15,18 +15,18 @@ func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void: func _arrive(acceleration: GSTTargetAcceleration, target_position: Vector3) -> GSTTargetAcceleration: - var to_target: = target_position - agent.position - var distance: = to_target.length() + var to_target := target_position - agent.position + var distance := to_target.length() if distance <= arrival_tolerance: acceleration.set_zero() else: - var desired_speed: = agent.max_linear_speed + var desired_speed := agent.max_linear_speed if distance <= deceleration_radius: desired_speed *= distance / deceleration_radius - var desired_velocity: = to_target * desired_speed/distance + var desired_velocity := to_target * desired_speed/distance desired_velocity = (desired_velocity - agent.linear_velocity) * 1.0 / time_to_reach diff --git a/project/src/behaviors/GSTAvoidCollisions.gd b/project/src/Behaviors/GSTAvoidCollisions.gd similarity index 88% rename from project/src/behaviors/GSTAvoidCollisions.gd rename to project/src/Behaviors/GSTAvoidCollisions.gd index d4ed8d2..2562b30 100644 --- a/project/src/behaviors/GSTAvoidCollisions.gd +++ b/project/src/Behaviors/GSTAvoidCollisions.gd @@ -21,7 +21,7 @@ func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAccele first_minimum_separation = 0 first_distance = 0 - var neighbor_count: = proximity.find_neighbors(_callback) + var neighbor_count := proximity.find_neighbors(_callback) if neighbor_count == 0 or not first_neighbor: acceleration.set_zero() @@ -39,9 +39,9 @@ func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAccele func report_neighbor(neighbor: GSTSteeringAgent) -> bool: - var relative_position: = neighbor.position - agent.position - var relative_velocity: = neighbor.linear_velocity - agent.linear_velocity - var relative_speed_squared: = relative_velocity.length_squared() + var relative_position := neighbor.position - agent.position + var relative_velocity := neighbor.linear_velocity - agent.linear_velocity + var relative_speed_squared := relative_velocity.length_squared() if relative_speed_squared == 0: return false diff --git a/project/src/behaviors/GSTBlend.gd b/project/src/Behaviors/GSTBlend.gd similarity index 95% rename from project/src/behaviors/GSTBlend.gd rename to project/src/Behaviors/GSTBlend.gd index 67f5899..310c6fa 100644 --- a/project/src/behaviors/GSTBlend.gd +++ b/project/src/Behaviors/GSTBlend.gd @@ -9,8 +9,8 @@ class_name GSTBlend # `GSTSteeringBehavior` and a `weight` key with a value of type float. -var _behaviors: = [] -var _accel: = GSTTargetAcceleration.new() +var _behaviors := [] +var _accel := GSTTargetAcceleration.new() func _init(agent: GSTSteeringAgent).(agent) -> void: diff --git a/project/src/behaviors/GSTCohesion.gd b/project/src/Behaviors/GSTCohesion.gd similarity index 100% rename from project/src/behaviors/GSTCohesion.gd rename to project/src/Behaviors/GSTCohesion.gd diff --git a/project/src/behaviors/GSTEvade.gd b/project/src/Behaviors/GSTEvade.gd similarity index 85% rename from project/src/behaviors/GSTEvade.gd rename to project/src/Behaviors/GSTEvade.gd index ce89767..b8448fd 100644 --- a/project/src/behaviors/GSTEvade.gd +++ b/project/src/Behaviors/GSTEvade.gd @@ -8,7 +8,7 @@ class_name GSTEvade func _init( agent: GSTSteeringAgent, target: GSTSteeringAgent, - max_predict_time: = 1.0).(agent, target, max_predict_time): + max_predict_time := 1.0).(agent, target, max_predict_time): pass diff --git a/project/src/behaviors/GSTFace.gd b/project/src/Behaviors/GSTFace.gd similarity index 88% rename from project/src/behaviors/GSTFace.gd rename to project/src/Behaviors/GSTFace.gd index 7a5c3dd..853acaa 100644 --- a/project/src/behaviors/GSTFace.gd +++ b/project/src/Behaviors/GSTFace.gd @@ -9,8 +9,8 @@ func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent, target) -> func _face(acceleration: GSTTargetAcceleration, target_position: Vector3) -> GSTTargetAcceleration: - var to_target: = target_position - agent.position - var distance_squared: = to_target.length_squared() + var to_target := target_position - agent.position + var distance_squared := to_target.length_squared() if distance_squared < agent.zero_linear_speed_threshold: acceleration.set_zero() diff --git a/project/src/behaviors/GSTFlee.gd b/project/src/Behaviors/GSTFlee.gd similarity index 100% rename from project/src/behaviors/GSTFlee.gd rename to project/src/Behaviors/GSTFlee.gd diff --git a/project/src/behaviors/GSTFollowPath.gd b/project/src/Behaviors/GSTFollowPath.gd similarity index 72% rename from project/src/behaviors/GSTFollowPath.gd rename to project/src/Behaviors/GSTFollowPath.gd index 49699a3..7acaaa9 100644 --- a/project/src/behaviors/GSTFollowPath.gd +++ b/project/src/Behaviors/GSTFollowPath.gd @@ -4,33 +4,33 @@ class_name GSTFollowPath var path: GSTPath -var path_offset: = 0.0 +var path_offset := 0.0 -var path_param: = {} +var path_param := {} -var arrive_enabled: = true -var prediction_time: = 0.0 +var arrive_enabled := true +var prediction_time := 0.0 func _init( agent: GSTSteeringAgent, path: GSTPath, - path_offset: = 0.0, - prediction_time: = 0.0).(agent, null) -> void: + path_offset := 0.0, + prediction_time := 0.0).(agent, null) -> void: self.path = path self.path_offset = path_offset self.prediction_time = prediction_time func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAcceleration: - var location: = ( + var location := ( agent.position if prediction_time == 0 else agent.position + (agent.linear_velocity * prediction_time)) - var distance: = path.calculate_distance(location, path_param) - var target_distance: = distance + path_offset + var distance := path.calculate_distance(location, path_param) + var target_distance := distance + path_offset - var target_position: = path.calculate_target_position(path_param, target_distance) + var target_position := path.calculate_target_position(path_param, target_distance) if arrive_enabled and path.is_open: if path_offset >= 0: diff --git a/project/src/behaviors/GSTLookWhereYouGo.gd b/project/src/Behaviors/GSTLookWhereYouGo.gd similarity index 88% rename from project/src/behaviors/GSTLookWhereYouGo.gd rename to project/src/Behaviors/GSTLookWhereYouGo.gd index 058becf..9c03af4 100644 --- a/project/src/behaviors/GSTLookWhereYouGo.gd +++ b/project/src/Behaviors/GSTLookWhereYouGo.gd @@ -12,5 +12,5 @@ func _calculate_steering(accel: GSTTargetAcceleration) -> GSTTargetAcceleration: accel.set_zero() return accel else: - var orientation: = atan2(agent.linear_velocity.x, -agent.linear_velocity.y) + var orientation := atan2(agent.linear_velocity.x, -agent.linear_velocity.y) return _match_orientation(accel, orientation) diff --git a/project/src/behaviors/GSTMatchOrientation.gd b/project/src/Behaviors/GSTMatchOrientation.gd similarity index 85% rename from project/src/behaviors/GSTMatchOrientation.gd rename to project/src/Behaviors/GSTMatchOrientation.gd index 8185dc9..ac89974 100644 --- a/project/src/behaviors/GSTMatchOrientation.gd +++ b/project/src/Behaviors/GSTMatchOrientation.gd @@ -15,14 +15,14 @@ func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void: func _match_orientation(acceleration: GSTTargetAcceleration, desired_orientation: float) -> GSTTargetAcceleration: - var rotation: = wrapf(desired_orientation - agent.orientation, -PI, PI) + var rotation := wrapf(desired_orientation - agent.orientation, -PI, PI) - var rotation_size: = abs(rotation) + var rotation_size := abs(rotation) if rotation_size <= alignment_tolerance: acceleration.set_zero() else: - var desired_rotation: = agent.max_angular_speed + var desired_rotation := agent.max_angular_speed if rotation_size <= deceleration_radius: desired_rotation *= rotation_size / deceleration_radius @@ -31,7 +31,7 @@ func _match_orientation(acceleration: GSTTargetAcceleration, desired_orientation acceleration.angular = (desired_rotation - agent.angular_velocity) / time_to_reach - var limited_acceleration: = abs(acceleration.angular) + var limited_acceleration := abs(acceleration.angular) if limited_acceleration > agent.max_angular_acceleration: acceleration.angular *= agent.max_angular_acceleration / limited_acceleration diff --git a/project/src/behaviors/GSTPriority.gd b/project/src/Behaviors/GSTPriority.gd similarity index 84% rename from project/src/behaviors/GSTPriority.gd rename to project/src/Behaviors/GSTPriority.gd index 4cb84df..cbe91ea 100644 --- a/project/src/behaviors/GSTPriority.gd +++ b/project/src/Behaviors/GSTPriority.gd @@ -4,13 +4,13 @@ class_name GSTPriority # acceleration. -var _behaviors: = [] +var _behaviors := [] var last_selected_index: int var threshold_for_zero: float -func _init(agent: GSTSteeringAgent, threshold_for_zero: = 0.001).(agent) -> void: +func _init(agent: GSTSteeringAgent, threshold_for_zero := 0.001).(agent) -> void: self.threshold_for_zero = threshold_for_zero @@ -26,11 +26,11 @@ func get_behavior_at(index: int) -> GSTSteeringBehavior: func _calculate_steering(accel: GSTTargetAcceleration) -> GSTTargetAcceleration: - var threshold_squared: = threshold_for_zero * threshold_for_zero + var threshold_squared := threshold_for_zero * threshold_for_zero last_selected_index = -1 - var size: = _behaviors.size() + var size := _behaviors.size() if size > 0: for i in range(size): diff --git a/project/src/behaviors/GSTPursue.gd b/project/src/Behaviors/GSTPursue.gd similarity index 75% rename from project/src/behaviors/GSTPursue.gd rename to project/src/Behaviors/GSTPursue.gd index 84b2efd..1e0f53b 100644 --- a/project/src/behaviors/GSTPursue.gd +++ b/project/src/Behaviors/GSTPursue.gd @@ -12,20 +12,20 @@ var max_predict_time: float func _init( agent: GSTSteeringAgent, target: GSTSteeringAgent, - max_predict_time: = 1.0).(agent) -> void: + max_predict_time := 1.0).(agent) -> void: self.target = target self.max_predict_time = max_predict_time func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAcceleration: - var target_position: = target.position - var distance_squared: = (target_position - agent.position).length_squared() + var target_position := target.position + var distance_squared := (target_position - agent.position).length_squared() - var speed_squared: = agent.linear_velocity.length_squared() - var predict_time: = max_predict_time + var speed_squared := agent.linear_velocity.length_squared() + var predict_time := max_predict_time if speed_squared > 0: - var predict_time_squared: = distance_squared / speed_squared + var predict_time_squared := distance_squared / speed_squared if predict_time_squared < max_predict_time * max_predict_time: predict_time = sqrt(predict_time_squared) diff --git a/project/src/behaviors/GSTSeek.gd b/project/src/Behaviors/GSTSeek.gd similarity index 100% rename from project/src/behaviors/GSTSeek.gd rename to project/src/Behaviors/GSTSeek.gd diff --git a/project/src/behaviors/GSTSeparation.gd b/project/src/Behaviors/GSTSeparation.gd similarity index 80% rename from project/src/behaviors/GSTSeparation.gd rename to project/src/Behaviors/GSTSeparation.gd index 9d9a573..7aa6692 100644 --- a/project/src/behaviors/GSTSeparation.gd +++ b/project/src/Behaviors/GSTSeparation.gd @@ -8,7 +8,7 @@ class_name GSTSeparation # # In effect, all neighbors produce a single repelling force. -var decay_coefficient: = 1.0 +var decay_coefficient := 1.0 var acceleration: GSTTargetAcceleration @@ -25,12 +25,12 @@ func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAccele func report_neighbor(neighbor: GSTSteeringAgent) -> bool: - var to_agent: = agent.position - neighbor.position + var to_agent := agent.position - neighbor.position - var distance_squared: = to_agent.length_squared() - var max_acceleration: = agent.max_linear_acceleration + var distance_squared := to_agent.length_squared() + var max_acceleration := agent.max_linear_acceleration - var strength: = decay_coefficient / distance_squared + var strength := decay_coefficient / distance_squared if strength > max_acceleration: strength = max_acceleration diff --git a/project/src/GSTAgentLocation.gd b/project/src/GSTAgentLocation.gd index df804c5..9a6261e 100644 --- a/project/src/GSTAgentLocation.gd +++ b/project/src/GSTAgentLocation.gd @@ -2,5 +2,5 @@ class_name GSTAgentLocation # Data type to represent an agent with a location and an orientation -var position: = Vector3.ZERO -var orientation: = 0.0 +var position := Vector3.ZERO +var orientation := 0.0 diff --git a/project/src/GSTGroupBehavior.gd b/project/src/GSTGroupBehavior.gd index 5a38843..6e98159 100644 --- a/project/src/GSTGroupBehavior.gd +++ b/project/src/GSTGroupBehavior.gd @@ -5,7 +5,7 @@ class_name GSTGroupBehavior var proximity: GSTProximity -var _callback: = funcref(self, "report_neighbor") +var _callback := funcref(self, "report_neighbor") func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent) -> void: diff --git a/project/src/GSTPath.gd b/project/src/GSTPath.gd index 4277025..58e1665 100644 --- a/project/src/GSTPath.gd +++ b/project/src/GSTPath.gd @@ -15,7 +15,7 @@ var _nearest_point_on_segment: Vector3 var _nearest_point_on_path: Vector3 -func _init(waypoints: Array, is_open: = false) -> void: +func _init(waypoints: Array, is_open := false) -> void: self.is_open = is_open create_path(waypoints) _nearest_point_on_segment = waypoints[0] @@ -39,7 +39,7 @@ func create_path(waypoints: Array) -> void: break else: current = waypoints[0] - var segment: = GSTSegment.new(previous, current) + var segment := GSTSegment.new(previous, current) path_length += segment.length segment.cumulative_length = path_length _segments.append(segment) @@ -50,7 +50,7 @@ func calculate_distance(agent_current_position: Vector3, path_parameter: Diction var nearest_segment: GSTSegment for i in range(_segments.size()): var segment: GSTSegment = _segments[i] - var distance_squared: = _calculate_point_segment_distance_squared( + var distance_squared := _calculate_point_segment_distance_squared( segment.begin, segment.end, agent_current_position) @@ -61,7 +61,7 @@ func calculate_distance(agent_current_position: Vector3, path_parameter: Diction nearest_segment = segment path_parameter.segment_index = i - var length_on_path: = ( + var length_on_path := ( nearest_segment.cumulative_length - _nearest_point_on_path.distance_to(nearest_segment.end)) @@ -86,7 +86,7 @@ func calculate_target_position(param: Dictionary, target_distance: float) -> Vec desired_segment = segment break - var distance: = desired_segment.cumulative_length - target_distance + var distance := desired_segment.cumulative_length - target_distance return ( (desired_segment.begin - desired_segment.end) * @@ -103,8 +103,8 @@ func get_end_point() -> Vector3: func _calculate_point_segment_distance_squared(start: Vector3, end: Vector3, position: Vector3) -> float: _nearest_point_on_segment = start - var start_end: = end - start - var start_end_length_squared: = start_end.length_squared() + var start_end := end - start + var start_end_length_squared := start_end.length_squared() if start_end_length_squared != 0: var t = (position - start).dot(start_end) / start_end_length_squared _nearest_point_on_segment += start_end * clamp(t, 0, 1) diff --git a/project/src/GSTSteeringAgent.gd b/project/src/GSTSteeringAgent.gd index 68c787a..55f5347 100644 --- a/project/src/GSTSteeringAgent.gd +++ b/project/src/GSTSteeringAgent.gd @@ -3,12 +3,12 @@ class_name GSTSteeringAgent # Extended agent data type that adds velocity, speed, and size data -var zero_linear_speed_threshold: = 0.01 -var max_linear_speed: = 0.0 -var max_linear_acceleration: = 0.0 -var max_angular_speed: = 0.0 -var max_angular_acceleration: = 0.0 -var linear_velocity: = Vector3.ZERO -var angular_velocity: = 0.0 -var bounding_radius: = 0.0 -var tagged: = false +var zero_linear_speed_threshold := 0.01 +var max_linear_speed := 0.0 +var max_linear_acceleration := 0.0 +var max_angular_speed := 0.0 +var max_angular_acceleration := 0.0 +var linear_velocity := Vector3.ZERO +var angular_velocity := 0.0 +var bounding_radius := 0.0 +var tagged := false diff --git a/project/src/GSTSteeringBehavior.gd b/project/src/GSTSteeringBehavior.gd index 961c49a..b8ac9e0 100644 --- a/project/src/GSTSteeringBehavior.gd +++ b/project/src/GSTSteeringBehavior.gd @@ -2,7 +2,7 @@ class_name GSTSteeringBehavior # Base class to calculate how an AI agent steers itself. -var enabled: = true +var enabled := true var agent: GSTSteeringAgent diff --git a/project/src/GSTTargetAcceleration.gd b/project/src/GSTTargetAcceleration.gd index a9caccf..4a6c74b 100644 --- a/project/src/GSTTargetAcceleration.gd +++ b/project/src/GSTTargetAcceleration.gd @@ -2,8 +2,8 @@ class_name GSTTargetAcceleration # A linear and angular amount of acceleration. -var linear: = Vector3.ZERO -var angular: = 0.0 +var linear := Vector3.ZERO +var angular := 0.0 func set_zero() -> void: diff --git a/project/src/GSTUtils.gd b/project/src/GSTUtils.gd index b366ff5..f63caf1 100644 --- a/project/src/GSTUtils.gd +++ b/project/src/GSTUtils.gd @@ -3,8 +3,8 @@ class_name GSTUtils static func clampedv3(vector: Vector3, limit: float) -> Vector3: - var length_squared: = vector.length_squared() - var limit_squared: = limit * limit + var length_squared := vector.length_squared() + var limit_squared := limit * limit if length_squared > limit_squared: vector *= sqrt(limit_squared / length_squared) return vector diff --git a/project/src/proximities/GSTInfiniteProximity.gd b/project/src/Proximities/GSTInfiniteProximity.gd similarity index 79% rename from project/src/proximities/GSTInfiniteProximity.gd rename to project/src/Proximities/GSTInfiniteProximity.gd index 0dd9b17..f873ee4 100644 --- a/project/src/proximities/GSTInfiniteProximity.gd +++ b/project/src/Proximities/GSTInfiniteProximity.gd @@ -8,10 +8,10 @@ func _init(agent: GSTSteeringAgent, agents: Array).(agent, agents) -> void: func find_neighbors(callback: FuncRef) -> int: - var neighbor_count: = 0 - var agent_count: = agents.size() + var neighbor_count := 0 + var agent_count := agents.size() for i in range(agent_count): - var current_agent: = agents[i] as GSTSteeringAgent + var current_agent := agents[i] as GSTSteeringAgent if current_agent != agent: if callback.call_func(current_agent): diff --git a/project/src/proximities/GSTProximity.gd b/project/src/Proximities/GSTProximity.gd similarity index 95% rename from project/src/proximities/GSTProximity.gd rename to project/src/Proximities/GSTProximity.gd index f746410..df40908 100644 --- a/project/src/proximities/GSTProximity.gd +++ b/project/src/Proximities/GSTProximity.gd @@ -5,7 +5,7 @@ class_name GSTProximity var agent: GSTSteeringAgent -var agents: = [] +var agents := [] func _init(agent: GSTSteeringAgent, agents: Array) -> void: diff --git a/project/src/proximities/GSTRadiusProximity.gd b/project/src/Proximities/GSTRadiusProximity.gd similarity index 73% rename from project/src/proximities/GSTRadiusProximity.gd rename to project/src/Proximities/GSTRadiusProximity.gd index 300fd11..511f8c0 100644 --- a/project/src/proximities/GSTRadiusProximity.gd +++ b/project/src/Proximities/GSTRadiusProximity.gd @@ -4,9 +4,9 @@ class_name GSTRadiusProximity # they lie within the specified radius. -var radius: = 0.0 +var radius := 0.0 -var _last_frame: = 0 +var _last_frame := 0 var _scene_tree: SceneTree @@ -16,22 +16,22 @@ func _init(agent: GSTSteeringAgent, agents: Array, radius: float).(agent, agents func find_neighbors(callback: FuncRef) -> int: - var agent_count: = agents.size() - var neighbor_count: = 0 + var agent_count := agents.size() + var neighbor_count := 0 - var current_frame: = _scene_tree.get_frame() if _scene_tree else -_last_frame + var current_frame := _scene_tree.get_frame() if _scene_tree else -_last_frame if current_frame != _last_frame: _last_frame = current_frame - var owner_position: = agent.position + var owner_position := agent.position for i in range(agent_count): - var current_agent: = agents[i] as GSTSteeringAgent + var current_agent := agents[i] as GSTSteeringAgent if current_agent != agent: - var distance_squared: = owner_position.distance_squared_to(current_agent.position) + var distance_squared := owner_position.distance_squared_to(current_agent.position) - var range_to: = radius + current_agent.bounding_radius + var range_to := radius + current_agent.bounding_radius if distance_squared < range_to * range_to: if callback.call_func(current_agent):