Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum EntityType {
- Player;
- Hagrid;
- }
- class Entity {
- public var position: FastVector3 = new FastVector3();
- public var type: EntityType;
- public function new(type: EntityType, x: Float, y: Float, z: Float) {
- this.type = type;
- this.position.x = x;
- this.position.y = y;
- this.position.z = z;
- }
- }
- class Player extends Entity {
- public var playerVar: Bool;
- public function new(type: EntityType, playerVar: Bool) {
- super(type, 0.0, 0.0, 0.0);
- this.playerVar = playerVar;
- }
- public function attack() {
- trace("Player attac!");
- }
- }
- class Hagrid extends Entity {
- public var text: String;
- public function new(type: EntityType, text: String) {
- super(type, 0.0, 0.0, 0.0);
- this.text = text;
- }
- public function attack() {
- trace("Hagrid slapped you with his dustbin lid sized hand.");
- }
- public function battleCry() {
- trace(text);
- }
- }
- // in some other class:
- public function new() {
- var e1: Entity = new Player(EntityType.Player, true);
- var e2: Entity = new Hagrid(EntityType.Hagrid, "Yer're wizard Harry!");
- var entities:Array<Entity> = [e1, e2];
- for (e in entities) {
- switch (e.type) {
- case EntityType.Player: {
- var e = cast(e, Player);
- e.attack();
- trace(e.playerVar);
- }
- case EntityType.Hagrid: {
- var e = cast(e, Hagrid);
- e.attack();
- e.battleCry();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement