-
Notifications
You must be signed in to change notification settings - Fork 24
Code snippets
Elliot Ford edited this page May 23, 2015
·
6 revisions
- Creating and using a simple Entity type
- Filtering entities by type (using inheritance)
- Creating an EntityListener
- Creating an AttributeListener
- Creating and scheduling an Action
- Adding and removing attributes
Creating and using a simple Entity type
public interface Friend extends Entity {
@GetAttribute
String getName();
@SetAttribute
void setName(String name);
}
Friend f = jalse.newEntity(Friend.class);
f.setName("Ellzord");
System.out.println(f.getName());
Filtering entities by type (using inheritance)
public interface Animal extends Entity{}
public interface FlyingAnimal extends Animal{}
...
jalse.streamEntitiesOfType(Animal.class).foreach(/* Feed */);
jalse.addEntityListener(new EntityListener() {
public void entityKilled(EntityEvent event) {
if (event.getEntity().isMarkedAsType(Evil.class)) {
/* Spawn more */
}
}
});
entity.addAttributeListener("danger", Attributes.BOOLEAN_TYPE, new AttributeListener<Boolean>(){
public void attributeAdded(AttributeEvent<Boolean> event) {
if (event.getValue()) {
/* Run like hell */
}
}
});
Creating and scheduling an Action
StrandedSurvivors living = jalse.newEntity(StrandedSurvivors.class);
for (int i = 0; i < 10; i++) {
living.newSurvivor();
}
living.scheduleForActor(new Action<StrandedSurvivors>() {
public void perform(ActionContext<StrandedSurvivors> context) {
context.getActor().streamSurvivors().foreach(Survivor::lookForFood);
}
}, 0, 1, TimeUnit.SECONDS);
Adding and removing attributes
entity.setAttribute("falling", Attributes.BOOLEAN_TYPE, true);
...
entity.removeAttribute("falling", Attributes.BOOLEAN_TYPE);
entity.setAttribute("death", Attributes.newTypeOf(Date.class), new Date());
Check out the Example projects and Code snippets!
Getting Started
- Getting the latest release
- Building from source
- Example projects
- Code snippets
- How to contribute
- Have bugs or questions?
How To Use
- JALSE
- Entities
- Attributes
- Actions
- Tags
Misc