Skip to content

Instantly share code, notes, and snippets.

@starikcetin
Created October 4, 2019 20:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starikcetin/de935cfc3b4180eef1f55cab596a5457 to your computer and use it in GitHub Desktop.
Save starikcetin/de935cfc3b4180eef1f55cab596a5457 to your computer and use it in GitHub Desktop.
// container component
// a constructor is automatically generated for a component that has the same order with field declaration
// for example, for position component following ctor is generated: (x, y, z)
component position
float x
float y
float z
// component with single field
component float health
// tag component
tag component destroyed
// event definition
event damageTaken
float damage
// entity generation
entity newSpaceship
postion = (10, 5, 6)
health = 100
// regular system
system positionSystem
// entity signature filters
all: position
any: x, y
none: z
// read component
pos = entity.position
// write component
entity.position = new pos
x: 5
y: 4
z: 3
entity.position = pos + (1, 2, 3)
// this is also possible
entity.position.x = 10
// this too
// if entity doesn't have a health, it will be added and then set
entity.health = 5
// add component
add destroyed to entity
add foo to entity
bar: baz
// remove component
remove position from entity
// raise an event
raise damageTaken
// sender -> target
fooEntity -> barEntity
// values
damage: 5
// reactive system
reactive system positionChangeSystem
// define which component this system reacts to
reacts to position
// entity signature filters
all: position
any: foo, bar
none: baz
oldPos = reaction.old
newPos = reaction.new
// event listener system
listener system damageTakenSystem
// define which event this system listens for
listens to damageTaken
// entity signature filters for the sender entity
sender:
all: position
// entity signature filters for the target entity
target:
all: position
// get the sender entity
sender = event.sender
// get the target entity
target = event.target
// read and operate on event values
origin.health -= event.damage
@Ale1
Copy link

Ale1 commented May 20, 2023

for your "damageTakenSystem", wouldn't you want to filter by entities that have "health" component. what happens when en entity with position component but no health component receives damage?

Suggestion: you could consider making use of the "!" to allow/disallow component creation by Setters. i.e :

spaceship.health = 5 // should throw error if health component is not part of spaceship.
spaceship.health! = 5 // will create health component if it doesnt exist. no error.

@starikcetin
Copy link
Author

Yes, the gameplay semantics are way off, this is more of a primer for how such a language would look like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment