Version 0.1 - 0.3.1
Added the World Added Mobs, and spawning those mobs at runtime Added simple camera movement Added simple UI/HUD
This commit is contained in:
103
scenes/entities/BaseEntity.cs
Normal file
103
scenes/entities/BaseEntity.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
1
scenes/entities/BaseEntity.cs.uid
Normal file
1
scenes/entities/BaseEntity.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b3o37f05w3fva
|
||||
51
scenes/entities/BaseEntity.tscn
Normal file
51
scenes/entities/BaseEntity.tscn
Normal file
@@ -0,0 +1,51 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://b0q03xfp1iy6t"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b3o37f05w3fva" path="res://scenes/entities/BaseEntity.cs" id="1_jutb3"]
|
||||
|
||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_jutb3"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_scwlb"]
|
||||
size = Vector2(2, 2)
|
||||
|
||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_o625d"]
|
||||
|
||||
[sub_resource type="Theme" id="Theme_jutb3"]
|
||||
|
||||
[node name="BaseEntity" type="Area2D"]
|
||||
script = ExtResource("1_jutb3")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = SubResource("PlaceholderTexture2D_jutb3")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="Sprite2D"]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_scwlb")
|
||||
|
||||
[node name="SelectedSprite2D" type="Sprite2D" parent="."]
|
||||
visible = false
|
||||
scale = Vector2(5, 5)
|
||||
texture = SubResource("PlaceholderTexture2D_o625d")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
visible = false
|
||||
anchors_preset = 12
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -23.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
size_flags_horizontal = 3
|
||||
theme = SubResource("Theme_jutb3")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Name"
|
||||
|
||||
[node name="Label2" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Type"
|
||||
16
scenes/entities/bumblebee/Bumblebee.cs
Normal file
16
scenes/entities/bumblebee/Bumblebee.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Bumblebee : BaseEntity
|
||||
{
|
||||
private FastNoiseLite fastNoise = new FastNoiseLite();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
|
||||
fastNoise.SetSeed(GD.RandRange(int.MinValue, int.MaxValue));
|
||||
|
||||
animationPlayer.Play("move");
|
||||
}
|
||||
}
|
||||
1
scenes/entities/bumblebee/Bumblebee.cs.uid
Normal file
1
scenes/entities/bumblebee/Bumblebee.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://svy5ypjbf0gl
|
||||
61
scenes/entities/bumblebee/bumblebee.tscn
Normal file
61
scenes/entities/bumblebee/bumblebee.tscn
Normal file
@@ -0,0 +1,61 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://b43wgesnaq4eg"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://b0q03xfp1iy6t" path="res://scenes/entities/BaseEntity.tscn" id="1_jg071"]
|
||||
[ext_resource type="Texture2D" uid="uid://cj5do47pclcnj" path="res://art/mobs/fly/bumblebee.png" id="2_opprm"]
|
||||
[ext_resource type="Script" uid="uid://svy5ypjbf0gl" path="res://scenes/entities/bumblebee/Bumblebee.cs" id="2_wfrvd"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_y1hpr"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [0]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_wfrvd"]
|
||||
resource_name = "move"
|
||||
length = 0.15
|
||||
loop_mode = 1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.0692609),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 1,
|
||||
"values": [0, 1]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_1wlul"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_y1hpr"),
|
||||
&"move": SubResource("Animation_wfrvd")
|
||||
}
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_wfrvd"]
|
||||
radius = 4.0
|
||||
|
||||
[node name="Bumblebee" instance=ExtResource("1_jg071")]
|
||||
script = ExtResource("2_wfrvd")
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("2_opprm")
|
||||
hframes = 2
|
||||
|
||||
[node name="AnimationPlayer" parent="Sprite2D" index="0"]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_1wlul")
|
||||
}
|
||||
|
||||
[node name="CollisionShape2D" parent="." index="1"]
|
||||
shape = SubResource("CircleShape2D_wfrvd")
|
||||
64
scenes/entities/fly/Fly.cs
Normal file
64
scenes/entities/fly/Fly.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Math = Ecosystem.utility.Math;
|
||||
|
||||
public partial class Fly : BaseEntity
|
||||
{
|
||||
[Export] public float _tx = 0;
|
||||
[Export] public float _ty = 10000f;
|
||||
[Export] public float StepSizeX = .01f;
|
||||
[Export] public float StepSizeY = .1f;
|
||||
|
||||
// private Perlin perlin = new Perlin();
|
||||
|
||||
private FastNoiseLite noise = new FastNoiseLite();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
|
||||
noise.SetSeed(GD.RandRange(int.MinValue, int.MaxValue));
|
||||
|
||||
// Position = ScreenSize / 2;
|
||||
animationPlayer.Play("fly");
|
||||
}
|
||||
|
||||
public void CreateRandom()
|
||||
{
|
||||
float randomTX = GD.Randf() % 10000;
|
||||
float randomTY = GD.Randf() % 10000;
|
||||
float randomStepSizeX = GD.Randf() % .1f;
|
||||
float randomStepSizeY = GD.Randf() % .1f;
|
||||
|
||||
_tx = randomTX;
|
||||
_ty = randomTY;
|
||||
StepSizeX = randomStepSizeX;
|
||||
StepSizeY = randomStepSizeY;
|
||||
}
|
||||
|
||||
private void step()
|
||||
{
|
||||
// double xNoise = perlin.Noise(_tx);
|
||||
// double yNoise = perlin.Noise(_ty);
|
||||
//
|
||||
|
||||
var xNoise = noise.GetNoise1D(_tx);
|
||||
var yNoise = noise.GetNoise1D(_ty);
|
||||
// var noiseVal = noise.GetNoise2D(_tx, _ty);
|
||||
|
||||
float x = Math.Map(xNoise, 0, 1, 0, ScreenSize.X);
|
||||
float y = Math.Map(yNoise, 0, 1, 0, ScreenSize.Y);
|
||||
|
||||
Position = new Vector2(
|
||||
x: Mathf.Clamp(x, 0, ScreenSize.X),
|
||||
y: Mathf.Clamp(y, 0, ScreenSize.Y));
|
||||
|
||||
_tx += StepSizeX;
|
||||
_ty += StepSizeY;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
step();
|
||||
}
|
||||
}
|
||||
1
scenes/entities/fly/Fly.cs.uid
Normal file
1
scenes/entities/fly/Fly.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cjf04oa55b5sb
|
||||
67
scenes/entities/fly/fly.tscn
Normal file
67
scenes/entities/fly/fly.tscn
Normal file
@@ -0,0 +1,67 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://imihi2lpdd0r"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://b0q03xfp1iy6t" path="res://scenes/entities/BaseEntity.tscn" id="1_dir30"]
|
||||
[ext_resource type="Texture2D" uid="uid://bcb027pj21is2" path="res://art/mobs/fly/fly_spritesheet.png" id="2_vd504"]
|
||||
[ext_resource type="Script" uid="uid://cjf04oa55b5sb" path="res://scenes/entities/fly/Fly.cs" id="2_wo7w7"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_k060o"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [0]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_wo7w7"]
|
||||
resource_name = "fly"
|
||||
length = 0.0593
|
||||
loop_mode = 1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.0333333),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 1,
|
||||
"values": [0, 1]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_88wi0"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_k060o"),
|
||||
&"fly": SubResource("Animation_wo7w7")
|
||||
}
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_8dfjp"]
|
||||
radius = 5.0
|
||||
height = 10.0
|
||||
|
||||
[node name="Fly" instance=ExtResource("1_dir30")]
|
||||
script = ExtResource("2_wo7w7")
|
||||
_tx = 0.0
|
||||
_ty = 10000.0
|
||||
StepSizeX = 0.01
|
||||
StepSizeY = 0.1
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture_filter = 1
|
||||
texture = ExtResource("2_vd504")
|
||||
hframes = 2
|
||||
|
||||
[node name="AnimationPlayer" parent="Sprite2D" index="0"]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_88wi0")
|
||||
}
|
||||
|
||||
[node name="CollisionShape2D" parent="." index="1"]
|
||||
shape = SubResource("CapsuleShape2D_8dfjp")
|
||||
Reference in New Issue
Block a user