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:
76
scenes/Camera2d.cs
Normal file
76
scenes/Camera2d.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Camera2d : Camera2D
|
||||
{
|
||||
private float targetZoom = 1.0f;
|
||||
private float minZoom = .1f;
|
||||
private float maxZoom = 1.0f;
|
||||
private float zoomIncrement = .1f;
|
||||
private float zoomRate = 8.0f;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
// Print the size of the viewport.
|
||||
GD.Print("Viewport Resolution is: ", GetViewport().GetVisibleRect().Size);
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
// Mouse in viewport coordinates.
|
||||
if (@event is InputEventMouseButton eventMouseButton)
|
||||
{
|
||||
GD.Print("Mouse Click/Unclick at: ", eventMouseButton.Position);
|
||||
|
||||
switch (eventMouseButton.ButtonIndex)
|
||||
{
|
||||
case MouseButton.Left:
|
||||
Position = eventMouseButton.Position;
|
||||
break;
|
||||
case MouseButton.WheelDown:
|
||||
zoomIn();
|
||||
break;
|
||||
case MouseButton.WheelUp:
|
||||
zoomOut();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (@event is InputEventMouseMotion eventMouseMotion)
|
||||
{
|
||||
Vector2 zoomThreshold = new Vector2(.2f, .2f); // When should the zoom doesnt be accounted
|
||||
Vector2 zoomThresholdSpeed = new Vector2(1.0f, 1.0f); // What value to use when the Threshold is reached
|
||||
|
||||
GD.Print("Mouse Motion at: ", eventMouseMotion.Position);
|
||||
|
||||
if (eventMouseMotion.ButtonMask == MouseButtonMask.Middle)
|
||||
Position -= eventMouseMotion.Relative * (Zoom < zoomThreshold ? zoomThresholdSpeed : Zoom);
|
||||
}
|
||||
|
||||
GD.Print("Camera Position: ", Position);
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
Zoom = Lerp(Zoom, targetZoom * Vector2.One, zoomRate * (float)delta);
|
||||
if (Zoom.X == targetZoom)
|
||||
SetPhysicsProcess(false);
|
||||
|
||||
GD.Print("Camera Zoom: ", Zoom);
|
||||
}
|
||||
|
||||
private void zoomIn()
|
||||
{
|
||||
targetZoom = Single.Max(targetZoom - zoomIncrement, minZoom);
|
||||
SetPhysicsProcess(true);
|
||||
}
|
||||
|
||||
private void zoomOut()
|
||||
{
|
||||
targetZoom = Single.Min(targetZoom + zoomIncrement, maxZoom);
|
||||
SetPhysicsProcess(true);
|
||||
}
|
||||
|
||||
public static Vector2 Lerp(Vector2 from, Vector2 to, float weight) => from + (to - from) * weight;
|
||||
}
|
||||
1
scenes/Camera2d.cs.uid
Normal file
1
scenes/Camera2d.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b3obsoy04p8gl
|
||||
17
scenes/Main.cs
Normal file
17
scenes/Main.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Main : Node
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
var screenSize = GetViewport().GetVisibleRect().Size;
|
||||
var camera = GetNode<Camera2D>("Camera2D");
|
||||
camera.Position = new Vector2(screenSize.X / 2, screenSize.Y / 2);
|
||||
|
||||
var spawner = GetNode("World/Spawner");
|
||||
|
||||
var flyPosition = camera.Position;
|
||||
// spawner.spawn_fly(flyPosition);
|
||||
}
|
||||
}
|
||||
1
scenes/Main.cs.uid
Normal file
1
scenes/Main.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dte8xibis5wf7
|
||||
41
scenes/camera_2d.gd
Normal file
41
scenes/camera_2d.gd
Normal file
@@ -0,0 +1,41 @@
|
||||
extends Camera2D
|
||||
|
||||
@export_group("Zoom")
|
||||
@export var _target_zoom: float = 1.0
|
||||
|
||||
func _ready() -> void:
|
||||
position = Vector2(500, 500)
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion:
|
||||
if event.button_mask == MOUSE_BUTTON_MASK_MIDDLE:
|
||||
position -= event.relative * zoom
|
||||
if event is InputEventMouseButton:
|
||||
if event.is_pressed():
|
||||
if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
|
||||
zoom_in()
|
||||
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
|
||||
zoom_out()
|
||||
|
||||
@export_group("Zoom")
|
||||
@export var MIN_ZOOM: float = 0.1
|
||||
@export var MAX_ZOOM: float = 1.0
|
||||
@export var ZOOM_INCREMENT: float = 0.1
|
||||
|
||||
func zoom_in():
|
||||
_target_zoom = max(_target_zoom - ZOOM_INCREMENT, MIN_ZOOM)
|
||||
set_physics_process(true)
|
||||
|
||||
func zoom_out():
|
||||
_target_zoom = min(_target_zoom + ZOOM_INCREMENT, MAX_ZOOM)
|
||||
set_physics_process(true)
|
||||
|
||||
const ZOOM_RATE: float = 8.0
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
zoom = lerp(
|
||||
zoom,
|
||||
_target_zoom * Vector2.ONE,
|
||||
ZOOM_RATE * delta
|
||||
)
|
||||
set_physics_process(not is_equal_approx(zoom.x, _target_zoom))
|
||||
1
scenes/camera_2d.gd.uid
Normal file
1
scenes/camera_2d.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://deol78luglq0w
|
||||
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")
|
||||
21
scenes/main.gd
Normal file
21
scenes/main.gd
Normal file
@@ -0,0 +1,21 @@
|
||||
extends Node
|
||||
|
||||
var screenSize: Vector2
|
||||
var spawner
|
||||
var camera
|
||||
|
||||
func _ready() -> void:
|
||||
screenSize = get_viewport().get_visible_rect().size
|
||||
spawner = $World/Spawner
|
||||
camera = $Camera2D
|
||||
|
||||
camera.position = Vector2(screenSize.x / 2, screenSize.x / 2)
|
||||
|
||||
var flyPosition = camera.position
|
||||
spawner.spawn_fly(flyPosition)
|
||||
|
||||
spawner.spawn_bee(flyPosition)
|
||||
|
||||
|
||||
func spawn_fly():
|
||||
spawner.spawn_fly(camera.position)
|
||||
1
scenes/main.gd.uid
Normal file
1
scenes/main.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bb6w1hp1i6k6t
|
||||
121
scenes/main.tscn
Normal file
121
scenes/main.tscn
Normal file
@@ -0,0 +1,121 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://bkw0abirq18mt"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://brbhyuelsuxyx" path="res://scenes/world/world.tscn" id="1_o5qli"]
|
||||
[ext_resource type="Script" uid="uid://bb6w1hp1i6k6t" path="res://scenes/main.gd" id="1_sugp2"]
|
||||
[ext_resource type="Script" uid="uid://deol78luglq0w" path="res://scenes/camera_2d.gd" id="2_0wfyh"]
|
||||
[ext_resource type="Script" uid="uid://8vkyddmxqfaf" path="res://scenes/menu_bar.gd" id="4_tbgi4"]
|
||||
[ext_resource type="Script" uid="uid://cmoqidhmxlccq" path="res://scenes/options_menu.gd" id="5_tefeu"]
|
||||
|
||||
[node name="Main" type="Node"]
|
||||
script = ExtResource("1_sugp2")
|
||||
|
||||
[node name="World" parent="." instance=ExtResource("1_o5qli")]
|
||||
|
||||
[node name="Spawner" parent="World" index="1"]
|
||||
position = Vector2(500, 500)
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
drag_left_margin = 0.5
|
||||
drag_top_margin = 0.5
|
||||
drag_right_margin = 0.5
|
||||
drag_bottom_margin = 0.5
|
||||
editor_draw_limits = true
|
||||
editor_draw_drag_margin = true
|
||||
script = ExtResource("2_0wfyh")
|
||||
|
||||
[node name="HUD" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="MenuBar" type="MenuBar" parent="HUD"]
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
grow_horizontal = 2
|
||||
script = ExtResource("4_tbgi4")
|
||||
|
||||
[node name="Entity" type="PopupMenu" parent="HUD/MenuBar"]
|
||||
auto_translate_mode = 1
|
||||
size = Vector2i(109, 100)
|
||||
item_count = 2
|
||||
item_0/text = "Fly"
|
||||
item_0/id = 0
|
||||
item_1/text = "Bumblebee"
|
||||
item_1/id = 1
|
||||
|
||||
[node name="Spawn" type="PopupMenu" parent="HUD/MenuBar"]
|
||||
size = Vector2i(109, 100)
|
||||
item_count = 2
|
||||
item_0/text = "Fly"
|
||||
item_0/id = 0
|
||||
item_1/text = "Bumblebee"
|
||||
item_1/id = 1
|
||||
|
||||
[node name="Options" type="PopupMenu" parent="HUD/MenuBar"]
|
||||
item_count = 2
|
||||
item_0/text = "Camera"
|
||||
item_0/id = 0
|
||||
item_1/text = "World"
|
||||
item_1/id = 1
|
||||
script = ExtResource("5_tefeu")
|
||||
|
||||
[node name="Camera" type="PopupMenu" parent="HUD/MenuBar/Options"]
|
||||
item_count = 2
|
||||
item_0/text = "Speed"
|
||||
item_0/id = 0
|
||||
item_1/text = "Position"
|
||||
item_1/id = 1
|
||||
|
||||
[node name="World" type="PopupMenu" parent="HUD/MenuBar/Options"]
|
||||
auto_translate_mode = 1
|
||||
item_count = 1
|
||||
item_0/text = "Generate"
|
||||
item_0/id = 0
|
||||
|
||||
[node name="SpawnMenuButton" type="MenuButton" parent="HUD"]
|
||||
visible = false
|
||||
anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -31.0
|
||||
offset_right = 60.0
|
||||
grow_vertical = 0
|
||||
text = "Spawn"
|
||||
item_count = 2
|
||||
popup/item_0/text = "Fly"
|
||||
popup/item_0/id = 0
|
||||
popup/item_1/text = "Bumblebee"
|
||||
popup/item_1/id = 1
|
||||
|
||||
[node name="Button" type="Button" parent="HUD"]
|
||||
visible = false
|
||||
anchors_preset = 7
|
||||
anchor_left = 0.5
|
||||
anchor_top = 1.0
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -42.5
|
||||
offset_top = -31.0
|
||||
offset_right = 42.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
text = "Spawn Fly"
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="HUD"]
|
||||
visible = false
|
||||
anchors_preset = 12
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
|
||||
[node name="Label" type="Label" parent="HUD/MarginContainer"]
|
||||
layout_mode = 2
|
||||
text = "Name:"
|
||||
|
||||
[node name="Label2" type="Label" parent="HUD/MarginContainer"]
|
||||
layout_mode = 2
|
||||
text = "Type"
|
||||
|
||||
[connection signal="index_pressed" from="HUD/MenuBar/Options" to="HUD/MenuBar" method="options_index_pressed"]
|
||||
[connection signal="pressed" from="HUD/Button" to="." method="spawn_fly"]
|
||||
|
||||
[editable path="World"]
|
||||
20
scenes/menu_bar.gd
Normal file
20
scenes/menu_bar.gd
Normal file
@@ -0,0 +1,20 @@
|
||||
extends MenuBar
|
||||
|
||||
func options_index_pressed(index):
|
||||
var curr_position = get_global_mouse_position()
|
||||
|
||||
if index == 0:
|
||||
options_camera_pressed(curr_position)
|
||||
elif index == 1:
|
||||
options_world_pressed(curr_position)
|
||||
|
||||
|
||||
func options_camera_pressed(position):
|
||||
var camera_menu = $Options/Camera
|
||||
camera_menu.position = position
|
||||
camera_menu.show()
|
||||
|
||||
func options_world_pressed(position):
|
||||
var world_menu = $Options/World
|
||||
world_menu.position = position
|
||||
world_menu.show()
|
||||
1
scenes/menu_bar.gd.uid
Normal file
1
scenes/menu_bar.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://8vkyddmxqfaf
|
||||
1
scenes/options_menu.gd
Normal file
1
scenes/options_menu.gd
Normal file
@@ -0,0 +1 @@
|
||||
extends PopupMenu
|
||||
1
scenes/options_menu.gd.uid
Normal file
1
scenes/options_menu.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cmoqidhmxlccq
|
||||
23
scenes/spawner/advanced_spwaner.gd
Normal file
23
scenes/spawner/advanced_spwaner.gd
Normal file
@@ -0,0 +1,23 @@
|
||||
extends Node
|
||||
|
||||
@export var scenes: Array[PackedScene]
|
||||
|
||||
# Spawn the corresponding Entity at position
|
||||
func spawn_entity(index, position):
|
||||
var entity = scenes[index].instantiate()
|
||||
|
||||
if entity is Node2D:
|
||||
entity.position = position
|
||||
|
||||
add_child(entity)
|
||||
|
||||
return entity
|
||||
|
||||
|
||||
|
||||
|
||||
func spawn_fly(position):
|
||||
return spawn_entity(0, position)
|
||||
|
||||
func spawn_bee(position):
|
||||
return spawn_entity(1, position)
|
||||
1
scenes/spawner/advanced_spwaner.gd.uid
Normal file
1
scenes/spawner/advanced_spwaner.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dkc807nt6d5jb
|
||||
17
scenes/spawner/spawner.gd
Normal file
17
scenes/spawner/spawner.gd
Normal file
@@ -0,0 +1,17 @@
|
||||
extends Node
|
||||
|
||||
const FlyScene = preload("res://scenes/entities/fly/fly.tscn")
|
||||
|
||||
func spawn_entity(entity_scene, position):
|
||||
# Instance the scene
|
||||
var entity = entity_scene.instantiate()
|
||||
|
||||
if entity is Node2D:
|
||||
entity.position = position
|
||||
|
||||
add_child(entity)
|
||||
|
||||
return entity
|
||||
|
||||
func spawn_fly(position):
|
||||
return spawn_entity(FlyScene, position)
|
||||
1
scenes/spawner/spawner.gd.uid
Normal file
1
scenes/spawner/spawner.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dxflnn04s7out
|
||||
17
scenes/spawner/spawner.tscn
Normal file
17
scenes/spawner/spawner.tscn
Normal file
@@ -0,0 +1,17 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://drwdehf7caidt"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dkc807nt6d5jb" path="res://scenes/spawner/advanced_spwaner.gd" id="1_eoeca"]
|
||||
[ext_resource type="PackedScene" uid="uid://imihi2lpdd0r" path="res://scenes/entities/fly/fly.tscn" id="2_wtxcb"]
|
||||
[ext_resource type="PackedScene" uid="uid://b43wgesnaq4eg" path="res://scenes/entities/bumblebee/bumblebee.tscn" id="3_uhn3r"]
|
||||
[ext_resource type="Texture2D" uid="uid://b6wg3uyaeju7u" path="res://art/spawner_fallback.png" id="4_byvvi"]
|
||||
|
||||
[node name="Spawner" type="Node2D"]
|
||||
script = ExtResource("1_eoeca")
|
||||
scenes = Array[PackedScene]([ExtResource("2_wtxcb"), ExtResource("3_uhn3r")])
|
||||
|
||||
[node name="Marker2D" type="Marker2D" parent="."]
|
||||
top_level = true
|
||||
gizmo_extents = 324.1
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("4_byvvi")
|
||||
91
scenes/world/World.cs
Normal file
91
scenes/world/World.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class World : Node2D
|
||||
{
|
||||
public enum GeneratorAlgorithm
|
||||
{
|
||||
RANDOM,
|
||||
FAST_NOISE_LITE
|
||||
}
|
||||
|
||||
|
||||
Vector2I darkGras = new Vector2I(0, 0);
|
||||
Vector2I brightGras = new Vector2I(1, 0);
|
||||
Vector2I flower = new Vector2I(2, 0);
|
||||
TileMapLayer tileMapLayer;
|
||||
|
||||
Vector2 screenSize;
|
||||
float worldWidth;
|
||||
float worldHeight;
|
||||
|
||||
[Export] GeneratorAlgorithm algorithm = GeneratorAlgorithm.RANDOM;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
screenSize = GetViewportRect().Size;
|
||||
worldWidth = screenSize.X;
|
||||
worldHeight = screenSize.Y;
|
||||
|
||||
tileMapLayer = GetNode<TileMapLayer>("TileMapLayer");
|
||||
|
||||
GD.Randomize();
|
||||
GenerateWorld();
|
||||
}
|
||||
|
||||
private void GenerateWorld()
|
||||
{
|
||||
switch (algorithm)
|
||||
{
|
||||
case GeneratorAlgorithm.RANDOM:
|
||||
GenerateWorldRandom();
|
||||
break;
|
||||
case GeneratorAlgorithm.FAST_NOISE_LITE:
|
||||
GenerateWorldSimplexNoise();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateWorldRandom()
|
||||
{
|
||||
for (int y = 0; y < worldHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < worldWidth; x++)
|
||||
{
|
||||
float rnd = GD.Randf();
|
||||
|
||||
if (rnd < .7f)
|
||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, darkGras);
|
||||
else if (rnd < .9f)
|
||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, brightGras);
|
||||
else
|
||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, flower);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateWorldSimplexNoise()
|
||||
{
|
||||
var noise = new FastNoiseLite();
|
||||
|
||||
noise.Seed = GD.RandRange(int.MinValue, int.MaxValue);
|
||||
noise.FractalOctaves = 2;
|
||||
|
||||
for (int y = 0; y < worldHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < worldWidth; x++)
|
||||
{
|
||||
var rnd = noise.GetNoise2D(x, y);
|
||||
|
||||
if (rnd < .3f)
|
||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, darkGras);
|
||||
else if (rnd < .6f)
|
||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, brightGras);
|
||||
else
|
||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, flower);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
scenes/world/World.cs.uid
Normal file
1
scenes/world/World.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ctanguxj2uhw7
|
||||
28
scenes/world/world.tscn
Normal file
28
scenes/world/world.tscn
Normal file
@@ -0,0 +1,28 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://brbhyuelsuxyx"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://d0brwy88sjvv1" path="res://art/world/grasv2.png" id="1_f3sb7"]
|
||||
[ext_resource type="Script" uid="uid://ctanguxj2uhw7" path="res://scenes/world/World.cs" id="1_rwgxs"]
|
||||
[ext_resource type="PackedScene" uid="uid://drwdehf7caidt" path="res://scenes/spawner/spawner.tscn" id="3_1fp7r"]
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_0xm2m"]
|
||||
texture = ExtResource("1_f3sb7")
|
||||
texture_region_size = Vector2i(32, 32)
|
||||
0:0/0 = 0
|
||||
1:0/0 = 0
|
||||
2:0/0 = 0
|
||||
|
||||
[sub_resource type="TileSet" id="TileSet_h2yge"]
|
||||
tile_size = Vector2i(32, 32)
|
||||
sources/0 = SubResource("TileSetAtlasSource_0xm2m")
|
||||
|
||||
[node name="World" type="Node2D"]
|
||||
script = ExtResource("1_rwgxs")
|
||||
algorithm = 1
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="TileMapLayer" type="TileMapLayer" parent="."]
|
||||
texture_filter = 1
|
||||
tile_set = SubResource("TileSet_h2yge")
|
||||
|
||||
[node name="Spawner" parent="." instance=ExtResource("3_1fp7r")]
|
||||
position = Vector2(50, 50)
|
||||
Reference in New Issue
Block a user