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:
gdz
2025-07-29 23:21:53 +02:00
parent 9cef1ddce2
commit 802918e5b8
46 changed files with 1087 additions and 1 deletions

91
scenes/world/World.cs Normal file
View 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);
}
}
}
}

View File

@@ -0,0 +1 @@
uid://ctanguxj2uhw7

28
scenes/world/world.tscn Normal file
View 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)