Added the World Added Mobs, and spawning those mobs at runtime Added simple camera movement Added simple UI/HUD
103 lines
2.7 KiB
C#
103 lines
2.7 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class BaseEntity : Area2D
|
|
{
|
|
[Signal]
|
|
public delegate BaseEntity EntitySelectedEventHandler();
|
|
|
|
[Signal]
|
|
public delegate BaseEntity EntityDeselectedEventHandler();
|
|
|
|
protected Vector2 ScreenSize;
|
|
protected AnimationPlayer animationPlayer;
|
|
protected Sprite2D sprite;
|
|
protected CollisionShape2D collisionShape;
|
|
|
|
protected bool selected;
|
|
|
|
|
|
public override void _Ready()
|
|
{
|
|
ScreenSize = GetViewportRect().Size;
|
|
|
|
sprite = GetNode<Sprite2D>("Sprite2D");
|
|
collisionShape = GetNode<CollisionShape2D>("CollisionShape2D");
|
|
animationPlayer = sprite.GetNode<AnimationPlayer>("AnimationPlayer");
|
|
}
|
|
|
|
public override void _UnhandledInput(InputEvent @event)
|
|
{
|
|
if (@event is InputEventMouseButton mouseEvent)
|
|
{
|
|
if (mouseEvent.IsPressed() && !mouseEvent.IsEcho())
|
|
{
|
|
switch (mouseEvent.ButtonIndex)
|
|
{
|
|
case MouseButton.Left:
|
|
if (collisionShape.Shape.GetRect().HasPoint(GetLocalMousePosition())) entitySelected();
|
|
else if (selected) entityDeselected();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void entitySelected()
|
|
{
|
|
selected = true;
|
|
GD.Print("Selected");
|
|
GetNode<Sprite2D>("SelectedSprite2D").Visible = true;
|
|
EmitSignalEntitySelected();
|
|
|
|
ShowInfo();
|
|
}
|
|
|
|
protected void entityDeselected()
|
|
{
|
|
selected = false;
|
|
GD.Print("Unselected");
|
|
GetNode<Sprite2D>("SelectedSprite2D").Visible = false;
|
|
|
|
EmitSignalEntityDeselected();
|
|
|
|
HideInfo();
|
|
|
|
}
|
|
|
|
protected void ShowInfo()
|
|
{
|
|
MarginContainer marginContainer = GetNode<MarginContainer>("MarginContainer");
|
|
Label nameLabel = GetNode<Label>("MarginContainer/VBoxContainer/Label");
|
|
Label positionLabel = GetNode<Label>("MarginContainer/VBoxContainer/Label2");
|
|
|
|
nameLabel.Text = $"Name: {Name}";
|
|
positionLabel.Text = $"Position: {Position}";
|
|
|
|
marginContainer.Show();
|
|
}
|
|
|
|
protected void HideInfo()
|
|
{
|
|
MarginContainer marginContainer = GetNode<MarginContainer>("MarginContainer");
|
|
marginContainer.Hide();
|
|
}
|
|
|
|
// public override void _MouseEnter()
|
|
// {
|
|
// GD.Print("MouseEnter");
|
|
//
|
|
// if (Input.IsMouseButtonPressed(MouseButton.Left))
|
|
// {
|
|
// GD.Print("Selected");
|
|
// selected = true;
|
|
// }
|
|
// }
|
|
|
|
public virtual void Create()
|
|
{
|
|
return;
|
|
}
|
|
} |