Initial Chest interaction setup.

WorldChunkRefactoring
Martin Felis 2023-01-04 22:49:00 +01:00
parent e3098c65a3
commit 14e5d47d91
11 changed files with 1259 additions and 52 deletions

BIN
assets/Objects/chest.blend Normal file

Binary file not shown.

BIN
assets/Objects/chest.glb Normal file

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -87,7 +87,7 @@ public class GroundMotionComponent
Vector3 prePhysicsVelocity = entity.Velocity;
entity.Velocity = entity.MoveAndSlide(entity.Velocity);
GD.Print("Pre : speed: " + prePhysicsVelocity.Length() + " Velocity: " + prePhysicsVelocity);
GD.Print("Post: speed: " + entity.Velocity.Length() + " Velocity: " + entity.Velocity);
//GD.Print("Pre : speed: " + prePhysicsVelocity.Length() + " Velocity: " + prePhysicsVelocity);
//GD.Print("Post: speed: " + entity.Velocity.Length() + " Velocity: " + entity.Velocity);
}
}

59
entities/Chest.cs Normal file
View File

@ -0,0 +1,59 @@
using Godot;
using System;
public class Chest : Entity
{
// Declare member variables here. Examples:
// private int a = 2;
// private string b = "text";
public bool IsMouseOver = false;
private MeshInstance _mesh;
private SpatialMaterial _previousMaterial;
[Signal]
delegate void EntityClicked(Entity entity);
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
_mesh = GetNode<MeshInstance>("Armature/Skeleton/Chest");
Connect("input_event", this, nameof(OnAreaInputEvent));
Connect("mouse_entered", this, nameof(OnAreaMouseEntered));
Connect("mouse_exited", this, nameof(OnAreaMouseExited));
}
public void OnAreaInputEvent(Node camera, InputEvent inputEvent, Vector3 position, Vector3 normal,
int shapeIndex)
{
if (IsMouseOver && inputEvent is InputEventMouseButton)
{
InputEventMouseButton mouseButtonEvent = (InputEventMouseButton)inputEvent;
if (mouseButtonEvent.ButtonIndex == 1 && mouseButtonEvent.Pressed)
{
EmitSignal("EntityClicked", this);
}
}
}
public void OnAreaMouseEntered()
{
IsMouseOver = true;
SpatialMaterial overrideMaterial = new SpatialMaterial();
overrideMaterial.AlbedoColor = new Color(1, 0, 0);
_mesh.MaterialOverride = overrideMaterial;
}
public void OnAreaMouseExited()
{
IsMouseOver = false;
_mesh.MaterialOverride = null;
}
// // Called every frame. 'delta' is the elapsed time since the previous frame.
// public override void _Process(float delta)
// {
//
// }
}

View File

@ -60,32 +60,6 @@ public class Player : Entity
}
}
public void OnPositionUpdated(Vector3 newPosition)
{
if (_worldInfo != null)
{
Vector2 new_offset_coord = _worldInfo.TileWorld.WorldToOffsetCoords(newPosition);
float tile_height = _worldInfo.TileWorld.GetHeightAtOffset(new_offset_coord);
if (_offsetCoord != new_offset_coord)
{
GD.Print("New offset coord " + new_offset_coord);
_offsetCoord = new_offset_coord;
}
if (_movable != null)
{
if (_movable.currentPosition.y < tile_height)
{
_movable.currentPosition.y = tile_height;
_movable.currentVelocity.y = 0;
}
}
}
Transform transform = Transform;
transform.origin = newPosition;
Transform = transform;
}
private void OnOrientationUpdated(float newOrientation)
{

View File

@ -26,6 +26,7 @@ public class AdaptiveWorldStream : Spatial
private Area _streamContainerArea;
private Spatial _streamContainerActiveTiles;
private Player _player;
private Chest _chest;
private TileWorld _tileWorld;
// Resources
@ -58,6 +59,7 @@ public class AdaptiveWorldStream : Spatial
_streamContainerArea = GetNode<Area>("StreamContainer/Area");
_streamContainerActiveTiles = GetNode<Spatial>("StreamContainer/ActiveTiles");
_player = GetNode<Player>("Player");
_chest = GetNode<Chest>("Chest");
_tileWorld = GetNode<TileWorld>("TileWorld");
Debug.Assert(_tileWorld != null);
@ -76,8 +78,9 @@ public class AdaptiveWorldStream : Spatial
// connect signals
_streamContainerArea.Connect("input_event", this, nameof(OnAreaInputEvent));
_streamContainer.Connect("TileSelected", this, nameof(OnTileSelected));
_streamContainer.Connect("TileClicked", this, nameof(OnTileClicked));
_tileWorld.Connect("WorldGenerated", this, nameof(OnWorldGenerated));
_chest.Connect("EntityClicked", this, nameof(OnEntityClicked));
// perform dependency injection
//_streamContainer.SetWorld(_tileWorld);
@ -166,12 +169,12 @@ public class AdaptiveWorldStream : Spatial
if (inputEvent is InputEventMouseButton && ((InputEventMouseButton) inputEvent).Pressed)
{
_streamContainer.EmitSignal("TileSelected", _streamContainer.GetTile3dAt(cellAtCursor.OffsetCoords));
_streamContainer.EmitSignal("TileClicked", _streamContainer.GetTile3dAt(cellAtCursor.OffsetCoords));
}
}
public void OnTileSelected(HexTile3D tile)
public void OnTileClicked(HexTile3D tile)
{
if (_player == null)
{
@ -184,14 +187,12 @@ public class AdaptiveWorldStream : Spatial
}
_player.Navigation.Plan(_player.GlobalTranslation, tile.GlobalTranslation);
}
// MovableComponent movableComponent = _player.GetNode<MovableComponent>("Movable");
// if (movableComponent == null)
// {
// return;
// }
//
// movableComponent.targetPosition = tile.Transform.origin;
public void OnEntityClicked(Entity entity)
{
GD.Print("Clicked on entity at " + entity.GlobalTranslation);
}

File diff suppressed because one or more lines are too long

View File

@ -18,7 +18,7 @@ public class HexTile3D : Spatial
// signals
[Signal]
delegate void TileSelected(HexTile3D tile3d);
delegate void TileClicked(HexTile3D tile3d);
// other member variables
private SpatialMaterial _undefinedMaterial;
@ -110,7 +110,7 @@ public class HexTile3D : Spatial
InputEventMouseButton mouseButtonEvent = (InputEventMouseButton)inputEvent;
if (mouseButtonEvent.ButtonIndex == 1 && mouseButtonEvent.Pressed)
{
EmitSignal("TileSelected", this);
EmitSignal("TileClicked", this);
}
}
}

View File

@ -21,7 +21,7 @@ public class StreamContainer : Spatial
[Export] public NodePath World;
[Signal]
delegate void TileSelected(HexTile3D tile3d);
delegate void TileClicked(HexTile3D tile3d);
// other members
private Rect2 _worldRect;
@ -109,7 +109,7 @@ public class StreamContainer : Spatial
{
RemovedCoords.Add(tile3D.OffsetCoords);
_activeTiles.RemoveChild(tile3D);
tile3D.Disconnect("TileSelected", this, nameof(OnTileClicked));
tile3D.Disconnect("TileClicked", this, nameof(OnTileClicked));
tile3D.QueueFree();
}
}
@ -188,7 +188,7 @@ public class StreamContainer : Spatial
HexTile3D tile3D = (HexTile3D)_hexTileScene.Instance();
tile3D.OffsetCoords = offsetCoords;
_activeTiles.AddChild(tile3D);
tile3D.Connect("TileSelected", this, nameof(OnTileClicked));
tile3D.Connect("TileClicked", this, nameof(OnTileClicked));
Transform tileTransform = tile3D.Transform;
tileTransform.origin.y = _tileWorld.GetHeightAtOffset(offsetCoords);
@ -209,6 +209,6 @@ public class StreamContainer : Spatial
public void OnTileClicked(HexTile3D tile)
{
GD.Print("Clicked on Tile at " + tile.OffsetCoords);
EmitSignal("TileSelected", tile);
EmitSignal("TileClicked", tile);
}
}

View File

@ -11,7 +11,7 @@ public class TileWorld : Spatial
// public members
public Image Heightmap;
public Vector2 Size = new Vector2(100, 100);
public float HeightScale = 5;
public float HeightScale = 10;
// private members
private HexGrid _hexGrid;
@ -27,8 +27,8 @@ public class TileWorld : Spatial
public void Generate()
{
// GenerateSimpleMap();
GenerateNoiseMap();
GenerateSimpleMap();
//GenerateNoiseMap();
EmitSignal("WorldGenerated");
}
@ -44,7 +44,7 @@ public class TileWorld : Spatial
{
foreach (int coord_y in Enumerable.Range(0, (int)Size.y))
{
SetHeightAtOffset(new Vector2(coord_x, coord_y), 0.5f);
SetHeightAtOffset(new Vector2(coord_x, coord_y), 5f);
}
}
}