player panel style

main
Benjamin Kraft 1 year ago
parent 94ef5fddfa
commit 0148e46c92
  1. 39
      Assets/Scripts/Game/AIPlayer.cs
  2. 4
      Assets/Scripts/Game/Player.cs
  3. 18
      Assets/Scripts/Game/RealPlayer.cs
  4. 2
      Assets/Scripts/GameUI.cs
  5. 10
      Assets/UI Toolkit/player_panel.uss
  6. 6
      ProjectSettings/ProjectSettings.asset

@ -1,5 +1,6 @@
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.UIElements;
namespace Game { namespace Game {
@ -10,6 +11,8 @@ namespace Game {
private bool isApproaching; private bool isApproaching;
private float lastDirection; private float lastDirection;
private bool lastGoingLeft, lastGoingRight;
private Label leftButton, rightButton;
public Difficulty Difficulty { get; set; } public Difficulty Difficulty { get; set; }
@ -19,25 +22,51 @@ namespace Game {
private float DistortAmount => 1 - 1 / ((float) Difficulty + 1); private float DistortAmount => 1 - 1 / ((float) Difficulty + 1);
protected new void Start() {
base.Start();
leftButton = GameUI.Singleton.GetGoButton(Side, "left");
rightButton = GameUI.Singleton.GetGoButton(Side, "right");
}
private void FixedUpdate() { private void FixedUpdate() {
var dt = Time.fixedDeltaTime; var dt = Time.fixedDeltaTime;
var target = GetTargetPosition(); var target = GetTargetPosition();
var h = Mathf.Max(Speed * dt, Width / 2); var h = Mathf.Max(Speed * dt, Width / 2);
goingLeft = target < X - h; goingLeftLinear = target < X - h;
goingRight = target > X + h; goingRightLinear = target > X + h;
if (goingLeft || goingRight) { if (goingLeftLinear || goingRightLinear) {
isApproaching = false; isApproaching = false;
lastDirection = goingLeft ? -1 : 1; lastDirection = goingLeftLinear ? -1 : 1;
TryLinearMove(dt); TryLinearMove(dt);
} else { } else {
if (!isApproaching) { if (!isApproaching) {
isApproaching = true; isApproaching = true;
currentSmoothV = Speed * lastDirection; currentSmoothV = Speed * lastDirection;
} }
ApproachPosition(target); ApproachPosition(target);
} }
bool goingLeft = isApproaching ? currentSmoothV < 0 : goingLeftLinear;
bool goingRight = isApproaching ? currentSmoothV > 0 : goingRightLinear;
switch (lastGoingLeft) {
case false when goingLeft:
break;
case true when !goingLeft:
break;
}
switch (lastGoingRight) {
case false when goingRight:
break;
case true when !goingRight:
break;
}
lastGoingLeft = goingLeft;
lastGoingRight = goingRight;
} }
// True if ball y velocity points towards player // True if ball y velocity points towards player

@ -27,7 +27,7 @@ namespace Game {
private const float BaseWidth = 6; private const float BaseWidth = 6;
private const float WidthMultiplier = 1.5f; private const float WidthMultiplier = 1.5f;
protected bool goingLeft, goingRight; protected bool goingLeftLinear, goingRightLinear;
public Side Side { get; set; } public Side Side { get; set; }
@ -145,7 +145,7 @@ namespace Game {
} }
protected void TryLinearMove(float h) { protected void TryLinearMove(float h) {
var trans = new Vector2((goingLeft ? -1 : 0) + (goingRight ? 1 : 0), 0); var trans = new Vector2((goingLeftLinear ? -1 : 0) + (goingRightLinear ? 1 : 0), 0);
trans *= Speed * h; trans *= Speed * h;
transform.Translate(trans, Space.World); transform.Translate(trans, Space.World);
ClampInsideBorders(); ClampInsideBorders();

@ -7,21 +7,23 @@ namespace Game {
private new void Start() { private new void Start() {
base.Start(); base.Start();
if (!isThisClient)
return;
GameUI.Singleton.buttonDown += (side, direction) => { GameUI.Singleton.buttonDown += (side, direction) => {
if (!side.Equals(Side)) if (!side.Equals(Side))
return; return;
if (direction == "left") if (direction == "left")
goingLeft = true; goingLeftLinear = true;
else else
goingRight = true; goingRightLinear = true;
}; };
GameUI.Singleton.buttonUp += (side, direction) => { GameUI.Singleton.buttonUp += (side, direction) => {
if (!side.Equals(Side)) if (!side.Equals(Side))
return; return;
if (direction == "left") if (direction == "left")
goingLeft = false; goingLeftLinear = false;
else else
goingRight = false; goingRightLinear = false;
}; };
} }
@ -33,12 +35,12 @@ namespace Game {
var keyboard = Keyboard.current; var keyboard = Keyboard.current;
switch (Side) { switch (Side) {
case Side.Top: case Side.Top:
goingLeft = keyboard.leftArrowKey.isPressed; goingLeftLinear = keyboard.leftArrowKey.isPressed;
goingRight = keyboard.rightArrowKey.isPressed; goingRightLinear = keyboard.rightArrowKey.isPressed;
break; break;
case Side.Bottom: case Side.Bottom:
goingLeft = keyboard.aKey.isPressed; goingLeftLinear = keyboard.aKey.isPressed;
goingRight = keyboard.dKey.isPressed; goingRightLinear = keyboard.dKey.isPressed;
break; break;
} }
} }

@ -62,7 +62,7 @@ public class GameUI : MonoBehaviour {
SetupGoButton(Side.Bottom, "right"); SetupGoButton(Side.Bottom, "right");
} }
private Label GetGoButton(Side sideVertical, string sideHorizontal) { public Label GetGoButton(Side sideVertical, string sideHorizontal) {
return PlayerPanel(sideVertical).Q<Label>("go_" + sideHorizontal); return PlayerPanel(sideVertical).Q<Label>("go_" + sideHorizontal);
} }

@ -6,10 +6,10 @@
border-right-color: rgb(141, 157, 255); border-right-color: rgb(141, 157, 255);
border-top-color: rgb(141, 157, 255); border-top-color: rgb(141, 157, 255);
border-bottom-color: rgb(141, 157, 255); border-bottom-color: rgb(141, 157, 255);
border-left-width: 3px; border-left-width: 7px;
border-right-width: 3px; border-right-width: 7px;
border-top-width: 3px; border-top-width: 7px;
border-bottom-width: 3px; border-bottom-width: 7px;
border-top-left-radius: 15px; border-top-left-radius: 15px;
border-bottom-left-radius: 15px; border-bottom-left-radius: 15px;
border-top-right-radius: 15px; border-top-right-radius: 15px;
@ -18,7 +18,7 @@
margin-right: 10px; margin-right: 10px;
margin-top: 10px; margin-top: 10px;
margin-bottom: 10px; margin-bottom: 10px;
background-color: rgb(91, 91, 91); background-color: rgba(91, 91, 91, 0.49);
flex-grow: 1; flex-grow: 1;
} }

@ -134,7 +134,7 @@ PlayerSettings:
16:10: 1 16:10: 1
16:9: 1 16:9: 1
Others: 1 Others: 1
bundleVersion: 1.0.2 bundleVersion: 1.0.3
preloadedAssets: [] preloadedAssets: []
metroInputSource: 0 metroInputSource: 0
wsaTransparentSwapchain: 0 wsaTransparentSwapchain: 0
@ -165,8 +165,8 @@ PlayerSettings:
iPhone: 0 iPhone: 0
tvOS: 0 tvOS: 0
overrideDefaultApplicationIdentifier: 0 overrideDefaultApplicationIdentifier: 0
AndroidBundleVersionCode: 10 AndroidBundleVersionCode: 11
AndroidMinSdkVersion: 24 AndroidMinSdkVersion: 26
AndroidTargetSdkVersion: 33 AndroidTargetSdkVersion: 33
AndroidPreferredInstallLocation: 1 AndroidPreferredInstallLocation: 1
aotOptions: aotOptions:

Loading…
Cancel
Save