Habitica
Computer games are real-time interactive agent-based simulators.
Object 2 reads updated state of Object 1 but not updated state of Object 3
Detects input events from devices
The overall behavior of a particular game object is fully determined
by the aggregation of its components (and attributes).
class Brainbot extends Unit {
private damage: number;
private currentWeapon: WeaponType;
constructor() {
super(UnitType.BRAIN_BOT);
}
init(attributes: UnitAttribs) {
// set default values
this.damage = DEFAULT_DAMAGE_BRAINBOT;
this.currentWeapon = WeaponType.LASERGUN;
this.attributes = attributes;
}
}
// stateless, the creature will jump each frame
creatureUpdate(delta: number, absolute: number) {
if(pressedKeys.has(KeyCode.UP)) {
this.creature.jump();
}
}
// a variable that makes certain actions possible only according to the current state
creatureUpdate(delta: number, absolute: number) {
if(pressedKeys.has(KeyCode.UP) && this.creature.state !== STATE_JUMPING) {
this.creature.changeState(STATE_JUMPING);
this.creature.jump();
}
}
class Builder {
private _position: Vector;
private _scale: Vector;
position(pos: Vector) {
this.position = pos;
return this;
}
scale(scale: Vector) {
this.scale = scale;
return this;
}
build() {
return new GameObject(this._position, this._scale);
}
}
new Builder().position(new Vector(12, 54)).scale(new Vector(2, 1)).build();
class UnitFactory {
private pikemanBuilder: Builder; // preconfigured to build pikemans
private musketeerBuilder: Builder; // preconfigured to build musketeers
private archerBuilder: Builder; // preconfigured to build archers
public spawnPikeman(position: Vector, faction: FactionType): GameObject {
return this.pikeman.position(position).faction(faction).build();
}
public spawnMusketeer(position: Vector, faction: FactionType): GameObject {
return this.musketeerBuilder.position(position).faction(faction).build();
}
public spawnArcher(position: Vector, faction: FactionType): GameObject {
return this.archerBuilder.position(position).faction(faction).build();
}
}
Uniform distribution
Gaussian distribution
float PerlinNoise2D(int x, int y, float persistence, int octaves, float zoom) {
float total = 0.0f;
// initial frequency and amplitude
float frequency = zoom;
float amplitude = 1.0f;
for (int i = 0; i < octaves; i++) {
// calculate noise
total = total + InterpolatedNoise(x*frequency, y*frequency) * amplitude;
// update frequency and amplitude
frequency = frequency * 2;
amplitude = amplitude * persistence;
}
return total; }
Oct-tree
Vector addition and subtraction
Magnitude of a vector
rope
revolute
prismatic
cone-twist
Perspective projection
Orthographic projection
Sprite animation
Skeletal 2D
Skeletal 3D
Vertex
Z-Fighting
// Doom 2: find player to chase
void A_Look (mobj_t* actor) {
mobj_t* targ;
actor->threshold = 0; // any shot will wake up
targ = actor->subsector->sector->soundtarget;
if (actor->flags & MF_AMBUSH){
if (P_CheckSight (actor, actor->target))
goto seeyou;
} else goto seeyou;
if (!P_LookForPlayers (actor, false)) return;
// go into chase state
seeyou:
P_ChasePlayer();
}
Node Type | Success | Failure | Running |
---|---|---|---|
Selector | If one child succeeds | If all children fail | If one child is running |
Sequence | If all children succeed | If one child fails | If one child is running |
Decorator | It depends... | It depends... | It depends... |
Parallel | If N children succeed | If M-N children succeed | If all children are running |
Action | When completed | Upon an error | During completion |
Condition | If true | If false | Never |
switch(actionType) {
case OBJECT_CREATED:
int objectType = reader->ReadDWord();
auto factory = creatorManager->FindObjectFactory(objectType);
auto newInstance = factory->CreateInstance(reader); // parse parameters
objects.push_back(newInstance);
break;
case OBJECT_DELETED:
int objectId = reader->ReadDWord();
sceneManager->removeObjectById(objectId);
...
}
It is better to be wrong on time than right but late
You are not prepared!