Fine tune movement, added looping screen

This commit is contained in:
maximus 2023-11-20 03:27:16 +00:00
parent abc2bb3379
commit 94f51b7c23
2 changed files with 30 additions and 6 deletions

View file

@ -1,3 +1,9 @@
[gd_scene format=3 uid="uid://635xs5haibcn"] [gd_scene load_steps=2 format=3 uid="uid://635xs5haibcn"]
[ext_resource type="PackedScene" uid="uid://ckh362yqjkpi0" path="res://scenes/Player.tscn" id="1_1w06w"]
[node name="Game" type="Node2D"] [node name="Game" type="Node2D"]
[node name="Player" parent="." instance=ExtResource("1_1w06w")]
position = Vector2(800, 450)
scale = Vector2(0.6, 0.6)

View file

@ -5,10 +5,12 @@ public partial class player : CharacterBody2D
{ {
[Export] [Export]
public Vector2 ScreenSize; public Vector2 ScreenSize;
[Export] [Export]
public int Speed { get; set; } = 10; public int MaxSpeed { get; set;} = 300;
[Export]
public int MainSpeed { get; set; } = 10;
[Export]
public int StrafeSpeed { get; set; } = 4;
[Export] [Export]
public float RotationSpeed { get; set; } = 2f; public float RotationSpeed { get; set; } = 2f;
@ -19,18 +21,34 @@ public partial class player : CharacterBody2D
Velocity = Transform.X * Input.GetAxis("down", "up") * Speed; Velocity = Transform.X * Input.GetAxis("down", "up") * Speed;
*/ */
// Movement, could probably move into its own methods instead of GetInput()
_rotationDirection = (int)Input.GetAxis("left", "right"); _rotationDirection = (int)Input.GetAxis("left", "right");
Velocity += (Transform.Y * Input.GetAxis("strafe_left", "strafe_right") + Transform.X * Input.GetAxis("down", "up")) * Speed; Velocity += (Transform.Y * Input.GetAxis("strafe_left", "strafe_right") * StrafeSpeed) + (Transform.X * Input.GetAxis("down", "up") * MainSpeed);
Velocity = Velocity.LimitLength(MaxSpeed);
if(Input.GetAxis("strafe_left", "strafe_right") == 0){
Velocity = Velocity.MoveToward(Vector2.Zero, 1.5f);
}
else if(Input.GetAxis("down", "up") == 0){
Velocity = Velocity.MoveToward(Vector2.Zero, 1.5f);
}
} }
public override void _Ready(){ // on init public override void _Ready(){ // on init
GD.Print("afa"); GD.Print(GetViewportRect().Size);
ScreenSize = GetViewportRect().Size; ScreenSize = GetViewportRect().Size;
} }
public override void _PhysicsProcess(double delta){ // every frame public override void _PhysicsProcess(double delta){ // every frame
GetInput(); GetInput();
Rotation += _rotationDirection * RotationSpeed * (float)delta; Rotation += _rotationDirection * RotationSpeed * (float)delta;
Velocity.LimitLength(MaxSpeed);
MoveAndSlide(); MoveAndSlide();
if (Position.Y < 0) {Position = new Vector2(Position.X, ScreenSize.Y);}
if (Position.Y > ScreenSize.Y) {Position = new Vector2(Position.X, 0);}
if (Position.X < 0) { Position = new Vector2(ScreenSize.X, Position.Y);}
if (Position.X > ScreenSize.X) { Position = new Vector2(0, Position.Y);}
} }
} }