Created
July 8, 2021 06:42
-
-
Save spacechase0/b396647167578d25bc066fd4a5f76ab1 to your computer and use it in GitHub Desktop.
SpaceECS (name subject to change)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node2D | |
func _physics_process(delta): | |
var vels = get_tree().get_nodes_in_group( "components/VelocityComponent" ) | |
for node in vels: | |
var vel = ComponentServer.get_component( node, "VelocityComponent" ) | |
node.move_and_collide( vel.velocity * delta ) | |
var velsCS = get_tree().get_nodes_in_group( "components/VelocityCSComponent" ) | |
for node in velsCS: | |
var vel = ComponentServer.get_component( node, "VelocityCSComponent" ) | |
node.move_and_collide( vel.Velocity * delta ) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node2D | |
func _ready(): | |
var c := VelocityComponent.new() | |
var dir := randf() * PI * 2 | |
c.velocity = Vector2( cos( dir ) * 100, sin( dir ) * 100 ) | |
ComponentServer.add_component( self, c ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Godot; | |
using System; | |
public class TestEntityCS : KinematicBody2D | |
{ | |
public override void _Ready() | |
{ | |
float dir = GD.Randf() * Mathf.Pi * 2; | |
ComponentServer.AddComponent( this, new VelocityCSComponent() | |
{ | |
Velocity = new Vector2( Mathf.Cos( dir ) * 100, Mathf.Sin( dir ) * 100 ) | |
} ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Component | |
class_name VelocityComponent # Not necessary | |
export var velocity : Vector2 = Vector2( 0, 0 ) | |
func _get_component_name(): # Is necessary | |
return "VelocityComponent" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Godot; | |
using System; | |
public class VelocityCSComponent : Component | |
{ | |
[Export] | |
public Vector2 Velocity = Vector2.Zero; | |
public override string _GetComponentName() | |
{ | |
return "VelocityCSComponent"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment