58 lines
1.4 KiB
C#
58 lines
1.4 KiB
C#
using System;
|
|
using Hazel;
|
|
|
|
namespace Sandbox {
|
|
|
|
public class Camera : Entity
|
|
{
|
|
// private TransformComponent m_Transform;
|
|
// private RigidBody2DComponent m_Rigidbody;
|
|
|
|
public float MoveSpeed;
|
|
public float DistanceFromPlayer = 5;
|
|
|
|
private Entity m_Player;
|
|
|
|
void OnCreate()
|
|
{
|
|
Console.WriteLine($"Camera.OnCreate - {ID}");
|
|
|
|
m_Player = FindEntityByName("Player");
|
|
}
|
|
|
|
|
|
void OnUpdate(float ts)
|
|
{
|
|
if(m_Player != null)
|
|
{
|
|
Translation = new Vector3(m_Player.Translation.XY, DistanceFromPlayer);
|
|
}
|
|
// Console.WriteLine($"Player.OnUpdate: {ts}");
|
|
|
|
float speed = MoveSpeed;
|
|
Vector3 velocity = Vector3.Zero;
|
|
|
|
if(Input.IsKeyDown(KeyCode.UP))
|
|
velocity.Y = 1.0f;
|
|
else if(Input.IsKeyDown(KeyCode.DOWN))
|
|
velocity.Y = -1.0f;
|
|
|
|
if(Input.IsKeyDown(KeyCode.LEFT))
|
|
velocity.X = -1.0f;
|
|
else if(Input.IsKeyDown(KeyCode.RIGHT))
|
|
velocity.X = 1.0f;
|
|
|
|
// m_Rigidbody.ApplyLinearImpulse(velocity.XY * speed, Vector2.Zero, true);
|
|
|
|
velocity *= speed;
|
|
|
|
Vector3 translation = Translation;
|
|
translation += velocity * ts;
|
|
Translation = translation;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|