72 lines
1.9 KiB
C#
72 lines
1.9 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class player : Camera3D
|
|
{
|
|
private const string _path = "/root/player/";
|
|
//private Camera3D _cam;
|
|
[Export]
|
|
private Label _con;
|
|
private Vector2 _screen;
|
|
private bool _mUp, _mDown, _mLeft, _mRight, _wIn, _wOut;
|
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
public override void _Ready()
|
|
{
|
|
//_cam = GetNode<Camera3D>(_path + "Camera3D");
|
|
//_con = GetNode<Label>(_path + "Camera3D/Label");
|
|
}
|
|
|
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
public override void _Process(double delta)
|
|
{
|
|
Vector3 rot = this.Rotation;
|
|
bool zin = true, zout = true;
|
|
|
|
this.Rotation -= rot;
|
|
if (this.Position.Y < 5)
|
|
zin = false;
|
|
else if (this.Position.Y > 20)
|
|
zout = false;
|
|
if (_mLeft && this.Position.X > -30)
|
|
this.Translate(new Vector3((float)-delta*10, 0, 0));
|
|
if (_mRight && this.Position.X < 30)
|
|
this.Translate(new Vector3((float)delta*10, 0, 0));
|
|
if (_mUp && this.Position.Z > -25)
|
|
this.Translate(new Vector3(0, 0, (float)-delta*10));
|
|
if (_mDown && this.Position.Z < 25)
|
|
this.Translate(new Vector3(0, 0, (float)delta*10));
|
|
this.Rotation += rot;
|
|
|
|
if (_wIn && zin)
|
|
this.Translate(new Vector3(0, 0, (float)-delta*10));
|
|
if (_wOut && zout)
|
|
this.Translate(new Vector3(0, 0, (float)delta*10));
|
|
|
|
_con.Set("text", this.Position);
|
|
}
|
|
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
_mLeft = _mRight = _mUp = _mDown = _wIn = _wOut = false;
|
|
|
|
if (@event is InputEventMouseMotion mouse) {
|
|
Vector2 vec = mouse.Position;
|
|
if (vec.X < 5)
|
|
_mLeft = true;
|
|
else if (vec.X > 1915)
|
|
_mRight = true;
|
|
if (vec.Y < 20)
|
|
_mUp = true;
|
|
else if (vec.Y > 1060)
|
|
_mDown = true;
|
|
}
|
|
else if (@event is InputEventMouseButton mousebtn) {
|
|
if (mousebtn.ButtonIndex == MouseButton.WheelUp)
|
|
_wIn = true;
|
|
else if (mousebtn.ButtonIndex == MouseButton.WheelDown)
|
|
_wOut = true;
|
|
}
|
|
}
|
|
}
|