ManiaMap.Godot
Procedural generation of metroidvania style maps for Godot .NET.
CellArea3D.cs
1using Godot;
2
4{
11 public partial class CellArea3D : Area3D
12 {
16 public int Row { get; private set; }
17
21 public int Column { get; private set; }
22
26 public RoomNode3D Room { get; private set; }
27
35 public static CellArea3D CreateInstance(int row, int column, RoomNode3D room, uint collisionMask)
36 {
37 var cell = new CellArea3D()
38 {
39 Row = row,
40 Column = column,
41 Room = room,
42 CollisionLayer = 0,
43 CollisionMask = collisionMask,
44 Position = room.CellCenterLocalPosition(row, column),
45 };
46
47 var shape = new BoxShape3D() { Size = room.CellSize };
48 var collisionShape = new CollisionShape3D() { Shape = shape };
49 cell.AddChild(collisionShape);
50 room.AddChild(cell);
51 return cell;
52 }
53
54 public override void _Ready()
55 {
56 base._Ready();
57 BodyEntered += OnBodyEntered;
58 AreaEntered += OnAreaEntered;
59 BodyExited += OnBodyExited;
60 AreaExited += OnAreaExited;
61 }
62
63 private void OnBodyEntered(Node body)
64 {
65 EmitOnCellEntered(body);
66 }
67
68 private void OnAreaEntered(Area3D area)
69 {
70 EmitOnCellEntered(area);
71 }
72
73 private void OnBodyExited(Node body)
74 {
75 EmitOnCellExited(body);
76 }
77
78 private void OnAreaExited(Area3D area)
79 {
80 EmitOnCellExited(area);
81 }
82
83 private void EmitOnCellEntered(Node collision)
84 {
85 Room.RoomState?.SetCellVisibility(Row, Column, true);
86 Room.EmitOnCellAreaEntered(this, collision);
87 }
88
89 private void EmitOnCellExited(Node collision)
90 {
91 Room.EmitOnCellAreaExited(this, collision);
92 }
93 }
94}
Provides area and body entering and exiting detection for a cell.
Definition: CellArea3D.cs:12
RoomNode3D Room
The containing room.
Definition: CellArea3D.cs:26
int Row
The cell row in the room.
Definition: CellArea3D.cs:16
static CellArea3D CreateInstance(int row, int column, RoomNode3D room, uint collisionMask)
Creates a new instance with child collision shape and adds it as a child of the specified room.
Definition: CellArea3D.cs:35
int Column
The cell column in the room.
Definition: CellArea3D.cs:21
A node serving as the top level of a 3D room.
Definition: RoomNode3D.cs:17
Vector3 CellCenterLocalPosition(int row, int column)
Returns the cell center local position for the specified cell index.
Definition: RoomNode3D.cs:294
Vector3 CellSize
The width and height of the room cells.
Definition: RoomNode3D.cs:55